From 6d05f0dc6e96ead24bb7e035e16f18031b1ede78 Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期五, 17 五月 2024 11:35:26 +0800
Subject: [PATCH] feat:看题新增查询条件

---
 src/main/resources/mapper/QuestionMapper.xml                                                       |    1 
 src/main/java/com/mindskip/xzs/service/impl/QuestionServiceImpl.java                               |    2 
 src/main/java/com/mindskip/xzs/controller/student/QuestionAnswerController.java                    |   36 ++----------------
 src/main/java/com/mindskip/xzs/service/impl/ExamPaperQuestionCustomerAnswerServiceImpl.java        |   10 +++-
 src/main/java/com/mindskip/xzs/repository/ExamPaperQuestionCustomerAnswerMapper.java               |    3 +
 src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java                              |    3 +
 src/main/java/com/mindskip/xzs/service/ExamPaperQuestionCustomerAnswerService.java                 |    3 +
 src/main/java/com/mindskip/xzs/viewmodel/student/question/answer/QuestionPageStudentRequestVM.java |   10 +++++
 src/main/resources/mapper/ExamPaperQuestionCustomerAnswerMapper.xml                                |   25 ++++++++----
 9 files changed, 47 insertions(+), 46 deletions(-)

diff --git a/src/main/java/com/mindskip/xzs/controller/student/QuestionAnswerController.java b/src/main/java/com/mindskip/xzs/controller/student/QuestionAnswerController.java
index 8e13452..881fc36 100644
--- a/src/main/java/com/mindskip/xzs/controller/student/QuestionAnswerController.java
+++ b/src/main/java/com/mindskip/xzs/controller/student/QuestionAnswerController.java
@@ -1,27 +1,17 @@
 package com.mindskip.xzs.controller.student;
 
+import com.github.pagehelper.PageInfo;
 import com.mindskip.xzs.base.BaseApiController;
 import com.mindskip.xzs.base.RestResponse;
-import com.mindskip.xzs.domain.*;
-import com.mindskip.xzs.domain.question.QuestionObject;
+import com.mindskip.xzs.domain.ExamPaperQuestionCustomerAnswer;
 import com.mindskip.xzs.service.*;
-import com.mindskip.xzs.utility.DateTimeUtil;
-import com.mindskip.xzs.utility.HtmlUtil;
-import com.mindskip.xzs.utility.JsonUtil;
-import com.mindskip.xzs.utility.PageInfoHelper;
 import com.mindskip.xzs.viewmodel.admin.question.ExamQuestionVO;
-import com.mindskip.xzs.viewmodel.admin.question.QuestionEditRequestVM;
 import com.mindskip.xzs.viewmodel.student.exam.ExamPaperSubmitItemVM;
-import com.mindskip.xzs.viewmodel.student.question.answer.QuestionAnswerVM;
 import com.mindskip.xzs.viewmodel.student.question.answer.QuestionAnswerVO;
 import com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentRequestVM;
 import com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentResponseVM;
-import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-
-import java.util.List;
-import java.util.stream.Collectors;
 
 @RestController("StudentQuestionAnswerController")
 @RequestMapping(value = "/api/student/question/answer")
@@ -45,26 +35,8 @@
     @RequestMapping(value = "/page", method = RequestMethod.POST)
     public RestResponse<PageInfo<QuestionPageStudentResponseVM>> pageList(@RequestBody QuestionPageStudentRequestVM model) {
         model.setCreateUser(getCurrentUser().getId());
-        PageInfo<ExamPaperQuestionCustomerAnswer> pageInfo = examPaperQuestionCustomerAnswerService.studentPage(model);
-        PageInfo<QuestionPageStudentResponseVM> page = PageInfoHelper.copyMap(pageInfo, q -> {
-//            Subject subject = subjectService.selectById(q.getSubjectId());
-            Integer[] ids = questionSubjectService.getQuestion(q.getQuestionId())
-                    .stream().map(QuestionSubject::getSubjectId).toArray(Integer[]::new);
-            String name = "";
-            if (ids.length > 0) {
-                name = subjectService.selectByIds(ids)
-                        .stream().map(Subject::getName).collect(Collectors.joining(","));
-            }
-            QuestionPageStudentResponseVM vm = modelMapper.map(q, QuestionPageStudentResponseVM.class);
-            vm.setCreateTime(DateTimeUtil.dateFormat(q.getCreateTime()));
-            TextContent textContent = textContentService.selectById(q.getQuestionTextContentId());
-            QuestionObject questionObject = JsonUtil.toJsonObject(textContent.getContent(), QuestionObject.class);
-            String clearHtml = HtmlUtil.clear(questionObject.getTitleContent());
-            vm.setShortTitle(clearHtml);
-            vm.setSubjectName(name);
-            return vm;
-        });
-        return RestResponse.ok(page);
+        PageInfo<QuestionPageStudentResponseVM> pageInfo = examPaperQuestionCustomerAnswerService.studentPage(model);
+        return RestResponse.ok(pageInfo);
     }
 
 
