|
@@ -1,9 +1,16 @@
|
|
|
package com.ruoyi.abuwx.service.impl.exam;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import com.ruoyi.abuwx.domain.exam.ExmQuestionAnswer;
|
|
|
+import com.ruoyi.abuwx.domain.exam.ExmQuestionOption;
|
|
|
import com.ruoyi.abuwx.domain.exam.ExmQuestionType;
|
|
|
+import com.ruoyi.abuwx.service.exam.IExmQuestionAnswerService;
|
|
|
+import com.ruoyi.abuwx.service.exam.IExmQuestionOptionService;
|
|
|
+import com.ruoyi.abuwx.service.exam.IExmQuestionTypeService;
|
|
|
import com.ruoyi.common.exception.base.BaseException;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
@@ -27,6 +34,15 @@ public class ExmQuestionServiceImpl implements IExmQuestionService
|
|
|
@Autowired
|
|
|
private ExmQuestionMapper exmQuestionMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IExmQuestionTypeService exmQuestionTypeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IExmQuestionAnswerService questionAnswerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IExmQuestionOptionService questionOptionService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询试题
|
|
|
*
|
|
@@ -61,8 +77,27 @@ public class ExmQuestionServiceImpl implements IExmQuestionService
|
|
|
public int insertExmQuestion(ExmQuestion exmQuestion)
|
|
|
{
|
|
|
int result = 0;
|
|
|
+ ExmQuestionType questionType = exmQuestionTypeService.selectExmQuestionTypeById(exmQuestion.getQuestionTypeId());
|
|
|
|
|
|
+ List<String> options = exmQuestion.getQuestionOptions();
|
|
|
+ List<String> answers = exmQuestion.getQuestionAnswers();
|
|
|
+ List<BigDecimal> scores = exmQuestion.getScores();
|
|
|
+
|
|
|
+ //校验
|
|
|
+ addValid(exmQuestion, options, answers, scores,
|
|
|
+ questionType);
|
|
|
+ exmQuestion.setCreateTime(new Date());
|
|
|
+ exmQuestion.setCreateUserId(CurLoginUserUtil.getUserId());
|
|
|
result = exmQuestionMapper.insertExmQuestion(exmQuestion);
|
|
|
+
|
|
|
+ // 添加答案
|
|
|
+ addQuestionAnswer(exmQuestion, answers, scores);
|
|
|
+
|
|
|
+ // 添加选项
|
|
|
+ addQuestionOption(exmQuestion, options);
|
|
|
+
|
|
|
+ // 保存附件
|
|
|
+// addQuestionFile(question, options);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -297,4 +332,61 @@ public class ExmQuestionServiceImpl implements IExmQuestionService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void addQuestionAnswer(ExmQuestion question, List<String> answers, List<BigDecimal> scores) {
|
|
|
+ List<ExmQuestionAnswer> questionAnswerList = questionAnswerService.getList(question.getId());
|
|
|
+ for (ExmQuestionAnswer questionAnswer : questionAnswerList) {
|
|
|
+ questionAnswerService.deleteExmQuestionAnswerById(questionAnswer.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (QuestionUtil.hasSingleChoice(question) || QuestionUtil.hasTrueFalse(question)) {
|
|
|
+ ExmQuestionAnswer questionAnswer = new ExmQuestionAnswer();
|
|
|
+ questionAnswer.setAnswer(answers.get(0));
|
|
|
+ questionAnswer.setScore(null);
|
|
|
+ questionAnswer.setQuestionId(question.getId());
|
|
|
+ questionAnswer.setNo(1l);
|
|
|
+ questionAnswerService.insertExmQuestionAnswer(questionAnswer);
|
|
|
+ } else if ((QuestionUtil.hasQA(question) && QuestionUtil.hasSubjective(question))) {// 答案有逗号,接收参数会分隔,这里合并一下
|
|
|
+ ExmQuestionAnswer questionAnswer = new ExmQuestionAnswer();
|
|
|
+ questionAnswer.setAnswer(StringUtils.join(answers, ","));
|
|
|
+ questionAnswer.setScore(null);
|
|
|
+ questionAnswer.setQuestionId(question.getId());
|
|
|
+ questionAnswer.setNo(1l);
|
|
|
+ questionAnswerService.insertExmQuestionAnswer(questionAnswer);
|
|
|
+ } else if (QuestionUtil.hasMultipleChoice(question)) {
|
|
|
+ ExmQuestionAnswer questionAnswer = new ExmQuestionAnswer();
|
|
|
+ Collections.sort(answers);// 页面前选b在选a,传值为ba,排序后在保存
|
|
|
+ questionAnswer.setAnswer(StringUtils.join(answers, ","));
|
|
|
+ questionAnswer.setScore(scores.get(0));
|
|
|
+ questionAnswer.setQuestionId(question.getId());
|
|
|
+ questionAnswer.setNo(1l);
|
|
|
+ questionAnswerService.insertExmQuestionAnswer(questionAnswer);
|
|
|
+ } else if (QuestionUtil.hasFillBlank(question)
|
|
|
+ || (QuestionUtil.hasQA(question) && QuestionUtil.hasObjective(question))) {
|
|
|
+ for (int i = 0; i < answers.size(); i++) {
|
|
|
+ ExmQuestionAnswer questionAnswer = new ExmQuestionAnswer();
|
|
|
+ questionAnswer.setAnswer(answers.get(i));
|
|
|
+ questionAnswer.setScore(scores.get(i));
|
|
|
+ questionAnswer.setQuestionId(question.getId());
|
|
|
+ questionAnswer.setNo(i + 1l);
|
|
|
+ questionAnswerService.insertExmQuestionAnswer(questionAnswer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addQuestionOption(ExmQuestion question, List<String> options) {
|
|
|
+ List<ExmQuestionOption> questionOptionList = questionOptionService.getList(question.getId());
|
|
|
+ for (ExmQuestionOption questionOption : questionOptionList) {
|
|
|
+ questionOptionService.deleteExmQuestionOptionById(questionOption.getId());
|
|
|
+ }
|
|
|
+ if (QuestionUtil.hasSingleChoice(question) || QuestionUtil.hasMultipleChoice(question)) {
|
|
|
+ for (int i = 0; i < options.size(); i++) {
|
|
|
+ ExmQuestionOption questionOption = new ExmQuestionOption();
|
|
|
+ questionOption.setQuestionId(question.getId());
|
|
|
+ questionOption.setOptions(options.get(i));
|
|
|
+ questionOption.setNo(i + 1l);
|
|
|
+ questionOptionService.insertExmQuestionOption(questionOption);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|