Browse Source

改造答卷数据记录的存储与查询,改成单条统一存储 单词查询逻辑匹配数据

zhaosongshan 7 months ago
parent
commit
2bb49cde95

+ 2 - 1
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/controller/student/QuestionAnswerController.java

@@ -65,7 +65,8 @@ public class QuestionAnswerController extends BaseApiController {
     public CommonResult<QuestionAnswerVM> select(@PathVariable Integer id) {
         QuestionAnswerVM vm = new QuestionAnswerVM();
         ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer = examPaperQuestionCustomerAnswerService.selectById(id);
-        ExamPaperSubmitItemVM questionAnswerVM = examPaperQuestionCustomerAnswerService.examPaperQuestionCustomerAnswerToVM(examPaperQuestionCustomerAnswer);
+        TextContent textContent = textContentService.selectById(examPaperQuestionCustomerAnswer.getTextContentId());
+        ExamPaperSubmitItemVM questionAnswerVM = examPaperQuestionCustomerAnswerService.examPaperQuestionCustomerAnswerToVM(examPaperQuestionCustomerAnswer, textContent);
         QuestionEditRequestVM questionVM = questionService.getQuestionEditRequestVM(examPaperQuestionCustomerAnswer.getQuestionId());
         vm.setQuestionVM(questionVM);
         vm.setQuestionAnswerVM(questionAnswerVM);

+ 2 - 1
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/service/ExamPaperQuestionCustomerAnswerService.java

@@ -1,6 +1,7 @@
 package vip.xiaonuo.exam.service;
 
 import vip.xiaonuo.exam.domain.ExamPaperQuestionCustomerAnswer;
+import vip.xiaonuo.exam.domain.TextContent;
 import vip.xiaonuo.exam.domain.other.ExamPaperAnswerUpdate;
 import vip.xiaonuo.exam.viewmodel.student.exam.ExamPaperSubmitItemVM;
 import vip.xiaonuo.exam.viewmodel.student.question.answer.QuestionPageStudentRequestVM;
@@ -27,7 +28,7 @@ public interface ExamPaperQuestionCustomerAnswerService extends BaseService<Exam
      * @param qa ExamPaperQuestionCustomerAnswer
      * @return ExamPaperSubmitItemVM
      */
-    ExamPaperSubmitItemVM examPaperQuestionCustomerAnswerToVM(ExamPaperQuestionCustomerAnswer qa);
+    ExamPaperSubmitItemVM examPaperQuestionCustomerAnswerToVM(ExamPaperQuestionCustomerAnswer qa, TextContent textContent);
 
 
     Integer selectAllCount();

+ 14 - 2
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/service/impl/ExamPaperAnswerServiceImpl.java

@@ -1,5 +1,7 @@
 package vip.xiaonuo.exam.service.impl;
 
+import cn.hutool.json.JSONString;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import vip.xiaonuo.auth.core.pojo.SaBaseLoginUser;
 import vip.xiaonuo.exam.domain.*;
@@ -97,8 +99,17 @@ public class ExamPaperAnswerServiceImpl extends BaseServiceImpl<ExamPaperAnswer>
         examPaperAnswerInfo.setExamPaper(examPaper);
         examPaperAnswerInfo.setExamPaperAnswer(examPaperAnswer);
         examPaperAnswerInfo.setExamPaperQuestionCustomerAnswers(examPaperQuestionCustomerAnswers);
-        examPaperQuestionCustomerAnswerService.insertList(examPaperQuestionCustomerAnswers);
         examPaperAnswerMapper.insertSelective(examPaperAnswer);
+        TextContent textContent = new TextContent();
+        String json = JSON.toJSONString(examPaperSubmitVM.getAnswerItems());
+        textContent.setContent(json);
+        textContent.setCreateTime(now);
+        textContentService.insertByFilter(textContent);
+        examPaperQuestionCustomerAnswers.forEach(customerAnswers->{
+            customerAnswers.setTextContentId(textContent.getId());
+            customerAnswers.setExamPaperAnswerId(examPaperAnswer.getId());
+        });
+        examPaperQuestionCustomerAnswerService.insertList(examPaperQuestionCustomerAnswers);
         return examPaperAnswerInfo;
     }
 
@@ -158,8 +169,9 @@ public class ExamPaperAnswerServiceImpl extends BaseServiceImpl<ExamPaperAnswer>
         examPaperSubmitVM.setDoTime(examPaperAnswer.getDoTime());
         examPaperSubmitVM.setScore(ExamUtil.scoreToVM(examPaperAnswer.getUserScore()));
         List<ExamPaperQuestionCustomerAnswer> examPaperQuestionCustomerAnswers = examPaperQuestionCustomerAnswerService.selectListByPaperAnswerId(examPaperAnswer.getId());
+        TextContent textContent = textContentService.selectById(examPaperQuestionCustomerAnswers.get(0).getTextContentId());
         List<ExamPaperSubmitItemVM> examPaperSubmitItemVMS = examPaperQuestionCustomerAnswers.stream()
-                .map(a -> examPaperQuestionCustomerAnswerService.examPaperQuestionCustomerAnswerToVM(a))
+                .map(a -> examPaperQuestionCustomerAnswerService.examPaperQuestionCustomerAnswerToVM(a,textContent))
                 .collect(Collectors.toList());
         examPaperSubmitVM.setAnswerItems(examPaperSubmitItemVMS);
         return examPaperSubmitVM;

+ 24 - 7
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/service/impl/ExamPaperQuestionCustomerAnswerServiceImpl.java

@@ -1,5 +1,6 @@
 package vip.xiaonuo.exam.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import vip.xiaonuo.exam.domain.ExamPaperAnswer;
 import vip.xiaonuo.exam.domain.ExamPaperQuestionCustomerAnswer;
@@ -20,6 +21,7 @@ import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -57,7 +59,8 @@ public class ExamPaperQuestionCustomerAnswerServiceImpl extends BaseServiceImpl<
     }
 
     @Override
