|
@@ -1,26 +1,21 @@
|
|
|
package com.miaxis.app.controller.h5;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.miaxis.common.annotation.Log;
|
|
|
import com.miaxis.common.constant.Constants;
|
|
|
import com.miaxis.common.core.controller.BaseController;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
-import com.miaxis.common.core.page.ResponsePageInfo;
|
|
|
-import com.miaxis.common.enums.BusinessTypeEnum;
|
|
|
-import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
import com.miaxis.question.domain.QuestionWrong;
|
|
|
-import com.miaxis.question.dto.QuestionWrongDTO;
|
|
|
-import com.miaxis.question.dto.QuestionWrongDelDTO;
|
|
|
-import com.miaxis.question.dto.QuestionWrongListDTO;
|
|
|
+import com.miaxis.question.dto.*;
|
|
|
import com.miaxis.question.service.IQuestionWrongService;
|
|
|
+import com.miaxis.question.vo.QuestionWrongIdDateVo;
|
|
|
import io.swagger.annotations.*;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -37,132 +32,131 @@ 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){
|
|
|
+ public Response<Integer> add(@RequestBody QuestionWrongDTO questionWrongDTO) {
|
|
|
//查询该用户已收藏的题目列表
|
|
|
QuestionWrongListDTO dto = new QuestionWrongListDTO();
|
|
|
dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
|
|
|
List<QuestionWrong> list = questionWrongService.selectQuestionWrongList(dto);
|
|
|
- long count = list.stream().filter(o -> questionWrongDTO.getQuestionId().equals(o.getQuestionId()) && questionWrongDTO.getKm().equals(o.getKm())).count();
|
|
|
+ long count = list.stream().filter(o -> questionWrongDTO.getQuestionId().equals(o.getQuestionId()) && questionWrongDTO.getKm().equals(o.getKm())).count();
|
|
|
if (count > 0) {
|
|
|
- throw new CustomException("该错已加入错题集");
|
|
|
+ //throw new CustomException("该错已加入错题集");
|
|
|
+ Response response = new Response(200, "该错已加入错题集");
|
|
|
+ return response;
|
|
|
}
|
|
|
QuestionWrong questionWrong = new QuestionWrong();
|
|
|
- BeanUtils.copyProperties(questionWrongDTO,questionWrong);
|
|
|
+ BeanUtils.copyProperties(questionWrongDTO, questionWrong);
|
|
|
questionWrong.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
|
|
|
return toResponse(questionWrongService.save(questionWrong) ? 1 : 0);
|
|
|
}
|
|
|
|
|
|
@PostMapping("wrongs")
|
|
|
- @ApiOperation("批量新增wrongs")
|
|
|
- public Response<Integer> wrongs(@RequestBody List<QuestionWrongDTO> list){
|
|
|
+ @ApiOperation("合并本机和云端错题")
|
|
|
+ public Response<Integer> wrongs(@RequestBody QuestionWrongYunDTO wrong) {
|
|
|
//查询该用户已收藏的题目列表
|
|
|
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<String> questionIdsStr = 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())) {
|
|
|
+ for (QuestionWgYunDTO wgYunDTO : wrong.getWrongs()) {
|
|
|
+ if (questionIdsStr.contains(wgYunDTO.getId() + "," + wrong.getKm())) {
|
|
|
continue;
|
|
|
}
|
|
|
QuestionWrong questionWrong = new QuestionWrong();
|
|
|
- BeanUtils.copyProperties(questionWrongDTO, questionWrong);
|
|
|
questionWrong.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
|
|
|
+ questionWrong.setKm(wrong.getKm());
|
|
|
+ questionWrong.setQuestionId(wgYunDTO.getId());
|
|
|
+ Date crDate = new Date(wgYunDTO.getTimestamp());
|
|
|
+ questionWrong.setCreateTime(crDate);
|
|
|
qlist.add(questionWrong);
|
|
|
}
|
|
|
-// if (qlist.isEmpty()) {
|
|
|
-// throw new CustomException("选中的错题都已收藏!");
|
|
|
-// }
|
|
|
+ if (qlist.isEmpty()) {
|
|
|
+ Response response = new Response(200, "选中的错题都已添加!");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
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 bakWrongs(@RequestBody QuestionWrongYunDTO wrong) {
|
|
|
+ //首先删除云端数据
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getStudent().getId();
|
|
|
+ QueryWrapper<QuestionWrong> queryWrapper = new QueryWrapper<QuestionWrong>();
|
|
|
+ queryWrapper.eq("user_id", userId);
|
|
|
+ queryWrapper.eq("km", wrong.getKm());
|
|
|
+ questionWrongService.remove(queryWrapper);
|
|
|
+
|
|
|
+ //保存上传的错题
|
|
|
+ List<QuestionWrong> qlist = new ArrayList<QuestionWrong>();
|
|
|
+ for (QuestionWgYunDTO wgYunDTO : wrong.getWrongs()) {
|
|
|
+ QuestionWrong questionWrong = new QuestionWrong();
|
|
|
+ questionWrong.setUserId(userId);
|
|
|
+ questionWrong.setKm(wrong.getKm());
|
|
|
+ questionWrong.setQuestionId(wgYunDTO.getId());
|
|
|
+ Date crDate = new Date(wgYunDTO.getTimestamp());
|
|
|
+ questionWrong.setCreateTime(crDate);
|
|
|
+ qlist.add(questionWrong);
|
|
|
+ }
|
|
|
+ if (qlist.isEmpty()) {
|
|
|
+ Response response = new Response(200, "该错已加入错题集(无须提示给用户)");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ return toResponse(questionWrongService.saveBatch(qlist) ? 1 : 0);
|
|
|
}
|
|
|
|
|
|
|
|
|
- @Log(title = "wrongQuestion", businessType = BusinessTypeEnum.DELETE)
|
|
|
@DeleteMapping("/cancel/{questionId}")
|
|
|
@ApiOperation("删除错题")
|
|
|
public Response<Integer> remove(
|
|
|
@ApiParam(name = "questionId", value = "问题id", required = true)
|
|
|
- @PathVariable String questionId
|
|
|
- ){
|
|
|
+ @PathVariable Long questionId
|
|
|
+ ) {
|
|
|
Long userId = SecurityUtils.getLoginUser().getStudent().getId();
|
|
|
- QueryWrapper<QuestionWrong> queryWrapper= new QueryWrapper<QuestionWrong>();
|
|
|
- queryWrapper.eq("user_id",userId);
|
|
|
- queryWrapper.eq("question_id",questionId);
|
|
|
+ QueryWrapper<QuestionWrong> queryWrapper = new QueryWrapper<QuestionWrong>();
|
|
|
+ queryWrapper.eq("user_id", userId);
|
|
|
+ queryWrapper.eq("question_id", questionId);
|
|
|
questionWrongService.remove(queryWrapper);
|
|
|
return Response.success();
|
|
|
|
|
|
}
|
|
|
|
|
|
- @Log(title = "wrongQuestion", businessType = BusinessTypeEnum.DELETE)
|
|
|
@DeleteMapping("/cancelAll")
|
|
|
@ApiOperation("清空错题")
|
|
|
- public Response<Integer> removeAll(@RequestBody QuestionWrongDelDTO questionWrongDelDTO){
|
|
|
+ public Response<Integer> removeAll(@RequestBody QuestionWrongDelDTO questionWrongDelDTO) {
|
|
|
Long userId = SecurityUtils.getLoginUser().getStudent().getId();
|
|
|
- QueryWrapper<QuestionWrong> queryWrapper= new QueryWrapper<QuestionWrong>();
|
|
|
- queryWrapper.eq("user_id",userId);
|
|
|
- queryWrapper.eq("km",questionWrongDelDTO.getKm());
|
|
|
- queryWrapper.eq("car_type",questionWrongDelDTO.getCarType());
|
|
|
+ QueryWrapper<QuestionWrong> queryWrapper = new QueryWrapper<QuestionWrong>();
|
|
|
+ queryWrapper.eq("user_id", userId);
|
|
|
+ queryWrapper.eq("km", questionWrongDelDTO.getKm());
|
|
|
questionWrongService.remove(queryWrapper);
|
|
|
return Response.success();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @GetMapping("/wrongByUser")
|
|
|
+ @ApiOperation("恢复云端错题到本机(根据用户获取错题)")
|
|
|
+ public Response<List<QuestionWrongIdDateVo>> appWrongByUser(@ModelAttribute QuestionWrongListDTO dto) {
|
|
|
+ dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
|
|
|
+ List<QuestionWrongIdDateVo> list = questionWrongService.selectWrongIdByUserId(dto);
|
|
|
+ return Response.success(list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/wrongCountByUser")
|
|
|
+ @ApiOperation("根据用户获取错题数")
|
|
|
+ public Response<Integer> wrongCountByUser(@ModelAttribute QuestionWrongListDTO dto) {
|
|
|
+ dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
|
|
|
+ Integer count = questionWrongService.selectWrongCountByUserId(dto);
|
|
|
+ return Response.success(count);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|