1
0
ting.yin 2 лет назад
Родитель
Сommit
451b4a488f

+ 41 - 2
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/exam/service/impl/ExamQuestionServiceImpl.java

@@ -3,11 +3,14 @@ package cn.com.qmth.stmms.biz.exam.service.impl;
 import cn.com.qmth.stmms.biz.common.BaseQueryService;
 import cn.com.qmth.stmms.biz.exam.dao.ExamQuestionDao;
 import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
+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.ExamService;
+import cn.com.qmth.stmms.biz.exam.service.SelectiveGroupService;
 import cn.com.qmth.stmms.biz.exam.service.query.ExamQuestionSearchQuery;
 import cn.com.qmth.stmms.common.enums.ObjectivePolicy;
 import cn.com.qmth.stmms.common.enums.ObjectiveStatus;
+import cn.com.qmth.stmms.common.utils.BigDecimalUtils;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -34,6 +37,9 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
     @Autowired
     private ExamService examService;
 
+    @Autowired
+    private SelectiveGroupService selectiveGroupService;
+
     @Transactional
     @Override
     public ExamQuestion save(ExamQuestion question) {
@@ -266,8 +272,41 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
 
     @Override
     public double sumTotalScore(int examId, String subjectCode, boolean objective) {
-        Double score = questionDao.sumTotalScore(examId, subjectCode, objective);
-        return score != null ? score.doubleValue() : 0d;
+        if (objective) {
+            Double score = questionDao.sumTotalScore(examId, subjectCode, objective);
+            return score != null ? score.doubleValue() : 0d;
+        } else {
+            List<SelectiveGroup> selectiveGroups = selectiveGroupService
+                    .findByExamIdAndSubjectCode(examId, subjectCode);
+            if (!selectiveGroups.isEmpty()) {
+                double totalScore = 0;
+                Map<Integer, SelectiveGroup> map = new HashMap<Integer, SelectiveGroup>();
+                for (SelectiveGroup selectiveGroup : selectiveGroups) {
+                    map.put(selectiveGroup.getMainNumber(), selectiveGroup);
+                }
+                List<ExamQuestion> questions = this.findByExamAndSubjectAndObjective(examId, subjectCode, false);
+                for (ExamQuestion examQuestion : questions) {
+                    if (map.containsKey(examQuestion.getMainNumber())) {
+                        examQuestion.setSelective(true);
+                        examQuestion.setSelectiveIndex(map.get(examQuestion.getMainNumber()).getSelectiveIndex());
+                    } else {
+                        // 非选做题总分
+                        totalScore = BigDecimalUtils.add(totalScore, examQuestion.getTotalScore());
+                    }
+                }
+                List<SelectiveGroup> indexGroup = selectiveGroupService.findIndexByExamIdAndSubjectCode(examId,
+                        subjectCode);
+                for (SelectiveGroup selectiveGroup : indexGroup) {
+                    // 选做题分组总分
+                    totalScore = BigDecimalUtils.add(totalScore,
+                            selectiveGroup.getPartScore() * selectiveGroup.getSelectiveCount());
+                }
+                return totalScore;
+            } else {
+                Double score = questionDao.sumTotalScore(examId, subjectCode, objective);
+                return score != null ? score.doubleValue() : 0d;
+            }
+        }
     }
 
     @Override

+ 27 - 29
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/MarkGroupController.java

@@ -443,7 +443,7 @@ public class MarkGroupController extends BaseExamController {
                 if (questionIds != null && reset.booleanValue()) {
                     // advance update
                     if (!checkSelective(examId, subjectCode, questionIds)) {
-                        addMessage(redirectAttributes, "选做题和非选做题不能在一组");
+                        addMessage(redirectAttributes, "选做题不合法!选做题和非选做题不能在一组,选做题不能跨组或垮区设置");
                         redirectAttributes.addAttribute("subjectCode", subjectCode);
                         redirectAttributes.addAttribute("number", number);
                         return "redirect:/admin/exam/group/edit-simple";
@@ -523,43 +523,41 @@ public class MarkGroupController extends BaseExamController {
     }
 
     private boolean checkSelective(Integer examId, String subjectCode, Integer[] questionIds) {
-        Set<Integer> selectiveMainNumbers = new HashSet<Integer>();
-        Set<Integer> mainNumbers = new HashSet<Integer>();
+        // 无选做题分组
         List<SelectiveGroup> list = selectiveGroupService.findByExamIdAndSubjectCode(examId, subjectCode);
-        for (SelectiveGroup selectiveGroup : list) {
-            selectiveMainNumbers.add(selectiveGroup.getMainNumber());
+        if (list.size() == 0) {
+            return true;
         }
         List<ExamQuestion> selectives = new ArrayList<ExamQuestion>();
+        Set<Integer> selectiveIndexs = new HashSet<Integer>();
+        Set<Integer> selectiveParts = new HashSet<Integer>();
         for (Integer questionId : questionIds) {
             ExamQuestion question = questionService.findById(questionId);
-            if (selectiveMainNumbers.contains(question.getMainNumber())) {
-                selectives.add(question);
+            for (SelectiveGroup selectiveGroup : list) {
+                if (selectiveGroup.getMainNumber().equals(question.getMainNumber())) {
+                    selectives.add(question);
+                    selectiveIndexs.add(selectiveGroup.getSelectiveIndex());
+                    selectiveParts.add(selectiveGroup.getSelectivePart());
+                }
             }
-            mainNumbers.add(question.getMainNumber());
-        }
-        // 一个分组内只能有一个选做题大题
-        // if (selectives.size() > 0 && mainNumbers.size() > 1) {
-        // return false;
-        // }
-        // 一个选做题大题内的小题必须在一个分组
-        // if (selectives.size() > 0) {
-        // for (Integer mainNumber : mainNumbers) {
-        // Long count =
-        // questionService.countByExamAndSubjectAndObjectiveAndMainNumber(examId,
-        // subjectCode, false,
-        // mainNumber);
-        // if (count != selectives.size()) {
-        // return false;
-        // }
-        // }
-        // }
-        if (questionIds.length == selectives.size()) {
-            return true;
         }
+        // 无选做题
         if (selectives.size() == 0) {
             return true;
         }
-        return false;
+        // 选做题和非选做题一组
+        if (selectives.size() != questionIds.length) {
+            return false;
+        }
+        // 一个评卷分组内只能有一个选做题分组的题
+        if (selectiveIndexs.size() > 1) {
+            return false;
+        }
+        // 一个评卷分组内只能有一个选做题分区的题
+        if (selectiveParts.size() > 1) {
+            return false;
+        }
+        return true;
     }
 
     @Logging(menu = "新增大题", type = LogType.ADD)
@@ -587,7 +585,7 @@ public class MarkGroupController extends BaseExamController {
             redirectAttributes.addAttribute("subjectCode", subjectCode);
             return "redirect:/admin/exam/group/add";
         } else if (!checkSelective(examId, subjectCode, questionIds)) {
-            addMessage(redirectAttributes, "选做题和非选做题不能在一组");
+            addMessage(redirectAttributes, "选做题不合法!选做题和非选做题不能在一组,选做题不能跨组或垮区设置");
             redirectAttributes.addAttribute("subjectCode", subjectCode);
             return "redirect:/admin/exam/group/add";
         } else {

+ 4 - 34
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/SelectiveGroupController.java

@@ -36,7 +36,6 @@ import cn.com.qmth.stmms.biz.exam.service.SelectiveGroupService;
 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.utils.BigDecimalUtils;
 
 @Controller("selectiveGroupController")
 @RequestMapping("/admin/exam/selectiveGroup")
@@ -176,7 +175,8 @@ public class SelectiveGroupController extends BaseExamController {
             }
             selectiveGroupService.save(list);
         }
-        calculate(examId, subjectCode);
+        subjectService.updateScore(examId, subjectCode, false,
+                questionService.sumTotalScore(examId, subjectCode, false));
         return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
     }
 
@@ -209,39 +209,9 @@ public class SelectiveGroupController extends BaseExamController {
             return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
         }
         selectiveGroupService.deleteByExamIdAndSubjectCodeAndSelectiveIndex(examId, subjectCode, selectiveIndex);
-        calculate(examId, subjectCode);
+        subjectService.updateScore(examId, subjectCode, false,
+                questionService.sumTotalScore(examId, subjectCode, false));
         return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
     }
 
-    private void calculate(int examId, String subjectCode) {
-        List<SelectiveGroup> selectiveGroups = selectiveGroupService.findByExamIdAndSubjectCode(examId, subjectCode);
-        if (!selectiveGroups.isEmpty()) {
-            double totalScore = 0;
-            Map<Integer, SelectiveGroup> map = new HashMap<Integer, SelectiveGroup>();
-            for (SelectiveGroup selectiveGroup : selectiveGroups) {
-                map.put(selectiveGroup.getMainNumber(), selectiveGroup);
-            }
-            List<ExamQuestion> questions = questionService.findByExamAndSubjectAndObjective(examId, subjectCode, false);
-            for (ExamQuestion examQuestion : questions) {
-                if (map.containsKey(examQuestion.getMainNumber())) {
-                    examQuestion.setSelective(true);
-                    examQuestion.setSelectiveIndex(map.get(examQuestion.getMainNumber()).getSelectiveIndex());
-                } else {
-                    // 非选做题总分
-                    totalScore = BigDecimalUtils.add(totalScore, examQuestion.getTotalScore());
-                }
-            }
-            List<SelectiveGroup> indexGroup = selectiveGroupService
-                    .findIndexByExamIdAndSubjectCode(examId, subjectCode);
-            for (SelectiveGroup selectiveGroup : indexGroup) {
-                // 选做题分组总分
-                totalScore = BigDecimalUtils.add(totalScore,
-                        selectiveGroup.getPartScore() * selectiveGroup.getSelectiveCount());
-            }
-            subjectService.updateScore(examId, subjectCode, false, totalScore);
-        } else {
-            subjectService.updateScore(examId, subjectCode, false,
-                    questionService.sumTotalScore(examId, subjectCode, false));
-        }
-    }
 }