فهرست منبع

美术阅卷11月新增需求-压力测试问题修复

wangliang 5 سال پیش
والد
کامیت
fa76b228e6

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

@@ -37,18 +37,16 @@ public interface MarkTaskRepo extends JpaRepository<MarkTask, Long>, JpaSpecific
 
     long countByQuestionIdIn(List<Long> questionIds);
 
-    @Query(value = "select count(1) from mark_task m left join paper p on m.paper_id = p.id where m.question_id = ? and p.batch_no = (select max(batch_no) from paper where question_id = ?) and m.marker_id = ?", nativeQuery = true)
-    long countByQuestionId(Long questionId, Long questionId1, Long markerId);
+    @Query(value = "select count(1) from mark_task m left 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)
+    long countByQuestionId(Long questionId, Long batchNo, Long markerId);
 
-    int countByQuestionIdAndStageAndResultIsNull(Long questionId, MarkStage stage);
-
-    @Query(value = "select count(1) from mark_task m left join paper p on m.paper_id = p.id where m.question_id = ?1 and m.stage = ?2 and m.result = ?3 and p.batch_no = (select max(batch_no) from paper where question_id = ?1)", nativeQuery = true)
-    int countByQuestionIdAndStageAndResult(Long questionId, int stage, String result);
+    @Query(value = "select count(1) from mark_task m left join paper p on m.paper_id = p.id where m.question_id = ?1 and m.stage = ?2 and m.result = ?3 and p.batch_no = ?4", nativeQuery = true)
+    int countByQuestionIdAndStageAndResult(Long questionId, int stage, String result,Long batchNo);
 
     int countByQuestionIdAndMarkerIdAndStageAndResultIsNull(Long questionId, Long markerId, MarkStage stage);
 
-    @Query(value = "select count(1) from mark_task m left 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 = (select max(batch_no) from paper where question_id = ?5)", nativeQuery = true)
-    int countByQuestionIdAndMarkerIdAndStageAndResult(Long questionId, Long markerId, int stage, String result, Long questionId1);
+    @Query(value = "select count(1) from mark_task m left 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", nativeQuery = true)
+    int countByQuestionIdAndMarkerIdAndStageAndResult(Long questionId, Long markerId, int stage, String result, Long batchNo);
 
     int countByWorkIdAndSubjectAndMarkerIdAndStageAndResult(Long workId, Subject subject, Long markerId, MarkStage stage, String result);
 
@@ -187,11 +185,11 @@ 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 left 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 is null and p.is_missing = ?4 and p.batch_no = (select max(batch_no) from paper where question_id = ?5)", nativeQuery = true)
-    int countByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(Long questionId, Long markerId, int stage, boolean isMissing, Long questionId1);
+    @Query(value = "SELECT count(1) from mark_task m left 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", nativeQuery = true)
+    int countByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(Long questionId, Long markerId, int stage, boolean isMissing, Long batchNo);
 
-    @Query(value = "SELECT count(1) from mark_task m left join paper p on m.paper_id = p.id where m.question_id = ?1 and m.marker_id = ?6 and m.stage = ?2 and m.result =?3 and p.is_missing = ?4 and p.batch_no = (select max(batch_no) from paper where question_id = ?5)", nativeQuery = true)
-    int countByQuestionIdAndStageAndResultAndIsMissing(Long questionId, int stage, String result, boolean isMissing, Long questionId1, Long markerId);
+    @Query(value = "SELECT count(1) from mark_task m left 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 = ?6 and m.stage = ?2 and m.result =?3", nativeQuery = true)
+    int countByQuestionIdAndStageAndResultAndIsMissing(Long questionId, int stage, String result, boolean isMissing,Long batchNo,Long markerId);
 
     MarkTask findByPaperIdAndSecretNumber(Long paperId, String secretNumber);
 
@@ -199,4 +197,6 @@ public interface MarkTaskRepo extends JpaRepository<MarkTask, Long>, JpaSpecific
 
     @Query("select max(mt.batchNo) from MarkTask mt where mt.questionId = ?1")
     Long findByQuestionId(Long questionId);
+
+    List<MarkTask> findByWorkIdAndSubjectAndStage(Long workId, Subject subject, MarkStage markStage);
 }

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

