Explorar o código

更新选做题区分规则

ting.yin hai 1 ano
pai
achega
143b4dc678

+ 2 - 1
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/mark/service/Impl/MarkServiceImpl.java

@@ -1476,7 +1476,8 @@ public class MarkServiceImpl implements MarkService {
      *
      * @param studentId
      */
-    private void checkStudentSubjective(Integer studentId, long groupCount, long unGroupQuestionCount) {
+    @Override
+    public void checkStudentSubjective(Integer studentId, long groupCount, long unGroupQuestionCount) {
         if (groupStudentDao.countByStudentIdAndStatus(studentId, SubjectiveStatus.MARKED) == groupCount
                 && unGroupQuestionCount == 0) {
             scoreCalculate(studentId);

+ 9 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/mark/service/MarkService.java

@@ -267,4 +267,13 @@ public interface MarkService {
      * @return
      */
     boolean rejectLibrary(MarkLibrary library, MarkStepDTO[] questionList, Integer userId, String reason);
+
+    /**
+     * 考生判断是否主观题全部评卷完成
+     * 
+     * @param studentId
+     * @param groupCount
+     * @param unGroupQuestionCount
+     */
+    void checkStudentSubjective(Integer studentId, long groupCount, long unGroupQuestionCount);
 }

+ 25 - 0
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/SelectiveGroupController.java

@@ -17,6 +17,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.core.task.AsyncTaskExecutor;
 import org.springframework.stereotype.Controller;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.ui.Model;
@@ -25,17 +27,22 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
 import cn.com.qmth.stmms.admin.dto.SelectivePartDTO;
+import cn.com.qmth.stmms.admin.thread.SubjectiveCalculateThread;
 import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
 import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
 import cn.com.qmth.stmms.biz.exam.model.MarkGroup;
 import cn.com.qmth.stmms.biz.exam.model.SelectiveGroup;
 import cn.com.qmth.stmms.biz.exam.service.ExamQuestionService;
+import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
 import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
 import cn.com.qmth.stmms.biz.exam.service.MarkGroupService;
 import cn.com.qmth.stmms.biz.exam.service.SelectiveGroupService;
+import cn.com.qmth.stmms.biz.lock.LockService;
+import cn.com.qmth.stmms.biz.mark.service.MarkService;
 import cn.com.qmth.stmms.common.annotation.Logging;
 import cn.com.qmth.stmms.common.enums.LogType;
 import cn.com.qmth.stmms.common.enums.ScorePolicy;
+import cn.com.qmth.stmms.common.enums.SubjectiveStatus;
 
 @Controller("selectiveGroupController")
 @RequestMapping("/admin/exam/selectiveGroup")
@@ -55,6 +62,19 @@ public class SelectiveGroupController extends BaseExamController {
     @Autowired
     private SelectiveGroupService selectiveGroupService;
 
+    @Qualifier("task-executor")
+    @Autowired
+    private AsyncTaskExecutor taskExecutor;
+
+    @Autowired
+    private LockService lockService;
+
+    @Autowired
+    private MarkService markService;
+
+    @Autowired
+    private ExamStudentService studentService;
+
     @Logging(menu = "选做题查询", type = LogType.QUERY)
     @RequestMapping
     public String list(HttpServletRequest request, Model model, @RequestParam String subjectCode) {
@@ -221,6 +241,11 @@ public class SelectiveGroupController extends BaseExamController {
             @RequestParam String subjectCode, @RequestParam Integer selectiveIndex, @RequestParam Integer policy) {
         int examId = getSessionExamId(request);
         selectiveGroupService.updateScorePolicy(examId, subjectCode, selectiveIndex, ScorePolicy.findByValue(policy));
+        List<Integer> studentList = studentService.findIdByExamIdAndSubjectCodeAndSubjectiveStatus(examId, subjectCode,
+                SubjectiveStatus.UNMARK, SubjectiveStatus.MARKED);
+        SubjectiveCalculateThread thread = new SubjectiveCalculateThread(examId, subjectCode, studentList, markService,
+                lockService, questionService, groupService);
+        taskExecutor.submit(thread);
         return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
     }
 

+ 70 - 0
stmms-web/src/main/java/cn/com/qmth/stmms/admin/thread/SubjectiveCalculateThread.java

@@ -0,0 +1,70 @@
+package cn.com.qmth.stmms.admin.thread;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import cn.com.qmth.stmms.biz.exam.service.ExamQuestionService;
+import cn.com.qmth.stmms.biz.exam.service.MarkGroupService;
+import cn.com.qmth.stmms.biz.lock.LockService;
+import cn.com.qmth.stmms.biz.mark.service.MarkService;
+import cn.com.qmth.stmms.common.enums.LockType;
+
+public class SubjectiveCalculateThread implements Runnable {
+
+    protected static Logger log = LoggerFactory.getLogger(SubjectiveCalculateThread.class);
+
+    private MarkService markService;
+
+    private ExamQuestionService questionService;
+
+    private MarkGroupService groupService;
+
+    private LockService lockService;
+
+    private Integer examId;
+
+    private String subjectCode;
+
+    private List<Integer> studentList;
+
+    public SubjectiveCalculateThread(Integer examId, String subjectCode, List<Integer> studentList,
+            MarkService markService, LockService lockService, ExamQuestionService questionService,
+            MarkGroupService groupService) {
+        this.markService = markService;
+        this.lockService = lockService;
+        this.questionService = questionService;
+        this.groupService = groupService;
+        this.examId = examId;
+        this.subjectCode = subjectCode;
+        this.studentList = studentList;
+    }
+
+    @Override
+    public void run() {
+        try {
+            lockService.waitlock(LockType.SCORE_CALCULATE, examId, subjectCode);
+            lockService.waitlock(LockType.EXAM_SUBJECT, examId, subjectCode);
+            log.info("delete question examId=" + examId + " subjectCode=" + subjectCode);
+            // 未分组的题目
+            long unGroupQuestionCount = questionService.countByExamIdAndSubjectAndObjectiveAndGroupNumberIsNull(examId,
+                    subjectCode, false);
+            // 考生整体状态与总分更新
+            long groupCount = groupService.countByExamAndSubject(examId, subjectCode);
+            for (Integer studentId : studentList) {
+                lockService.waitlock(LockType.STUDENT, studentId);
+                markService.checkStudentSubjective(studentId, groupCount, unGroupQuestionCount);
+            }
+        } catch (Exception e) {
+            log.error("delete group error", e);
+        } finally {
+            for (Integer studentId : studentList) {
+                lockService.unlock(LockType.STUDENT, studentId);
+            }
+            lockService.unlock(LockType.EXAM_SUBJECT, examId, subjectCode);
+            lockService.unlock(LockType.SCORE_CALCULATE, examId, subjectCode);
+        }
+    }
+
+}