|
@@ -6,7 +6,9 @@ import com.miaxis.common.constant.Constants;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
import com.miaxis.question.domain.QuestionCollection;
|
|
|
import com.miaxis.question.dto.QuestionCollectionDTO;
|
|
@@ -86,6 +88,14 @@ public class QuestionWrongController extends BaseController{
|
|
|
@PostMapping
|
|
|
@ApiOperation("新增wrong")
|
|
|
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())).count();
|
|
|
+ if (count > 0) {
|
|
|
+ throw new CustomException("该错目已收藏");
|
|
|
+ }
|
|
|
QuestionWrong questionWrong = new QuestionWrong();
|
|
|
BeanUtils.copyProperties(questionWrongDTO,questionWrong);
|
|
|
questionWrong.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
|
|
@@ -95,13 +105,24 @@ public class QuestionWrongController extends BaseController{
|
|
|
@PostMapping("wrongs")
|
|
|
@ApiOperation("批量新增wrongs")
|
|
|
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<Long> questionIds = dblist.stream().map(o -> o.getQuestionId()).collect(Collectors.toList());
|
|
|
List<QuestionWrong> qlist = new ArrayList<QuestionWrong>();
|
|
|
- for (QuestionWrongDTO questionWrongDTO: list) {
|
|
|
+ for (QuestionWrongDTO questionWrongDTO : list) {
|
|
|
+ if (questionIds.contains(questionWrongDTO.getQuestionId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
QuestionWrong questionWrong = new QuestionWrong();
|
|
|
- BeanUtils.copyProperties(questionWrongDTO,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);
|
|
|
}
|
|
|
|