积分汇总保留2位小数

main
fhv 4 months ago
parent 7c3e917d97
commit 3e7dd7ad22
  1. 11
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualScore/service/impl/DepartCompTotalScoreServiceImpl.java

@ -1,6 +1,7 @@
package org.jeecg.modules.demo.annualScore.service.impl; package org.jeecg.modules.demo.annualScore.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.demo.annualScore.entity.DepartCompTotalScore; import org.jeecg.modules.demo.annualScore.entity.DepartCompTotalScore;
import org.jeecg.modules.demo.annualScore.entity.PersonalCompScore; import org.jeecg.modules.demo.annualScore.entity.PersonalCompScore;
@ -9,10 +10,10 @@ import org.jeecg.modules.demo.annualScore.service.IDepartCompTotalScoreService;
import org.jeecg.modules.demo.annualScore.service.IPersonalCompScoreService; import org.jeecg.modules.demo.annualScore.service.IPersonalCompScoreService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -44,10 +45,14 @@ public class DepartCompTotalScoreServiceImpl extends ServiceImpl<DepartCompTotal
); );
double totalScore = 0; double totalScore = 0;
DecimalFormat decimalFormat = new DecimalFormat(totalScore + "");
decimalFormat.setMaximumFractionDigits(2); // 保留两位小数
decimalFormat.setRoundingMode(RoundingMode.HALF_UP); // 设置具体的进位机制
if (!ObjectUtils.isEmpty(personalCompScoreList)) { if (!ObjectUtils.isEmpty(personalCompScoreList)) {
totalScore = personalCompScoreList.stream().mapToDouble(PersonalCompScore::getScore).sum(); totalScore = personalCompScoreList.stream().mapToDouble(PersonalCompScore::getScore).sum();
} }
departCompTotalScore.setScore(totalScore); departCompTotalScore.setScore(new Double(decimalFormat.format(totalScore)));
//id不为空,院系的某一年度已汇总过,重新汇算 //id不为空,院系的某一年度已汇总过,重新汇算
if (StringUtils.isNotEmpty(departCompTotalScore.getId())) { if (StringUtils.isNotEmpty(departCompTotalScore.getId())) {

Loading…
Cancel
Save