diff --git a/src/main/java/com/mindskip/xzs/repository/ExamPaperQuestionCustomerAnswerMapper.java b/src/main/java/com/mindskip/xzs/repository/ExamPaperQuestionCustomerAnswerMapper.java
index 2b4effe..6cf81c5 100644
--- a/src/main/java/com/mindskip/xzs/repository/ExamPaperQuestionCustomerAnswerMapper.java
+++ b/src/main/java/com/mindskip/xzs/repository/ExamPaperQuestionCustomerAnswerMapper.java
@@ -4,6 +4,7 @@
 import com.mindskip.xzs.domain.other.ExamPaperAnswerUpdate;
 import com.mindskip.xzs.domain.other.KeyValue;
 import com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentRequestVM;
+import com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentResponseVM;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -15,7 +16,7 @@
 
     List<ExamPaperQuestionCustomerAnswer> selectListByPaperAnswerId(Integer id);
 
-    List<ExamPaperQuestionCustomerAnswer> studentPage(QuestionPageStudentRequestVM requestVM);
+    List<QuestionPageStudentResponseVM> studentPage(QuestionPageStudentRequestVM requestVM);
 
     int insertList(List<ExamPaperQuestionCustomerAnswer> list);
 
diff --git a/src/main/java/com/mindskip/xzs/service/ExamPaperQuestionCustomerAnswerService.java b/src/main/java/com/mindskip/xzs/service/ExamPaperQuestionCustomerAnswerService.java
index 375c198..27cc83e 100644
--- a/src/main/java/com/mindskip/xzs/service/ExamPaperQuestionCustomerAnswerService.java
+++ b/src/main/java/com/mindskip/xzs/service/ExamPaperQuestionCustomerAnswerService.java
@@ -5,12 +5,13 @@
 import com.mindskip.xzs.viewmodel.student.exam.ExamPaperSubmitItemVM;
 import com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentRequestVM;
 import com.github.pagehelper.PageInfo;
