Kaynağa Gözat

format code

deason 5 yıl önce
ebeveyn
işleme
38ca838b93

+ 42 - 26
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/PaperDetailUnitServiceImpl.java

@@ -13,6 +13,7 @@ import cn.com.qmth.examcloud.core.questions.service.PaperDetailUnitService;
 import cn.com.qmth.examcloud.core.questions.service.PaperService;
 import cn.com.qmth.examcloud.core.questions.service.QuesService;
 import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperDetailUnitExp;
+import cn.com.qmth.examcloud.core.questions.service.cache.QuestionCache;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import org.bson.types.ObjectId;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -50,6 +51,9 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
     @Autowired
     MongoTemplate mongoTemplate;
 
+    @Autowired
+    QuestionCache questionCache;
+
     @Autowired
     RedisClient redisClient;
 
@@ -78,68 +82,80 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
 
     /**
      * 保存小题
-     *
-     * @param pduExp
-     * @return
      */
-    public PaperDetailUnit savePaperDetailUnit(PaperDetailUnitExp pduExp, User user) {
-        PaperDetailUnit oldPdu = Model.of(paperDetailUnitRepo.findById(pduExp.getId()));
-        if (oldPdu.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
-            if (pduExp.getQuestion().getId().equals(oldPdu.getQuestion().getId())) {
+    public PaperDetailUnit savePaperDetailUnit(PaperDetailUnitExp updateUnit, User user) {
+        PaperDetailUnit baseUnit = Model.of(paperDetailUnitRepo.findById(updateUnit.getId()));
+        Question baseQuestion = baseUnit.getQuestion();
+        Question updateQuestion = updateUnit.getQuestion();
+
+        if (baseUnit.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
+            if (updateQuestion.getId().equals(baseQuestion.getId())) {
                 // 更新对象为套题本身
-                oldPdu.setQuestion(quesService.saveQues(pduExp.getQuestion()));
+                baseUnit.setQuestion(quesService.saveQues(updateQuestion));
             } else {
-                List<Double> subScoreList = oldPdu.getSubScoreList();
-                int size = oldPdu.getQuestion().getSubQuestions().size();
+                List<Double> subScoreList = baseUnit.getSubScoreList();
+                int size = baseQuestion.getSubQuestions().size();
                 boolean match = false;
+
                 // 判断更新的对象是哪个子题
                 for (int index = 1; index <= size; index++) {
                     // 检查子题分数,确保没有错误数据
                     if (subScoreList.size() < index) {
                         subScoreList.add(0d);
                     }
-                    Question sub = oldPdu.getQuestion().getSubQuestions().get(index - 1);
-                    if (pduExp.getQuestion().getId().equals(sub.getId())) {
+
+                    Question sub = baseQuestion.getSubQuestions().get(index - 1);
+                    if (updateQuestion.getId().equals(sub.getId())) {
                         // 匹配到子题
-                        subScoreList.set(index - 1, pduExp.getScore());
-                        oldPdu.getQuestion().getSubQuestions().set(index - 1, pduExp.getQuestion());
+                        subScoreList.set(index - 1, updateUnit.getScore());
+                        baseQuestion.getSubQuestions().set(index - 1, updateQuestion);
+
                         //重新计算套题的难度,公开度
                         boolean publicity = false;
                         double totalSum = 0d;
                         double totalDou = 0d;
-                        for (int i = 0; i < oldPdu.getQuestion().getSubQuestions().size(); i++) {
-                            Question subQuestion = oldPdu.getQuestion().getSubQuestions().get(i);
+                        for (int i = 0; i < baseQuestion.getSubQuestions().size(); i++) {
+                            Question subQuestion = baseQuestion.getSubQuestions().get(i);
                             //设置公开度
                             if (subQuestion.getPublicity()) {
                                 publicity = true;
                             }
+
                             if (subQuestion.getDifficultyDegree() == null) {
                                 subQuestion.setDifficultyDegree(0.5);
                             }
+
                             totalSum = subQuestion.getDifficultyDegree() * subScoreList.get(i) + totalSum;
                             totalDou = subScoreList.get(i) + totalDou;
                         }
+
                         BigDecimal b = new BigDecimal(totalSum / totalDou);
                         Double difficulty = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
-                        oldPdu.getQuestion().setDifficultyDegree(difficulty);
-                        oldPdu.getQuestion().setPublicity(publicity);
+                        baseQuestion.setDifficultyDegree(difficulty);
+                        baseQuestion.setPublicity(publicity);
                         match = true;
                     }
                 }
+
                 if (match) {
-                    oldPdu.setQuestion(quesService.saveQues(oldPdu.getQuestion()));
+                    baseUnit.setQuestion(quesService.saveQues(baseQuestion));
                 }
+
                 // 更新套题unit当前总分与子题分数
-                oldPdu.setSubScoreList(subScoreList);
+                baseUnit.setSubScoreList(subScoreList);
             }
         } else {
-            oldPdu.setQuestion(quesService.saveQues(pduExp.getQuestion()));
-            oldPdu.setScore(pduExp.getScore());
+            baseUnit.setQuestion(quesService.saveQues(updateQuestion));
+            baseUnit.setScore(updateUnit.getScore());
         }
-        // 同时要跟新小题里面的Qustion对象
-        oldPdu = paperDetailUnitRepo.save(oldPdu);
-        paperService.formatPaper(oldPdu.getPaper(), user);
-        return oldPdu;
+
+        // 同时要跟新小题里面的Question对象
+        paperDetailUnitRepo.save(baseUnit);
+
+        Paper paper = baseUnit.getPaper();
+        paperService.formatPaper(paper, user);
+
+        return baseUnit;
     }
 
     /**

+ 0 - 6
examcloud-core-questions-starter/pom.xml

@@ -81,12 +81,6 @@
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
-                <configuration>
-                    <jvmArguments>
-                        -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9990
-                    </jvmArguments>
-                    <fork>true</fork>
-                </configuration>
             </plugin>
         </plugins>
     </build>