he2802 4 anni fa
parent
commit
92f1a5c136

+ 100 - 0
zhongzheng-api/src/main/java/com/zhongzheng/controller/collect/CollectQuestionController.java

@@ -0,0 +1,100 @@
+package com.zhongzheng.controller.collect;
+
+import com.zhongzheng.common.annotation.Log;
+import com.zhongzheng.common.core.controller.BaseController;
+import com.zhongzheng.common.core.domain.AjaxResult;
+import com.zhongzheng.common.core.page.TableDataInfo;
+import com.zhongzheng.common.enums.BusinessType;
+import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.framework.web.service.WxTokenService;
+import com.zhongzheng.modules.bank.vo.QuestionVo;
+import com.zhongzheng.modules.collect.bo.CollectQuestionAddBo;
+import com.zhongzheng.modules.collect.bo.CollectQuestionQueryBo;
+import com.zhongzheng.modules.collect.domain.CollectQuestion;
+import com.zhongzheng.modules.collect.service.ICollectQuestionService;
+import com.zhongzheng.modules.user.entity.ClientLoginUser;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 收藏题目Controller
+ *
+ * @author ruoyi
+ * @date 2021-06-24
+ */
+@Api(value = "收藏题目控制器", tags = {"收藏题目管理"})
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@RestController
+@RequestMapping("/collect/question")
+public class CollectQuestionController extends BaseController {
+
+    private final ICollectQuestionService iCollectQuestionService;
+
+    private final WxTokenService wxTokenService;
+
+    /**
+     * 查询收藏题目列表
+     */
+    @ApiOperation("查询收藏题目列表,按题型")
+    @GetMapping("/list")
+    public TableDataInfo<QuestionVo> list(CollectQuestionQueryBo bo) {
+        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        bo.setUserId(loginUser.getUser().getUserId());
+        startPage();
+        List<QuestionVo> list = iCollectQuestionService.selectList(bo);
+        return getDataTable(list);
+    }
+    /**
+     * 查询收藏题目列表
+     */
+    @ApiOperation("查询收藏题目列表,按题型")
+    @GetMapping("/exam_list")
+    public TableDataInfo<QuestionVo> exam_list(CollectQuestionQueryBo bo) {
+        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        bo.setUserId(loginUser.getUser().getUserId());
+        startPage();
+        List<QuestionVo> list = iCollectQuestionService.selectExamList(bo);
+        return getDataTable(list);
+    }
+
+
+    /**
+     * 获取收藏题目详细信息
+     */
+    @ApiOperation("获取收藏题目详细信息")
+    @GetMapping("/getInfo")
+    public AjaxResult<CollectQuestion> getInfo(Long questionId,Long examId) {
+        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        return AjaxResult.success(iCollectQuestionService.queryQuestionById(loginUser.getUser().getUserId(),questionId,examId));
+    }
+
+    /**
+     * 新增收藏题目
+     */
+    @ApiOperation("新增收藏题目")
+    @Log(title = "收藏题目", businessType = BusinessType.INSERT)
+    @PostMapping()
+    public AjaxResult<Void> add(@RequestBody CollectQuestionAddBo bo) {
+        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        bo.setUserId(loginUser.getUser().getUserId());
+        return toAjax(iCollectQuestionService.insertByAddBo(bo) ? 1 : 0);
+    }
+
+
+
+    /**
+     * 删除收藏题目
+     */
+    @ApiOperation("删除收藏题目")
+    @Log(title = "收藏题目" , businessType = BusinessType.DELETE)
+    @PostMapping("/delete/{collectQuestionIds}")
+    public AjaxResult<Void> remove(@PathVariable Long[] collectQuestionIds) {
+        return toAjax(iCollectQuestionService.deleteWithValidByIds(Arrays.asList(collectQuestionIds), true) ? 1 : 0);
+    }
+}

+ 2 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/collect/bo/CollectQuestionAddBo.java

@@ -27,6 +27,6 @@ public class CollectQuestionAddBo {
     /** 添加时间 */
     @ApiModelProperty("添加时间")
     private Long createTime;
-    @ApiModelProperty("题库ID")
-    private Long bankId;
+    @ApiModelProperty("试卷ID")
+    private Long examId;
 }

+ 2 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/collect/bo/CollectQuestionEditBo.java

@@ -29,6 +29,6 @@ public class CollectQuestionEditBo {
     /** 用户ID */
     @ApiModelProperty("用户ID")
     private Long userId;
-    @ApiModelProperty("题库ID")
-    private Long bankId;
+    @ApiModelProperty("试卷ID")
+    private Long examId;
 }

+ 5 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/collect/bo/CollectQuestionQueryBo.java

@@ -43,7 +43,10 @@ public class CollectQuestionQueryBo extends BaseEntity {
 	@ApiModelProperty("用户ID")
 	private Long userId;
 
-	@ApiModelProperty("题库ID")
-	private Long bankId;
+	@ApiModelProperty("试卷ID")
+	private Long examId;
+	@ApiModelProperty("类型")
+	private Long type;
+
 
 }

+ 2 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/collect/domain/CollectQuestion.java

@@ -38,7 +38,7 @@ private static final long serialVersionUID=1L;
     /** 添加时间 */
     @TableField(fill = FieldFill.INSERT)
     private Long createTime;
-    @ApiModelProperty("题库ID")
-    private Long bankId;
+    @ApiModelProperty("试卷ID")
+    private Long examId;
 
 }

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/collect/mapper/CollectQuestionMapper.java

