Commit fc7da8e2 by yangyang

统计加时间查询、答题时间时分秒记录提交

parent e0c8a682
...@@ -58,24 +58,24 @@ public class ScoreController { ...@@ -58,24 +58,24 @@ public class ScoreController {
} }
// 单位统计 // 单位统计
@GetMapping("/scoreDwTj") @GetMapping("/scoreDwTj/{kssj}/{jssj}")
public ApiResult findTjDw() { public ApiResult findTjDw(@PathVariable("kssj") String kssj,@PathVariable("jssj") String jssj) {
List<DwScoreTj> listResult = scoreService.findTjDw(); List<DwScoreTj> listResult = scoreService.findTjDw(kssj,jssj);
return ApiResultHandler.buildApiResult(200, "根据统计成绩", listResult); return ApiResultHandler.buildApiResult(200, "根据统计成绩", listResult);
} }
// 单位统计透视 // 单位统计透视
@GetMapping("/scoreDwTsTj/{page}/{size}/{clazz}") @GetMapping("/scoreDwTsTj/{page}/{size}/{clazz}/{kssj}/{jssj}")
public ApiResult findTjTsDw(@PathVariable("page") Integer page, @PathVariable("size") Integer size,@PathVariable("clazz") String clazz) { public ApiResult findTjTsDw(@PathVariable("page") Integer page, @PathVariable("size") Integer size,@PathVariable("clazz") String clazz,@PathVariable("kssj") String kssj,@PathVariable("jssj") String jssj) {
Page<StudentScoreTj> scorePage = new Page<>(page, size); Page<StudentScoreTj> scorePage = new Page<>(page, size);
IPage<StudentScoreTj> listResult = scoreService.findTjTsDw(scorePage, clazz); IPage<StudentScoreTj> listResult = scoreService.findTjTsDw(scorePage, clazz,kssj,jssj);
return ApiResultHandler.buildApiResult(200, "根据单位查询每个人统计成绩", listResult); return ApiResultHandler.buildApiResult(200, "根据单位查询每个人统计成绩", listResult);
} }
// 全部人员统计导出 // 全部人员统计导出
@GetMapping("/listAllStudentScoreTj/{clazz}") @GetMapping("/listAllStudentScoreTj/{clazz}/{kssj}/{jssj}")
public void listAllStudentScoreTj(@PathVariable("clazz") String clazz, HttpServletResponse response)throws Exception { public void listAllStudentScoreTj(@PathVariable("clazz") String clazz,@PathVariable("kssj") String kssj,@PathVariable("jssj") String jssj, HttpServletResponse response)throws Exception {
List<StudentScoreTj> list = scoreService.listAllStudentScoreTj(clazz); List<StudentScoreTj> list = scoreService.listAllStudentScoreTj(clazz,kssj,jssj);
ExportExcelUtil<StudentScoreTj> exportExcelUtil = new ExportExcelUtil<>(); ExportExcelUtil<StudentScoreTj> exportExcelUtil = new ExportExcelUtil<>();
String[] headersName = {"ip","姓名","答题次数","答题量","答题正确率","总成绩","单位"}; String[] headersName = {"ip","姓名","答题次数","答题量","答题正确率","总成绩","单位"};
String[] headersField = {"studentId","studentName","count","dtcount","right","countsum","clazz"}; String[] headersField = {"studentId","studentName","count","dtcount","right","countsum","clazz"};
......
...@@ -23,7 +23,7 @@ public interface ScoreMapper { ...@@ -23,7 +23,7 @@ public interface ScoreMapper {
List<Score> findAll(); List<Score> findAll();
// 分页 // 分页
@Select("select scoreId,examCode,studentId,subject,ptScore,etScore,score,answerDate from score where studentId = #{studentId} order by scoreId desc") @Select("select scoreId,examCode,studentId,subject,ptScore,etScore,score,answerDate from score where studentId = #{studentId} order by answerDate desc")
IPage<Score> findById(Page<?> page,@Param("studentId") String studentId); IPage<Score> findById(Page<?> page,@Param("studentId") String studentId);
// 不分页 // 不分页
...@@ -42,20 +42,42 @@ public interface ScoreMapper { ...@@ -42,20 +42,42 @@ public interface ScoreMapper {
StudentScoreTj findTjById(String studentId); StudentScoreTj findTjById(String studentId);
// 单位统计 // 单位统计
@Select("select clazz,count(s.studentId) as count,IFNULL(sum(etScore),0) as countsum,count(distinct s.studentId) as rycount from student t left join score s on s.studentId = t.studentId GROUP BY clazz") @Select("<script> select clazz,count(s.studentId) as count,IFNULL(sum(etScore),0) as countsum,count(distinct s.studentId) as rycount from student t left join score s on s.studentId = t.studentId where 1=1"
List<DwScoreTj> findTjDw(); +"<if test='kssj != \"null\"'>"
+" and s.answerDate <![CDATA[>=]]> #{kssj}"
+ "</if>"
+"<if test='jssj != \"null\"'>"
+" and s.answerDate <![CDATA[<=]]> #{jssj}"
+ "</if>"
+" GROUP BY clazz"
+"</script>")
List<DwScoreTj> findTjDw(@Param("kssj") String kssj,@Param("jssj")String jssj);
// 单位统计数据透视 // 单位统计数据透视
@Select("select t.studentId,t.studentName,count(s.studentId) as count,IFNULL(sum(etScore),0) as countsum from student t left join score s on s.studentId = t.studentId where t.clazz=#{clazz} GROUP BY t.studentId order by sum(etScore) desc") @Select("<script> select t.studentId,t.studentName,count(s.studentId) as count,IFNULL(sum(etScore),0) as countsum from student t left join score s on s.studentId = t.studentId where t.clazz=#{clazz}"
IPage<StudentScoreTj> findTjTsDw(Page<?> page,@Param("clazz") String clazz); +"<if test='kssj != \"null\"'>"
+" and s.answerDate <![CDATA[>=]]> #{kssj}"
+ "</if>"
+"<if test='jssj != \"null\"'>"
+" and s.answerDate <![CDATA[<=]]> #{jssj}"
+ "</if>"
+" GROUP BY t.studentId order by sum(etScore) desc"
+"</script>")
IPage<StudentScoreTj> findTjTsDw(Page<?> page,@Param("clazz") String clazz,@Param("kssj") String kssj,@Param("jssj")String jssj);
// 全部人员数据 // 全部人员数据
@Select("<script> select t.studentId,t.studentName,t.clazz as clazz,count(s.studentId) as count,IFNULL(sum(etScore),0) as countsum from student t left join score s on s.studentId = t.studentId" @Select("<script> select t.studentId,t.studentName,t.clazz as clazz,count(s.studentId) as count,IFNULL(sum(etScore),0) as countsum from student t left join score s on s.studentId = t.studentId where 1=1"
+"<if test='clazz != \"null\"'>" +"<if test='clazz != \"null\"'>"
+"where t.clazz=#{clazz}" +" and t.clazz=#{clazz}"
+ "</if>"
+"<if test='kssj != \"null\"'>"
+" and s.answerDate <![CDATA[>=]]> #{kssj}"
+ "</if>"
+"<if test='jssj != \"null\"'>"
+" and s.answerDate <![CDATA[<=]]> #{jssj}"
+ "</if>" + "</if>"
+"GROUP BY t.studentId order by sum(etScore) desc" +" GROUP BY t.studentId order by sum(etScore) desc"
+"</script>") +"</script>")
List<StudentScoreTj> listAllStudentScoreTj(@Param("clazz") String clazz); List<StudentScoreTj> listAllStudentScoreTj(@Param("clazz") String clazz,@Param("kssj") String kssj,@Param("jssj")String jssj);
} }
...@@ -6,6 +6,7 @@ import com.exam.entity.DwScoreTj; ...@@ -6,6 +6,7 @@ import com.exam.entity.DwScoreTj;
import com.exam.entity.Score; import com.exam.entity.Score;
import com.exam.entity.StudentScoreTj; import com.exam.entity.StudentScoreTj;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.List; import java.util.List;
...@@ -22,9 +23,9 @@ public interface ScoreService { ...@@ -22,9 +23,9 @@ public interface ScoreService {
StudentScoreTj findTjById(String studentId); StudentScoreTj findTjById(String studentId);
List<DwScoreTj> findTjDw(); List<DwScoreTj> findTjDw(String kssj,String jssj);
IPage<StudentScoreTj> findTjTsDw(Page<StudentScoreTj> page,String clazz); IPage<StudentScoreTj> findTjTsDw(Page<StudentScoreTj> page,String clazz,String kssj,String jssj);
List<StudentScoreTj> listAllStudentScoreTj(@Param("clazz") String clazz); List<StudentScoreTj> listAllStudentScoreTj(@Param("clazz") String clazz,String kssj,String jssj);
} }
...@@ -12,10 +12,12 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -12,10 +12,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import java.io.IOException; import java.io.IOException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionException;
...@@ -32,6 +34,8 @@ public class ScoreServiceImpl implements ScoreService { ...@@ -32,6 +34,8 @@ public class ScoreServiceImpl implements ScoreService {
private ThreadPoolTaskExecutor threadPoolTaskExecutor; private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Override @Override
public int add(Score score) { public int add(Score score) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
score.setAnswerDate(sdf.format(new Date()));
return scoreMapper.add(score); return scoreMapper.add(score);
} }
...@@ -72,10 +76,10 @@ public class ScoreServiceImpl implements ScoreService { ...@@ -72,10 +76,10 @@ public class ScoreServiceImpl implements ScoreService {
} }
@Override @Override
public List<DwScoreTj> findTjDw() { public List<DwScoreTj> findTjDw(String kssj,String jssj) {
// 管理员:单位,答题人数,答题次数,答题正确率,总成绩 // 管理员:单位,答题人数,答题次数,答题正确率,总成绩
percentInstance.setMinimumFractionDigits(2); percentInstance.setMinimumFractionDigits(2);
List<DwScoreTj> findTjDw = scoreMapper.findTjDw(); List<DwScoreTj> findTjDw = scoreMapper.findTjDw(kssj,jssj);
findTjDw.stream().forEach(p->{ findTjDw.stream().forEach(p->{
int dtcount = 0; int dtcount = 0;
String right = "0%"; String right = "0%";
...@@ -91,9 +95,9 @@ public class ScoreServiceImpl implements ScoreService { ...@@ -91,9 +95,9 @@ public class ScoreServiceImpl implements ScoreService {
} }
@Override @Override
public IPage<StudentScoreTj> findTjTsDw(Page<StudentScoreTj> page,String clazz) { public IPage<StudentScoreTj> findTjTsDw(Page<StudentScoreTj> page,String clazz,String kssj,String jssj) {
percentInstance.setMinimumFractionDigits(2); percentInstance.setMinimumFractionDigits(2);
IPage<StudentScoreTj> listPage = scoreMapper.findTjTsDw(page,clazz); IPage<StudentScoreTj> listPage = scoreMapper.findTjTsDw(page,clazz,kssj, jssj);
listPage.getRecords().stream().forEach(p->{ listPage.getRecords().stream().forEach(p->{
int dtcount = 0; int dtcount = 0;
String right = "0%"; String right = "0%";
...@@ -108,9 +112,9 @@ public class ScoreServiceImpl implements ScoreService { ...@@ -108,9 +112,9 @@ public class ScoreServiceImpl implements ScoreService {
} }
@Override @Override
public List<StudentScoreTj> listAllStudentScoreTj(String clazz) { public List<StudentScoreTj> listAllStudentScoreTj(String clazz,String kssj,String jssj) {
percentInstance.setMinimumFractionDigits(2); percentInstance.setMinimumFractionDigits(2);
List<StudentScoreTj> list = scoreMapper.listAllStudentScoreTj(clazz); List<StudentScoreTj> list = scoreMapper.listAllStudentScoreTj(clazz,kssj,jssj);
// 存储结果集 // 存储结果集
List<CompletableFuture<?>> futures = new ArrayList<>(); List<CompletableFuture<?>> futures = new ArrayList<>();
for(StudentScoreTj p:list) { for(StudentScoreTj p:list) {
...@@ -135,6 +139,17 @@ public class ScoreServiceImpl implements ScoreService { ...@@ -135,6 +139,17 @@ public class ScoreServiceImpl implements ScoreService {
} }
// 等待全部完成 // 等待全部完成
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
// 总成绩/答题量 用户分数总和计算
int sumScore = list.stream().mapToInt(e->Integer.parseInt(e.getCountsum().toString())).sum();
int dtcount = list.stream().mapToInt(e->Integer.parseInt(e.getCount().toString())).sum();
String right = "0%";
if(dtcount!=0){
right = percentInstance.format((double) (sumScore)/(dtcount));
}
StudentScoreTj studentScoreTjAll = new StudentScoreTj();
studentScoreTjAll.setRight(right);
studentScoreTjAll.setCountsum(sumScore);
list.add(studentScoreTjAll);
return list; return list;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment