From 7ab75635d24b098fe923a3c2917cd4f8440cfa6f Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Tue, 7 May 2024 11:24:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=9A=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=9C=88=E6=8A=A5=E5=8F=91=E7=94=B5=E9=87=8F=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E4=B8=BA=E4=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/MainSystemMonitoringServiceImpl.java | 36 +++++++++-------- .../impl/OperStationMonthReportServiceImpl.java | 45 ++++++++++++++++++++++ .../hnac/hzims/operational/util/ObjectUtils.java | 7 ++++ 3 files changed, 71 insertions(+), 17 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/MainSystemMonitoringServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/MainSystemMonitoringServiceImpl.java index afe634e..ea01dee 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/MainSystemMonitoringServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/MainSystemMonitoringServiceImpl.java @@ -64,6 +64,8 @@ import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; +import static com.hnac.hzims.operational.util.ObjectUtils.objDivide; + @Service @Slf4j @RequiredArgsConstructor @@ -1369,37 +1371,37 @@ public class MainSystemMonitoringServiceImpl implements IMainSystemMonitoringSer Map value = deviceMap.getValue(); //当月发电量 BigDecimal powerMon = value.entrySet().stream().filter(s -> currentMon.equals(s.getKey())).map(s -> BigDecimal.valueOf(s.getValue()).setScale(1, RoundingMode.UP)).reduce(BigDecimal.ZERO, BigDecimal::add); - stationReportVO.setFinishPowerMon(powerMon.toString()); + stationReportVO.setFinishPowerMon(objDivide(String.valueOf(powerMon)).toString()); //获取计划月发电量 R planPowerMonR = planGenertionClient.planGenerationMonthCount(stationEntity.getCode(), month); double planPowerMon =0; if (planPowerMonR.isSuccess()&&ObjectUtil.isNotEmpty(planPowerMonR.getData())) { planPowerMon = planPowerMonR.getData().doubleValue(); } - stationReportVO.setPowerMonPlan(planPowerMon); + stationReportVO.setPowerMonPlan(objDivide(String.valueOf(planPowerMon)).doubleValue()); //当年发电量 BigDecimal powerYear = value.entrySet().stream().filter(s -> listByYear.contains(s.getKey())).map(s -> BigDecimal.valueOf(s.getValue()).setScale(1, RoundingMode.UP)).reduce(BigDecimal.ZERO, BigDecimal::add); - stationReportVO.setFinishPowerYear(powerYear.toString()); + stationReportVO.setFinishPowerYear(objDivide(String.valueOf(powerYear)).toString()); //获取计划年发电量 - Double planPowerYear = planGenertionClient.getPlanPowerYear(Collections.singletonList(stationEntity.getId().toString()), yearMon[0]); - stationReportVO.setPowerYearPlan(planPowerYear); + Double planPowerYear = planGenertionClient.getPlanPowerYear(Collections.singletonList(stationEntity.getCode()), yearMon[0]); + stationReportVO.setPowerYearPlan(objDivide(String.valueOf(planPowerYear)).doubleValue()); if (ObjectUtil.isNotEmpty(stationReportVO.getPowerMonPlan()) &&ObjectUtil.isNotEmpty(stationReportVO.getFinishPowerMon()) && BigDecimal.valueOf(stationReportVO.getPowerMonPlan()).compareTo(BigDecimal.ZERO)!=0){ BigDecimal monRate = new BigDecimal(stationReportVO.getFinishPowerMon()).multiply(new BigDecimal(100)) .divide(BigDecimal.valueOf(stationReportVO.getPowerMonPlan()), 2, RoundingMode.UP); - stationReportVO.setPowerMonRate(monRate.doubleValue()+"%"); + stationReportVO.setPowerMonRate(String.valueOf(monRate.doubleValue())); }else { - stationReportVO.setPowerMonRate(new Double(0)+"%"); + stationReportVO.setPowerMonRate(new Double(0).toString()); } if (ObjectUtil.isNotEmpty(stationReportVO.getFinishPowerYear()) &&ObjectUtil.isNotEmpty(stationReportVO.getPowerYearPlan()) && BigDecimal.valueOf(stationReportVO.getPowerYearPlan()).compareTo(BigDecimal.ZERO)!=0){ BigDecimal yearRate = new BigDecimal(stationReportVO.getFinishPowerYear()).multiply(new BigDecimal(100)) .divide(BigDecimal.valueOf(stationReportVO.getPowerYearPlan()), 2, RoundingMode.UP); - stationReportVO.setPowerYearRate(yearRate.doubleValue()+"%"); + stationReportVO.setPowerYearRate(String.valueOf(yearRate.doubleValue())); }else { - stationReportVO.setPowerYearRate(new Double(0)+"%"); + stationReportVO.setPowerYearRate(new Double(0).toString()); } reportVOS.add(stationReportVO); } @@ -1474,33 +1476,33 @@ public class MainSystemMonitoringServiceImpl implements IMainSystemMonitoringSer } } Double finishPowerMon = BigDecimal.valueOf(powerCount.get()).doubleValue(); - stationReportVO.setFinishPowerMon(finishPowerMon.toString()); + stationReportVO.setFinishPowerMon(objDivide(String.valueOf(finishPowerMon)).toString()); Double finishPowerYear = BigDecimal.valueOf(powerCountYear.get()).doubleValue(); - stationReportVO.setFinishPowerYear(finishPowerYear.toString()); + stationReportVO.setFinishPowerYear(objDivide(String.valueOf(finishPowerYear)).toString()); //当年的计划发电量 Double planPowerYear = planGenertionClient.getPlanPowerYear(Collections.singletonList(stationId), year); - stationReportVO.setPowerYearPlan(planPowerYear); + stationReportVO.setPowerYearPlan(objDivide(String.valueOf(planPowerYear)).doubleValue()); //当月的计划发电量 R planPowerMonR = planGenertionClient.planGenerationMonthCount(stationId, month); Double planPowerMon = planPowerMonR.getData().doubleValue(); - stationReportVO.setPowerMonPlan(planPowerMon); + stationReportVO.setPowerMonPlan(objDivide(String.valueOf(planPowerMon)).doubleValue()); if (ObjectUtil.isNotEmpty(stationReportVO.getPowerMonPlan()) &&ObjectUtil.isNotEmpty(stationReportVO.getFinishPowerMon()) && BigDecimal.valueOf(stationReportVO.getPowerMonPlan()).compareTo(BigDecimal.ZERO)!=0){ BigDecimal monRate = new BigDecimal(stationReportVO.getFinishPowerMon()).multiply(new BigDecimal(100)) .divide(BigDecimal.valueOf(stationReportVO.getPowerMonPlan()), 2, RoundingMode.UP); - stationReportVO.setPowerMonRate(monRate.doubleValue()+"%"); + stationReportVO.setPowerMonRate(String.valueOf(monRate.doubleValue())); }else { - stationReportVO.setPowerMonRate(new Double(0)+"%"); + stationReportVO.setPowerMonRate(new Double(0).toString()); } if (ObjectUtil.isNotEmpty(stationReportVO.getFinishPowerYear()) &&ObjectUtil.isNotEmpty(stationReportVO.getPowerYearPlan()) && BigDecimal.valueOf(stationReportVO.getPowerYearPlan()).compareTo(BigDecimal.ZERO)!=0){ BigDecimal yearRate = new BigDecimal(stationReportVO.getFinishPowerYear()).multiply(new BigDecimal(100)) .divide(BigDecimal.valueOf(stationReportVO.getPowerYearPlan()), 2, RoundingMode.UP); - stationReportVO.setPowerYearRate(yearRate.doubleValue()+"%"); + stationReportVO.setPowerYearRate(String.valueOf(yearRate.doubleValue())); }else { - stationReportVO.setPowerYearRate(new Double(0)+"%"); + stationReportVO.setPowerYearRate(new Double(0).toString()); } stationReportVOList.add(stationReportVO); return stationReportVOList; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java index 95b22cf..1f80b1b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java @@ -57,6 +57,7 @@ import org.springblade.system.vo.DeptVO; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -349,6 +350,7 @@ public class OperStationMonthReportServiceImpl implements IOperStationMonthRepor reportVOS.addAll(stationReportVOList); }); } + getSumStationRunReport(reportVOS); stationReportAllVo.setStationReportVOList(reportVOS); }catch (Exception e){ log.error("", e); @@ -510,6 +512,49 @@ public class OperStationMonthReportServiceImpl implements IOperStationMonthRepor return stationReportAllVo; } + private static void getSumStationRunReport(List reportVOS) { + //合计 + StationRunReportVO stationRunReportVO=new StationRunReportVO(); + stationRunReportVO.setStationName("合计"); + if (CollectionUtil.isNotEmpty(reportVOS)){ + double sumPowerMonPlan = reportVOS.stream().mapToDouble(StationRunReportVO::getPowerMonPlan).sum(); + stationRunReportVO.setPowerMonPlan(sumPowerMonPlan); + double sumFinishPowerMon = reportVOS.stream().map(StationRunReportVO::getFinishPowerMon).mapToDouble(s -> Double.valueOf(s)).sum(); + stationRunReportVO.setFinishPowerMon(String.valueOf(sumFinishPowerMon)); + if (!ObjectUtils.isEmpty(sumPowerMonPlan)) { + BigDecimal powerMonRate = new BigDecimal(sumFinishPowerMon).divide(new BigDecimal(sumPowerMonPlan)).setScale(2, BigDecimal.ROUND_UP); + stationRunReportVO.setPowerMonRate(String.valueOf(powerMonRate)); + }else { + stationRunReportVO.setPowerMonRate("0.0"); + } + double sumPowerYearPlan = reportVOS.stream().mapToDouble(StationRunReportVO::getPowerYearPlan).sum(); + stationRunReportVO.setPowerYearPlan(sumPowerYearPlan); + double sumFinishPowerYear = reportVOS.stream().map(StationRunReportVO::getFinishPowerYear).mapToDouble(s -> Double.valueOf(s)).sum(); + stationRunReportVO.setFinishPowerYear(String.valueOf(sumFinishPowerYear)); + if (!ObjectUtils.isEmpty(sumPowerYearPlan)){ + BigDecimal powerYearRate = new BigDecimal(sumFinishPowerYear).divide(new BigDecimal(sumPowerYearPlan)).setScale(2, BigDecimal.ROUND_UP); + stationRunReportVO.setPowerYearRate(String.valueOf(powerYearRate)); + }else { + stationRunReportVO.setPowerYearRate("0.0"); + } + stationRunReportVO.setIndex(reportVOS.size()+1); + }else { + stationRunReportVO.setPowerMonPlan(0.0d); + stationRunReportVO.setFinishPowerMon("0.0"); + stationRunReportVO.setPowerYearPlan(0.0d); + stationRunReportVO.setFinishPowerYear("0.0"); + stationRunReportVO.setPowerMonRate("0.0"); + stationRunReportVO.setPowerYearRate("0.0"); + stationRunReportVO.setIndex(1); + } + reportVOS.add(stationRunReportVO); + reportVOS = reportVOS.stream().map(s -> { + s.setPowerMonRate(s.getPowerMonRate()+"%"); + s.setPowerYearRate(s.getPowerYearRate()+"%"); + return s; + }).collect(Collectors.toList()); + } + /** * 导出统计月报 * @param response diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java index 9feb555..341e2d5 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java @@ -10,6 +10,7 @@ import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -81,4 +82,10 @@ public class ObjectUtils { } return result; } + + public static BigDecimal objDivide(String s){ + BigDecimal bigDecimal = new BigDecimal(s); + BigDecimal res = bigDecimal.divide(new BigDecimal(10000)).setScale(2, BigDecimal.ROUND_UP); + return res; + } }