Browse Source

线下版本-优化-20201116

xiaof 4 years ago
parent
commit
2dcf0b0a64

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

@@ -52,10 +52,10 @@ 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 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)
     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 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and p.level = ?4 and p.score_batch_no = ?5 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.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)
     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 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and p.level = ?4 and p.score_batch_no is not null 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.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)
     int countScoreByQuestionIdAndMarkerIdAndStageAndResultAll(Long questionId, Long markerId, int stage, String result);
     /**
      * 查询评卷员的评卷任务
@@ -172,7 +172,7 @@ 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.batch_no = ?5 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 countByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(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_missing = ?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 null and p.is_shift = 0 and p.is_shift_score = 0", 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.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_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)
@@ -191,10 +191,10 @@ public interface MarkTaskRepo extends JpaRepository<MarkTask, Long>, JpaSpecific
 
     List<MarkTask> findByWorkId(Long workId);
 
-    @Query(value = "SELECT count(1) from mark_task m inner join paper p on m.paper_id = p.id and p.is_missing = ?4 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null and p.is_shift = 1", 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.is_shift = 1 where m.question_id = ?1 and m.marker_id = ?2 and m.stage = ?3 and m.result is null", nativeQuery = true)
     int countShiftByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(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_missing = ?4 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 = 1", 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.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.batch_no is not null where m.question_id = ?1 and m.marker_id = ?2", nativeQuery = true)
@@ -214,4 +214,13 @@ public interface MarkTaskRepo extends JpaRepository<MarkTask, Long>, JpaSpecific
     int countByWorkIdAndSubjectAndStage(Long workId, Subject subject, MarkStage stage);
 
     int countByWorkIdAndStageAndResultNotNull(Long id, MarkStage level);
+
+    @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id where m.work_id = ?1 and m.subject = ?2 and m.marker_id = ?3 and m.stage = ?4 and m.result is null and p.is_shift = true", nativeQuery = true)
+    int countByWorkIdAndSubjectAndMarkerIdAndStageAndShiftAndResult(Long workId, String subject, Long valueOf, int stage);
+
+    @Query(value = "select count(1) from mark_task m inner join paper p on m.paper_id = p.id where m.work_id = ?1 and m.subject = ?2 and m.marker_id = ?3 and m.stage = ?4 and m.result is null and p.is_shift_score = 1", nativeQuery = true)
+    int countByWorkIdAndSubjectAndMarkerIdAndStageAndShiftScoreAndResult(Long workId, String subject, Long valueOf, int stage);
+
+    @Query(value = "select count(1) from mark_task m where m.work_id = ?1 and m.subject = ?2 and m.marker_id = ?3 and m.stage = ?4 and m.is_rejected = 1", nativeQuery = true)
+    int findByWorkIdAndSubjectAndMarkerIdAndStageReject(Long workId, String subject, Long valueOf, int stage);
 }

+ 30 - 12
stmms-ms-marking/src/main/java/cn/com/qmth/stmms/ms/marking/api/MarkTaskApi.java

@@ -30,6 +30,8 @@ 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 java.math.BigDecimal;
 import java.util.*;
@@ -98,6 +100,8 @@ public class MarkTaskApi {
         MarkUser markUser = markUserRepo.findOne(markerId);
         Specification<MarkTask> specification = (root, query, builder) -> {
             List<Predicate> predicates = new ArrayList<>();
+            List<Predicate> onPredicates = new ArrayList<>();
+            Join<MarkTask, Paper> join = root.join("paper", JoinType.INNER);
             if (Objects.nonNull(questionId)) {
                 predicates.add(builder.equal(root.get("questionId"), questionId));
             }
@@ -106,8 +110,10 @@ public class MarkTaskApi {
             if (level == null) {
                 predicates.add(builder.isNull(root.get("result")));
                 if (stage == MarkStage.SCORE) {
-                    predicates.add(builder.equal(root.get("paper").get("isShift"), false));
-                    predicates.add(builder.equal(root.get("paper").get("isShiftScore"), false));
+//                    predicates.add(builder.equal(root.get("paper").get("isShift"), false));
+//                    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));
                 }
             } else if (stage == MarkStage.LEVEL) {
                 //查询
@@ -116,34 +122,46 @@ public class MarkTaskApi {
 //                    Long batchNo = paperRepo.findByQuestionId(questionId);
                     Long batchNo = paperRepo.findMaxBatchNoByWorkIdAndSubject(workId, markUser.getSubject());
                     if (!Objects.isNull(batchNo)) {
-                        predicates.add(builder.equal(root.get("paper").get("batchNo"), batchNo));
+//                        predicates.add(builder.equal(root.get("paper").get("batchNo"), batchNo));
+                        onPredicates.add(builder.equal(join.get("batchNo"), batchNo));
                     }
                 }
             } else if (stage == MarkStage.SCORE) {
 //                Long batchNo = paperRepo.findScoreBatchNoByQuestionId(questionId);
                 Long batchNo = paperRepo.findMaxScoreBatchNoByWorkIdAndSubject(workId, markUser.getSubject());
-                predicates.add(builder.equal(root.get("paper").get("level"), level));
+//                predicates.add(builder.equal(root.get("paper").get("level"), level));
+                onPredicates.add(builder.equal(join.get("level"), level));
                 predicates.add(builder.isNotNull(root.get("result")));
-                predicates.add(builder.equal(root.get("paper").get("isShift"), false));
+//                predicates.add(builder.equal(root.get("paper").get("isShift"), false));
 //                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){
-                    predicates.add(builder.isNotNull(root.get("paper").get("scoreBatchNo")));
+//                    predicates.add(builder.isNotNull(root.get("paper").get("scoreBatchNo")));
+                    onPredicates.add(builder.isNotNull(join.get("scoreBatchNo")));
                 } else {
-                    predicates.add(builder.equal(root.get("paper").get("scoreBatchNo"), batchNo));
+//                    predicates.add(builder.equal(root.get("paper").get("scoreBatchNo"), batchNo));
+                    onPredicates.add(builder.equal(join.get("scoreBatchNo"), batchNo));
                 }
             }
             if (isSample != null) {
-                predicates.add(builder.equal(root.get("paper").get("isSample"), isSample));
+//                predicates.add(builder.equal(root.get("paper").get("isSample"), isSample));
+                onPredicates.add(builder.equal(join.get("isSample"), isSample));
             }
             if (reject != null) {
-                predicates.add(builder.equal(root.get("paper").get("isRejected"), reject));
+//                predicates.add(builder.equal(root.get("paper").get("isRejected"), reject));
+                onPredicates.add(builder.equal(join.get("isRejected"), reject));
             }
-            predicates.add(builder.equal(root.get("paper").get("isMissing"), false));
-            predicates.add(builder.equal(root.get("paper").get("active"), true));
+//            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("active"), true));
             //过滤考区
             if (Objects.nonNull(areaCode)) {
-                predicates.add(builder.equal(root.get("paper").get("areaCode"), areaCode));
+//                predicates.add(builder.equal(root.get("paper").get("areaCode"), areaCode));
+                onPredicates.add(builder.equal(join.get("areaCode"), areaCode));
             }
+            join.on(onPredicates.toArray(new Predicate[onPredicates.size()]));
 //            predicates.add(builder.equal(root.get("isActive"), false));
             return builder.and(predicates.toArray(new Predicate[predicates.size()]));
         };

+ 9 - 5
stmms-ms-marking/src/main/java/cn/com/qmth/stmms/ms/marking/assembler/QuestionStatAssembler.java

@@ -75,12 +75,16 @@ public class QuestionStatAssembler {
 //        List<Paper> papers = paperRepo.findByWorkIdAndSubject(workId, subject);
 //        long shift = papers.stream().filter(m->m.isShift()).count();
 //        long shiftScore = papers.stream().filter(m->m.isShiftScore()).count();
-        List<MarkTask> tasks = markTaskRepo.findByWorkIdAndSubjectAndMarkerIdAndStage(workId, subject, Long.valueOf(qStats[1].toString()), MarkStage.LEVEL);
-        long shift = tasks.stream().filter(m -> m.getPaper().isShift() && Objects.isNull(m.getResult())).count();
-        List<MarkTask> tasks1 = markTaskRepo.findByWorkIdAndSubjectAndMarkerIdAndStage(workId, subject, Long.valueOf(qStats[1].toString()), MarkStage.SCORE);
-        long shiftScore = tasks1.stream().filter(m -> m.getPaper().isShiftScore() && Objects.isNull(m.getResult())).count();
+//        List<MarkTask> tasks = markTaskRepo.findByWorkIdAndSubjectAndMarkerIdAndStage(workId, subject, Long.valueOf(qStats[1].toString()), MarkStage.LEVEL);
+//        long shift1 = tasks.stream().filter(m -> m.getPaper().isShift() && Objects.isNull(m.getResult())).count();
+
+        int shift = markTaskRepo.countByWorkIdAndSubjectAndMarkerIdAndStageAndShiftAndResult(workId, subject.name(), Long.valueOf(qStats[1].toString()), MarkStage.LEVEL.ordinal());
+//        List<MarkTask> tasks1 = markTaskRepo.findByWorkIdAndSubjectAndMarkerIdAndStage(workId, subject, Long.valueOf(qStats[1].toString()), MarkStage.SCORE);
+//        long shiftScore1 = tasks1.stream().filter(m -> m.getPaper().isShiftScore() && Objects.isNull(m.getResult())).count();
+        int shiftScore = markTaskRepo.countByWorkIdAndSubjectAndMarkerIdAndStageAndShiftScoreAndResult(workId, subject.name(), Long.valueOf(qStats[1].toString()), MarkStage.SCORE.ordinal());
         //所有打回
-        long rejectCount = tasks.stream().filter(m->m.isRejected()).count();
+//        long rejectCount = tasks.stream().filter(m->m.isRejected()).count();
+        int rejectCount = markTaskRepo.findByWorkIdAndSubjectAndMarkerIdAndStageReject(workId, subject.name(), Long.valueOf(qStats[1].toString()), MarkStage.LEVEL.ordinal());
         MarkQuestionStatDTO qpDTO = null;
         if (qStats != null) {
             qpDTO = new MarkQuestionStatDTO();