@@ -76,9 +76,9 @@ public interface PaperRepo extends JpaRepository<Paper, Long>, JpaSpecificationE
             "SUM(IF(p.`is_arbitrated` = 1, 1, 0))" +
             "FROM paper p " +
             "WHERE p.`question_id` = ? and p.is_missing = false " +
-            "AND p.batch_no = (select max(batch_no) from paper where question_id = ?)" +
+            "AND p.batch_no = ? " +
             "GROUP BY p.`level` ORDER BY p.`level`", nativeQuery = true)
-    List<Object[]> countGroupByLevel(Long questionId, Long questionId1);
+    List<Object[]> countGroupByLevel(Long questionId, Long batchNo);
 
     /**
      * 统计科目指定试题的各档位数量

+ 44 - 18
stmms-ms-marking/src/main/java/cn/com/qmth/stmms/ms/marking/api/MakrerApi.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.stmms.ms.marking.api;
 
+import cn.com.qmth.stmms.ms.commons.threadPool.MyThreadPool;
 import cn.com.qmth.stmms.ms.commons.utils.SqlUtil;
 import cn.com.qmth.stmms.ms.core.domain.Level;
 import cn.com.qmth.stmms.ms.core.domain.MarkStage;
@@ -15,17 +16,15 @@ import cn.com.qmth.stmms.ms.marking.assembler.QuestionStatAssembler;
 import cn.com.qmth.stmms.ms.marking.dto.LevelStatDTO;
 import cn.com.qmth.stmms.ms.marking.dto.MarkerDTO;
 import cn.com.qmth.stmms.ms.marking.dto.QuestionStatDTO;
-import com.alibaba.fastjson.JSONObject;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
 import java.util.stream.Collectors;
 
 /**
@@ -100,6 +99,9 @@ public class MakrerApi {
         return markUsers;
     }
 
+    @Autowired
+    MyThreadPool myThreadPool;
+
     /**
      * 评卷员分档数量及占比数据
      *
@@ -113,19 +115,34 @@ public class MakrerApi {
         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);
+        Future future = myThreadPool.arbitratePoolTaskExecutor.submit(new Callable<Map<String, Long>>() {
+
+            @Override
+            public Map<String, Long> call() throws Exception {
+                Map<String, Long> map = new HashMap<>();
+                //当前老师当前试卷的评档次数(不分档位)
+                long kdtotal = markTaskRepo.countByQuestionId(questionId, batchNo, marker.getId());
+                //当前老师所有的评档次数(不分档位)
+                long total = paperRepo.countByWorkIdAndQuestionId(markSubject.getWorkId(), questionId);
+                map.put("kdtotal", kdtotal);
+                map.put("total", total);
+                return map;
+            }
+        });
         //统计workId下各考点的数量
-        paperRepo.countGroupByLevel(questionId, questionId)
+        paperRepo.countGroupByLevel(questionId, batchNo)
                 .forEach(o -> {
                     LevelStatDTO levelStatDTO = levelStatAssembler.toDTO(o);
                     levelStatDTO.setGcount(levelStatDTO.getCount());
                     if (Objects.isNull(levelStatDTO.getId())) {
                         //求任务数为null的条数
 //                        int count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResultIsNull(questionId, marker.getId(), MarkStage.LEVEL);
-                        int count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), false, questionId);
+                        int count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResultIsNullAndIsMissing(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), false, batchNo);
                         levelStatDTO.setCount(count);
                     } else {
 //                        int count = markTaskRepo.countByQuestionIdAndStageAndResult(questionId, MarkStage.LEVEL, levelStatDTO.getId().toString());
-                        int count = markTaskRepo.countByQuestionIdAndStageAndResultAndIsMissing(questionId, MarkStage.LEVEL.ordinal(), levelStatDTO.getId().toString(), false, questionId, marker.getId());
+                        int count = markTaskRepo.countByQuestionIdAndStageAndResultAndIsMissing(questionId, MarkStage.LEVEL.ordinal(), levelStatDTO.getId().toString(), false, batchNo, marker.getId());
                         levelStatDTO.setCount(count);
                     }
                     levelStatDTOs.add(levelStatDTO);
@@ -140,33 +157,42 @@ public class MakrerApi {
                 dto.setPercent(0.0);
 
                 //当前老师当前档位评档次数(所有考试)
-                int countNew = markTaskRepo.countByQuestionIdAndStageAndResultAndIsMissing(questionId, MarkStage.LEVEL.ordinal(), level.getCode(), false, questionId, marker.getId());
+                int countNew = markTaskRepo.countByQuestionIdAndStageAndResultAndIsMissing(questionId, MarkStage.LEVEL.ordinal(), level.getCode(), false, batchNo, marker.getId());
+                dto.setPercent(countNew == 0 ? 0D : dto.getPercent());
                 dto.setCount(countNew);
                 levelStatDTOs.add(dto);
             }
         }
-        //当前老师当前试卷的评档次数(不分档位)
-        long kdtotal = markTaskRepo.countByQuestionId(questionId, questionId, marker.getId());
-        //当前老师所有的评档次数(不分档位)
-        long total = paperRepo.countByWorkIdAndQuestionId(markSubject.getWorkId(), questionId);
+        long kdtotal = 0L,total = 0L;
+        if(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 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() / kdtotal;
+                double p = (double) o.getCount() / finalKdtotal;
                 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() / total;
+                double gp = (double) o.getGcount() / finalTotal;
                 BigDecimal gbd = new BigDecimal(gp).setScale(3, RoundingMode.HALF_EVEN);
                 o.setGpercent(gbd.doubleValue());
 
-                int count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResult(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), o.getId().toString(), questionId);
-                o.setPercent(count == 0 ? 0 : o.getPercent());
-                o.setCount(count);
+//                int count = markTaskRepo.countByQuestionIdAndMarkerIdAndStageAndResult(questionId, marker.getId(), MarkStage.LEVEL.ordinal(), o.getId().toString(), batchNo);
+//                o.setPercent(count == 0 ? 0 : o.getPercent());
+//                o.setCount(count);
             }
         });
         return levelStatDTOs;

+ 33 - 13
stmms-ms-marking/src/main/java/cn/com/qmth/stmms/ms/marking/service/AssignTaskService.java

@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -57,7 +58,8 @@ public class AssignTaskService {
         if (paperCount % randomBundleSize != 0) {
             randomBundleCount += 1;
         }
-
+        List<MarkTask> markTaskList = markTaskRepo.findByWorkIdAndSubjectAndStage(markSubject.getWorkId(), markSubject.getSubject(), markSubject.getStage());
+        Map<Long, MarkTask> randomMap = markTaskList.stream().collect(Collectors.toMap(MarkTask::getRandomSeqNew, Function.identity(), (dto1, dto2) -> dto1));
         for (int i = 0; i < randomBundleCount; i++) {
             int fromIndex = i * randomBundleSize;
             int endIndex = i * randomBundleSize + randomBundleSize;
@@ -74,7 +76,7 @@ public class AssignTaskService {
 
                 for (int j = 0; j < markerPaperList.size(); j++) {
                     Paper paper = markerPaperList.get(j);
-                    Long random = getRandom(marker.getId(), paper.getId(), marker.getWorkId(), paper.getExamNumber());
+                    Long random = getRandom(marker.getId(), paper.getId(), marker.getWorkId(), paper.getExamNumber(), randomMap);
                     MarkTask markTask = new MarkTask(marker, paper, markSubject.getStage(), random, markSubject.getTest());
                     markTask.setRandomSeq(i * randomBundleSize + j + 1);
                     markTasks.add(markTask);
@@ -106,17 +108,22 @@ public class AssignTaskService {
     @Transactional
     public void assignForGrouping(List<Paper> papers, List<MarkerGroup> markerGroups, MarkSubject markSubject) throws Exception {
         markerGroups = markerGroups.stream().filter(m -> m.getMarkers().size() > 0).collect(Collectors.toList());
+        int sum = markerGroups.stream().mapToInt(m -> m.getMarkers().size()).sum();
         int groupSize = markerGroups.size();
         int idx = 0;
         long currentTime = System.currentTimeMillis();
         Iterator<Paper> iterator = papers.iterator();
+        List<MarkTask> markTaskList = new ArrayList<>(papers.size() * sum);
+        List<Paper> paperList = new ArrayList<>(papers.size());
+        List<MarkTask> markTasks = markTaskRepo.findByWorkIdAndSubjectAndStage(markSubject.getWorkId(), markSubject.getSubject(), markSubject.getStage());
+        Map<Long, MarkTask> randomMap = markTasks.stream().collect(Collectors.toMap(MarkTask::getRandomSeqNew, Function.identity(), (dto1, dto2) -> dto1));
         while (iterator.hasNext()) {
             if (idx >= groupSize) {
                 idx = 0;
             }
             Paper paper = iterator.next();
             for (MarkUser marker : markerGroups.get(idx).getMarkers()) {
-                Long random = getRandom(marker.getId(), paper.getId(), marker.getWorkId(), paper.getExamNumber());
+                Long random = getRandom(marker.getId(), paper.getId(), marker.getWorkId(), paper.getExamNumber(), randomMap);
                 MarkTask markTask = null;
                 if (Objects.equals(MarkStage.SCORE, markSubject.getStage())) {
                     markTask = new MarkTask(marker, paper, markSubject.getStage(), random, markSubject.getTest());
@@ -124,22 +131,31 @@ public class AssignTaskService {
                 } else {
                     markTask = new MarkTask(marker, paper, markSubject.getStage(), random, markSubject.getTest());
                 }
-                markTaskRepo.save(markTask);
+                markTaskList.add(markTask);
+                randomMap.put(random, markTask);
+//                markTaskRepo.save(markTask);
             }
             if (markSubject.getTest() != 1) {
                 if (MarkStage.LEVEL.equals(markSubject.getStage())) {
                     //将paper置为激活
                     paper.setActive(true);
                     paper.setBatchNo(currentTime);
-                    paperRepo.save(paper);
-
+//                    paperRepo.save(paper);
+                    paperList.add(paper);
                     //更新subject表formal为正试评卷
-                    markSubject.setFormal(true);
-                    markSubjectRepo.saveAndFlush(markSubject);
+//                    markSubject.setFormal(true);
+//                    markSubjectRepo.saveAndFlush(markSubject);
                 }
             }
             idx++;
         }
+        markTaskRepo.save(markTaskList);
+        paperRepo.save(paperList);
+        if (markSubject.getTest() != 1) {
+            //更新subject表formal为正试评卷
+            markSubject.setFormal(true);
+            markSubjectRepo.saveAndFlush(markSubject);
+        }
         //只有全部任务投放完成,才能删除分组
         int count = paperRepo.countByWorkIdAndSubjectAndIsMissingFalseAndActiveFalseAndBatchNoIsNullAndTest(markSubject.getWorkId(), markSubject.getSubject(), 0);
         //进入分档阶段后,清空当前分组,以便打分阶段前重新分组
@@ -158,22 +174,26 @@ public class AssignTaskService {
      * @param paperId
      * @param workId
      * @param examNumber
+     * @param randomMap
      * @return
      * @throws Exception
      */
