Browse Source

错题本

jinxia.mo 1 month ago
parent
commit
0e296caa8b

+ 53 - 0
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontWrongBookController.java

@@ -0,0 +1,53 @@
+package com.ruoyi.web.controller.front;
+
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.learn.service.ILearnWrongBookService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.web.bind.annotation.*;
+
+@Api(tags = "前端V2 错题本")
+@RestController
+@RequestMapping("front/v2/wrongBook")
+public class FrontWrongBookController extends BaseController {
+    private final ILearnWrongBookService wrongBookService;
+
+    public FrontWrongBookController(ILearnWrongBookService wrongBookService) {
+        this.wrongBookService = wrongBookService;
+    }
+
+    /**
+     *
+     * @return
+     */
+    @ApiOperation("错题涉及的学科")
+    @GetMapping("subjects")
+    public AjaxResult subjects() {
+        return AjaxResult.success(wrongBookService.findSubject());
+    }
+
+    @ApiOperation("错题列表")
+    @GetMapping("wrongQuestions")
+    public TableDataInfo wrongQuestions(@ApiParam("科目id") @RequestParam Long subjectId,
+                                        @ApiParam(value = "页数", example = "1") @RequestParam Integer pageNum,
+                                        @ApiParam(value = "页大小", example = "15") @RequestParam Integer pageSize) {
+        startPage();
+        return getDataTable(wrongBookService.findWrongQuestions(subjectId));
+    }
+
+    @ApiOperation("错题考卷列表")
+    @GetMapping("wrongExaminees")
+    public TableDataInfo wrongExaminees(@ApiParam("错题id") @RequestParam Long wrongId) {
+        return getDataTable(wrongBookService.findWrongExaminees(wrongId));
+    }
+
+    @ApiOperation("删除错题")
+    @PostMapping("deleteWrongQuestion")
+    public AjaxResult deleteWrongQuestion(Long questionId) {
+        return  AjaxResult.success(wrongBookService.deleteByQuestion(SecurityUtils.getLoginUser().getUserId(), questionId));
+    }
+}

+ 81 - 43
ie-system/src/main/java/com/ruoyi/learn/domain/LearnWrongBook.java

@@ -1,6 +1,8 @@
 package com.ruoyi.learn.domain;
 
 import java.util.Date;
+import java.util.List;
+
 import com.fasterxml.jackson.annotation.JsonFormat;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
@@ -9,7 +11,7 @@ import com.ruoyi.common.core.domain.BaseEntity;
 
 /**
  * 学生错题本对象 learn_wrong_book
- * 
+ *
  * @author ruoyi
  * @date 2025-09-25
  */
@@ -101,213 +103,249 @@ public class LearnWrongBook extends BaseEntity
     /** 是否收藏 */
     @Excel(name = "是否收藏")
     private Long collect;
+    String answer;
+    List<String> attachments;
+    String typeId;
+    private String qtpye;
+
+    public String getQtpye() {
+        return qtpye;
+    }
+
+    public void setQtpye(String qtpye) {
+        this.qtpye = qtpye;
+    }
+
+    public String getTypeId() {
+        return typeId;
+    }
+
+    public void setTypeId(String typeId) {
+        this.typeId = typeId;
+    }
+
+    public String getAnswer() {
+        return answer;
+    }
+
+    public void setAnswer(String answer) {
+        this.answer = answer;
+    }
+
+    public List<String> getAttachments() {
+        return attachments;
+    }
+
+    public void setAttachments(List<String> attachments) {
+        this.attachments = attachments;
+    }
 
-    public void setWrongId(Long wrongId) 
+    public void setWrongId(Long wrongId)
     {
         this.wrongId = wrongId;
     }
 
-    public Long getWrongId() 
+    public Long getWrongId()
     {
         return wrongId;
     }
 
-    public void setStudentId(Long studentId) 
+    public void setStudentId(Long studentId)
     {
         this.studentId = studentId;
     }
 
-    public Long getStudentId() 
+    public Long getStudentId()
     {
         return studentId;
     }
 
-    public void setQuestionId(Long questionId) 
+    public void setQuestionId(Long questionId)
     {
         this.questionId = questionId;
     }
 
-    public Long getQuestionId() 
+    public Long getQuestionId()
     {
         return questionId;
     }
 
-    public void setSource(String source) 
+    public void setSource(String source)
     {
         this.source = source;
     }
 
-    public String getSource() 
+    public String getSource()
     {
         return source;
     }
 
-    public void setState(Long state) 
+    public void setState(Long state)
     {
         this.state = state;
     }
 
-    public Long getState() 
+    public Long getState()
     {
         return state;
     }
 
-    public void setKnownledgeId(Long knownledgeId) 
+    public void setKnownledgeId(Long knownledgeId)
     {
         this.knownledgeId = knownledgeId;
     }
 
-    public Long getKnownledgeId() 
+    public Long getKnownledgeId()
     {
         return knownledgeId;
     }
 
-    public void setSubjectId(Long subjectId) 
+    public void setSubjectId(Long subjectId)
     {
         this.subjectId = subjectId;
     }
 
-    public Long getSubjectId() 
+    public Long getSubjectId()
     {
         return subjectId;
     }
 
-    public void setPaperId(Long paperId) 
+    public void setPaperId(Long paperId)
     {
         this.paperId = paperId;
     }
 
-    public Long getPaperId() 
+    public Long getPaperId()
     {
         return paperId;
     }
 
-    public void setAnswers(String answers) 
+    public void setAnswers(String answers)
     {
         this.answers = answers;
     }
 
-    public String getAnswers() 
+    public String getAnswers()
     {
         return answers;
     }
 
-    public void setAnswer1(String answer1) 
+    public void setAnswer1(String answer1)
     {
         this.answer1 = answer1;
     }
 
-    public String getAnswer1() 
+    public String getAnswer1()
     {
         return answer1;
     }
 
-    public void setAnswer2(String answer2) 
+    public void setAnswer2(String answer2)
     {
         this.answer2 = answer2;
     }
 
-    public String getAnswer2() 
+    public String getAnswer2()
     {
         return answer2;
     }
 
-    public void setScoreTotal(Long scoreTotal) 
+    public void setScoreTotal(Long scoreTotal)
     {
         this.scoreTotal = scoreTotal;
     }
 
-    public Long getScoreTotal() 
+    public Long getScoreTotal()
     {
         return scoreTotal;
     }
 
-    public void setScore(Long score) 
+    public void setScore(Long score)
     {
         this.score = score;
     }
 
-    public Long getScore() 
+    public Long getScore()
     {
         return score;
     }
 
-    public void setScoreLevel(String scoreLevel) 
+    public void setScoreLevel(String scoreLevel)
     {
         this.scoreLevel = scoreLevel;
     }
 
-    public String getScoreLevel() 
+    public String getScoreLevel()
     {
         return scoreLevel;
     }
 
-    public void setScoreRate(Long scoreRate) 
+    public void setScoreRate(Long scoreRate)
     {
         this.scoreRate = scoreRate;
     }
 
-    public Long getScoreRate() 
+    public Long getScoreRate()
     {
         return scoreRate;
     }
 
-    public void setWrongCount(Long wrongCount) 
+    public void setWrongCount(Long wrongCount)
     {
         this.wrongCount = wrongCount;
     }
 
-    public Long getWrongCount() 
+    public Long getWrongCount()
     {
         return wrongCount;
     }
 
-    public void setRightCount(Long rightCount) 
+    public void setRightCount(Long rightCount)
     {
         this.rightCount = rightCount;
     }
 
-    public Long getRightCount() 
+    public Long getRightCount()
     {
         return rightCount;
     }
 
-    public void setTotalCount(Long totalCount) 
+    public void setTotalCount(Long totalCount)
     {
         this.totalCount = totalCount;
     }
 
-    public Long getTotalCount() 
+    public Long getTotalCount()
     {
         return totalCount;
     }
 
-    public void setCreatedTime(Date createdTime) 
+    public void setCreatedTime(Date createdTime)
     {
         this.createdTime = createdTime;
     }
 
-    public Date getCreatedTime() 
+    public Date getCreatedTime()
     {
         return createdTime;
     }
 
-    public void setUpdatedTime(Date updatedTime) 
+    public void setUpdatedTime(Date updatedTime)
     {
         this.updatedTime = updatedTime;
     }
 
-    public Date getUpdatedTime() 
+    public Date getUpdatedTime()
     {
         return updatedTime;
     }
 
