小么熊🐻 1 år sedan
förälder
incheckning
cfeeb5b048

+ 148 - 0
jpcj-admin/src/main/java/com/miaxis/pc/controller/question/PcQuestionThreeWrongController.java

@@ -0,0 +1,148 @@
+package com.miaxis.pc.controller.question;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.common.utils.SecurityUtils;
+import com.miaxis.question.domain.QuestionThreeWrong;
+import com.miaxis.question.dto.QuestionThreeWrongListDTO;
+import com.miaxis.question.dto.QuestionThreeWrongYunDTO;
+import com.miaxis.question.dto.QuestionWgYunDTO;
+import com.miaxis.question.dto.QuestionWrongListDTO;
+import com.miaxis.question.service.IQuestionThreeWrongService;
+import com.miaxis.question.vo.QuestionWrongIdDateVo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 【wrong】Controller
+ *
+ * @author miaxis
+ * @date 2021-08-19
+ */
+@RestController
+@RequestMapping("/question/threeWrong")
+@Api(tags={"【PC-错题】"})
+public class PcQuestionThreeWrongController extends BaseController {
+
+    @Autowired
+    private IQuestionThreeWrongService questionThreeWrongService;
+
+
+
+
+    @PostMapping("wrongs")
+    @ApiOperation("合并本机和云端错题")
+    public Response<Integer> wrongs(@RequestBody QuestionThreeWrongYunDTO wrong) {
+        //查询该用户已收藏的题目列表
+        QuestionThreeWrongListDTO dto = new QuestionThreeWrongListDTO();
+        dto.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
+        List<QuestionThreeWrong> dblist = questionThreeWrongService.selectQuestionThreeWrongList(dto);
+        List<String> questionIdsStr = dblist.stream().map(o -> o.getQuestionId()+"").collect(Collectors.toList());
+
+        List<QuestionThreeWrong> qlist = new ArrayList<QuestionThreeWrong>();
+        for (QuestionWgYunDTO wgYunDTO : wrong.getWrongs()) {
+            if (questionIdsStr.contains(wgYunDTO.getId())) {
+                continue;
+            }
+            QuestionThreeWrong questionThreeWrong = new QuestionThreeWrong();
+            questionThreeWrong.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
+            questionThreeWrong.setQuestionId(wgYunDTO.getId());
+            questionThreeWrong.setDeviceType(2);
+            Date crDate = new Date(wgYunDTO.getTimestamp());
+            questionThreeWrong.setCreateTime(crDate);
+            qlist.add(questionThreeWrong);
+        }
+        if (qlist.isEmpty()) {
+            Response response = new Response(200, "选中的错题都已添加!");
+            return response;
+        }
+        return toResponse(questionThreeWrongService.saveBatch(qlist) ? 1 : 0);
+    }
+
+
+    @PostMapping("bakWrongs")
+    @ApiOperation("备份本机错题到云端")
+    public Response bakWrongs(@RequestBody QuestionThreeWrongYunDTO wrong) {
+        //首先删除云端数据
+        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
+        QueryWrapper<QuestionThreeWrong> queryWrapper = new QueryWrapper<QuestionThreeWrong>();
+        queryWrapper.eq("user_id", userId);
+        questionThreeWrongService.remove(queryWrapper);
+
+        //保存上传的错题
+        List<QuestionThreeWrong> qlist = new ArrayList<QuestionThreeWrong>();
+        for (QuestionWgYunDTO wgYunDTO : wrong.getWrongs()) {
+            QuestionThreeWrong questionThreeWrong = new QuestionThreeWrong();
+            questionThreeWrong.setUserId(userId);
+            questionThreeWrong.setQuestionId(wgYunDTO.getId());
+            questionThreeWrong.setDeviceType(2);
+            Date crDate = new Date(wgYunDTO.getTimestamp());
+            questionThreeWrong.setCreateTime(crDate);
+            qlist.add(questionThreeWrong);
+        }
+        if (qlist.isEmpty()) {
+            Response response = new Response(200, "该错已加入错题集(无须提示给用户)");
+            return response;
+        }
+        return toResponse(questionThreeWrongService.saveBatch(qlist) ? 1 : 0);
+    }
+
+
+    @DeleteMapping("/cancel/{questionId}")
+    @ApiOperation("删除错题")
+    public Response<Integer> remove(
+            @ApiParam(name = "questionId", value = "问题id", required = true)
+            @PathVariable Long questionId
+    ) {
+        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
+        QueryWrapper<QuestionThreeWrong> queryWrapper = new QueryWrapper<QuestionThreeWrong>();
+        queryWrapper.eq("user_id", userId);
+        queryWrapper.eq("question_id", questionId);
+        queryWrapper.eq("device_type",2);
+        questionThreeWrongService.remove(queryWrapper);
+        return Response.success();
+
+    }
+
+    @DeleteMapping("/cancelAll")
+    @ApiOperation("清空错题")
+    public Response<Integer> removeAll() {
+        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
+        QueryWrapper<QuestionThreeWrong> queryWrapper = new QueryWrapper<QuestionThreeWrong>();
+        queryWrapper.eq("user_id", userId);
+        queryWrapper.eq("device_type",2);
+        questionThreeWrongService.remove(queryWrapper);
+        return Response.success();
+    }
+
+
+    @GetMapping("/wrongByUser")
+    @ApiOperation("恢复云端错题到本机(根据用户获取错题)")
+    public Response<List<QuestionWrongIdDateVo>> appWrongByUser(@ModelAttribute QuestionThreeWrongListDTO dto) {
+        dto.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
+        dto.setDeviceType(2);
+        List<QuestionWrongIdDateVo> list = questionThreeWrongService.selectThreeWrongIdByUserId(dto);
+        return Response.success(list);
+    }
+
+
+    @GetMapping("/wrongCountByUser")
+    @ApiOperation("根据用户获取错题数")
+    public Response<Integer> wrongCountByUser(@ModelAttribute QuestionWrongListDTO dto) {
+        dto.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
+        dto.setDeviceType(2);
+        Integer count = questionThreeWrongService.selectThreeWrongCountByUserId(dto);
+        return Response.success(count);
+    }
+
+
+}