+import com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentResponseVM;
 
 import java.util.List;
 
 public interface ExamPaperQuestionCustomerAnswerService extends BaseService<ExamPaperQuestionCustomerAnswer> {
 
-    PageInfo<ExamPaperQuestionCustomerAnswer> studentPage(QuestionPageStudentRequestVM requestVM);
+    PageInfo<QuestionPageStudentResponseVM> studentPage(QuestionPageStudentRequestVM requestVM);
 
     List<ExamPaperQuestionCustomerAnswer> selectListByPaperAnswerId(Integer id);
 
diff --git a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperQuestionCustomerAnswerServiceImpl.java b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperQuestionCustomerAnswerServiceImpl.java
index 06c9422..73cb064 100644
--- a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperQuestionCustomerAnswerServiceImpl.java
+++ b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperQuestionCustomerAnswerServiceImpl.java
@@ -10,11 +10,13 @@
 import com.mindskip.xzs.service.TextContentService;
 import com.mindskip.xzs.utility.DateTimeUtil;
 import com.mindskip.xzs.utility.ExamUtil;
+import com.mindskip.xzs.utility.HtmlUtil;
 import com.mindskip.xzs.utility.JsonUtil;
 import com.mindskip.xzs.viewmodel.student.exam.ExamPaperSubmitItemVM;
 import com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentRequestVM;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentResponseVM;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -37,9 +39,11 @@
 
 
     @Override
-    public PageInfo<ExamPaperQuestionCustomerAnswer> studentPage(QuestionPageStudentRequestVM requestVM) {
-        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() ->
-                examPaperQuestionCustomerAnswerMapper.studentPage(requestVM)
+    public PageInfo<QuestionPageStudentResponseVM> studentPage(QuestionPageStudentRequestVM requestVM) {
+        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize()).doSelectPageInfo(() ->
+                examPaperQuestionCustomerAnswerMapper.studentPage(requestVM).stream().peek(
+                        q -> q.setShortTitle(HtmlUtil.clear(q.getShortTitle()))
+                ).collect(Collectors.toList())
         );
     }
 
diff --git a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java
index ef9e53f..f0d9dc0 100644
--- a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java
+++ b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java
@@ -161,6 +161,9 @@
                 .flatMap(t -> t.getQuestionItems().stream()
                         .map(q -> q.getId()))
                 .collect(Collectors.toList());
+        if (ObjectUtils.isEmpty(questionIds)) {
+            throw new RuntimeException("璇ヨ瘯鍗锋病鏈夐鐩�");
+        }
         List<Question> questions = questionMapper.selectByIds(questionIds);
         //鍗曢�夋暟閲�
         Integer singleChoice = questions.stream().filter(e -> e.getQuestionType() == 1).collect(Collectors.toList()).size();
diff --git a/src/main/java/com/mindskip/xzs/service/impl/QuestionServiceImpl.java b/src/main/java/com/mindskip/xzs/service/impl/QuestionServiceImpl.java
index b3bee77..bdb28c9 100644
--- a/src/main/java/com/mindskip/xzs/service/impl/QuestionServiceImpl.java
+++ b/src/main/java/com/mindskip/xzs/service/impl/QuestionServiceImpl.java
@@ -265,7 +265,7 @@
 
     @Override
     public PageInfo<QuestionPageStudentResponseVM> selectQuestion(QuestionPageStudentRequestVM model) {
-        return PageHelper.startPage(model.getPageIndex(), model.getPageSize(), "id desc").doSelectPageInfo(() ->
+        return PageHelper.startPage(model.getPageIndex(), model.getPageSize()).doSelectPageInfo(() ->
                 questionMapper.selectQuestion(model).stream().peek(
                         q -> q.setShortTitle(HtmlUtil.clear(q.getShortTitle()))
                 ).collect(Collectors.toList())
diff --git a/src/main/java/com/mindskip/xzs/viewmodel/student/question/answer/QuestionPageStudentRequestVM.java b/src/main/java/com/mindskip/xzs/viewmodel/student/question/answer/QuestionPageStudentRequestVM.java
index 174b9bd..428b1cc 100644
--- a/src/main/java/com/mindskip/xzs/viewmodel/student/question/answer/QuestionPageStudentRequestVM.java
+++ b/src/main/java/com/mindskip/xzs/viewmodel/student/question/answer/QuestionPageStudentRequestVM.java
@@ -7,6 +7,16 @@
 
     private String subjectName;
 
+    private String shortTitle;
+
+    public String getShortTitle() {
+        return shortTitle;
+    }
+
+    public void setShortTitle(String shortTitle) {
+        this.shortTitle = shortTitle;
+    }
+
     public String getSubjectName() {
         return subjectName;
     }
diff --git a/src/main/resources/mapper/ExamPaperQuestionCustomerAnswerMapper.xml b/src/main/resources/mapper/ExamPaperQuestionCustomerAnswerMapper.xml
index 4552fb3..6eb21eb 100644
--- a/src/main/resources/mapper/ExamPaperQuestionCustomerAnswerMapper.xml
+++ b/src/main/resources/mapper/ExamPaperQuestionCustomerAnswerMapper.xml
@@ -228,14 +228,23 @@
   </select>
 
 
-  <select id="studentPage" resultMap="BaseResultMap" parameterType="com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentRequestVM">
-    SELECT
-    <include refid="Base_Column_List"/>
-    FROM t_exam_paper_question_customer_answer
-    <where>
-      and do_right=FALSE
-      and create_user=#{createUser}
-    </where>
+  <select id="studentPage" resultType="com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentResponseVM" parameterType="com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentRequestVM">
+    select a.id,
+           a.question_type,
+           JSON_VALUE(d.content, '$.titleContent') as shortTitle,
+           GROUP_CONCAT(DISTINCT c.name)                    as subjectName,
+           a.create_time
+    from t_exam_paper_question_customer_answer a
+           inner join t_question_subject b on a.question_id = b.question_id and b.deleted = 0
+           inner join t_subject c on b.subject_id = c.id and c.deleted = 0
+           inner join t_text_content d on a.question_text_content_id = d.id
+    where
+      a.do_right = FALSE
+      and a.create_user = #{createUser}
+      and JSON_VALUE(d.content, '$.titleContent') like concat('%', #{shortTitle}, '%')
+    group by a.question_id, question_type
+    HAVING GROUP_CONCAT(c.name) like concat('%',  #{subjectName}, '%')
+    order by a.question_id desc
   </select>
 
 
diff --git a/src/main/resources/mapper/QuestionMapper.xml b/src/main/resources/mapper/QuestionMapper.xml
index b47999b..5b3b415 100644
--- a/src/main/resources/mapper/QuestionMapper.xml
+++ b/src/main/resources/mapper/QuestionMapper.xml
@@ -307,6 +307,7 @@
                  inner join t_subject c on b.subject_id = c.id and c.deleted = 0
                  inner join t_text_content d on a.info_text_content_id = d.id
         where a.deleted = 0
+        AND JSON_VALUE(d.content, '$.titleContent') like concat('%', #{shortTitle}, '%')
         group by a.id, question_type, a.create_time
         HAVING GROUP_CONCAT(c.name) like concat('%', #{subjectName}, '%')
         order by a.create_time

--
Gitblit v1.8.0