From 8c5638160f2327cc4ad8d99fa45985c655f9246b Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Tue, 17 Oct 2023 17:22:03 +0800 Subject: [PATCH] =?UTF-8?q?debug=20=E9=A9=BE=E9=A9=B6=E8=88=B1=E7=AE=97?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/task/CockpitStatsStatisticsTask.java | 37 ++++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/CockpitStatsStatisticsTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/CockpitStatsStatisticsTask.java index 04f8bec..08b2c52 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/CockpitStatsStatisticsTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/CockpitStatsStatisticsTask.java @@ -125,6 +125,8 @@ public class CockpitStatsStatisticsTask { //如果结果不为空 就删除之前的 插入最新的数据 if(CollUtil.isNotEmpty(res)){ + //计算增长率 + computeRates(res); List list = cockpitStatsService.list(); List ids = list.stream().map(CockpitStats::getId).collect(Collectors.toList()); cockpitStatsService.removeByIds(ids); @@ -135,6 +137,27 @@ public class CockpitStatsStatisticsTask { log.info("驾驶舱数据统计任务结束====={}s",stopWatch.getTotalTimeSeconds()); } + private void computeRates(List res) { + Map map = res.stream().collect(Collectors.toMap(r -> r.getRegionCode() + r.getYear(), r -> r)); + for(CockpitStats cockpitStats : res){ + if(Objects.isNull(cockpitStats.getYear())){ + continue; + } + //算增长率 + //去年的数据 用于算 增长比例 + if(cockpitStats.getYear().equals(DashboardConstant.CockpitStats.NONE_YEAR)){ + Integer thisYear = LocalDateTime.now().getYear(); + CockpitStats thisYearData = map.get(cockpitStats.getRegionCode() + thisYear); + CockpitStats lastYearData = map.get(cockpitStats.getRegionCode() + (thisYear - 1)); + buidMonitorRise(cockpitStats,thisYearData,lastYearData); + }else{ + CockpitStats lastYearData = map.get(cockpitStats.getRegionCode() + (cockpitStats.getYear() - 1)); + buidMonitorRise(cockpitStats,cockpitStats,lastYearData); + } + } + + } + /** * 统计的具体逻辑 * @param regionCode @@ -172,8 +195,6 @@ public class CockpitStatsStatisticsTask { baseProjCount = count.intValue(); } - - //1.项目监测 //1.1 超期在建项目 Integer overdueConstructionProjectsNum = projects.stream().filter(p -> { @@ -204,18 +225,6 @@ public class CockpitStatsStatisticsTask { //1.5 验收不达标 cockpitStats.setMonitorAcceptConditionsNotStandardsNum(0); - //算增长率 - //去年的数据 用于算 增长比例 - if(Objects.isNull(year)){ - Integer thisYear = LocalDateTime.now().getYear(); - CockpitStats thisYearData = statisticsData(regionCode, regionName, thisYear); - CockpitStats lastYearData = statisticsData(regionCode, regionName, thisYear - 1); - buidMonitorRise(cockpitStats,thisYearData,lastYearData); - }else{ - CockpitStats lastYearData = statisticsData(regionCode, regionName, year); - buidMonitorRise(cockpitStats,cockpitStats,lastYearData); - } - //1.6 总申报金额 Double totalDeclaredAmount = projects.stream().mapToDouble(p -> Objects.nonNull(p.getDeclareAmount()) ? p.getDeclareAmount().doubleValue() : 0.0).sum(); cockpitStats.setMonitorDeclaredAmount(BigDecimal.valueOf(totalDeclaredAmount));