|
@@ -70,8 +70,11 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void save(PaperDTO paperDTO) {
|
|
|
- // 校验数据
|
|
|
- this.checkData(paperDTO);
|
|
|
+ //校验数据
|
|
|
+ checkData(paperDTO);
|
|
|
+ //校验分数
|
|
|
+ checkQuestionScore(paperDTO);
|
|
|
+
|
|
|
Paper paper = new Paper();
|
|
|
BeanUtils.copyProperties(paperDTO, paper);
|
|
|
//保存试卷
|
|
@@ -80,6 +83,50 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
|
|
|
paperRuleGroupService.saveAll(paper, paperDTO.getGroupList());
|
|
|
}
|
|
|
|
|
|
+ public void checkQuestionScore(PaperDTO paperDTO) {
|
|
|
+ if (paperDTO.getJoinType().equals(JoinType.SJ.getCode())) {//随机组卷
|
|
|
+ for (PaperRuleGroup group : paperDTO.getGroupList()) {
|
|
|
+ if (Objects.isNull(group.getPerScore()) || group.getPerScore() == 0.0) {
|
|
|
+ throw new JeecgBootException("题目组: " + group.getTitle() + "分值须大于0!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (paperDTO.getJoinType().equals(JoinType.XT.getCode()) || paperDTO.getJoinType().equals(JoinType.CT.getCode())) {
|
|
|
+ //选题组卷或者抽题组卷
|
|
|
+ for (PaperRuleGroup group : paperDTO.getGroupList()) {
|
|
|
+ List<Question> questionList = group.getQuestionList();
|
|
|
+ if (CollectionUtils.isEmpty(questionList)) {
|
|
|
+ throw new JeecgBootException(group.getTitle() + "题目列表不能为空!");
|
|
|
+ }
|
|
|
+ if (QuestionType.COMBINATION.getCode().equals(group.getQuestionType())) {//组合题
|
|
|
+ for (Question question : questionList) {
|
|
|
+ List<Question> subQuestionList = question.getSubQuestionList();
|
|
|
+ for (Question subQuestion : subQuestionList) {
|
|
|
+ if (Objects.isNull(subQuestion.getScore()) || subQuestion.getScore() == 0.0) {
|
|
|
+ throw new JeecgBootException("组合题子题目:【" + subString(subQuestion.getContent()) + "】分值须大于0!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (Question question : questionList) {
|
|
|
+ if (Objects.isNull(question.getScore()) || question.getScore() == 0.0) {
|
|
|
+ throw new JeecgBootException("题目:【" + subString(question.getContent()) + "】分值须大于0!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 截取字符串
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String subString(String content) {
|
|
|
+ return content.length() > 50 ? content.substring(0, 50) + "..." : content;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 校验试卷信息
|
|
|
*
|
|
@@ -93,10 +140,10 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
|
|
|
throw new JeecgBootException("组卷方式不能为空!");
|
|
|
}
|
|
|
if (Objects.isNull(dto.getTotalScore()) || dto.getTotalScore().doubleValue() == 0) {
|
|
|
- throw new JeecgBootException("试卷总分不能为空!");
|
|
|
+ throw new JeecgBootException("试卷总分不能为0!");
|
|
|
}
|
|
|
if (Objects.isNull(dto.getQuestionCount()) || dto.getQuestionCount().intValue() == 0) {
|
|
|
- throw new JeecgBootException("试卷总题数不能为空!");
|
|
|
+ throw new JeecgBootException("试卷总题数不能为0!");
|
|
|
}
|
|
|
|
|
|
checkFillOption(dto);
|