|
@@ -7,10 +7,7 @@ import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
import com.miaxis.question.domain.QuestionInfo;
|
|
|
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.QuestionWrongYunDTO;
|
|
|
+import com.miaxis.question.dto.*;
|
|
|
import com.miaxis.question.service.IQuestionWrongService;
|
|
|
import com.miaxis.question.vo.QuestionWrongIdDateVo;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -21,6 +18,7 @@ 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;
|
|
|
|
|
@@ -31,58 +29,59 @@ import java.util.stream.Collectors;
|
|
|
* @date 2021-08-19
|
|
|
*/
|
|
|
@RestController
|
|
|
-@RequestMapping(Constants.STUDENT_PREFIX+"/question/wrong")
|
|
|
-@Api(tags={"【APP-错题】"})
|
|
|
-public class QuestionWrongController extends BaseController{
|
|
|
+@RequestMapping(Constants.STUDENT_PREFIX + "/question/wrong")
|
|
|
+@Api(tags = {"【APP-错题】"})
|
|
|
+public class QuestionWrongController extends BaseController {
|
|
|
@Autowired
|
|
|
private IQuestionWrongService questionWrongService;
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 新增wrong
|
|
|
*/
|
|
|
@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("该错已加入错题集");
|
|
|
- Response response = new Response(200,"该错已加入错题集");
|
|
|
+ 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("合并本机和云端错题")
|
|
|
- public Response<Integer> wrongs(@RequestBody QuestionWrongYunDTO wrong){
|
|
|
+ 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> questionIdsStr = 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 (Long qid : wrong.getQuestionIds()) {
|
|
|
- if (questionIdsStr.contains(qid+","+wrong.getKm())) {
|
|
|
+ for (QuestionWgYunDTO wgYunDTO : wrong.getWrongs()) {
|
|
|
+ if (questionIdsStr.contains(wgYunDTO.getQuestionId() + "," + wrong.getKm())) {
|
|
|
continue;
|
|
|
}
|
|
|
QuestionWrong questionWrong = new QuestionWrong();
|
|
|
questionWrong.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
|
|
|
questionWrong.setKm(wrong.getKm());
|
|
|
- questionWrong.setQuestionId(qid);
|
|
|
+ questionWrong.setQuestionId(wgYunDTO.getQuestionId());
|
|
|
+ Date crDate = new Date(wgYunDTO.getTimestamp() * 1000);
|
|
|
+ questionWrong.setCreateTime(crDate);
|
|
|
qlist.add(questionWrong);
|
|
|
}
|
|
|
if (qlist.isEmpty()) {
|
|
|
- Response response = new Response(200,"选中的错题都已添加!");
|
|
|
+ Response response = new Response(200, "选中的错题都已添加!");
|
|
|
return response;
|
|
|
}
|
|
|
return toResponse(questionWrongService.saveBatch(qlist) ? 1 : 0);
|
|
@@ -91,43 +90,43 @@ public class QuestionWrongController extends BaseController{
|
|
|
|
|
|
@PostMapping("bakWrongs")
|
|
|
@ApiOperation("备份本机错题到云端")
|
|
|
- public Response bakWrongs(@RequestBody QuestionWrongYunDTO wrong){
|
|
|
+ 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());
|
|
|
+ queryWrapper.eq("user_id", userId);
|
|
|
+ queryWrapper.eq("km", wrong.getKm());
|
|
|
questionWrongService.remove(queryWrapper);
|
|
|
|
|
|
//保存上传的错题
|
|
|
List<QuestionWrong> qlist = new ArrayList<QuestionWrong>();
|
|
|
- for (Long qid : wrong.getQuestionIds()) {
|
|
|
+ for (QuestionWgYunDTO wgYunDTO : wrong.getWrongs()) {
|
|
|
QuestionWrong questionWrong = new QuestionWrong();
|
|
|
questionWrong.setUserId(userId);
|
|
|
questionWrong.setKm(wrong.getKm());
|
|
|
- questionWrong.setQuestionId(qid);
|
|
|
+ questionWrong.setQuestionId(wgYunDTO.getQuestionId());
|
|
|
+ Date crDate = new Date(wgYunDTO.getTimestamp() * 1000);
|
|
|
+ questionWrong.setCreateTime(crDate);
|
|
|
qlist.add(questionWrong);
|
|
|
}
|
|
|
if (qlist.isEmpty()) {
|
|
|
- Response response = new Response(200,"该错已加入错题集(无须提示给用户)");
|
|
|
+ Response response = new Response(200, "该错已加入错题集(无须提示给用户)");
|
|
|
return response;
|
|
|
}
|
|
|
return toResponse(questionWrongService.saveBatch(qlist) ? 1 : 0);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@DeleteMapping("/cancel/{questionId}")
|
|
|
@ApiOperation("删除错题")
|
|
|
- public Response<Integer> remove(
|
|
|
+ public Response<Integer> remove(
|
|
|
@ApiParam(name = "questionId", value = "问题id", required = true)
|
|
|
@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();
|
|
|
|
|
@@ -135,11 +134,11 @@ public class QuestionWrongController extends BaseController{
|
|
|
|
|
|
@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<QuestionWrong> queryWrapper = new QueryWrapper<QuestionWrong>();
|
|
|
+ queryWrapper.eq("user_id", userId);
|
|
|
+ queryWrapper.eq("km", questionWrongDelDTO.getKm());
|
|
|
questionWrongService.remove(queryWrapper);
|
|
|
return Response.success();
|
|
|
}
|
|
@@ -147,7 +146,7 @@ public class QuestionWrongController extends BaseController{
|
|
|
|
|
|
@GetMapping("/wrongByUser")
|
|
|
@ApiOperation("小程序恢复云端错题到本机(根据用户获取错题)")
|
|
|
- public Response<List<QuestionInfo>> wrongByUser(@ModelAttribute QuestionWrongListDTO dto){
|
|
|
+ public Response<List<QuestionInfo>> wrongByUser(@ModelAttribute QuestionWrongListDTO dto) {
|
|
|
dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
|
|
|
List<QuestionInfo> list = questionWrongService.selectWrongByUserId(dto);
|
|
|
return Response.success(list);
|
|
@@ -155,7 +154,7 @@ public class QuestionWrongController extends BaseController{
|
|
|
|
|
|
@GetMapping("/appWrongByUser")
|
|
|
@ApiOperation("app恢复云端错题到本机(根据用户获取错题)")
|
|
|
- public Response<List<QuestionWrongIdDateVo>> appWrongByUser(@ModelAttribute QuestionWrongListDTO dto){
|
|
|
+ public Response<List<QuestionWrongIdDateVo>> appWrongByUser(@ModelAttribute QuestionWrongListDTO dto) {
|
|
|
dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
|
|
|
List<QuestionWrongIdDateVo> list = questionWrongService.selectWrongIdByUserId(dto);
|
|
|
return Response.success(list);
|
|
@@ -164,7 +163,7 @@ public class QuestionWrongController extends BaseController{
|
|
|
|
|
|
@GetMapping("/wrongCountByUser")
|
|
|
@ApiOperation("根据用户获取错题数")
|
|
|
- public Response<Integer> wrongCountByUser(@ModelAttribute QuestionWrongListDTO dto){
|
|
|
+ public Response<Integer> wrongCountByUser(@ModelAttribute QuestionWrongListDTO dto) {
|
|
|
dto.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
|
|
|
Integer count = questionWrongService.selectWrongCountByUserId(dto);
|
|
|
return Response.success(count);
|