@@ -18,4 +18,6 @@ public interface CollectQuestionMapper extends BaseMapper<CollectQuestion> {
 
     List<QuestionVo> selectList(CollectQuestionQueryBo bo);
 
+    List<QuestionVo> selectExamList(CollectQuestionQueryBo bo);
+
 }

+ 3 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/collect/service/ICollectQuestionService.java

@@ -26,7 +26,9 @@ public interface ICollectQuestionService extends IService<CollectQuestion> {
 
 
 
-	CollectQuestion queryQuestionById(Long userID, Long questionId);
+	CollectQuestion queryQuestionById(Long userID, Long questionId, Long examId);
+
+	List<QuestionVo> selectExamList(CollectQuestionQueryBo bo);
 
 	/**
 	 * 查询列表

+ 9 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/collect/service/impl/CollectQuestionServiceImpl.java

@@ -43,15 +43,23 @@ public class CollectQuestionServiceImpl extends ServiceImpl<CollectQuestionMappe
         return BeanUtil.toBean(db, CollectQuestionVo.class);
     }
 
+
+
     @Override
-    public CollectQuestion queryQuestionById(Long userID, Long questionId) {
+    public CollectQuestion queryQuestionById(Long userID, Long questionId, Long examId) {
         CollectQuestion info = getOne(new LambdaQueryWrapper<CollectQuestion>()
                 .eq(CollectQuestion::getQuestionId,questionId)
                 .eq(CollectQuestion::getUserId,userID)
+                .eq(CollectQuestion::getExamId,examId)
                 .last("limit 1"));
         return info;
     }
 
+    @Override
+    public List<QuestionVo> selectExamList(CollectQuestionQueryBo bo) {
+        return collectQuestionMapper.selectExamList(bo);
+    }
+
     @Override
     public List<CollectQuestionVo> queryList(CollectQuestionQueryBo bo) {
         LambdaQueryWrapper<CollectQuestion> lqw = Wrappers.lambdaQuery();

+ 12 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/collect/vo/CollectQuestionVo.java

@@ -4,6 +4,7 @@ import com.zhongzheng.common.annotation.Excel;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
+import io.swagger.models.auth.In;
 import lombok.Data;
 import java.util.Date;
 
@@ -32,7 +33,16 @@ public class CollectQuestionVo {
 	@Excel(name = "用户ID")
 	@ApiModelProperty("用户ID")
 	private Long userId;
-	@ApiModelProperty("题库ID")
-	private Long bankId;
+	@ApiModelProperty("试卷ID")
+	private Long examId;
+
+	@ApiModelProperty("试卷名称")
+	private String examName;
+
+	@ApiModelProperty("题目数量")
+	private Integer questionNum;
+
+	@ApiModelProperty("题目文本")
+	private String content;
 
 }

+ 35 - 4
zhongzheng-system/src/main/resources/mapper/modules/collect/CollectQuestionMapper.xml

@@ -9,10 +9,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="questionId" column="question_id"/>
         <result property="userId" column="user_id"/>
         <result property="createTime" column="create_time"/>
-        <result property="bankId" column="bank_id"/>
+        <result property="examId" column="exam_id"/>
     </resultMap>
 
-    <select id="selectList" parameterType="com.zhongzheng.modules.collect.domain.CollectQuestion"  resultType="com.zhongzheng.modules.bank.domain.Question">
+    <resultMap type="com.zhongzheng.modules.collect.vo.CollectQuestionVo" id="CollectQuestionVoResult">
+        <result property="collectQuestionId" column="collect_question_id"/>
+        <result property="questionId" column="question_id"/>
+        <result property="userId" column="user_id"/>
+        <result property="createTime" column="create_time"/>
+        <result property="examId" column="exam_id"/>
+        <result property="examName" column="exam_name"/>
+        <result property="questionNum" column="question_num"/>
+        <result property="content" column="content"/>
+    </resultMap>
+
+    <select id="selectList" parameterType="com.zhongzheng.modules.collect.bo.CollectQuestionQueryBo"  resultType="CollectQuestionVoResult">
         SELECT
         q.*
         FROM
@@ -23,9 +34,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="userId != null and userId != ''">
             AND user_id = #{userId}
         </if>
-        <if test="bankId != null and bankId != ''">
-            AND bank_id = #{bankId}
+        <if test="type != null and type != ''">
+            AND q.type = #{type}
+        </if>
+
+    </select>
+
+    <select id="selectExamList" parameterType="com.zhongzheng.modules.collect.bo.CollectQuestionQueryBo"  resultType="CollectQuestionVoResult">
+        SELECT
+        e.*,
+        COUNT( cq.question_id ) question_num
+        FROM
+        collect_question cq
+        LEFT JOIN exam e ON cq.exam_id = e.exam_id
+        WHERE
+        1 = 1
+        <if test="userId != null and userId != ''">
+            AND user_id = #{userId}
+        </if>
+        <if test="examId != null and examId != ''">
+            AND e.exam_id = #{examId}
         </if>
+        GROUP BY
+        e.exam_id
 
     </select>
 

+ 21 - 0
zhongzheng-system/src/main/resources/mapper/modules/user/UserExamRecordMapper.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zhongzheng.modules.user.mapper.UserExamRecordMapper">
+
+    <resultMap type="com.zhongzheng.modules.user.domain.UserExamRecord" id="UserExamRecordResult">
+        <result property="recordId" column="record_id"/>
+        <result property="examId" column="exam_id"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="userId" column="user_id"/>
+        <result property="status" column="status"/>
+        <result property="goodsId" column="goods_id"/>
+        <result property="reportStatus" column="report_status"/>
+        <result property="performance" column="performance"/>
+        <result property="wrongIds" column="wrong_ids"/>
+    </resultMap>
+
+
+</mapper>