修复权重更新时没有限制总和小于1

beetlsql3-dev
yaodan 2 years ago
parent bdaa53702b
commit e1cf301e30

@ -559,6 +559,8 @@ public class TeacherOpenCourseScoreDashboardService extends CoreBaseService<Teac
continue;
}
TeacherOpenCourseScoreDashboard scoreDashboard = new TeacherOpenCourseScoreDashboard();
scoreDashboard.setTeacherOpenCourseScoreDashboardId(teacherOpenCourseScoreDashboard.getTeacherOpenCourseScoreDashboardId());
@ -938,14 +940,19 @@ public class TeacherOpenCourseScoreDashboardService extends CoreBaseService<Teac
totalScore = totalScore.add(formatSignScore).add(formatCourseScore).add(formatRealOperationScore).add(formatQuestionHomeworkScore).add(formatExamScore).add(formatChatScore);
//加上手动的分数
totalScore = totalScore.add(ObjectUtil.defaultIfNull(teacherOpenCourseScoreDashboard.getManualScore(), BigDecimal.ZERO));
totalScore = totalScore.setScale(1, RoundingMode.HALF_UP);
scoreDashboard.setTotalScore(totalScore);
//成绩状态
lastStatus(weight, totalScore, scoreDashboard);
}
}
{
// 手动调整,最总分数
BigDecimal totalScore = scoreDashboard.getTotalScore();
BigDecimal manualScore = ObjectUtil.defaultIfNull(teacherOpenCourseScoreDashboard.getManualScore(), BigDecimal.ZERO);
BigDecimal lastScore = totalScore.add(manualScore);
scoreDashboard.setLastScore(ObjectUtil.defaultIfNull(lastScore, BigDecimal.ZERO));
lastStatus(weight, scoreDashboard.getLastScore(), scoreDashboard);
}
updateTemplate(scoreDashboard);
}
return true;
@ -1087,19 +1094,16 @@ public class TeacherOpenCourseScoreDashboardService extends CoreBaseService<Teac
}
}
//拿到原来的总成绩,减去手动调整的分数,再加上新的手动调整的分数
//拿到原来的总成绩
BigDecimal totalScore = ObjectUtil.defaultIfNull(teacherOpenCourseScoreDashboard.getTotalScore(), BigDecimal.ZERO);
BigDecimal oldManualScore = ObjectUtil.defaultIfNull(teacherOpenCourseScoreDashboard.getManualScore(), BigDecimal.ZERO);
totalScore = totalScore.subtract(oldManualScore).add(ObjectUtil.defaultIfNull(manualScore, BigDecimal.ZERO));
teacherOpenCourseScoreDashboard.setTotalScore(totalScore);
BigDecimal lastScore = totalScore.add(ObjectUtil.defaultIfNull(manualScore, BigDecimal.ZERO));
teacherOpenCourseScoreDashboard.setManualScore(ObjectUtil.defaultIfNull(manualScore, BigDecimal.ZERO));
teacherOpenCourseScoreDashboard.setLastScore(lastScore);
TeacherOpenCourseScoreWeight weight = weightDao.single(teacherOpenCourseId);
if (weight == null) {
lastStatus(weight, totalScore, teacherOpenCourseScoreDashboard);
if (weight != null) {
lastStatus(weight, lastScore, teacherOpenCourseScoreDashboard);
}
updateTemplate(teacherOpenCourseScoreDashboard);
}
}

@ -1,5 +1,6 @@
package com.ibeetl.jlw.service;
import cn.hutool.core.util.ObjectUtil;
import cn.jlw.util.ToolUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@ -19,6 +20,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@ -102,6 +104,22 @@ public class TeacherOpenCourseScoreWeightService extends CoreBaseService<Teacher
public String edit(TeacherOpenCourseScoreWeightQuery teacherOpenCourseScoreWeightQuery){
String msg = "";
TeacherOpenCourseScoreWeight teacherOpenCourseScoreWeight = teacherOpenCourseScoreWeightQuery.pojo();
BigDecimal signInResult = new BigDecimal(ObjectUtil.defaultIfNull(teacherOpenCourseScoreWeight.getSignInResult(), "0"));
BigDecimal chapterContactResult = new BigDecimal(ObjectUtil.defaultIfNull(teacherOpenCourseScoreWeight.getChapterContactResult(), "0"));
BigDecimal coursePracticeResult = new BigDecimal(ObjectUtil.defaultIfNull(teacherOpenCourseScoreWeight.getCoursePracticeResult(), "0"));
BigDecimal homeworkResult = new BigDecimal(ObjectUtil.defaultIfNull(teacherOpenCourseScoreWeight.getHomeworkResult(), "0"));
BigDecimal examinationResult = new BigDecimal(ObjectUtil.defaultIfNull(teacherOpenCourseScoreWeight.getExaminationResult(), "0"));
BigDecimal interactionResult = new BigDecimal(ObjectUtil.defaultIfNull(teacherOpenCourseScoreWeight.getInteractionResult(), "0"));
BigDecimal weightTotal = signInResult.add(chapterContactResult).add(coursePracticeResult).add(homeworkResult).add(examinationResult).add(interactionResult);
if (weightTotal.compareTo(BigDecimal.ONE)>0) {
msg = "权重总和不能大于1";
return msg;
}
teacherOpenCourseScoreWeightDao.updateTemplateById(teacherOpenCourseScoreWeight);
return msg;
}

Loading…
Cancel
Save