Przeglądaj źródła

美术阅卷10月新增需求-分档比例BUG修复

wangliang 5 lat temu
rodzic
commit
8bb1a25860

+ 12 - 12
stmms-ms-core/src/main/java/cn/com/qmth/stmms/ms/core/repository/MarkTaskRepo.java

@@ -112,21 +112,21 @@ public interface MarkTaskRepo extends JpaRepository<MarkTask, Long>, JpaSpecific
     List<Object[]> countGroupByLevel(Long markerId);
 
 
-    //    @Query(value = "SELECT COUNT(*) FROM mark_task t " +
-//            "WHERE t.`marker_id` = ? and t.stage = 1 and t.result = ? ", nativeQuery = true)
-//    int countByLevelAndResult(Long markerId, String result);
-    //2019.10.16修改为所有老师的评卷
     @Query(value = "SELECT COUNT(*) FROM mark_task t " +
-            "WHERE t.`question_id` in (?) and t.stage = 1 and t.result = ? ", nativeQuery = true)
-    int countByLevelAndResult(Long questionId, String result);
-
-    //    @Query(value = "SELECT COUNT(*) FROM mark_task t " +
-//            "WHERE t.`marker_id` = ? and t.stage = 1 and t.result is null", nativeQuery = true)
-//    int countByLevel(Long markerId);
+            "WHERE t.`marker_id` = ? and t.stage = 1 and t.result = ? ", nativeQuery = true)
+    int countByLevelAndResult(Long markerId, String result);
     //2019.10.16修改为所有老师的评卷
+//    @Query(value = "SELECT COUNT(*) FROM mark_task t " +
+//            "WHERE t.`question_id` in (?) and t.stage = 1 and t.result = ? ", nativeQuery = true)
+//    int countByLevelAndResult(Long questionId, String result);
+
     @Query(value = "SELECT COUNT(*) FROM mark_task t " +
-            "WHERE t.`question_id` in (?) and t.stage = 1 and t.result is null", nativeQuery = true)
-    int countByLevel(Long questionId);
+            "WHERE t.`marker_id` = ? and t.stage = 1 and t.result is null", nativeQuery = true)
+    int countByLevel(Long markerId);
+    //2019.10.16修改为所有老师的评卷
+//    @Query(value = "SELECT COUNT(*) FROM mark_task t " +
+//            "WHERE t.`question_id` in (?) and t.stage = 1 and t.result is null", nativeQuery = true)
+//    int countByLevel(Long questionId);
 
     int countByQuestionIdInAndStageAndResult(List<Long> questionIds, MarkStage stage, String result);
 

+ 14 - 0
stmms-ms-core/src/main/java/cn/com/qmth/stmms/ms/core/repository/PaperRepo.java

@@ -63,6 +63,20 @@ public interface PaperRepo extends JpaRepository<Paper, Long>, JpaSpecificationE
             "GROUP BY p.`level` ORDER BY p.`level`", nativeQuery = true)
     List<Object[]> countGroupByLevel(Long questionId);
 