-    public void setCollect(Long collect) 
+    public void setCollect(Long collect)
     {
         this.collect = collect;
     }
 
-    public Long getCollect() 
+    public Long getCollect()
     {
         return collect;
     }

+ 19 - 8
ie-system/src/main/java/com/ruoyi/learn/mapper/LearnWrongBookMapper.java

@@ -1,19 +1,22 @@
 package com.ruoyi.learn.mapper;
 
 import java.util.List;
+import java.util.Map;
+
+import com.ruoyi.dz.domain.DzSubject;
 import com.ruoyi.learn.domain.LearnWrongBook;
 
 /**
  * 学生错题本Mapper接口
- * 
+ *
  * @author ruoyi
  * @date 2025-09-25
  */
-public interface LearnWrongBookMapper 
+public interface LearnWrongBookMapper
 {
     /**
      * 查询学生错题本
-     * 
+     *
      * @param wrongId 学生错题本主键
      * @return 学生错题本
      */
@@ -21,7 +24,7 @@ public interface LearnWrongBookMapper
 
     /**
      * 查询学生错题本列表
-     * 
+     *
      * @param learnWrongBook 学生错题本
      * @return 学生错题本集合
      */
@@ -29,7 +32,7 @@ public interface LearnWrongBookMapper
 
     /**
      * 新增学生错题本
-     * 
+     *
      * @param learnWrongBook 学生错题本
      * @return 结果
      */
@@ -37,7 +40,7 @@ public interface LearnWrongBookMapper
 
     /**
      * 修改学生错题本
-     * 
+     *
      * @param learnWrongBook 学生错题本
      * @return 结果
      */
@@ -45,7 +48,7 @@ public interface LearnWrongBookMapper
 
     /**
      * 删除学生错题本
-     * 
+     *
      * @param wrongId 学生错题本主键
      * @return 结果
      */
@@ -53,9 +56,17 @@ public interface LearnWrongBookMapper
 
     /**
      * 批量删除学生错题本
-     * 
+     *
      * @param wrongIds 需要删除的数据主键集合
      * @return 结果
      */
     public int deleteLearnWrongBookByWrongIds(Long[] wrongIds);
+
+    public int deleteByQuestion(LearnWrongBook wrongBook);
+
+    public List<LearnWrongBook> findWrongQuestions(Map cond);
+
+    public List<LearnWrongBook> findWrongExaminees(Long wrongId);
+
+    public int deleteByQuestion(Long studentId, Long questionId);
 }

+ 23 - 8
ie-system/src/main/java/com/ruoyi/learn/service/ILearnWrongBookService.java

@@ -1,19 +1,26 @@
 package com.ruoyi.learn.service;
 
 import java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.dz.domain.DzSubject;
 import com.ruoyi.learn.domain.LearnWrongBook;
 
 /**
  * 学生错题本Service接口
- * 
+ *
  * @author ruoyi
  * @date 2025-09-25
  */
-public interface ILearnWrongBookService 
+public interface ILearnWrongBookService
 {
     /**
      * 查询学生错题本
-     * 
+     *
      * @param wrongId 学生错题本主键
      * @return 学生错题本
      */
@@ -21,7 +28,7 @@ public interface ILearnWrongBookService
 
     /**
      * 查询学生错题本列表
-     * 
+     *
      * @param learnWrongBook 学生错题本
      * @return 学生错题本集合
      */
@@ -29,7 +36,7 @@ public interface ILearnWrongBookService
 
     /**
      * 新增学生错题本
-     * 
+     *
      * @param learnWrongBook 学生错题本
      * @return 结果
      */
@@ -37,7 +44,7 @@ public interface ILearnWrongBookService
 
     /**
      * 修改学生错题本
-     * 
+     *
      * @param learnWrongBook 学生错题本
      * @return 结果
      */
@@ -45,7 +52,7 @@ public interface ILearnWrongBookService
 
     /**
      * 批量删除学生错题本
-     * 
+     *
      * @param wrongIds 需要删除的学生错题本主键集合
      * @return 结果
      */
@@ -53,9 +60,17 @@ public interface ILearnWrongBookService
 
     /**
      * 删除学生错题本信息
-     * 
+     *
      * @param wrongId 学生错题本主键
      * @return 结果
      */
     public int deleteLearnWrongBookByWrongId(Long wrongId);
+
+    public List<DzSubject> findSubject();
+
+    public List<LearnWrongBook> findWrongQuestions(Long subjectId);
+
+    public List<LearnWrongBook> findWrongExaminees(Long wrongId);
+
+    public int deleteByQuestion(Long studentId, Long questionId);
 }

