Browse Source

线下版本-分档、打分优化-20201122

xiaof 4 years ago
parent
commit
25fdc9e794

+ 1 - 1
stmms-ms-collect/src/main/java/cn/com/qmth/stmms/ms/collect/api/CollectApi.java

@@ -1057,7 +1057,7 @@ public class CollectApi {
         try {
             //首先根据workId和阶段去查所有试卷
             StringBuffer sql = new StringBuffer();
-            sql.append("SELECT s.id studentId, p.work_id workId, p.subject, p.area_code areaCode, p.exam_number examNumber FROM paper p LEFT JOIN student s ON p.work_id = s.work_id AND p.exam_number = s.exam_number WHERE p.score is not null and p.work_id = ").append(workId).append(" AND p.subject = '").append(subject).append("'");
+            sql.append("SELECT s.id studentId, p.work_id workId, p.subject, p.area_code areaCode, p.exam_number examNumber FROM paper p LEFT JOIN student s ON p.work_id = s.work_id AND p.exam_number = s.exam_number WHERE p.work_id = ").append(workId).append(" AND p.subject = '").append(subject).append("'");
             if (areaId != null) {
                 sql.append(" and p.area_code = ").append(areaId);
             }

+ 31 - 6
stmms-ms-collect/src/main/java/cn/com/qmth/stmms/ms/collect/util/RotateTask.java

@@ -72,6 +72,7 @@ public class RotateTask implements Runnable {
                             + File.separator + paper.getAreaCode() + File.separator + imageMd5;
 
                     //缩略图旋转生成
+                    LOGGER.info("加密-生成缩略图:原文件名{},读取原始文件开始", imageMd5);
                     String thumbOldPath = thumbPath + ".jpg";
                     String thumbTempPath = thumbPath + "temp.jpg";
                     File thumbOldFile = new File(thumbOldPath);
@@ -83,11 +84,22 @@ public class RotateTask implements Runnable {
                     is.close();
                     outputStream.flush();
                     outputStream.close();
+                    LOGGER.info("加密-生成缩略图:原文件名{},读取原始文件结束,temp图片是否存在:{}", imageMd5, thumbTempFile.exists());
 
                     //原图旋转
-                    ImageCompression.rotate(thumbTempFile, thumbTempFile, degree);
-                    thumbOldFile.renameTo(new File(thumbNew + "_" + start + ".jpg"));
-                    thumbTempFile.renameTo(new File(thumbOldPath));
+                    try {
+                        ImageCompression.rotate(thumbTempFile, thumbTempFile, degree);
+                    } catch (IOException e) {
+                        LOGGER.info("加密-生成缩略图:原文件名{},旋转失败,错误原因:{}", imageMd5, e.getMessage());
+                    }
+                    LOGGER.info("加密-生成缩略图:原文件名{},重命名开始", imageMd5);
+                    File thumbFileNew = new File(thumbNew + "_" + start + ".jpg");
+                    thumbFileNew.delete();
+                    thumbOldFile.renameTo(thumbFileNew);
+                    thumbOldFile.delete();
+                    thumbTempFile.renameTo(thumbOldFile);
+                    LOGGER.info("加密-生成缩略图:原文件名{},重命名结束", imageMd5);
+
                     //加密旋转图
                     InputStream is1 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(thumbOldFile));
                     OutputStream outputStream1 = new FileOutputStream(thumbOldFile);
@@ -95,8 +107,10 @@ public class RotateTask implements Runnable {
                     is1.close();
                     outputStream1.flush();
                     outputStream1.close();
+                    LOGGER.info("加密-生成缩略图:原文件名{},加密旋转图结束", imageMd5);
 
                     //裁切原图旋转生成
+                    LOGGER.info("加密-生成裁切图:原文件名{},读取原始文件开始", imageMd5);
                     String imageOldPath = imagePath + ".jpg";
                     String imageTempPath = imagePath + "temp.jpg";
                     File imageOldFile = new File(imageOldPath);
@@ -108,11 +122,21 @@ public class RotateTask implements Runnable {
                     is2.close();
                     outputStream2.flush();
                     outputStream2.close();
+                    LOGGER.info("加密-生成裁切图:原文件名{},读取原始文件结束,temp图片是否存在:{}", imageMd5, imageTempFile.exists());
 
                     //原图旋转
-                    ImageCompression.rotate(imageTempFile, imageTempFile, degree);
-                    imageOldFile.renameTo(new File(imageNew + "_" + start + ".jpg"));
-                    imageTempFile.renameTo(new File(imageOldPath));
+                    try {
+                        ImageCompression.rotate(imageTempFile, imageTempFile, degree);
+                    } catch (IOException e) {
+                        LOGGER.info("加密-生成裁切图:原文件名{},旋转失败,错误原因:{}", imageMd5, e.getMessage());
+                    }
+                    LOGGER.info("加密-生成裁切图:原文件名{},重命名开始", imageMd5);
+                    File imageFileNew = new File(imageNew + "_" + start + ".jpg");
+                    imageFileNew.delete();
+                    imageOldFile.renameTo(imageFileNew);
+                    imageOldFile.delete();
+                    imageTempFile.renameTo(imageOldFile);
+                    LOGGER.info("加密-生成裁切图:原文件名{},重命名结束", imageMd5);
                     //加密旋转图
                     InputStream is3 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(imageOldFile));
                     OutputStream outputStream3 = new FileOutputStream(imageOldFile);
@@ -120,6 +144,7 @@ public class RotateTask implements Runnable {
                     is3.close();
                     outputStream3.flush();
                     outputStream3.close();
+                    LOGGER.info("加密-生成裁切图:原文件名{},加密旋转图结束", imageMd5);
 
                     InputStream is4 = new FileInputStream(imageOldFile);
                     sliceMD5 = DigestUtils.md5Hex(is4);

+ 1 - 4
stmms-ms-core/src/main/java/cn/com/qmth/stmms/ms/core/domain/Paper.java

@@ -13,10 +13,7 @@ import java.util.Date;
  */
 @Entity
 @Table(indexes = {
-        @Index(name = "idx_paper_index", columnList = "idx"),
-        @Index(name = "idx_paper_exam_number", columnList = "examNumber"),
-        @Index(name = "idx_paper_area_code", columnList = "areaCode"),
-        @Index(name = "idx_paper_student_name", columnList = "studentName")})
+        @Index(name = "idx_paper_exam_number", columnList = "examNumber")})
 public class Paper implements Serializable {
 
     private static final long serialVersionUID = 3200579901138269179L;

+ 13 - 0
stmms-ms-core/src/main/java/cn/com/qmth/stmms/ms/core/domain/task/MarkTask.java

@@ -95,6 +95,9 @@ public class MarkTask implements Serializable {
 
     private Integer displayNumber;
 
+    //是否标准卷
+    private boolean isSample;
+
     public Long getBatchNo() {
         return batchNo;
     }
@@ -160,6 +163,7 @@ public class MarkTask implements Serializable {
         this.secretNumber = marker.getId() + subject.ordinal() + paper.getAreaCode() + randomSeqNew;
         this.randomSeqNew = randomSeqNew;
         this.test = test != TrialEnum.DEFAULT.getId() ? TrialEnum.START_TRIAL.getId() : test;
+        this.isSample = paper.isSample();
     }
 
     public MarkTask(MarkUser marker, Paper paper, Level level, MarkStage stage, Long randomSeqNew, int test) {
@@ -179,6 +183,7 @@ public class MarkTask implements Serializable {
 
         this.result = paper.getLevel();
         this.level = paper.getLevel();
+        this.isSample = paper.isSample();
         this.levelValue = level.getLevelValue();
         this.updatedOn = new Date();
     }
@@ -337,4 +342,12 @@ public class MarkTask implements Serializable {
     public void setLevel(String level) {
         this.level = level;
     }
+
+    public boolean isSample() {
+        return isSample;
+    }
+
+    public void setSample(boolean sample) {
+        isSample = sample;
+    }
 }

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

@@ -38,22 +38,25 @@ public interface MarkTaskRepo extends JpaRepository<MarkTask, Long>, JpaSpecific
      */
     long countByMarkerId(Long markerId);
 
-    @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.batch_no = ?2 where m.question_id = ?1 and m.marker_id = ?3", nativeQuery = true)
+    @Query(value = "select count(1) from (select * from mark_task where question_id = ?1 and marker_id = ?3) m inner join paper p on m.paper_id = p.id and p.batch_no = ?2", nativeQuery = true)
     long countByQuestionId(Long questionId, Long batchNo, Long markerId);
 
+    @Query(value = "select count(1) from mark_task m where m.question_id = ?1 and m.marker_id = ?3 and m.batch_no = ?2", nativeQuery = true)
+    long countByQuestionIdAndBatchNo(Long questionId, Long batchNo, Long markerId);
+
     @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.score_batch_no = ?2 where m.question_id = ?1 and m.marker_id = ?3", nativeQuery = true)
     long countScoreByQuestionId(Long questionId, Long batchNo, Long markerId);
 
     @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.score_batch_no is not null where m.question_id = ?1 and m.marker_id = ?2", nativeQuery = true)
     long countScoreByQuestionIdAll(Long questionId, Long markerId);
 
-    @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result = ?4 and p.batch_no = ?5 and p.is_rejected = false", nativeQuery = true)
+    @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.batch_no = ?5 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result = ?4 and m.is_rejected = false", nativeQuery = true)
     int countByQuestionIdAndMarkerIdAndStageAndResult(Long questionId, Long markerId, int stage, String result, Long batchNo);
 
-    @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result = ?4 and p.batch_no is not null and p.is_rejected = false ", nativeQuery = true)
+    @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.batch_no is not null where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result = ?4 and m.is_rejected = false", nativeQuery = true)
     int countByQuestionIdAndMarkerIdAndStageAndResultAll(Long questionId, Long markerId, int stage, String result);
 
-    @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.level = ?4 and p.score_batch_no = ?5 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is not null", nativeQuery = true)
+    @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.score_batch_no = ?5 and p.level = ?4 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is not null", nativeQuery = true)
     int countScoreByQuestionIdAndMarkerIdAndStageAndResult(Long questionId, Long markerId, int stage, String result, Long batchNo);
 
     @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.level = ?4 and p.score_batch_no is not null where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is not null", nativeQuery = true)
@@ -170,12 +173,18 @@ public interface MarkTaskRepo extends JpaRepository<MarkTask, Long>, JpaSpecific
             "WHERE t.workId = ?1 and t.subject = ?2 and t.markerId = ?3 and t.stage = ?4 and t.questionId = ?5 ")
     Integer findRandomSeqByWorkIdAndSubjectAndMarkerIdAndStageAndQuestionId(Long workId, Subject subject, Long markerId, MarkStage stage, Long questionId);
 
-    @Query(value = "SELECT count(1) from mark_task m inner join (select id from paper where is_missing = ?4 and batch_no = ?5 and is_rejected = false) p on m.paper_id = p.id where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null", nativeQuery = true)
+    @Query(value = "SELECT count(1) from mark_task m inner join (select * from paper where batch_no = ?5 and is_missing = ?4 and is_rejected = false) p on m.paper_id = p.id where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null", nativeQuery = true)
     int countByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(Long questionId, Long markerId, int stage, boolean isMissing, Long batchNo);
 
+    @Query(value = "SELECT count(1) from mark_task m where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null and m.batch_no = ?4 and m.is_rejected = false", nativeQuery = true)
+    int countByQuestionIdAndMarkerIdAndStageAndResultNull(Long questionId, Long markerId, int stage, Long batchNo);
+
     @Query(value = "SELECT count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.is_missing = ?4 and p.score_batch_no = ?5 and p.is_shift = 0 and p.is_shift_score = 0 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null", nativeQuery = true)
     int countScoreByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(Long questionId, Long markerId, int stage, boolean isMissing, Long batchNo);
 
+    @Query(value = "SELECT count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.is_shift = 0 and p.is_shift_score = 0 and p.score_batch_no = ?4 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null", nativeQuery = true)
+    int countScoreByQuestionIdAndMarkerIdAndStageAndResultIsNull(Long questionId, Long markerId, int stage, Long batchNo);
+
     @Query(value = "SELECT count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.is_missing = ?4 and p.score_batch_no is not null where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null and p.is_shift = 0 and p.is_shift_score = 0", nativeQuery = true)
     int countScoreByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissingAll(Long questionId, Long markerId, int stage, boolean isMissing);
 
@@ -198,18 +207,27 @@ public interface MarkTaskRepo extends JpaRepository<MarkTask, Long>, JpaSpecific
     @Query(value = "SELECT count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.is_missing = ?4 and p.is_shift = 0 and p.is_shift_score = 1 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null", nativeQuery = true)
     int countShiftScoreByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(Long questionId, Long id, int ordinal, boolean b);
 
+    @Query(value = "SELECT count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.is_shift = 0 and p.is_shift_score = 1 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null", nativeQuery = true)
+    int countShiftScoreByQuestionIdAndMarkerIdAndStageAndResultIsNull(Long questionId, Long id, int ordinal);
+
     @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.batch_no is not null where m.question_id = ?1 and m.marker_id = ?2", nativeQuery = true)
     long countByQuestionIdAll(Long questionId, Long markId);
 
     @Query(value = "SELECT count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.is_missing = ?4 and p.batch_no is not null where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null and p.is_rejected = false", nativeQuery = true)
     int countByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissingAll(Long questionId, Long markerId, int stage, boolean isMissing);
 
+    @Query(value = "SELECT count(1) from mark_task m where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null and m.batch_no is not null and m.is_rejected = false", nativeQuery = true)
+    int countByQuestionIdAndMarkerIdAndStageAndResultIsNullAll(Long questionId, Long markerId, int stage);
+
     @Query(value = "SELECT count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.is_missing = ?4 and p.batch_no is not null where m.question_id = ?1 and m.marker_id = ?5 and m.stage = ?2 and m.result =?3 and p.is_rejected = false", nativeQuery = true)
     int countByQuestionIdAndStageAndResultAndIsMissingAll(Long questionId, int stage, String result, boolean isMissing,Long markerId);
 
-    @Query(value = "SELECT count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.is_missing = ?4 and p.batch_no is not null where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and p.is_rejected = true  and m.is_rejected = true", nativeQuery = true)
+    @Query(value = "SELECT count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.is_missing = ?4 and p.batch_no is not null where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and p.is_rejected = true", nativeQuery = true)
     int countByQuestionIdAndMarkerIdAndStageAndIsRejectedTrueAndIsMissing(Long questionId, Long markerId, int ordinal,boolean isMissing);
 
+    @Query(value = "SELECT count(1) from mark_task m where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and  m.batch_no is not null and m.is_rejected = true", nativeQuery = true)
+    int countByQuestionIdAndMarkerIdAndStageAndIsRejectedTrue(Long questionId, Long markerId, int ordinal);
+
     List<MarkTask> findByWorkIdAndSubjectAndMarkerIdAndStage(Long workId, Subject subject, Long valueOf, MarkStage stage);
 
     int countByWorkIdAndSubjectAndStage(Long workId, Subject subject, MarkStage stage);
@@ -232,6 +250,6 @@ public interface MarkTaskRepo extends JpaRepository<MarkTask, Long>, JpaSpecific
     List<Object[]> findAllByWorkId(Long workId);
 
     @Modifying
-    @Query("update MarkTask m set m.level = ?1 where m.paper.id = ?2")
+    @Query(value = "update mark_task m set m.level = ?1 where m.paper_id = ?2", nativeQuery = true)
     void updateLevelByPaperId(String level, Long id);
 }

+ 11 - 4
stmms-ms-core/src/main/java/cn/com/qmth/stmms/ms/core/repository/PaperRepo.java

@@ -86,11 +86,11 @@ public interface PaperRepo extends JpaRepository<Paper, Long>, JpaSpecificationE
     List<Object[]> countGroupByLevel(Long questionId, Long batchNo);
 
     @Query(value = "SELECT p.`level`,COUNT(*)," +
-            "SUM(IF(p.`is_rejected` = 1, 1, 0))," +
-            "SUM(IF(p.`is_arbitrated` = 1, 1, 0))" +
+            "SUM(p.`is_rejected`)," +
+            "SUM(p.`is_arbitrated`)" +
             "FROM paper p " +
-            "WHERE p.`question_id` = ? and p.is_missing = false and p.batch_no is not null " +
-            "GROUP BY p.`level` ORDER BY p.`level`", nativeQuery = true)
+            "WHERE p.`question_id` = ? and p.batch_no is not null " +
+            "GROUP BY p.`level`", nativeQuery = true)
     List<Object[]> countGroupByLevel(Long questionId);
 
     /**
@@ -191,6 +191,8 @@ public interface PaperRepo extends JpaRepository<Paper, Long>, JpaSpecificationE
 
     long countByWorkIdAndQuestionId(Long workId, Long questionId);
 
+    long countByQuestionId(Long questionId);
+
     /**
      * 统计同一个考生的paper数量
      *
@@ -285,6 +287,8 @@ public interface PaperRepo extends JpaRepository<Paper, Long>, JpaSpecificationE
     long countByWorkIdAndSubjectAndQuestionIdAndLevel(Long workId,
                                                       Subject subject, Long id, String code);
 
+    long countByQuestionIdAndLevelAndSubjectAndWorkId(Long questionId, String code, Subject subject ,Long workId);
+
     long countByWorkIdAndSubjectAndQuestionId(Long workId, Subject subject,
                                               Long id);
 
@@ -370,6 +374,9 @@ public interface PaperRepo extends JpaRepository<Paper, Long>, JpaSpecificationE
     @Query("select max(p.scoreBatchNo) from Paper p where p.workId = ?1 and p.subject = ?2")
     Long findMaxScoreBatchNoByWorkIdAndSubject(Long workId, Subject subject);
 
+    @Query(value = "select p.score_batch_no from paper p where p.work_id = ?1 and p.subject = ?2 order by score_batch_no desc limit 1", nativeQuery = true)
+    Long findScoreBatchNoByWorkIdAndSubject(Long workId, Subject subject);
+
     List<Paper> findByworkIdAndSubjectAndQuestionIdAndIsMissingAndTestAndLevelIsNull(Long workId, Subject valueOf, Long questionId, boolean b, int ordinal);
 
 //    List<Paper> findByWorkIdAndSubjectAndInspectRange(Long workId, Subject subject, Long inspectRange);

+ 70 - 58
stmms-ms-marking/src/main/java/cn/com/qmth/stmms/ms/marking/api/MakrerApi.java

@@ -133,11 +133,19 @@ 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<>();
+        long t1 = System.currentTimeMillis();
         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));
-//        Long batchNo = paperRepo.findByQuestionId(questionId);
-        Long batchNo = paperRepo.findMaxBatchNoByWorkIdAndSubject(marker.getWorkId(), marker.getSubject());
+
+        Integer levelShowAllPaper = ParamCache.paramMap.get(marker.getWorkId()).getLevelShowAllPaper();
+        Long batchNo = null;
+        if(levelShowAllPaper == 0){
+            batchNo = paperRepo.findMaxBatchNoByWorkIdAndSubject(marker.getWorkId(), marker.getSubject());
+        }
+        long t2 = System.currentTimeMillis();
+        System.out.println("l1:"+(t2-t1));
+        Long finalBatchNo = batchNo;
         Future future = myThreadPool.arbitratePoolTaskExecutor.submit(new Callable<Map<String, Long>>() {
 
             @Override
@@ -145,11 +153,15 @@ public class MakrerApi {
                 Map<String, Long> map = new HashMap<>();
                 //当前老师当前批次试卷总数
                 long kdtotal;
-                if (ParamCache.paramMap.get(marker.getWorkId()).getLevelShowAllPaper() == 1) {
+                long t21 = System.currentTimeMillis();
+                if (levelShowAllPaper == 1) {
                     kdtotal = markTaskRepo.countByQuestionIdAll(questionId, marker.getId());
                 } else {
-                    kdtotal = markTaskRepo.countByQuestionId(questionId, batchNo, marker.getId());
+//                    kdtotal = markTaskRepo.countByQuestionId(questionId, finalBatchNo, marker.getId());
+                    kdtotal = markTaskRepo.countByQuestionIdAndBatchNo(questionId, finalBatchNo, marker.getId());
                 }
+                long t22 = System.currentTimeMillis();
+                System.out.println("l61:"+(t22-t21));
                 //当前考区内试卷总数
                 long total = paperRepo.countByWorkIdAndQuestionId(markSubject.getWorkId(), questionId);
                 map.put("kdtotal", kdtotal);
@@ -157,27 +169,38 @@ public class MakrerApi {
                 return map;
             }
         });
-        long t1 = System.currentTimeMillis();
+        long t3 = System.currentTimeMillis();
+        System.out.println("l2:"+(t3-t2));
         //当前考区各档位定档数量
-        paperRepo.countGroupByLevel(questionId)
-                .forEach(o -> {
+        List<Object[]> list = paperRepo.countGroupByLevel(questionId);
+        long t4 = System.currentTimeMillis();
+        System.out.println("l3:"+(t4-t3));
+        list.forEach(o -> {
                     LevelStatDTO levelStatDTO = levelStatAssembler.toDTO(o);
                     levelStatDTO.setGcount(levelStatDTO.getCount());
                     if (Objects.isNull(levelStatDTO.getId())) {
                         //求任务数为null的条数
                         int count;
-                        if (ParamCache.paramMap.get(marker.getWorkId()).getLevelShowAllPaper() == 1) {
-                            count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissingAll(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), false);
+                        long t41 = System.currentTimeMillis();
+                        if (levelShowAllPaper == 1) {
+                            count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResultIsNullAll(questionId, marker.getId(), MarkStage.LEVEL.ordinal());
                         } else {
-                            count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), false, batchNo);
+                            count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResultNull(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), finalBatchNo);
                         }
+                        long t42 = System.currentTimeMillis();
+                        System.out.println("l41:"+(t42-t41));
                         //查询当前老师打回个数
-                        int rejectCount = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndIsRejectedTrueAndIsMissing(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), false);
+//                        int rejectCount = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndIsRejectedTrueAndIsMissing(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), false);
+                        int rejectCount = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndIsRejectedTrue(questionId, marker.getId(), MarkStage.LEVEL.ordinal());
+                        long t43 = System.currentTimeMillis();
+                        System.out.println("l42:"+(t43-t42));
                         levelStatDTO.setCount(count);
                         levelStatDTO.setRejected(rejectCount);
                     }
                     levelStatDTOs.add(levelStatDTO);
                 });
+        long t5 = System.currentTimeMillis();
+        System.out.println("l4:"+(t5-t4));
         for (Level level : levels) {
             //所有档位依次比较
             long count = levelStatDTOs.stream().filter(l -> String.valueOf(l.getId()).equals(level.getCode())).count();
@@ -186,28 +209,19 @@ public class MakrerApi {
                 dto.setId(level.getCode());
                 dto.setCount(0);
                 dto.setPercent(0.0);
-
-                //当前老师当前档位评档次数(所有考试)
-//                int countNew;
-//                if (ParamCache.paramMap.get(marker.getWorkId()).getLevelShowAllPaper() == 1) {
-////                    countNew = markTaskRepo.countByQuestionIdAndStageAndResultAndIsMissingAll(questionId, MarkStage.LEVEL.ordinal(), level.getCode(), false, marker.getId());
-//                } else {
-//                    countNew = markTaskRepo.countByQuestionIdAndStageAndResultAndIsMissing(questionId, MarkStage.LEVEL.ordinal(), level.getCode(), false, batchNo, marker.getId());
-//                }
-//                dto.setCount(countNew);
                 levelStatDTOs.add(dto);
             }
         }
+        long t6 = System.currentTimeMillis();
+        System.out.println("l5:"+(t6-t5));
         long kdtotal = 0L, total = 0L;
         if (Objects.nonNull(future) && Objects.nonNull(future.get())) {
             Map<String, Long> map = (Map<String, Long>) future.get();
             kdtotal = map.get("kdtotal");
             total = map.get("total");
         }
-//        //当前老师当前试卷的评档次数(不分档位)
-//        long kdtotal = markTaskRepo.countByQuestionId(questionId, batchNo, marker.getId());
-//        //当前老师所有的评档次数(不分档位)
-//        long total = paperRepo.countByWorkIdAndQuestionId(markSubject.getWorkId(), questionId);
+        long t7 = System.currentTimeMillis();
+        System.out.println("l6:"+(t7-t6));
 
         long finalKdtotal = kdtotal;
         long finalTotal = total;
@@ -215,21 +229,19 @@ public class MakrerApi {
             if (o.getId() != null) {
                 //当前老师各档位数量
                 int countNew;
-                if (ParamCache.paramMap.get(marker.getWorkId()).getLevelShowAllPaper() == 1) {
-//                            count = markTaskRepo.countByQuestionIdAndStageAndResultAndIsMissingAll(questionId, MarkStage.LEVEL.ordinal(), levelStatDTO.getId().toString(), false, marker.getId());
+                if (levelShowAllPaper == 1) {
                     countNew = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResultAll(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), String.valueOf(o.getId()));
                 } else {
-//                            count = markTaskRepo.countByQuestionIdAndStageAndResultAndIsMissing(questionId, MarkStage.LEVEL.ordinal(), levelStatDTO.getId().toString(), false, batchNo, marker.getId());
-                    countNew = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResult(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), String.valueOf(o.getId()), batchNo);
+                    countNew = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResult(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), String.valueOf(o.getId()), finalBatchNo);
                 }
                 o.setCount(countNew);
                 //该档位考区内已定档数量
-                long gcountNew = paperRepo.countByWorkIdAndSubjectAndQuestionIdAndLevel(marker.getWorkId(), markSubject.getSubject(), questionId, String.valueOf(o.getId()));
+//                long gcountNew = paperRepo.countByWorkIdAndSubjectAndQuestionIdAndLevel(marker.getWorkId(), markSubject.getSubject(), questionId, String.valueOf(o.getId()));
+                long gcountNew = paperRepo.countByQuestionIdAndLevelAndSubjectAndWorkId(questionId, String.valueOf(o.getId()), markSubject.getSubject(), marker.getWorkId());
                 o.setGcount((int) gcountNew);
 
                 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 = finalKdtotal == 0 ? 0 : (double) o.getCount() / finalKdtotal * 100;
                 BigDecimal bd = new BigDecimal(p).setScale(3, RoundingMode.HALF_EVEN);
                 o.setPercent(bd.doubleValue());
@@ -238,16 +250,10 @@ public class MakrerApi {
                 double gp = finalTotal == 0 ? 0 : (double) o.getGcount() / finalTotal * 100;
                 BigDecimal gbd = new BigDecimal(gp).setScale(3, RoundingMode.HALF_EVEN);
                 o.setGpercent(gbd.doubleValue());
-//                int count;
-//                if (ParamCache.paramMap.get(marker.getWorkId()).getLevelShowAllPaper() == 1) {
-//                    count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResultAll(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), o.getId().toString());
-//                } else {
-//                    count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResult(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), o.getId().toString(), batchNo);
-//                }
-//                o.setPercent(count == 0 ? 0 : o.getPercent());
-//                o.setCount(count);
             }
         });
+        long t8 = System.currentTimeMillis();
+        System.out.println("l7:"+(t8-t7));
         Collections.sort(levelStatDTOs, (o1, o2) -> {
             if (o1.getId() == null || o2.getId() == null) {
                 return 1;
@@ -267,36 +273,46 @@ public class MakrerApi {
     @RequestMapping(value = "{marker}/stat/scores", method = RequestMethod.GET)
     public List<LevelStatDTO> scoreStats(@PathVariable MarkUser marker, @RequestParam Long questionId) throws Exception {
         List<LevelStatDTO> levelStatDTOs = new ArrayList<>();
+        long t1 = System.currentTimeMillis();
         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));
-//        Long batchNo = paperRepo.findScoreBatchNoByQuestionId(questionId);
         Long batchNo = paperRepo.findMaxScoreBatchNoByWorkIdAndSubject(marker.getWorkId(), marker.getSubject());
+        long t2 = System.currentTimeMillis();
+        System.out.println("s1:"+(t2-t1));
         Future future = myThreadPool.arbitratePoolTaskExecutor.submit(new Callable<Map<String, Long>>() {
 
             @Override
-            public Map<String, Long> call() throws Exception {
+            public Map<String, Long> call() {
                 Map<String, Long> map = new HashMap<>();
-                //当前老师当前试卷的评档次数(不分档位)
-//                long kdtotal = markTaskRepo.countScoreByQuestionId(questionId, batchNo, marker.getId());
                 //当前老师所有的评档次数(不分档位)
-                long total = paperRepo.countByWorkIdAndQuestionId(markSubject.getWorkId(), questionId);
-//                map.put("kdtotal", kdtotal);
+//                long total = paperRepo.countByWorkIdAndQuestionId(markSubject.getWorkId(), questionId);
+                long total = paperRepo.countByQuestionId(questionId);
                 map.put("total", total);
                 return map;
             }
         });
+        long t3 = System.currentTimeMillis();
+        System.out.println("s2:"+(t3-t2));
         LevelStatDTO levelStatDTO = new LevelStatDTO();
         //求任务数为null的条数
-        int totalCount = markTaskRepo.countScoreByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(questionId, marker.getId(), MarkStage.SCORE.ordinal(), false, batchNo);
+//        int totalCount = markTaskRepo.countScoreByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(questionId, marker.getId(), MarkStage.SCORE.ordinal(), false, batchNo);
+        int totalCount = markTaskRepo.countScoreByQuestionIdAndMarkerIdAndStageAndResultIsNull(questionId, marker.getId(), MarkStage.SCORE.ordinal(), batchNo);
         levelStatDTO.setCount(totalCount);
+        long t4 = System.currentTimeMillis();
+        System.out.println("s3:"+(t4-t3));
         //查询改档
         int shiftCount = markTaskRepo.countShiftByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), false);
         levelStatDTO.setShift(shiftCount);
+        long t5 = System.currentTimeMillis();
+        System.out.println("s4:"+(t5-t4));
         //查询改档打分
-        int shiftScoreCount = markTaskRepo.countShiftScoreByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(questionId, marker.getId(), MarkStage.SCORE.ordinal(), false);
+//        int shiftScoreCount = markTaskRepo.countShiftScoreByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(questionId, marker.getId(), MarkStage.SCORE.ordinal(), false);
+        int shiftScoreCount = markTaskRepo.countShiftScoreByQuestionIdAndMarkerIdAndStageAndResultIsNull(questionId, marker.getId(), MarkStage.SCORE.ordinal());
         levelStatDTO.setShiftScore(shiftScoreCount);
         levelStatDTOs.add(levelStatDTO);
+        long t6 = System.currentTimeMillis();
+        System.out.println("s5:"+(t6-t5));
 
         for (Level level : levels) {
             //所有档位依次比较
@@ -308,32 +324,26 @@ public class MakrerApi {
                 dto.setPercent(0.0);
 
                 //当前老师当前档位评档次数(所有考试)
-                int countNew = 0;
-                /*if (ParamCache.paramMap.get(marker.getWorkId()).getScoreShowAllPaper() == 1) {
-                    countNew = markTaskRepo.countScoreByQuestionIdAndStageAndResultAndIsMissingAll(questionId, MarkStage.SCORE.ordinal(), level.getCode(), false, marker.getId());
-                } else {
-                    countNew = markTaskRepo.countScoreByQuestionIdAndStageAndResultAndIsMissing(questionId, MarkStage.SCORE.ordinal(), level.getCode(), false, batchNo, marker.getId());
-                }*/
-                dto.setCount(countNew);
+                dto.setCount(0);
                 levelStatDTOs.add(dto);
             }
         }
-        long kdtotal = 0L, total = 0L;
+        long t7 = System.currentTimeMillis();
+        System.out.println("s6:"+(t7-t6));
+        long total = 0L;
         if (Objects.nonNull(future) && Objects.nonNull(future.get())) {
             Map<String, Long> map = (Map<String, Long>) future.get();
-//            kdtotal = map.get("kdtotal");
             total = map.get("total");
         }
+        long t8 = System.currentTimeMillis();
+        System.out.println("s7:"+(t8-t7));
 
-        long finalKdtotal = kdtotal;
         long finalTotal = total;
         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() / finalKdtotal;
-//                BigDecimal bd = new BigDecimal(p).setScale(3, RoundingMode.HALF_EVEN);
                 o.setPercent(0D);
 
                 o.setGcount(Objects.isNull(o.getGcount()) ? 0 : o.getGcount());
@@ -351,6 +361,8 @@ public class MakrerApi {
                 o.setCount(count);
             }
         });