-    public ExamPaperSubmitItemVM examPaperQuestionCustomerAnswerToVM(ExamPaperQuestionCustomerAnswer qa) {
+    public ExamPaperSubmitItemVM examPaperQuestionCustomerAnswerToVM(ExamPaperQuestionCustomerAnswer qa, TextContent textContent) {
+        System.out.println("qaqaqaqaqaqa "+qa);
         ExamPaperSubmitItemVM examPaperSubmitItemVM = new ExamPaperSubmitItemVM();
         examPaperSubmitItemVM.setId(qa.getId());
         examPaperSubmitItemVM.setQuestionId(qa.getQuestionId());
@@ -65,7 +68,7 @@ public class ExamPaperQuestionCustomerAnswerServiceImpl extends BaseServiceImpl<
         examPaperSubmitItemVM.setItemOrder(qa.getItemOrder());
         examPaperSubmitItemVM.setQuestionScore(ExamUtil.scoreToVM(qa.getQuestionScore()));
         examPaperSubmitItemVM.setScore(ExamUtil.scoreToVM(qa.getCustomerScore()));
-        setSpecialToVM(examPaperSubmitItemVM, qa);
+        setSpecialToVM(examPaperSubmitItemVM, qa, textContent);
         return examPaperSubmitItemVM;
     }
 
@@ -91,22 +94,36 @@ public class ExamPaperQuestionCustomerAnswerServiceImpl extends BaseServiceImpl<
         return examPaperQuestionCustomerAnswerMapper.updateScore(examPaperAnswerUpdates);
     }
 
-    private void setSpecialToVM(ExamPaperSubmitItemVM examPaperSubmitItemVM, ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer) {
+    private void setSpecialToVM(ExamPaperSubmitItemVM examPaperSubmitItemVM, ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer, TextContent textContent) {
         QuestionTypeEnum questionTypeEnum = QuestionTypeEnum.fromCode(examPaperQuestionCustomerAnswer.getQuestionType());
+        List<JSONObject> content = JsonUtil.toJsonListObject(textContent.getContent(), JSONObject.class);
+        int questionId = examPaperQuestionCustomerAnswer.getQuestionId();
         switch (questionTypeEnum) {
             case MultipleChoice:
                 examPaperSubmitItemVM.setContent(examPaperQuestionCustomerAnswer.getAnswer());
                 examPaperSubmitItemVM.setContentArray(ExamUtil.contentToArray(examPaperQuestionCustomerAnswer.getAnswer()));
                 break;
             case GapFilling:
-                TextContent textContent = textContentService.selectById(examPaperQuestionCustomerAnswer.getTextContentId());
-                List<String> correctAnswer = JsonUtil.toJsonListObject(textContent.getContent(), String.class);
+                List<String> correctAnswer = new ArrayList<String>();
+                assert content != null;
+                for(JSONObject d : content){
+                    if(d.getIntValue("questionId") == questionId){
+                        correctAnswer = d.getJSONArray("contentArray").toJavaList(String.class);
+                        break;
+                    }
+                }
                 examPaperSubmitItemVM.setContentArray(correctAnswer);
                 break;
             default:
                 if (QuestionTypeEnum.needSaveTextContent(examPaperQuestionCustomerAnswer.getQuestionType())) {
-                    TextContent content = textContentService.selectById(examPaperQuestionCustomerAnswer.getTextContentId());
-                    examPaperSubmitItemVM.setContent(content.getContent());
+                    String contentAnswer = "";
+                    for(JSONObject d : content){
+                        if(d.getIntValue("questionId") == questionId){
+                            contentAnswer = d.getString("content");
+                            break;
+                        }
+                    }
+                    examPaperSubmitItemVM.setContent(contentAnswer);
                 } else {
                     examPaperSubmitItemVM.setContent(examPaperQuestionCustomerAnswer.getAnswer());
                 }