瀏覽代碼

fix: 分组设置保存加入仲裁值不能大于试题分数的校验

caozixuan 9 月之前
父節點
當前提交
ca1b45533b
共有 1 個文件被更改,包括 28 次插入4 次删除
  1. 28 4
      src/main/java/cn/com/qmth/mps/service/impl/PaperGroupServiceImpl.java

+ 28 - 4
src/main/java/cn/com/qmth/mps/service/impl/PaperGroupServiceImpl.java

@@ -1,8 +1,10 @@
 package cn.com.qmth.mps.service.impl;
 package cn.com.qmth.mps.service.impl;
 
 
 import java.util.*;
 import java.util.*;
+import java.util.stream.Collectors;
 
 
 import cn.com.qmth.mps.bean.*;
 import cn.com.qmth.mps.bean.*;
+import cn.com.qmth.mps.entity.PaperDetailUnitEntity;
 import cn.com.qmth.mps.enums.ArbitrateMethod;
 import cn.com.qmth.mps.enums.ArbitrateMethod;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -33,6 +35,8 @@ import cn.com.qmth.mps.vo.paper.GroupInfoVo;
 import cn.com.qmth.mps.vo.paper.GroupVo;
 import cn.com.qmth.mps.vo.paper.GroupVo;
 import cn.com.qmth.mps.vo.paper.PaperGroupDomain;
 import cn.com.qmth.mps.vo.paper.PaperGroupDomain;
 
 
+import javax.annotation.Resource;
+
 @Service
 @Service
 public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroupEntity> implements PaperGroupService {
 public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroupEntity> implements PaperGroupService {
 	@Autowired
 	@Autowired
@@ -198,6 +202,9 @@ public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroup
 		if (Objects.isNull(paperId)) {
 		if (Objects.isNull(paperId)) {
 			throw new StatusException("试卷结构ID不能为空");
 			throw new StatusException("试卷结构ID不能为空");
 		}
 		}
+		List<PaperDetailUnitEntity> questionDatasource = paperDetailUnitService.list(
+				new QueryWrapper<PaperDetailUnitEntity>().lambda().eq(PaperDetailUnitEntity::getPaperId, paperId));
+
 		Integer groupNumber = domain.getNumber();
 		Integer groupNumber = domain.getNumber();
 		if (Objects.isNull(groupNumber)) {
 		if (Objects.isNull(groupNumber)) {
 			throw new StatusException("分组号不能为空");
 			throw new StatusException("分组号不能为空");
@@ -221,27 +228,44 @@ public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroup
 			if (Objects.isNull(arbitrateMethod)) {
 			if (Objects.isNull(arbitrateMethod)) {
 				throw new StatusException("仲裁方式未设置");
 				throw new StatusException("仲裁方式未设置");
 			}
 			}
-			if (ArbitrateMethod.GROUP_ARBITRATE.equals(arbitrateMethod) && (Objects.isNull(arbitrateThreshold) || (
-					arbitrateThreshold < 0))) {
-				throw new StatusException("仲裁阈值未正确设置");
+			if (ArbitrateMethod.GROUP_ARBITRATE.equals(arbitrateMethod)) {
+				if (Objects.isNull(arbitrateThreshold) || (arbitrateThreshold < 0)) {
+					throw new StatusException("仲裁值未正确设置");
+				}
 			}
 			}
 		}
 		}
 
 
+		double totalScore = 0.0;
 		for (PaperGroupUnit u : domain.getGroupUnits()) {
 		for (PaperGroupUnit u : domain.getGroupUnits()) {
 			// 小题仲裁阈值
 			// 小题仲裁阈值
 			Double questionArbitrateThreshold = u.getArbitrateThreshold();
 			Double questionArbitrateThreshold = u.getArbitrateThreshold();
 			if (u.getDetailNumber() == null || u.getDetailUnitNumber() == null) {
 			if (u.getDetailNumber() == null || u.getDetailUnitNumber() == null) {
 				throw new StatusException("大题号、小题号不能为空");
 				throw new StatusException("大题号、小题号不能为空");
 			}
 			}
+
+			List<PaperDetailUnitEntity> questionList = questionDatasource.stream()
+					.filter(e -> e.getDetailNumber().equals(u.getDetailNumber()) && e.getNumber().equals(u.getDetailUnitNumber())).collect(Collectors.toList());
+			if (questionList.size() != 1) {
+				throw new StatusException(String.format("题目%d-%d不存在,或存在多个", u.getDetailNumber(), u.getDetailUnitNumber()));
+			}
+			double questionScore = questionList.get(0).getScore();
+			totalScore = totalScore + questionScore;
 			if (ArbitrateMethod.QUESTION_ARBITRATE.equals(arbitrateMethod)) {
 			if (ArbitrateMethod.QUESTION_ARBITRATE.equals(arbitrateMethod)) {
 				if (Objects.isNull(questionArbitrateThreshold) || questionArbitrateThreshold < 0) {
 				if (Objects.isNull(questionArbitrateThreshold) || questionArbitrateThreshold < 0) {
-					throw new StatusException("仲裁阈值未正确设置");
+					throw new StatusException("仲裁值未正确设置");
+				}
+				if (questionArbitrateThreshold > questionScore) {
+					throw new StatusException(String.format("题目%d-%d仲裁值大于题目分数", u.getDetailNumber(), u.getDetailUnitNumber()));
 				}
 				}
 			}
 			}
 			if (!doubleEnable || ArbitrateMethod.GROUP_ARBITRATE.equals(arbitrateMethod)) {
 			if (!doubleEnable || ArbitrateMethod.GROUP_ARBITRATE.equals(arbitrateMethod)) {
 				u.setArbitrateThreshold(null);
 				u.setArbitrateThreshold(null);
 			}
 			}
 		}
 		}
+		if (ArbitrateMethod.GROUP_ARBITRATE.equals(arbitrateMethod) && arbitrateThreshold > totalScore) {
+			throw new StatusException("仲裁值大于分组总分");
+		}
+
 		PaperEntity paper = paperService.getById(paperId);
 		PaperEntity paper = paperService.getById(paperId);
 		if (paper == null) {
 		if (paper == null) {
 			throw new StatusException("未找到试卷结构");
 			throw new StatusException("未找到试卷结构");