+    /**
+     * 统计workId各档位数量
+     *
+     * @param workId
+     * @return
+     */
+    @Query(value = "SELECT p.`level`,COUNT(*)," +
+            "SUM(IF(p.`is_rejected` = 1, 1, 0))," +
+            "SUM(IF(p.`is_arbitrated` = 1, 1, 0))" +
+            "FROM paper p " +
+            "WHERE p.`work_id` = ? " +
+            "GROUP BY p.`level` ORDER BY p.`level`", nativeQuery = true)
+    List<Object[]> countGroupByLevelAndWorkId(Long workId);
+
     /**
      * 统计科目各试题已评数及总数(打分阶段)
      *

+ 122 - 47
stmms-ms-marking/src/main/java/cn/com/qmth/stmms/ms/marking/api/MakrerApi.java

@@ -1,7 +1,6 @@
 package cn.com.qmth.stmms.ms.marking.api;
 
 import cn.com.qmth.stmms.ms.commons.utils.SqlUtil;
-import cn.com.qmth.stmms.ms.core.domain.ExamQuestion;
 import cn.com.qmth.stmms.ms.core.domain.Level;
 import cn.com.qmth.stmms.ms.core.domain.MarkStage;
 import cn.com.qmth.stmms.ms.core.domain.MarkSubject;
@@ -106,55 +105,126 @@ public class MakrerApi {
      */
     @RequestMapping(value = "{marker}/stat/levels", method = RequestMethod.GET)
     public List<LevelStatDTO> levelStats(@PathVariable MarkUser marker, @RequestParam Long questionId) throws Exception {
-        List<LevelStatDTO> levelStatDTOs = new ArrayList<>();
+//        List<LevelStatDTO> levelStatDTOs = new ArrayList<>();
 //        markTaskRepo.countGroupByLevel(marker.getId())
 //                .forEach(o -> {
 //                    levelStatAssembler.toDTO(o);
 //                    levelStatDTOs.add();
 //                });
-        ExamQuestion examQuestion = examQuestionRepo.findOne(questionId);
-        if (Objects.isNull(examQuestion)) {
-            throw new Exception("当前考试试卷为空");
-        }
-        //获取当前考试当前科目所在地区的所有questionId
-        List<ExamQuestion> examQuestionList = examQuestionRepo.findAllByAreaCodeAndSubjectAndWorkId(examQuestion.getAreaCode(), examQuestion.getSubject(), examQuestion.getWorkId());
-        List<Long> questionIds = examQuestionList.stream()
-                .map(m -> m.getId())
-                .collect(Collectors.toList());
-        StringBuilder startSql = new StringBuilder("select t.`result`,sum(if(t.questionId <> t.currentQuesId, 0, t.sumCount)) as sumCount from(SELECT t.result,COUNT(*) as sumCount,t.question_id as questionId,? as currentQuesId FROM mark_task t WHERE t.`question_id` in ( ");
-        String endSql = " ) and t.stage = 1 GROUP BY t.`result`,t.question_id ORDER BY t.result) t group by t.`result` ";
-        questionIds.forEach(o -> startSql.append(o).append(","));
-        //当前老师当前试卷的评档次数
-        StringBuilder sql = new StringBuilder(startSql.toString().substring(0, startSql.toString().length() - 1));
-        sql.append(endSql);
-        String finalSql = sqlUtil.sqlPrint(sql.toString(), questionId);
-        List list = sqlUtil.execSqlForMap(finalSql);
+//        ExamQuestion examQuestion = examQuestionRepo.findOne(questionId);
+//        if (Objects.isNull(examQuestion)) {
+//            throw new Exception("当前考试试卷为空");
+//        }
+//        //获取当前考试当前科目所在地区的所有questionId
+//        List<ExamQuestion> examQuestionList = examQuestionRepo.findAllByAreaCodeAndSubjectAndWorkId(examQuestion.getAreaCode(), examQuestion.getSubject(), examQuestion.getWorkId());
+//        List<Long> questionIds = examQuestionList.stream()
+//                .map(m -> m.getId())
+//                .collect(Collectors.toList());
+//        StringBuilder startSql = new StringBuilder("select t.`result`,sum(if(t.questionId <> t.currentQuesId, 0, t.sumCount)) as sumCount from(SELECT t.result,COUNT(*) as sumCount,t.question_id as questionId,? as currentQuesId FROM mark_task t WHERE t.`question_id` in ( ");
+//        String endSql = " ) and t.stage = 1 GROUP BY t.`result`,t.question_id ORDER BY t.result) t group by t.`result` ";
+//        questionIds.forEach(o -> startSql.append(o).append(","));
+//        //当前老师当前试卷的评档次数
+//        StringBuilder sql = new StringBuilder(startSql.toString().substring(0, startSql.toString().length() - 1));
+//        sql.append(endSql);
+//        String finalSql = sqlUtil.sqlPrint(sql.toString(), questionId);
+//        List list = sqlUtil.execSqlForMap(finalSql);
+//        MarkSubject markSubject = markSubjectRepo.findOne(marker.getWorkId() + "-" + marker.getSubject().toString());
+//        List<Level> levels = levelRepo.findByWorkId(markSubject.getWorkId());
+//        Map<String, Level> levelMap = levels.stream().collect(Collectors.toMap(Level::getCode, l -> l));
+////        Map<String, LevelStatDTO> filterLevelMap = new HashMap<>();
+//        for (int i = 0; i < list.size(); i++) {
+//            Map map = (Map) list.get(i);
+//            List finalList = (List) map.values().stream()
+//                    .collect(Collectors.toList());
+//            Object[] o = finalList.toArray();
+//            LevelStatDTO levelStatDTO = levelStatAssembler.toDTO(o);
+//            if (levelStatDTO.getId() == null) {
+//                //当前老师未评档的次数
+////              int gcount = markTaskRepo.countByLevel(marker.getId());
+//                int gcount = markTaskRepo.countByQuestionIdInAndStageAndResultIsNull(questionIds, MarkStage.LEVEL);
+//                levelStatDTO.setGcount(gcount);
+//                levelStatDTOs.add(levelStatDTO);
+//            } else {
+//                //当前老师每个档位已评档位的次数
+////              int gcount = markTaskRepo.countByLevelAndResult(marker.getId(), levelStatDTO.getId().toString());
+//                int gcount = markTaskRepo.countByQuestionIdInAndStageAndResult(questionIds, MarkStage.LEVEL, levelStatDTO.getId().toString());
+//                levelStatDTO.setGcount(gcount);
+//            }
+//            if (Objects.nonNull(levelMap.get(levelStatDTO.getId()))) {
+//                levelStatDTOs.add(levelStatDTO);
+//            }
+//        }
+//        for (Level level : levels) {
+//            //所有档位依次比较
+//            long count = levelStatDTOs.stream().filter(l -> String.valueOf(l.getId()).equals(level.getCode())).count();
+//            if (count == 0) {
+//                LevelStatDTO dto = new LevelStatDTO();
+//                dto.setId(level.getCode());
+//                dto.setCount(0);
+//                dto.setPercent(0.0);
+//
+//                //当前老师当前档位评档次数(所有考试)
+////                int gcount = markTaskRepo.countByLevelAndResult(marker.getId(), level.getCode());
+//                int gcount = markTaskRepo.countByQuestionIdInAndStageAndResult(questionIds, MarkStage.LEVEL, level.getCode());
+//                dto.setGcount(gcount);
+//                levelStatDTOs.add(dto);
+//            }
+//        }
+//
+//        //当前老师当前试卷的评档次数(不分档位)
+////        long kdtotal = markTaskRepo.countByMarkerIdAndQuestionId(marker.getId(), questionId);
+//        long kdtotal = markTaskRepo.countByQuestionIdIn(questionIds);
+//        //当前老师所有的评档次数(不分档位)
+//        long total = markTaskRepo.countByMarkerId(marker.getId());
+////        long total = markTaskRepo.countByQuestionId(questionId);
+//
+//        levelStatDTOs.forEach(o -> {
+//            if (o.getId() != null) {
+//                o.setPt(levelMap.get(o.getId()).getPt());
+//                o.setKdpt(levelMap.get(o.getId()).getKdpt());
+//                double p = (double) o.getCount() / total;
+//                BigDecimal bd = new BigDecimal(p).setScale(3, RoundingMode.HALF_EVEN);
+//                o.setPercent(bd.doubleValue());
+//
+//                double gp = (double) o.getGcount() / kdtotal;
+//                BigDecimal gbd = new BigDecimal(gp).setScale(3, RoundingMode.HALF_EVEN);
+//                o.setGpercent(gbd.doubleValue());
+//            }
+//        });
+//        return levelStatDTOs;
+        List<LevelStatDTO> levelStatDTOs = new ArrayList<>();
+//        ExamQuestion examQuestion = examQuestionRepo.findOne(questionId);
+//        if (Objects.isNull(examQuestion)) {
+//            throw new Exception("当前考试试卷为空");
+//        }
         MarkSubject markSubject = markSubjectRepo.findOne(marker.getWorkId() + "-" + marker.getSubject().toString());
         List<Level> levels = levelRepo.findByWorkId(markSubject.getWorkId());
         Map<String, Level> levelMap = levels.stream().collect(Collectors.toMap(Level::getCode, l -> l));
-//        Map<String, LevelStatDTO> filterLevelMap = new HashMap<>();
-        for (int i = 0; i < list.size(); i++) {
-            Map map = (Map) list.get(i);
-            List finalList = (List) map.values().stream()
-                    .collect(Collectors.toList());
-            Object[] o = finalList.toArray();
-            LevelStatDTO levelStatDTO = levelStatAssembler.toDTO(o);
-            if (levelStatDTO.getId() == null) {
-                //当前老师未评档的次数
-//              int gcount = markTaskRepo.countByLevel(marker.getId());
-                int gcount = markTaskRepo.countByQuestionIdInAndStageAndResultIsNull(questionIds, MarkStage.LEVEL);
-                levelStatDTO.setGcount(gcount);
-                levelStatDTOs.add(levelStatDTO);
-            } else {
-                //当前老师每个档位已评档位的次数
-//              int gcount = markTaskRepo.countByLevelAndResult(marker.getId(), levelStatDTO.getId().toString());
-                int gcount = markTaskRepo.countByQuestionIdInAndStageAndResult(questionIds, MarkStage.LEVEL, levelStatDTO.getId().toString());
-                levelStatDTO.setGcount(gcount);
-            }
-            if (Objects.nonNull(levelMap.get(levelStatDTO.getId()))) {
-                levelStatDTOs.add(levelStatDTO);
-            }
-        }
+        //统计workId下各考点的数量
+        paperRepo.countGroupByLevel(questionId)
+                .forEach(o -> {
+//                    levelStatDTOs.add(levelStatAssembler.toDTO(o));
+                    LevelStatDTO levelStatDTO = levelStatAssembler.toDTO(o);
+                    if (Objects.isNull(levelStatDTO.getId())) {
+                        int gcount = markTaskRepo.countByLevel(marker.getId());
+                        levelStatDTO.setGcount(gcount);
+                        levelStatDTOs.add(levelStatDTO);
+                    } else {
+                        int gcount = markTaskRepo.countByLevelAndResult(marker.getId(), levelStatDTO.getId().toString());
+                        levelStatDTO.setGcount(gcount);
+                    }
+                    if (Objects.nonNull(levelMap.get(levelStatDTO.getId()))) {
+                        levelStatDTOs.add(levelStatDTO);
+                    }
+//                    if (levelStatDTO.getId() == null) {
+//                        //当前老师未评档的次数
+//                        //              int gcount = markTaskRepo.countByLevel(marker.getId());
+//                        int gcount = markTaskRepo.countByQuestionIdInAndStageAndResultIsNull(questionIds, MarkStage.LEVEL);
+//                        levelStatDTO.setGcount(gcount);
+//                        levelStatDTOs.add(levelStatDTO);
+//                    }
+                });
+
         for (Level level : levels) {
             //所有档位依次比较
             long count = levelStatDTOs.stream().filter(l -> String.valueOf(l.getId()).equals(level.getCode())).count();
@@ -165,28 +235,30 @@ public class MakrerApi {
                 dto.setPercent(0.0);
 
                 //当前老师当前档位评档次数(所有考试)
-//                int gcount = markTaskRepo.countByLevelAndResult(marker.getId(), level.getCode());
-                int gcount = markTaskRepo.countByQuestionIdInAndStageAndResult(questionIds, MarkStage.LEVEL, level.getCode());
+                int gcount = markTaskRepo.countByLevelAndResult(marker.getId(), level.getCode());
+//                int gcount = markTaskRepo.countByQuestionIdInAndStageAndResult(questionIds, MarkStage.LEVEL, level.getCode());
                 dto.setGcount(gcount);
                 levelStatDTOs.add(dto);
             }
         }
 
         //当前老师当前试卷的评档次数(不分档位)
-//        long kdtotal = markTaskRepo.countByMarkerIdAndQuestionId(marker.getId(), questionId);
-        long kdtotal = markTaskRepo.countByQuestionIdIn(questionIds);
+        long kdtotal = markTaskRepo.countByMarkerIdAndQuestionId(marker.getId(), questionId);
+//        long kdtotal = markTaskRepo.countByQuestionIdIn(questionIds);
         //当前老师所有的评档次数(不分档位)
-        long total = markTaskRepo.countByMarkerId(marker.getId());
+        long total = paperRepo.countByWorkIdAndQuestionId(markSubject.getWorkId(), questionId);
 //        long total = markTaskRepo.countByQuestionId(questionId);
 
         levelStatDTOs.forEach(o -> {
             if (o.getId() != null) {
                 o.setPt(levelMap.get(o.getId()).getPt());
                 o.setKdpt(levelMap.get(o.getId()).getKdpt());
+                o.setCount(Objects.isNull(o.getCount()) ? 0 : o.getCount());
                 double p = (double) o.getCount() / total;
                 BigDecimal bd = new BigDecimal(p).setScale(3, RoundingMode.HALF_EVEN);
                 o.setPercent(bd.doubleValue());
 
+                o.setGcount(Objects.isNull(o.getGcount()) ? 0 : o.getGcount());
                 double gp = (double) o.getGcount() / kdtotal;
                 BigDecimal gbd = new BigDecimal(gp).setScale(3, RoundingMode.HALF_EVEN);
                 o.setGpercent(gbd.doubleValue());
@@ -195,6 +267,9 @@ public class MakrerApi {
         return levelStatDTOs;
     }
 
+    @Autowired
+    private PaperRepo paperRepo;
+
     /**
      * 各试题统计数据
      *