From 394a460804ab0dee5f2afe95583e2cf38cda6a34 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期二, 04 六月 2024 17:06:18 +0800
Subject: [PATCH] 试卷类修改

---
 src/main/java/com/ycl/jxkg/service/impl/QuestionServiceImpl.java |   56 ++++++++++++++++++++++----------------------------------
 1 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/src/main/java/com/ycl/jxkg/service/impl/QuestionServiceImpl.java b/src/main/java/com/ycl/jxkg/service/impl/QuestionServiceImpl.java
index 076b5ed..7b83e10 100644
--- a/src/main/java/com/ycl/jxkg/service/impl/QuestionServiceImpl.java
+++ b/src/main/java/com/ycl/jxkg/service/impl/QuestionServiceImpl.java
@@ -1,12 +1,14 @@
 package com.ycl.jxkg.service.impl;
 
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ycl.jxkg.domain.other.KeyValue;
-import com.ycl.jxkg.domain.Question;
-import com.ycl.jxkg.domain.TextContent;
+import com.ycl.jxkg.domain.entity.Question;
+import com.ycl.jxkg.domain.entity.TextContent;
 import com.ycl.jxkg.domain.enums.QuestionStatusEnum;
 import com.ycl.jxkg.domain.enums.QuestionTypeEnum;
 import com.ycl.jxkg.domain.question.QuestionItemObject;
 import com.ycl.jxkg.domain.question.QuestionObject;
+import com.ycl.jxkg.domain.vo.admin.question.QuestionResponseVO;
 import com.ycl.jxkg.mapper.QuestionMapper;
 import com.ycl.jxkg.service.QuestionService;
 import com.ycl.jxkg.service.SubjectService;
@@ -14,13 +16,13 @@
 import com.ycl.jxkg.utils.DateTimeUtil;
 import com.ycl.jxkg.utils.JsonUtil;
 import com.ycl.jxkg.utils.ExamUtil;
-import com.ycl.jxkg.vo.admin.question.QuestionEditItemVO;
-import com.ycl.jxkg.vo.admin.question.QuestionEditRequestVO;
-import com.ycl.jxkg.vo.admin.question.QuestionPageRequestVO;
+import com.ycl.jxkg.domain.vo.admin.question.QuestionEditItemVO;
+import com.ycl.jxkg.domain.vo.admin.question.QuestionEditRequestVO;
+import com.ycl.jxkg.domain.vo.admin.question.QuestionPageRequestVO;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import lombok.RequiredArgsConstructor;
 import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -29,22 +31,16 @@
 import java.util.stream.Collectors;
 
 @Service
-public class QuestionServiceImpl extends BaseServiceImpl<Question> implements QuestionService {
+@RequiredArgsConstructor
+public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements QuestionService {
 
     private final QuestionMapper questionMapper;
     private final TextContentService textContentService;
     private final SubjectService subjectService;
 
-    @Autowired
-    public QuestionServiceImpl(QuestionMapper questionMapper, TextContentService textContentService, SubjectService subjectService) {
-        super(questionMapper);
-        this.textContentService = textContentService;
-        this.questionMapper = questionMapper;
-        this.subjectService = subjectService;
-    }
 
     @Override
-    public PageInfo<Question> page(QuestionPageRequestVO requestVM) {
+    public PageInfo<QuestionResponseVO> page(QuestionPageRequestVO requestVM) {
         return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() ->
                 questionMapper.page(requestVM)
         );
@@ -58,10 +54,7 @@
         Integer gradeLevel = subjectService.levelBySubjectId(model.getSubjectId());
 
         //棰樺共銆佽В鏋愩�侀�夐」绛� 鎻掑叆
-        TextContent infoTextContent = new TextContent();
-        infoTextContent.setCreateTime(now);
-        setQuestionInfoFromVM(infoTextContent, model);
-        textContentService.insertByFilter(infoTextContent);
+        String questionObject = setQuestionInfoFromVM(model);
 
         Question question = new Question();
         question.setSubjectId(model.getSubjectId());
@@ -72,10 +65,9 @@
         question.setCorrectFromVM(model.getCorrect(), model.getCorrectArray());
         question.setScore(ExamUtil.scoreFromVM(model.getScore()));
         question.setDifficult(model.getDifficult());
-        question.setInfoTextContentId(infoTextContent.getId());
+        question.setContent(questionObject);
         question.setCreateUser(userId);
-        question.setDeleted(false);
-        questionMapper.insertSelective(question);
+        questionMapper.insert(question);
         return question;
     }
 
@@ -83,34 +75,30 @@
     @Transactional
     public Question updateFullQuestion(QuestionEditRequestVO model) {
         Integer gradeLevel = subjectService.levelBySubjectId(model.getSubjectId());
-        Question question = questionMapper.selectByPrimaryKey(model.getId());
+        Question question = questionMapper.selectById(model.getId());
         question.setSubjectId(model.getSubjectId());
         question.setGradeLevel(gradeLevel);
         question.setScore(ExamUtil.scoreFromVM(model.getScore()));
         question.setDifficult(model.getDifficult());
         question.setCorrectFromVM(model.getCorrect(), model.getCorrectArray());
-        questionMapper.updateByPrimaryKeySelective(question);
-
         //棰樺共銆佽В鏋愩�侀�夐」绛� 鏇存柊
-        TextContent infoTextContent = textContentService.selectById(question.getInfoTextContentId());
-        setQuestionInfoFromVM(infoTextContent, model);
-        textContentService.updateByIdFilter(infoTextContent);
-
+        String questionObject = setQuestionInfoFromVM(model);
+        question.setContent(questionObject);
+        questionMapper.updateById(question);
         return question;
     }
 
     @Override
     public QuestionEditRequestVO getQuestionEditRequestVM(Integer questionId) {
         //棰樼洰鏄犲皠
-        Question question = questionMapper.selectByPrimaryKey(questionId);
+        Question question = questionMapper.selectById(questionId);
         return getQuestionEditRequestVM(question);
     }
 
     @Override
     public QuestionEditRequestVO getQuestionEditRequestVM(Question question) {
         //棰樼洰鏄犲皠
-        TextContent questionInfoTextContent = textContentService.selectById(question.getInfoTextContentId());
-        QuestionObject questionObject = JsonUtil.toJsonObject(questionInfoTextContent.getContent(), QuestionObject.class);
+        QuestionObject questionObject = JsonUtil.toJsonObject(question.getContent(), QuestionObject.class);
         QuestionEditRequestVO questionEditRequestVO = new QuestionEditRequestVO();
         BeanUtils.copyProperties(question, questionEditRequestVO);
         questionEditRequestVO.setTitle(questionObject.getTitleContent());
@@ -152,7 +140,7 @@
         return questionEditRequestVO;
     }
 
-    public void setQuestionInfoFromVM(TextContent infoTextContent, QuestionEditRequestVO model) {
+    public String setQuestionInfoFromVM(QuestionEditRequestVO model) {
         List<QuestionItemObject> itemObjects = model.getItems().stream().map(i ->
                 {
                     QuestionItemObject item = new QuestionItemObject();
@@ -168,7 +156,7 @@
         questionObject.setAnalyze(model.getAnalyze());
         questionObject.setTitleContent(model.getTitle());
         questionObject.setCorrect(model.getCorrect());
-        infoTextContent.setContent(JsonUtil.toJsonStr(questionObject));
+        return JsonUtil.toJsonStr(questionObject);
     }
 
     @Override

--
Gitblit v1.8.0