+        long t9 = System.currentTimeMillis();
+        System.out.println("s8:"+(t9-t8));
         return levelStatDTOs;
     }
 

+ 39 - 20
stmms-ms-marking/src/main/java/cn/com/qmth/stmms/ms/marking/api/MarkTaskApi.java

@@ -29,10 +29,7 @@ import org.springframework.orm.jpa.vendor.OpenJpaDialect;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.Join;
-import javax.persistence.criteria.JoinType;
-import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.*;
 import java.math.BigDecimal;
 import java.util.*;
 
@@ -118,7 +115,7 @@ public class MarkTaskApi {
             } else if (stage == MarkStage.LEVEL) {
                 //查询
                 predicates.add(builder.equal(root.get("result"), level));
-                if(ParamCache.paramMap.get(workId).getLevelShowAllPaper() == 0) {
+                if (ParamCache.paramMap.get(workId).getLevelShowAllPaper() == 0) {
 //                    Long batchNo = paperRepo.findByQuestionId(questionId);
                     Long batchNo = paperRepo.findMaxBatchNoByWorkIdAndSubject(workId, markUser.getSubject());
                     if (!Objects.isNull(batchNo)) {
@@ -136,7 +133,7 @@ public class MarkTaskApi {
 //                predicates.add(builder.equal(root.get("paper").get("isShiftScore"), false));
                 onPredicates.add(builder.equal(join.get("isShift"), false));
 //                onPredicates.add(builder.equal(join.get("isShiftScore"), false));
-                if(ParamCache.paramMap.get(workId).getScoreShowAllPaper() == 1){
+                if (ParamCache.paramMap.get(workId).getScoreShowAllPaper() == 1) {
 //                    predicates.add(builder.isNotNull(root.get("paper").get("scoreBatchNo")));
                     onPredicates.add(builder.isNotNull(join.get("scoreBatchNo")));
                 } else {
@@ -148,13 +145,15 @@ public class MarkTaskApi {
 //                predicates.add(builder.equal(root.get("paper").get("isSample"), isSample));
                 onPredicates.add(builder.equal(join.get("isSample"), isSample));
             }
-            if (reject != null) {
+            if (reject != null && reject) {
 //                predicates.add(builder.equal(root.get("paper").get("isRejected"), reject));
                 onPredicates.add(builder.equal(join.get("isRejected"), reject));
+            } else {
+                predicates.add(builder.equal(root.get("isRejected"), reject));
             }
 //            predicates.add(builder.equal(root.get("paper").get("isMissing"), false));
 //            predicates.add(builder.equal(root.get("paper").get("active"), true));
-            onPredicates.add(builder.equal(join.get("isMissing"), false));
+//            onPredicates.add(builder.equal(join.get("isMissing"), false));
             onPredicates.add(builder.equal(join.get("active"), true));
             //过滤考区
             if (Objects.nonNull(areaCode)) {
@@ -165,7 +164,19 @@ public class MarkTaskApi {
 //            predicates.add(builder.equal(root.get("isActive"), false));
             return builder.and(predicates.toArray(new Predicate[predicates.size()]));
         };
-        Sort sort = new Sort( "randomSeq","level", "serialNumber", "randomSeqNew");
+//        Sort sort = new Sort( "randomSeq","level", "is_sample","serialNumber", "randomSeqNew");
+        List<Sort.Order> orders = new ArrayList<>();
+        Sort.Order order1=new Sort.Order(Sort.Direction.ASC, "randomSeq");
+        orders.add(order1);
+        Sort.Order order2=new Sort.Order(Sort.Direction.DESC, "isSample");
+        orders.add(order2);
+        Sort.Order order3=new Sort.Order(Sort.Direction.ASC, "level");
+        orders.add(order3);
+        Sort.Order order4=new Sort.Order(Sort.Direction.ASC, "serialNumber");
+        orders.add(order4);
+        Sort.Order order5=new Sort.Order(Sort.Direction.ASC, "randomSeqNew");
+        orders.add(order5);
+        Sort sort = new Sort(orders);
         Pageable pageable1 = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), sort);
         Page<MarkTask> markTasks = markTaskRepo.findAll(specification, pageable1);
 
@@ -222,14 +233,14 @@ public class MarkTaskApi {
             if (isShift != null) {
                 //查询
                 predicates.add(builder.equal(root.get("paper").get("isShift"), isShift));
-                if(isShift){
+                if (isShift) {
                     predicates.add(builder.equal(root.get("stage"), MarkStage.LEVEL));
                     predicates.add(builder.isNull(root.get("result")));
                 }
             }
             if (isShiftScore != null && isShiftScore && !isShift) {
                 predicates.add(builder.equal(root.get("paper").get("isShiftScore"), isShiftScore));
-                if(isShiftScore){
+                if (isShiftScore) {
                     predicates.add(builder.equal(root.get("stage"), MarkStage.SCORE));
                     predicates.add(builder.isNull(root.get("result")));
                 }
@@ -297,7 +308,7 @@ public class MarkTaskApi {
     /**
      * 批量提交评卷任务
      *
-     * @param body     评卷内容
+     * @param body 评卷内容
      * @return
      */
     @RequestMapping(value = "batch", method = RequestMethod.PATCH)
@@ -305,7 +316,7 @@ public class MarkTaskApi {
         MarkStage stage = MarkStage.valueOf(body.get("stage"));
         String markIds = body.get("taskIds");
         String result = body.get("result");
-        if(Objects.isNull(markIds)){
+        if (Objects.isNull(markIds)) {
             throw new RuntimeException("请选择待评试卷");
         }
         String[] ids = markIds.split(",");
@@ -365,6 +376,16 @@ public class MarkTaskApi {
         List<MarkTaskDTO> markTaskDTOs = new ArrayList<>();
         Sort sort = new Sort(Sort.Direction.DESC, "updatedOn");
         Pageable pageable = new PageRequest(0, 5, sort);
+        Long batchNo = null;
+        Long socreBatchNo = null;
+        if (stage == MarkStage.LEVEL) {
+             batchNo = paperRepo.findByQuestionId(questionId);
+        }else if (stage == MarkStage.SCORE) {
+            socreBatchNo=paperRepo.findScoreBatchNoByQuestionId(questionId);
+        }
+
+        Long finalBatchNo = batchNo;
+        Long finalSocreBatchNo = socreBatchNo;
         Specification<MarkTask> specification = (root, query, builder) -> {
             List<Predicate> predicates = new ArrayList<>();
             if (Objects.nonNull(questionId)) {
@@ -374,17 +395,16 @@ public class MarkTaskApi {
             predicates.add(builder.equal(root.get("stage"), stage));
             if (stage == MarkStage.LEVEL) {
                 //查询
-                Long batchNo = paperRepo.findByQuestionId(questionId);
-                if (!Objects.isNull(batchNo)) {
-                    predicates.add(builder.equal(root.get("paper").get("batchNo"), batchNo));
+                if (!Objects.isNull(finalBatchNo)) {
+                    predicates.add(builder.equal(root.get("paper").get("batchNo"), finalBatchNo));
                 }
                 predicates.add(builder.isNotNull(root.get("result")));
                 //分档需要过滤标准卷
                 predicates.add(builder.equal(root.get("paper").get("isSample"), false));
             } else if (stage == MarkStage.SCORE) {
-                Long socreBatchNo = paperRepo.findScoreBatchNoByQuestionId(questionId);
-                if (!Objects.isNull(socreBatchNo)) {
-                    predicates.add(builder.equal(root.get("paper").get("scoreBatchNo"), socreBatchNo));
+
+                if (!Objects.isNull(finalSocreBatchNo)) {
+                    predicates.add(builder.equal(root.get("paper").get("scoreBatchNo"), finalSocreBatchNo));
                 }
                 predicates.add(builder.isNotNull(root.get("result")));
             }
@@ -394,7 +414,6 @@ public class MarkTaskApi {
             }
             return builder.and(predicates.toArray(new Predicate[predicates.size()]));
         };
-
         Page<MarkTask> markTasks = markTaskRepo.findAll(specification, pageable);
         markTasks.getContent().forEach(m -> {
             markTaskDTOs.add(markTaskAssembler.toDTO(m));

+ 1 - 0
stmms-ms-marking/src/main/java/cn/com/qmth/stmms/ms/marking/service/AssignTaskService.java

@@ -171,6 +171,7 @@ public class AssignTaskService {
                     } else {
                         markTask = new MarkTask(marker, paper, markSubject.getStage(), random, markSubject.getTest());
                     }
+                    markTask.setBatchNo(currentTime);
                 }
                 markTaskList.add(markTask);
                 randomMap.put(random, markTask);

+ 1 - 0
stmms-ms-marking/src/main/java/cn/com/qmth/stmms/ms/marking/service/MarkingService.java

@@ -280,6 +280,7 @@ public class MarkingService {
             markTask.setRejected(false);
             markTask.setResult(level);
             markTask.setLevel(level);
+            markTask.setSample(paper.isSample());
         }
         markTaskRepo.save(markTasks);
         levelsLog(markTasks, paper);