+ 0 - 1
jpcj-admin/src/main/java/com/miaxis/pc/controller/question/PcQuestionWrongController.java

@@ -1,7 +1,6 @@
 package com.miaxis.pc.controller.question;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.miaxis.common.constant.Constants;
 import com.miaxis.common.core.controller.BaseController;
 import com.miaxis.common.core.domain.Response;
 import com.miaxis.common.utils.SecurityUtils;

+ 51 - 0
jpcj-service/src/main/java/com/miaxis/question/domain/QuestionThreeWrong.java

@@ -0,0 +1,51 @@
+package com.miaxis.question.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.miaxis.common.annotation.Excel;
+import com.miaxis.common.core.domain.BaseBusinessEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * wrong对象 question_wrong
+ *
+ * @author miaxis
+ * @date 2021-08-19
+ */
+@Data
+@TableName("question_three_wrong")
+@ApiModel(value = "QuestionThreeWrong", description = "wrong对象 question_three_wrong")
+public class QuestionThreeWrong extends BaseBusinessEntity {
+    private static final long serialVersionUID = 1L;
+
+    /** 主键 */
+    @TableId(value = "id")
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    /** 用户ID */
+    @Excel(name = "用户ID")
+    @TableField("user_id")
+    @ApiModelProperty(value = "用户ID")
+    private Long userId;
+
+    /** 题目ID */
+    @Excel(name = "题目ID")
+    @TableField("question_id")
+    @ApiModelProperty(value = "题目ID")
+    private Long questionId;
+
+
+
+    /** 终端类型 1:H5  2:PC端 */
+    @Excel(name = "终端类型 1:H5  2:PC端")
+    @TableField("device_type")
+    @ApiModelProperty(value = "终端类型 1:H5  2:PC端")
+    private Integer deviceType;
+
+
+
+}

+ 27 - 0
jpcj-service/src/main/java/com/miaxis/question/dto/QuestionThreeWrongListDTO.java

@@ -0,0 +1,27 @@
+package com.miaxis.question.dto;
+
+import com.miaxis.common.core.domain.BaseBusinessEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * wrong对象 question_wrong
+ *
+ * @author miaxis
+ * @date 2021-08-19
+ */
+@Data
+public class QuestionThreeWrongListDTO extends BaseBusinessEntity {
+
+
+    @ApiModelProperty(value = "用户ID",hidden = true)
+    private Long userId;
+
+    @ApiModelProperty(value = "题目ID",hidden = true)
+    private Long questionId;
+
+    @ApiModelProperty(value = "终端类型",hidden = true)
+    private Integer deviceType;
+
+
+}

+ 23 - 0
jpcj-service/src/main/java/com/miaxis/question/dto/QuestionThreeWrongYunDTO.java

@@ -0,0 +1,23 @@
+package com.miaxis.question.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * wrong对象 question_wrong
+ *
+ * @author miaxis
+ * @date 2021-08-19
+ */
+@Data
+public class QuestionThreeWrongYunDTO {
+
+
+    @ApiModelProperty(value = "题目ID", required = true)
+    private List<QuestionWgYunDTO> wrongs;
+
+
+
+}

+ 31 - 0
jpcj-service/src/main/java/com/miaxis/question/mapper/QuestionThreeWrongMapper.java