-    public Long getRandom(Long markerId, Long paperId, Long workId, String examNumber) throws Exception {
-        int count = 0, result = 0;
+    public Long getRandom(Long markerId, Long paperId, Long workId, String examNumber, Map<Long, MarkTask> randomMap) throws Exception {
+        int count = 0;
         Long random = 0L;
         while (true) {
             random = RandomUtil.randomMap.get(workId).get(new Random().nextInt(RandomUtil.randomMap.get(workId).size()));
+            if (Objects.isNull(randomMap) || randomMap.size() == 0) {
+                break;
+            }
 //            random = RandomUtil.randomList.get(new Random().nextInt(RandomUtil.randomList.size()));
-            result = markTaskRepo.countByMarkerIdAndPaperIdAndWorkIdAndRandomSeqNew(markerId, paperId, workId, random);
-            if (result == 0 && random != Long.parseLong(examNumber.substring(3, examNumber.length()))) {
+//            result = markTaskRepo.countByMarkerIdAndPaperIdAndWorkIdAndRandomSeqNew(markerId, paperId, workId, random);
+            if (Objects.isNull(randomMap.get(random))) {
                 break;
             } else {
                 count++;
             }
-            if (count > 100) {
+            if (count > 10000) {
 //                throw new Exception("重复几率较高,建议重新生成随机号");
                 RandomUtil.getRandom(workId, true);
             }