From 9cf09ad9b35d105e36fc21de1bc6b6b3997c6949 Mon Sep 17 00:00:00 2001 From: zhc077 <565291854@qq.com> Date: Fri, 5 Jul 2024 18:04:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B2=B3=E5=8D=97=E6=9C=BA=E7=94=B5=E8=81=8C?= =?UTF-8?q?=E4=B8=9A=E5=AD=A6=E9=99=A2-=E5=A4=A7=E5=B1=8F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CompSystemBigScreenServiceImpl.java | 51 ++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/bigScreen/service/CompSystemBigScreenServiceImpl.java b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/bigScreen/service/CompSystemBigScreenServiceImpl.java index b6aa8c6c..4fdcf79e 100644 --- a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/bigScreen/service/CompSystemBigScreenServiceImpl.java +++ b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/bigScreen/service/CompSystemBigScreenServiceImpl.java @@ -2,6 +2,7 @@ package org.jeecg.modules.demo.bigScreen.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.jeecg.common.exception.JeecgBootException; +import org.jeecg.common.util.ComputeUtils; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.demo.abilityEvaluation.entity.DepartAbilityEvaluation; import org.jeecg.modules.demo.abilityEvaluation.entity.PersonalAbilityEvaluation; @@ -39,6 +40,8 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.DecimalFormat; import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -162,8 +165,27 @@ public class CompSystemBigScreenServiceImpl implements CompSystemBigScreenServic List departAbilityEvaluations = iDepartAbilityEvaluationService.list(new LambdaQueryWrapper() .eq(DepartAbilityEvaluation::getDepetId, departId)); + List vos = new LinkedList<>(); + Map> capacityIdListMap = Optional.ofNullable(departAbilityEvaluations).orElse(new LinkedList<>()).stream() + .collect(Collectors.groupingBy(DepartAbilityEvaluation::getCapacityId)); + //遍历分组后的结果 + Optional.ofNullable(capacityIdListMap).orElse(new LinkedHashMap<>()).forEach((key, value) -> { + List departAbilityEvaluationList = value; + double sum = departAbilityEvaluationList.stream().mapToDouble(obj -> obj.getValue()).sum(); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.setMaximumFractionDigits(2); // 保留两位小数 + decimalFormat.setRoundingMode(RoundingMode.HALF_UP); // 设置具体的进位机制 + double val = ComputeUtils.div2(sum, departAbilityEvaluationList.size()); + DepartAbilityEvaluation vo = new DepartAbilityEvaluation(); + vo.setDepetId(departId); + vo.setValue(val); + vo.setCapacityId(key); + vo.setCapacityName(departAbilityEvaluationList.get(0).getCapacityName()); + vos.add(vo); + }); //能力评估 - resultMap.put("departAbilityEvaluation", departAbilityEvaluations); + resultMap.put("departAbilityEvaluation", vos); + List years = DateUtils.getLastxYear(5); List annualList = iAnnualService.list(new LambdaQueryWrapper() @@ -320,13 +342,13 @@ public class CompSystemBigScreenServiceImpl implements CompSystemBigScreenServic Map compCounts = new LinkedHashMap<>(); Long compCount = iCompService.count(); - Long pointCount = iAnnualCompPointService.count(); +// Long pointCount = iAnnualCompPointService.count(); //比赛数 compCounts.put("compCount", compCount); - //年度项目比赛数 - compCounts.put("pointCount", pointCount); - //总报名数数 Long count = iAnnualCompetitionProjectRegistrationService.count(); + //总人数 + compCounts.put("pointCount", count); + //人个报名人数 Long personCount = iAnnualCompetitionProjectRegistrationService.count(new LambdaQueryWrapper() .eq(AnnualCompetitionProjectRegistration::getEntryFormat, "0")); //学生人数 @@ -337,7 +359,24 @@ public class CompSystemBigScreenServiceImpl implements CompSystemBigScreenServic resultMap.put("compCounts", compCounts); List departAbilityEvaluations = iDepartAbilityEvaluationService.list(); - resultMap.put("abilityEvaluation", departAbilityEvaluations); + List vos = new LinkedList<>(); + Map> capacityIdListMap = Optional.ofNullable(departAbilityEvaluations).orElse(new LinkedList<>()).stream() + .collect(Collectors.groupingBy(DepartAbilityEvaluation::getCapacityId)); + //遍历分组后的结果 + Optional.ofNullable(capacityIdListMap).orElse(new LinkedHashMap<>()).forEach((key, value) -> { + List departAbilityEvaluationList = value; + double sum = departAbilityEvaluationList.stream().mapToDouble(obj -> obj.getValue()).sum(); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.setMaximumFractionDigits(2); // 保留两位小数 + decimalFormat.setRoundingMode(RoundingMode.HALF_UP); // 设置具体的进位机制 + double val = ComputeUtils.div2(sum, departAbilityEvaluationList.size()); + DepartAbilityEvaluation vo = new DepartAbilityEvaluation(); + vo.setValue(val); + vo.setCapacityId(key); + vo.setCapacityName(departAbilityEvaluationList.get(0).getCapacityName()); + vos.add(vo); + }); + resultMap.put("abilityEvaluation", vos); List years = DateUtils.getLastxYear(5); List annualList = iAnnualService.list(new LambdaQueryWrapper().in(Annual::getAnnualName, years).orderByAsc(Annual::getAnnualName));