@@ -0,0 +1,31 @@
+package com.miaxis.question.mapper;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.miaxis.question.domain.QuestionThreeWrong;
+import com.miaxis.question.domain.QuestionWrong;
+import com.miaxis.question.dto.QuestionThreeWrongListDTO;
+import com.miaxis.question.dto.QuestionWrongListDTO;
+import com.miaxis.question.vo.QuestionWrongIdDateVo;
+
+import java.util.List;
+
+/**
+ * wrongMapper接口
+ *
+ * @author miaxis
+ * @date 2021-08-19
+ */
+public interface QuestionThreeWrongMapper extends BaseMapper<QuestionThreeWrong> {
+    /**
+     * 查询wrong列表
+     *
+     * @param questionThreeWrong wrong
+     * @return wrong集合
+     */
+    List<QuestionThreeWrong> selectQuestionThreeWrongList(QuestionThreeWrongListDTO questionThreeWrong);
+
+    List<QuestionWrongIdDateVo> selectThreeWrongIdByUserId(QuestionThreeWrongListDTO dto);
+
+    Integer selectThreeWrongCountByUserId(QuestionWrongListDTO dto);
+}

+ 31 - 0
jpcj-service/src/main/java/com/miaxis/question/service/IQuestionThreeWrongService.java

@@ -0,0 +1,31 @@
+package com.miaxis.question.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.miaxis.question.domain.QuestionThreeWrong;
+import com.miaxis.question.dto.QuestionThreeWrongListDTO;
+import com.miaxis.question.dto.QuestionWrongListDTO;
+import com.miaxis.question.vo.QuestionWrongIdDateVo;
+
+import java.util.List;
+
+/**
+ * wrongService接口
+ *
+ * @author miaxis
+ * @date 2021-08-19
+ */
+public interface IQuestionThreeWrongService extends IService<QuestionThreeWrong> {
+    /**
+     * 查询wrong列表
+     *
+     * @param questionThreeWrong wrong
+     * @return wrong集合
+     */
+    List<QuestionThreeWrong> selectQuestionThreeWrongList(QuestionThreeWrongListDTO questionThreeWrong);
+
+
+    List<QuestionWrongIdDateVo> selectThreeWrongIdByUserId(QuestionThreeWrongListDTO dto);
+
+    Integer selectThreeWrongCountByUserId(QuestionWrongListDTO dto);
+}

+ 0 - 1
jpcj-service/src/main/java/com/miaxis/question/service/IQuestionWrongService.java

@@ -3,7 +3,6 @@ package com.miaxis.question.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.miaxis.question.domain.QuestionWrong;
-import com.miaxis.question.dto.QuestionCollectionListDTO;
 import com.miaxis.question.dto.QuestionWrongListDTO;
 import com.miaxis.question.vo.QuestionWrongIdDateVo;
 

+ 52 - 0
jpcj-service/src/main/resources/mapper/question/QuestionThreeWrongMapper.xml

@@ -0,0 +1,52 @@
+<?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.miaxis.question.mapper.QuestionThreeWrongMapper">
+
+    <resultMap type="QuestionThreeWrong" id="QuestionThreeWrongResult">
+        <result property="id"    column="id"    />
+        <result property="userId"    column="user_id"    />
+        <result property="questionId"    column="question_id"    />
+        <result property="deviceType"    column="device_type"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="updateTime"    column="update_time"    />
+    </resultMap>
+
+    <sql id="selectQuestionThreeWrongVo">
+        select * from question_three_wrong
+    </sql>
+
+    <select id="selectQuestionThreeWrongList" parameterType="QuestionThreeWrong" resultMap="QuestionThreeWrongResult">
+        <include refid="selectQuestionThreeWrongVo"/>
+        <where>
+            <if test="userId != null and userId !='' "> and user_id = #{userId}</if>
+            <if test="deviceType != null and deviceType!='' "> and q2.device_type = #{deviceType}</if>
+        </where>
+    </select>
+
+
+
+    <select id="selectThreeWrongIdByUserId" resultType="com.miaxis.question.vo.QuestionWrongIdDateVo">
+
+        select q1.id,q2.create_time from three_force q1 join question_wrong q2 on q1.id = q2.question_id
+        <where>
+            <if test="userId != null and userId !='' "> and q2.user_id = #{userId}</if>
+            <if test="deviceType != null and deviceType!='' "> and q2.device_type = #{deviceType}</if>
+        </where>
+        order by q2.create_time
+    </select>
+
+    <select id="selectThreeWrongCountByUserId" resultType="java.lang.Integer">
+
+        select count(1) from three_force q1 join question_wrong q2 on q1.id = q2.question_id
+        <where>
+            <if test="userId != null and userId !='' "> and q2.user_id = #{userId}</if>
+            <if test="km != null and km!='' "> and q2.km = #{km}</if>
+            <if test="deviceType != null and deviceType!='' "> and q2.device_type = #{deviceType}</if>
+        </where>
+
+    </select>
+
+
+</mapper>