Browse Source

debug 驾驶舱算法

master
PoffyZhang 1 year ago
parent
commit
8c5638160f
1 changed files with 23 additions and 14 deletions
  1. +23
    -14
      pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/CockpitStatsStatisticsTask.java

+ 23
- 14
pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/CockpitStatsStatisticsTask.java View File

@@ -125,6 +125,8 @@ public class CockpitStatsStatisticsTask {


//如果结果不为空 就删除之前的 插入最新的数据 //如果结果不为空 就删除之前的 插入最新的数据
if(CollUtil.isNotEmpty(res)){ if(CollUtil.isNotEmpty(res)){
//计算增长率
computeRates(res);
List<CockpitStats> list = cockpitStatsService.list(); List<CockpitStats> list = cockpitStatsService.list();
List<Long> ids = list.stream().map(CockpitStats::getId).collect(Collectors.toList()); List<Long> ids = list.stream().map(CockpitStats::getId).collect(Collectors.toList());
cockpitStatsService.removeByIds(ids); cockpitStatsService.removeByIds(ids);
@@ -135,6 +137,27 @@ public class CockpitStatsStatisticsTask {
log.info("驾驶舱数据统计任务结束====={}s",stopWatch.getTotalTimeSeconds()); log.info("驾驶舱数据统计任务结束====={}s",stopWatch.getTotalTimeSeconds());
} }


private void computeRates(List<CockpitStats> res) {
Map<String, CockpitStats> 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 * @param regionCode
@@ -172,8 +195,6 @@ public class CockpitStatsStatisticsTask {
baseProjCount = count.intValue(); baseProjCount = count.intValue();
} }




//1.项目监测 //1.项目监测
//1.1 超期在建项目 //1.1 超期在建项目
Integer overdueConstructionProjectsNum = projects.stream().filter(p -> { Integer overdueConstructionProjectsNum = projects.stream().filter(p -> {
@@ -204,18 +225,6 @@ public class CockpitStatsStatisticsTask {
//1.5 验收不达标 //1.5 验收不达标
cockpitStats.setMonitorAcceptConditionsNotStandardsNum(0); 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 总申报金额 //1.6 总申报金额
Double totalDeclaredAmount = projects.stream().mapToDouble(p -> Objects.nonNull(p.getDeclareAmount()) ? p.getDeclareAmount().doubleValue() : 0.0).sum(); Double totalDeclaredAmount = projects.stream().mapToDouble(p -> Objects.nonNull(p.getDeclareAmount()) ? p.getDeclareAmount().doubleValue() : 0.0).sum();
cockpitStats.setMonitorDeclaredAmount(BigDecimal.valueOf(totalDeclaredAmount)); cockpitStats.setMonitorDeclaredAmount(BigDecimal.valueOf(totalDeclaredAmount));


Loading…
Cancel
Save