理论试题管理代码调整

This commit is contained in:
tiger_zhou 2022-09-26 13:03:34 +08:00
parent 35fd58eb1d
commit d8079d98f2
5 changed files with 35 additions and 36 deletions

View File

@ -120,8 +120,8 @@ public class PagerQuestionBankController {
}
/*@PostMapping(path = "answer/{questionId}")
public void answer(@PathVariable Long questionId,@RequestBody List<String> answer){
/* @PostMapping(path = "answer/{questionId}")
public void answer(@PathVariable Long questionId,@RequestBody List<Integer> answer){
this.questionBankService.answer(questionId,answer);
}*/
}

View File

@ -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<PaperQuestion, Long, Pa
@Select("<script>" +
"select * from paper_question where 1 = 1 " +
"<choose>" +
"<when test=\"projectCode == 'DEFAULT'\">"+
"<when test=\"projectCode == '"+ Project.DEFAULT_PROJECT_CODE +"'\">"+
" and project_code is null" +
"</when>"+
" <otherwise>"+

View File

@ -109,29 +109,29 @@ public class PagerQuestionService {
/**
* 检测题目是否正确
* @param questionId 题目id
* @param answer 检测的答案
* @param answerIds 检测的答案Id
* @return
*/
public boolean answer(Long questionId,List<String> answer){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answer),"题目答案不能为空");
public boolean answer(Long questionId,List<Integer> answerIds){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answerIds),"题目答案不能为空");
PaperQuestionVO vo = this.getQuestion(questionId,true);
List<String> newAnswerList = answer.stream().filter(Objects::nonNull).map(String::trim).distinct().collect(Collectors.toList());
List<String> optionList = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).map(d->d.getContent().trim()).collect(Collectors.toList());
List<Integer> newAnswerList = answerIds.stream().filter(Objects::nonNull)/*.map(String::trim)*/.distinct().collect(Collectors.toList());
List<Integer> 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<String> sourceOptionList = Lists.newArrayList();
List<Integer> 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

View File

@ -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<PaperQuestionOptionVO2> convert2VOList(List<RaceQuestionOption> options){
List<PaperQuestionOptionVO2> voList = new ArrayList<>();

View File

@ -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<PaperQuestionVO> convert2VOList(List<PaperQuestion> questions){