diff --git a/src/main/java/club/joylink/rtss/controller/competition/question/PagerQuestionBankController.java b/src/main/java/club/joylink/rtss/controller/competition/question/PagerQuestionBankController.java index 65598782f..b43038772 100644 --- a/src/main/java/club/joylink/rtss/controller/competition/question/PagerQuestionBankController.java +++ b/src/main/java/club/joylink/rtss/controller/competition/question/PagerQuestionBankController.java @@ -120,8 +120,8 @@ public class PagerQuestionBankController { } - /*@PostMapping(path = "answer/{questionId}") - public void answer(@PathVariable Long questionId,@RequestBody List answer){ +/* @PostMapping(path = "answer/{questionId}") + public void answer(@PathVariable Long questionId,@RequestBody List answer){ this.questionBankService.answer(questionId,answer); }*/ } diff --git a/src/main/java/club/joylink/rtss/dao/paper/PagerQuestionDAO.java b/src/main/java/club/joylink/rtss/dao/paper/PagerQuestionDAO.java index 9f3a5111b..950f9d090 100644 --- a/src/main/java/club/joylink/rtss/dao/paper/PagerQuestionDAO.java +++ b/src/main/java/club/joylink/rtss/dao/paper/PagerQuestionDAO.java @@ -3,6 +3,7 @@ package club.joylink.rtss.dao.paper; import club.joylink.rtss.dao.MyBatisBaseDao; import club.joylink.rtss.entity.paper.question.PaperQuestion; import club.joylink.rtss.entity.paper.question.PaperQuestionExample; +import club.joylink.rtss.entity.project.Project; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; @@ -15,7 +16,7 @@ public interface PagerQuestionDAO extends MyBatisBaseDao" + "select * from paper_question where 1 = 1 " + "" + - ""+ + ""+ " and project_code is null" + ""+ " "+ diff --git a/src/main/java/club/joylink/rtss/services/papger/PagerQuestionService.java b/src/main/java/club/joylink/rtss/services/papger/PagerQuestionService.java index efa0df643..b19d7480f 100644 --- a/src/main/java/club/joylink/rtss/services/papger/PagerQuestionService.java +++ b/src/main/java/club/joylink/rtss/services/papger/PagerQuestionService.java @@ -109,29 +109,29 @@ public class PagerQuestionService { /** * 检测题目是否正确 * @param questionId 题目id - * @param answer 检测的答案 + * @param answerIds 检测的答案Id * @return */ - public boolean answer(Long questionId,List answer){ - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answer),"题目答案不能为空"); + public boolean answer(Long questionId,List answerIds){ + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answerIds),"题目答案不能为空"); PaperQuestionVO vo = this.getQuestion(questionId,true); - List newAnswerList = answer.stream().filter(Objects::nonNull).map(String::trim).distinct().collect(Collectors.toList()); - List optionList = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).map(d->d.getContent().trim()).collect(Collectors.toList()); + List newAnswerList = answerIds.stream().filter(Objects::nonNull)/*.map(String::trim)*/.distinct().collect(Collectors.toList()); + List optionList = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).map(d->d.getId()).collect(Collectors.toList()); if(Objects.equals(BusinessConsts.TheoryType.select.name(),vo.getType()) || Objects.equals(BusinessConsts.TheoryType.judge.name(),vo.getType())){ - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() != 1 ,"单选,判断题答案只能有一个!"); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() == 1 ,"单选,判断题答案只能有一个!"); }else if(Objects.equals(BusinessConsts.TheoryType.multi.name(),vo.getType())){ - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() < 2 ,"多选题答案最少需要2个"); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(newAnswerList.size() > optionList.size(),"多选题答案与标准答案数量不匹配"); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() > 2 ,"多选题答案最少需要2个"); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() < optionList.size(),"多选题答案与标准答案数量不匹配"); } - List sourceOptionList = Lists.newArrayList(); + List sourceOptionList = Lists.newArrayList(); sourceOptionList.addAll(optionList); optionList.removeAll(newAnswerList); if(CollectionUtils.isEmpty(optionList)){ return true; } - log.info("检查题目[{}]答案,获取原答案[{}],正确答案[{}] 有[{}]没有答对",questionId, Joiner.on(",").join(answer),Joiner.on(",").join(sourceOptionList),Joiner.on(",").join(optionList)); + log.info("检查题目[{}]答案,获取原答案[{}],正确答案[{}] 有[{}]没有答对",questionId, Joiner.on(",").join(answerIds),Joiner.on(",").join(sourceOptionList),Joiner.on(",").join(optionList)); return false; } @@ -189,15 +189,6 @@ public class PagerQuestionService { }else if(questionVO.isMulti()){ this.checkQuestionTypeForMulti(questionVO,"多选题正确答案必须是2个以上!"); } - /* BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue( - (Objects.equals(BusinessConsts.TheoryType.select.name(), questionVO.getType()) || - Objects.equals(BusinessConsts.TheoryType.judge.name(), questionVO.getType())) && - questionVO.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).count() == 1, - "单选或判断题正确答案有且只有一个!"); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue( - (Objects.equals(BusinessConsts.TheoryType.multi.name(), questionVO.getType())) && - questionVO.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).count() <= 1, - "多选题正确答案必须是2个以上!");*/ PaperQuestion question = questionVO.convert2DB(); question.setCreateUserId(accountVO.getId()); question.setCreateTime(LocalDateTime.now()); @@ -232,7 +223,7 @@ public class PagerQuestionService { private void checkQuestionTypeForMulti(PaperQuestionVO vo,String errStr){ long answerCount = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).count(); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(answerCount <=1,errStr); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(answerCount > 2,errStr); } @Transactional diff --git a/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionOptionVO2.java b/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionOptionVO2.java index 7ca8e2ca5..1eb69efba 100644 --- a/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionOptionVO2.java +++ b/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionOptionVO2.java @@ -19,8 +19,8 @@ import java.util.List; @NoArgsConstructor public class PaperQuestionOptionVO2 implements Cloneable { - private Long id; - private Long questionId; + private int id; +// private Long questionId; /** * 选项 */ @@ -33,21 +33,21 @@ public class PaperQuestionOptionVO2 implements Cloneable { private Boolean correct; public PaperQuestionOptionVO2(RaceQuestionOption questionOption) { - this.id = questionOption.getId(); - this.questionId = questionOption.getQuestionId(); + this.id = questionOption.getId().intValue(); +// this.questionId = questionOption.getQuestionId(); this.content = questionOption.getContent(); this.correct = questionOption.getCorrect(); } - public RaceQuestionOption convert2DB() { - RaceQuestionOption questionOption = new RaceQuestionOption(); - questionOption.setId(id); - questionOption.setQuestionId(questionId); - questionOption.setContent(content); - questionOption.setCorrect(correct); - - return questionOption; - } +// public RaceQuestionOption convert2DB() { +// RaceQuestionOption questionOption = new RaceQuestionOption(); +// questionOption.setId(id); +//// questionOption.setQuestionId(questionId); +// questionOption.setContent(content); +// questionOption.setCorrect(correct); +// +// return questionOption; +// } public static List convert2VOList(List options){ List voList = new ArrayList<>(); diff --git a/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionVO.java b/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionVO.java index 685f5c40f..c6cd782a5 100644 --- a/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionVO.java @@ -74,11 +74,18 @@ public class PaperQuestionVO implements Cloneable { question.setTopic(topic); question.setProjectCode(Project.isDefault(Project.valueOf(projectCode)) ? null : projectCode); question.setCompanyId(companyId); + this.setOptionId(); question.setQuestions(JsonUtils.writeValueAsString(this.optionList)); question.setRaceLable(this.raceLable); question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); return question; } + private void setOptionId(){ + int i = 0; + for (PaperQuestionOptionVO2 vo : this.optionList) { + vo.setId(i++); + } + } public static List convert2VOList(List questions){