+ 64 - 8
ie-system/src/main/java/com/ruoyi/learn/service/impl/LearnWrongBookServiceImpl.java

@@ -1,6 +1,14 @@
 package com.ruoyi.learn.service.impl;
 
 import java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.dz.domain.DzSubject;
+import com.ruoyi.dz.mapper.DzSubjectMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.learn.mapper.LearnWrongBookMapper;
@@ -9,19 +17,21 @@ import com.ruoyi.learn.service.ILearnWrongBookService;
 
 /**
  * 学生错题本Service业务层处理
- * 
+ *
  * @author ruoyi
  * @date 2025-09-25
  */
 @Service
-public class LearnWrongBookServiceImpl implements ILearnWrongBookService 
+public class LearnWrongBookServiceImpl implements ILearnWrongBookService
 {
     @Autowired
     private LearnWrongBookMapper learnWrongBookMapper;
+    @Autowired
+    private DzSubjectMapper subjectMapper;
 
     /**
      * 查询学生错题本
-     * 
+     *
      * @param wrongId 学生错题本主键
      * @return 学生错题本
      */
@@ -33,7 +43,7 @@ public class LearnWrongBookServiceImpl implements ILearnWrongBookService
 
     /**
      * 查询学生错题本列表
-     * 
+     *
      * @param learnWrongBook 学生错题本
      * @return 学生错题本
      */
@@ -45,7 +55,7 @@ public class LearnWrongBookServiceImpl implements ILearnWrongBookService
 
     /**
      * 新增学生错题本
-     * 
+     *
      * @param learnWrongBook 学生错题本
      * @return 结果
      */
@@ -57,7 +67,7 @@ public class LearnWrongBookServiceImpl implements ILearnWrongBookService
 
     /**
      * 修改学生错题本
-     * 
+     *
      * @param learnWrongBook 学生错题本
      * @return 结果
      */
@@ -69,7 +79,7 @@ public class LearnWrongBookServiceImpl implements ILearnWrongBookService
 
     /**
      * 批量删除学生错题本
-     * 
+     *
      * @param wrongIds 需要删除的学生错题本主键
      * @return 结果
      */
@@ -81,7 +91,7 @@ public class LearnWrongBookServiceImpl implements ILearnWrongBookService
 
     /**
      * 删除学生错题本信息
-     * 
+     *
      * @param wrongId 学生错题本主键
      * @return 结果
      */
@@ -90,4 +100,50 @@ public class LearnWrongBookServiceImpl implements ILearnWrongBookService
     {
         return learnWrongBookMapper.deleteLearnWrongBookByWrongId(wrongId);
     }
+
+    public List<DzSubject> findSubject() {
+        return subjectMapper.selectDzSubjectList(new DzSubject());
+    }
+
+    public List<LearnWrongBook> findWrongQuestions(Long subjectId) {
+        Map cond = Maps.newHashMap();
+        cond.put("subjectId", subjectId);
+        cond.put("studentId", SecurityUtils.getUserId());
+        List<LearnWrongBook> wrongBookList = learnWrongBookMapper.findWrongQuestions(cond);
+        wrongBookList.stream().forEach(t -> {
+            setAnswerAttachemnts(t, t.getAnswers());
+//            t.setTypeId(cacheService.getQuestionType(t.getQtpye()));
+            t.setTypeId(null);
+        });
+        return wrongBookList;
+    }
+
+    public List<LearnWrongBook> findWrongExaminees(Long wrongId) {
+        return learnWrongBookMapper.findWrongExaminees(wrongId);
+    }
+
+    public int deleteByQuestion(Long studentId, Long questionId) {
+        LearnWrongBook b = new LearnWrongBook();
+        b.setStudentId(studentId);
+        b.setQuestionId(questionId);
+        return learnWrongBookMapper.deleteByQuestion(b);
+    }
+
+    private void setAnswerAttachemnts(LearnWrongBook dto, String answer) {
+        if (StringUtils.isNotBlank(answer)) {
+            String[] answerArray = StringUtils.splitByWholeSeparatorPreserveAllTokens(answer, "$@");
+            if (answerArray.length > 0) {
+                dto.setAnswer(answerArray[0]);
+                if (answerArray.length > 1) {
+                    List<String> attacheList = Lists.newArrayList();
+                    for (int i = 1; i < answerArray.length; i++) {
+                        if (StringUtils.isNotBlank(answerArray[i]) && !"null".equals(answerArray[i])) {
+                            attacheList.add(answerArray[i]);
+                        }
+                    }
+                    dto.setAttachments(attacheList);
+                }
+            }
+        }
+    }
 }

