Procházet zdrojové kódy

收藏错题接口修改

小么熊🐻 před 2 roky
rodič
revize
f1fd74816e

+ 23 - 70
nbjk-admin/src/main/java/com/miaxis/app/controller/question/QuestionCollectionController.java

@@ -37,48 +37,7 @@ public class QuestionCollectionController extends BaseController {
     @Autowired
     private IQuestionCollectionService questionCollectionService;
 
-    /**
-     * 查询collection列表
-     */
-
-    @GetMapping("/list")
-    @ApiOperation("查询collection列表")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "pageNum", value = "当前页码", dataType = "int", paramType = "query", required = false),
-            @ApiImplicitParam(name = "pageSize", value = "每页数据量", dataType = "int", paramType = "query", required = false),
-    })
-    public ResponsePageInfo<QuestionCollection> list(@ModelAttribute QuestionCollectionListDTO dto) {
-        dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
-        startPage();
-        List<QuestionCollection> list = questionCollectionService.selectQuestionCollectionList(dto);
-        return toResponsePageInfo(list);
-    }
 
-    /**
-     * 导出collection列表
-     */
-//    @PreAuthorize("@ss.hasPermi('question:collection:export')")
-//    @Log(title = "collection", businessType = BusinessTypeEnum.EXPORT)
-//    @GetMapping("/export")
-//    @ApiOperation("导出collection列表Excel")
-//    public Response<String> export(@ModelAttribute QuestionCollection questionCollection){
-//        List<QuestionCollection> list = questionCollectionService.selectQuestionCollectionList(questionCollection);
-//        ExcelUtil<QuestionCollection> util = new ExcelUtil<QuestionCollection>(QuestionCollection.class);
-//        return util.exportExcel(list, "collection");
-//    }
-
-    /**
-     * 获取collection详细信息
-     */
-//    @PreAuthorize("@ss.hasPermi('question:collection:query')")
-    @GetMapping(value = "/{id}")
-    @ApiOperation("获取collection详细信息")
-    public Response<QuestionCollection> getInfo(
-            @ApiParam(name = "id", value = "collection参数", required = true)
-            @PathVariable("id") Long id
-    ) {
-        return Response.success(questionCollectionService.getById(id));
-    }
 
     /**
      * 新增collection
@@ -102,7 +61,7 @@ public class QuestionCollectionController extends BaseController {
     }
 
     @PostMapping("collections")
-    @ApiOperation("批量新增collection")
+    @ApiOperation("合并本机和云端收藏")
     public Response<Integer> collections(@RequestBody List<QuestionCollectionDTO> list) {
         //查询该用户已收藏的题目列表
         QuestionCollectionListDTO dto = new QuestionCollectionListDTO();
@@ -110,7 +69,6 @@ public class QuestionCollectionController extends BaseController {
         List<QuestionCollection> dblist = questionCollectionService.selectQuestionCollectionList(dto);
         List<String> questionIds = dblist.stream().map(o -> (o.getQuestionId()+","+o.getKm())).collect(Collectors.toList());
 
-
         List<QuestionCollection> qlist = new ArrayList<QuestionCollection>();
         for (QuestionCollectionDTO questionCollectionDTO : list) {
             if (questionIds.contains(questionCollectionDTO.getQuestionId()+","+questionCollectionDTO.getKm())) {
@@ -128,34 +86,31 @@ public class QuestionCollectionController extends BaseController {
     }
 
 
-    /**
-     * 修改collection
-     */
-    @Log(title = "collection", businessType = BusinessTypeEnum.UPDATE)
-    @PutMapping
-    @ApiOperation("修改collection")
-    public Response<Integer> edit(@RequestBody QuestionCollectionDTO questionCollectionDTO) {
-        QuestionCollection questionCollection = new QuestionCollection();
-        BeanUtils.copyProperties(questionCollectionDTO, questionCollection);
-        questionCollection.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
-        return toResponse(questionCollectionService.updateById(questionCollection) ? 1 : 0);
-    }
+    @PostMapping("bakCollections")
+    @ApiOperation("备份本机收藏到云端")
+    public Response<Integer> bakCollections(@RequestBody List<QuestionCollectionDTO> list,Integer km) {
+        //首先删除云端数据
+        Long userId = SecurityUtils.getLoginUser().getStudent().getId();
+        QueryWrapper<QuestionCollection> queryWrapper = new QueryWrapper<QuestionCollection>();
+        queryWrapper.eq("user_id",userId);
+        queryWrapper.eq("km",km);
+        questionCollectionService.remove(queryWrapper);
 
-    /**
-     * 删除collection
-     */
-    @Log(title = "collection", businessType = BusinessTypeEnum.DELETE)
-    @DeleteMapping("/{ids}")
-    @ApiOperation("删除collection")
-    public Response<Integer> remove(
-            @ApiParam(name = "ids", value = "collectionids参数", required = true)
-            @PathVariable Long[] ids
-    ) {
-        return toResponse(questionCollectionService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+        //保存上传的收藏题
+        List<QuestionCollection> qlist = new ArrayList<QuestionCollection>();
+        for (QuestionCollectionDTO questionCollectionDTO : list) {
+            QuestionCollection questionCollection = new QuestionCollection();
+            BeanUtils.copyProperties(questionCollectionDTO, questionCollection);
+            questionCollection.setUserId(userId);
+            qlist.add(questionCollection);
+        }
+        if (qlist.isEmpty()) {
+            throw new CustomException("请先收藏题目。");
+        }
+        return toResponse(questionCollectionService.saveBatch(qlist) ? 1 : 0);
     }
 
 
-    @Log(title = "collectionQuestion", businessType = BusinessTypeEnum.DELETE)
     @DeleteMapping("/cancel/{questionId}")
     @ApiOperation("取消收藏")
     public Response<Integer> remove(
@@ -171,7 +126,6 @@ public class QuestionCollectionController extends BaseController {
     }
 
 
-    @Log(title = "collectionQuestion", businessType = BusinessTypeEnum.DELETE)
     @DeleteMapping("/cancelAll")
     @ApiOperation("清空收藏")
     public  Response<Integer> removeAll(@RequestBody QuestionCollectionDelDTO questionCollectionDelDTO){
@@ -179,14 +133,13 @@ public class QuestionCollectionController extends BaseController {
         QueryWrapper<QuestionCollection> queryWrapper = new QueryWrapper<QuestionCollection>();
         queryWrapper.eq("user_id",userId);
         queryWrapper.eq("km",questionCollectionDelDTO.getKm());
-        queryWrapper.eq("car_type",questionCollectionDelDTO.getCarType());
         questionCollectionService.remove(queryWrapper);
         return Response.success();
     }
 
 
     @GetMapping("/collectionByUser")
-    @ApiOperation("根据用户获取收藏列表")
+    @ApiOperation("恢复云端收藏到本机(根据用户获取收藏题)")
     public Response<List<QuestionInfo>> collectionByUser(@ModelAttribute QuestionCollectionListDTO dto){
         dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
         List<QuestionInfo> list = questionCollectionService.selectCollectionByUserId(dto);

+ 28 - 54
nbjk-admin/src/main/java/com/miaxis/app/controller/question/QuestionWrongController.java

@@ -49,40 +49,11 @@ public class QuestionWrongController extends BaseController{
     @Autowired
     private IQuestionWrongService questionWrongService;
 
-    /**
-     * 查询wrong列表
-     */
-    @GetMapping("/list")
-    @ApiOperation("查询wrong列表")
-        @ApiImplicitParams({
-            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
-            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
-    })
-    public ResponsePageInfo<QuestionWrong> list(@ModelAttribute QuestionWrongListDTO dto){
-        startPage();
-        dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
-        List<QuestionWrong> list = questionWrongService.selectQuestionWrongList(dto);
-        return toResponsePageInfo(list);
-    }
 
 
-
-    /**
-     * 获取wrong详细信息
-     */
-    @GetMapping(value = "/{id}")
-    @ApiOperation("获取wrong详细信息")
-    public Response<QuestionWrong> getInfo(
-            @ApiParam(name = "id", value = "wrong参数", required = true)
-            @PathVariable("id") Long id
-    ){
-        return Response.success(questionWrongService.getById(id));
-    }
-
     /**
      * 新增wrong
      */
-    @Log(title = "wrong", businessType = BusinessTypeEnum.INSERT)
     @PostMapping
     @ApiOperation("新增wrong")
     public Response<Integer> add(@RequestBody QuestionWrongDTO questionWrongDTO){
@@ -101,13 +72,14 @@ public class QuestionWrongController extends BaseController{
     }
 
     @PostMapping("wrongs")
-    @ApiOperation("批量新增wrongs")
+    @ApiOperation("合并本机和云端错题")
     public Response<Integer> wrongs(@RequestBody List<QuestionWrongDTO> list){
         //查询该用户已收藏的题目列表
         QuestionWrongListDTO dto = new QuestionWrongListDTO();
         dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
         List<QuestionWrong> dblist = questionWrongService.selectQuestionWrongList(dto);
         List<String> questionIds = dblist.stream().map(o -> o.getQuestionId()+","+o.getKm()).collect(Collectors.toList());
+
         List<QuestionWrong> qlist = new ArrayList<QuestionWrong>();
         for (QuestionWrongDTO questionWrongDTO : list) {
             if (questionIds.contains(questionWrongDTO.getQuestionId()+","+questionWrongDTO.getKm())) {
@@ -119,36 +91,39 @@ public class QuestionWrongController extends BaseController{
             qlist.add(questionWrong);
         }
         if (qlist.isEmpty()) {
-            throw new CustomException("选中的错题都已收藏!");
+            throw new CustomException("选中的错题都已添加!");
         }
         return toResponse(questionWrongService.saveBatch(qlist) ? 1 : 0);
     }
 
-    /**
-     * 修改wrong
-     */
-    @Log(title = "wrong", businessType = BusinessTypeEnum.UPDATE)
-    @PutMapping
-    @ApiOperation("修改wrong")
-    public Response<Integer> edit(@RequestBody QuestionWrong questionWrong){
-        return toResponse(questionWrongService.updateById(questionWrong) ? 1 : 0);
-    }
 
-    /**
-     * 删除wrong
-     */
-    @Log(title = "wrong", businessType = BusinessTypeEnum.DELETE)
-	@DeleteMapping("/{ids}")
-    @ApiOperation("删除wrong")
-    public  Response<Integer> remove(
-            @ApiParam(name = "ids", value = "wrongids参数", required = true)
-            @PathVariable Long[] ids
-    ){
-        return toResponse(questionWrongService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+    @PostMapping("bakWrongs")
+    @ApiOperation("备份本机错题到云端")
+    public Response<Integer> bakWrongs(@RequestBody List<QuestionWrongDTO> list,Integer km){
+        //首先删除云端数据
+        Long userId = SecurityUtils.getLoginUser().getStudent().getId();
+        QueryWrapper<QuestionWrong> queryWrapper = new QueryWrapper<QuestionWrong>();
+        queryWrapper.eq("user_id",userId);
+        queryWrapper.eq("km",km);
+        questionWrongService.remove(queryWrapper);
+
+        //保存上传的错题
+        List<QuestionWrong> qlist = new ArrayList<QuestionWrong>();
+        for (QuestionWrongDTO questionWrongDTO : list) {
+            QuestionWrong questionWrong = new QuestionWrong();
+            BeanUtils.copyProperties(questionWrongDTO, questionWrong);
+            questionWrong.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
+            qlist.add(questionWrong);
+        }
+        if (qlist.isEmpty()) {
+            throw new CustomException("选中的错题都已添加!");
+        }
+        return toResponse(questionWrongService.saveBatch(qlist) ? 1 : 0);
     }
 
 
-    @Log(title = "wrongQuestion", businessType = BusinessTypeEnum.DELETE)
+
+
     @DeleteMapping("/cancel/{questionId}")
     @ApiOperation("删除错题")
     public  Response<Integer> remove(
@@ -164,7 +139,6 @@ public class QuestionWrongController extends BaseController{
 
     }
 
-    @Log(title = "wrongQuestion", businessType = BusinessTypeEnum.DELETE)
     @DeleteMapping("/cancelAll")
     @ApiOperation("清空错题")
     public  Response<Integer> removeAll(@RequestBody QuestionWrongDelDTO questionWrongDelDTO){
@@ -178,7 +152,7 @@ public class QuestionWrongController extends BaseController{
 
 
     @GetMapping("/wrongByUser")
-    @ApiOperation("根据用户获取错题列表")
+    @ApiOperation("恢复云端错题到本机(根据用户获取收错题)")
     public Response<List<QuestionInfo>> wrongByUser(@ModelAttribute QuestionWrongListDTO dto){
         dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
         List<QuestionInfo> list = questionWrongService.selectWrongByUserId(dto);

+ 0 - 3
nbjk-service/src/main/java/com/miaxis/question/dto/QuestionCollectionDTO.java

@@ -27,8 +27,5 @@ public class QuestionCollectionDTO {
     @ApiModelProperty(value = "考试科目(科目一、科目二、科目三、科目四)",required=true)
     private String km;
 
-    /** 车型 */
-    @ApiModelProperty(value = "车型(小车 、客车、货车、摩托车)",required=true)
-    private String carType;
 
 }

+ 3 - 0
nbjk-service/src/main/java/com/miaxis/question/service/IQuestionWrongService.java

@@ -2,6 +2,8 @@ package com.miaxis.question.service;
 
 import java.util.List;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.miaxis.question.domain.QuestionCollection;
 import com.miaxis.question.domain.QuestionInfo;
 import com.miaxis.question.domain.QuestionWrong;
 import com.baomidou.mybatisplus.extension.service.IService;
@@ -25,4 +27,5 @@ public interface IQuestionWrongService extends IService<QuestionWrong>{
     List<QuestionInfo> selectWrongByUserId(QuestionWrongListDTO dto);
 
     Integer selectWrongCountByUserId(QuestionWrongListDTO dto);
+
 }