理论试题管理代码调整,支持乱序预览及测试答题
This commit is contained in:
parent
676ee99043
commit
80307e835d
@ -57,11 +57,16 @@ public class PagerQuestionBankController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取题目信息
|
* 获取题目信息或预览
|
||||||
*/
|
*/
|
||||||
@GetMapping(path = "/org/{questionId}")
|
@GetMapping(path = "/org/{questionId}")
|
||||||
public PaperQuestionVO getQuestion(@PathVariable Long questionId) {
|
public PaperQuestionVO getQuestion(@PathVariable Long questionId,@RequestParam(name = "random",defaultValue = "false") boolean random) {
|
||||||
return questionBankService.getQuestion(questionId, false);
|
return questionBankService.getQuestion(questionId, false,random);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(path = "/org/test/answer/{questionId}")
|
||||||
|
public boolean testAnswer(@PathVariable Long questionId,@RequestBody List<Integer> answers){
|
||||||
|
return this.questionBankService.answer(questionId,answers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,4 +126,6 @@ public class PagerQuestionBankController {
|
|||||||
questionBankService.deleteQuestion(questionId);
|
questionBankService.deleteQuestion(questionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ public class PagerQuestionService {
|
|||||||
* @param doNotCheckDel 是否检测数据状态是否删除 true = 不检测,false=检测
|
* @param doNotCheckDel 是否检测数据状态是否删除 true = 不检测,false=检测
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PaperQuestionVO getQuestion(Long questionId,boolean doNotCheckDel) {
|
public PaperQuestionVO getQuestion(Long questionId,boolean doNotCheckDel,boolean random) {
|
||||||
PaperQuestionWithBLOBs question = questionDAO.selectByPrimaryKey(questionId);
|
PaperQuestionWithBLOBs question = questionDAO.selectByPrimaryKey(questionId);
|
||||||
boolean isDel = Objects.nonNull(question) || question.getIsDel() == BusinessConsts.DBLogicDelete.NORMAL.ordinal();
|
boolean isDel = Objects.nonNull(question) || question.getIsDel() == BusinessConsts.DBLogicDelete.NORMAL.ordinal();
|
||||||
if(doNotCheckDel){
|
if(doNotCheckDel){
|
||||||
@ -106,6 +106,9 @@ public class PagerQuestionService {
|
|||||||
}
|
}
|
||||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(isDel);
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(isDel);
|
||||||
PaperQuestionVO questionVO = new PaperQuestionVO(question);
|
PaperQuestionVO questionVO = new PaperQuestionVO(question);
|
||||||
|
if(random){
|
||||||
|
Collections.shuffle(questionVO.getOptionList());
|
||||||
|
}
|
||||||
return questionVO;
|
return questionVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,17 +120,17 @@ public class PagerQuestionService {
|
|||||||
*/
|
*/
|
||||||
public boolean answer(Long questionId,List<Integer> answerIds){
|
public boolean answer(Long questionId,List<Integer> answerIds){
|
||||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answerIds),"题目答案不能为空");
|
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answerIds),"题目答案不能为空");
|
||||||
PaperQuestionVO vo = this.getQuestion(questionId,true);
|
PaperQuestionVO vo = this.getQuestion(questionId,true,false);
|
||||||
List<Integer> newAnswerList = answerIds.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
List<Integer> newAnswerList = answerIds.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||||
if(Objects.equals(BusinessConsts.TheoryType.select.name(),vo.getType())
|
/* if(Objects.equals(BusinessConsts.TheoryType.select.name(),vo.getType())
|
||||||
|| Objects.equals(BusinessConsts.TheoryType.judge.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())){
|
}else if(Objects.equals(BusinessConsts.TheoryType.multi.name(),vo.getType())){
|
||||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() > 2 ,"多选题答案最少需要2个");
|
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() >= 2 ,"多选题答案最少需要2个");
|
||||||
}
|
}*/
|
||||||
Collections.sort(answerIds);
|
Collections.sort(newAnswerList);
|
||||||
String answerStr = Joiner.on(",").skipNulls().join(answerIds);
|
String answerStr = Joiner.on(",").skipNulls().join(newAnswerList);
|
||||||
if(Objects.equals(answerStr,vo.getQuestionAnswer())){
|
if(Objects.equals(answerStr,vo.getAnswer())){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
log.info("检查题目[{}]答案,获取原答案[{}],正确答案[{}] ",questionId, answerStr,vo.getQuestionAnswer());
|
log.info("检查题目[{}]答案,获取原答案[{}],正确答案[{}] ",questionId, answerStr,vo.getQuestionAnswer());
|
||||||
|
Loading…
Reference in New Issue
Block a user