+ 32 - 5
ie-system/src/main/resources/mapper/learn/LearnWrongBookMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.learn.mapper.LearnWrongBookMapper">
-    
+
     <resultMap type="LearnWrongBook" id="LearnWrongBookResult">
         <result property="wrongId"    column="wrong_id"    />
         <result property="studentId"    column="student_id"    />
@@ -26,6 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="createdTime"    column="created_time"    />
         <result property="updatedTime"    column="updated_time"    />
         <result property="collect"    column="collect"    />
+        <result property="qtpye"    column="qtpye"    />
     </resultMap>
 
     <sql id="selectLearnWrongBookVo">
@@ -34,7 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectLearnWrongBookList" parameterType="LearnWrongBook" resultMap="LearnWrongBookResult">
         <include refid="selectLearnWrongBookVo"/>
-        <where>  
+        <where>
             <if test="studentId != null "> and student_id = #{studentId}</if>
             <if test="questionId != null "> and question_id = #{questionId}</if>
             <if test="source != null  and source != ''"> and source = #{source}</if>
@@ -57,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="collect != null "> and collect = #{collect}</if>
         </where>
     </select>
-    
+
     <select id="selectLearnWrongBookByWrongId" parameterType="Long" resultMap="LearnWrongBookResult">
         <include refid="selectLearnWrongBookVo"/>
         where wrong_id = #{wrongId}
@@ -143,9 +144,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteLearnWrongBookByWrongIds" parameterType="String">
-        delete from learn_wrong_book where wrong_id in 
+        delete from learn_wrong_book where wrong_id in
         <foreach item="wrongId" collection="array" open="(" separator="," close=")">
             #{wrongId}
         </foreach>
     </delete>
-</mapper>
+
+    <delete id="deleteByQuestion" parameterType="LearnWrongBook">
+        delete from learn_wrong_book where student_id = #{studentId} and question_id = #{questionId}
+    </delete>
+
+    <select id="findWrongExaminees" parameterType="Long" resultMap="LearnWrongBookResult">
+        SELECT wd.`examinee_id`, wd.paper_id, p.`paperName`, p.`paperType` paper_type, e.`begin_time` created_time
+        FROM `learn_wrong_detail` wd
+        JOIN `learn_paper` p ON wd.`paper_id` = p.`id`
+        JOIN `learn_examinee` e ON e.`examinee_id` = wd.`examinee_id`
+        WHERE wd.wrong_id = #{wrongId}
+    </select>
+
+    <select id="findWrongQuestions" parameterType="map" resultMap="LearnWrongBookResult">
+        SELECT wb.`wrong_id`, wb.`question_id`, q.`title`, q.parse, wb.`knownledge_id`, k.`name` knownledge_name, wb.`wrong_count`, q.qtpye
+        ,q.option_a,q.option_b,q.option_c,q.option_d,q.option_e,q.option_f,q.option_g,q.answer1,q.answer2,q.title0,wb.answers, qc.question_id>0 collect
+        FROM `learn_wrong_book` wb
+        JOIN `learn_questions` q ON wb.`question_id` = q.`id`
+        LEFT JOIN `learn_knowledge_tree` k ON wb.`knownledge_id` = k.`id`
+        LEFT JOIN mxjb_question_collection qc on qc.question_id = q.id and qc.user_id = 11
+        <where>
+            wb.`student_id` = #{creatorId} AND q.`qtpye` IN ('判断题', '单选题', '选择题','单项选择','单项选择题','多选题')
+            <if test="subjectId != null "> and wb.`subject_id` = #{subjectId}</if>
+        </where>
+
+    </select>
+</mapper>