Sfoglia il codice sorgente

add:权重设置更改

caozixuan 1 anno fa
parent
commit
7b07d6edeb

+ 15 - 26
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ObeCourseWeightServiceImpl.java

@@ -27,7 +27,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
-import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -148,7 +147,6 @@ public class ObeCourseWeightServiceImpl extends ServiceImpl<ObeCourseWeightMappe
     @Transactional
     @Override
     public void saveCourseWeight(ObeCourseWeightParam obeCourseWeightParam, SysUser requestUser) {
-        // TODO: 2024/6/8 保存逻辑变更
         List<String> errorMsgList = new ArrayList<>();
         Long requestUserId = requestUser.getId();
         Long obeCourseOutlineId = obeCourseWeightParam.getObeCourseOutlineId();
@@ -178,14 +176,15 @@ public class ObeCourseWeightServiceImpl extends ServiceImpl<ObeCourseWeightMappe
                 throw ExceptionResultEnum.ERROR.exception("课程目标不存在");
             }
 
+            // 目标整体权重
             BigDecimal totalWeight = courseWeightDto.getTotalWeight();
             obeCourseTarget.setTotalWeight(totalWeight);
             obeCourseTarget.updateInfo(requestUserId);
             obeCourseTargetList.add(obeCourseTarget);
             checkTargetTotalWeight = checkTargetTotalWeight.add(totalWeight);
 
+            BigDecimal checkWeight = BigDecimal.ZERO;
             // 评价方式整体权重检测(自定义)
-            BigDecimal checkEvaluationCustomTotalWeight = BigDecimal.ZERO;
             List<CourseWeightDetailDto> detailDtoList = courseWeightDto.getEvaluationList();
             for (CourseWeightDetailDto detail : detailDtoList) {
                 Long evaluationId = detail.getEvaluationId();
@@ -194,22 +193,16 @@ public class ObeCourseWeightServiceImpl extends ServiceImpl<ObeCourseWeightMappe
 
                 Boolean enable = detail.getEnable();
                 BigDecimal weight = detail.getWeight();
+                if (enable) {
+                    checkWeight = checkWeight.add(weight);
+                }
+
                 if (enable && CourseEvaluationTypeEnum.CUSTOM.equals(evaluationType)) {
                     if (evaluationMap.containsKey(evaluationId)) {
-                        throw ExceptionResultEnum.ERROR.exception("评价方式只能被一个课程目标使用");
+                        throw ExceptionResultEnum.ERROR.exception("平时成绩类评价方式只能被一个课程目标使用");
                     } else {
                         evaluationMap.put(evaluationId, evaluationType);
                     }
-                    checkEvaluationCustomTotalWeight = checkEvaluationCustomTotalWeight.add(weight);
-
-                }
-
-                BigDecimal denominator = new BigDecimal(100);
-                // 目标分值计算: 100 * 目标占比 * 评价方式占比
-                BigDecimal targetScore = new BigDecimal(0);
-                if (enable) {
-                    targetScore = new BigDecimal(100).multiply(totalWeight).divide(denominator, 2, RoundingMode.HALF_UP)
-                            .multiply(weight).divide(denominator, 2, RoundingMode.HALF_UP);
                 }
 
                 ObeCourseWeight obeCourseWeight = new ObeCourseWeight();
@@ -219,18 +212,14 @@ public class ObeCourseWeightServiceImpl extends ServiceImpl<ObeCourseWeightMappe
                 obeCourseWeight.setEvaluationId(evaluationId);
                 obeCourseWeight.setEnable(enable);
                 obeCourseWeight.setWeight(weight);
-                obeCourseWeight.setTargetScore(targetScore);
+                // 目标分值计算: 3.3.4版本目标分值直接等于权重
+                obeCourseWeight.setTargetScore(weight);
                 obeCourseWeight.insertInfo(requestUserId);
                 obeCourseWeightList.add(obeCourseWeight);
             }
-            // 数据校验2:各课程目标下自定义评价方式的总权重应等于100%;
-            int checkEvaluationTotalWeightCompareResult = checkEvaluationCustomTotalWeight.compareTo(new BigDecimal(100));
-            if (checkEvaluationTotalWeightCompareResult > 0) {
-                errorMsgList.add(String.format("课程目标[%s]下评价方式的总权重为[%s],超过[%s]", obeCourseTarget.getTargetName(),
-                        String.valueOf(checkEvaluationCustomTotalWeight) + '%', "100%"));
-            } else if (checkEvaluationTotalWeightCompareResult < 0) {
-                errorMsgList.add(String.format("课程目标[%s]下评价方式的总权重为[%s],低于[%s]", obeCourseTarget.getTargetName(),
-                        String.valueOf(checkEvaluationCustomTotalWeight) + '%', "100%"));
+            if (totalWeight.compareTo(checkWeight) != 0) {
+                throw ExceptionResultEnum.ERROR.exception(
+                        String.format("课程目标[%s]的权重设置有误,各评价方式权重之和不等于整体权重", obeCourseTarget.getTargetName()));
             }
         }
 
@@ -266,9 +255,9 @@ public class ObeCourseWeightServiceImpl extends ServiceImpl<ObeCourseWeightMappe
                 .set(ObeCourseTarget::getTotalWeight, null);
         obeCourseTargetService.update(courseTargetUpdateWrapper);
 
-        UpdateWrapper<ObeCourseOutline> teachCourseUpdateWrapper = new UpdateWrapper<>();
-        teachCourseUpdateWrapper.lambda().eq(ObeCourseOutline::getId, obeCourseOutlineId)
+        UpdateWrapper<ObeCourseOutline> obeCourseOutlineUpdateWrapper = new UpdateWrapper<>();
+        obeCourseOutlineUpdateWrapper.lambda().eq(ObeCourseOutline::getId, obeCourseOutlineId)
                 .set(ObeCourseOutline::getWeightSettingSign, null);
-        obeCourseOutlineService.update(teachCourseUpdateWrapper);
+        obeCourseOutlineService.update(obeCourseOutlineUpdateWrapper);
     }
 }