Browse Source

指标池

malijun 5 months ago
parent
commit
93e4075afb
1 changed files with 41 additions and 20 deletions
  1. 41 20
      ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java

+ 41 - 20
ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java

@@ -1600,7 +1600,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
             StationInfoDay day, month, year;
             List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
             for (ProEconReportIndicatorPool pool : pools) {
-                String stationId = pool.getWindpowerstationId();
+                String stationId = pool.getForeignKeyId();
                 day = dayMap.get(stationId);
                 pool.setRfdldb(day.getRfdl().doubleValue());
                 pool.setRswdldb(day.getSwdl().doubleValue());
@@ -1743,34 +1743,55 @@ public class JavaFunctionJobHandler extends IJobHandler {
         List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
         Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
 
+//        QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
+//        wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
+
         QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
-        wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
+        wrapperrp.eq("record_date", time0)
+                .in("foreign_key_id", days.stream().map(TurbineInfoDay::getStationId).collect(Collectors.toList()));
         List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
+
+
+
         wrapperrp = new QueryWrapper<>();
         wrapperrp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
         List<ProEconReportIndicatorPool> pools2 = reportIndicatorPoolService.list(wrapperrp);
 
         TurbineInfoDay day, month, year;
         String projectId;
-        for (ProEconReportIndicatorPool pool : pools) {
-            projectId = pool.getProjectId();
-            day = dayMap.get(projectId);
-            pool.setRpjfs(day.getPjfs());
-            month = monthMap.get(projectId);
-            pool.setYpjfs(month.getPjfs());
-            year = yearMap.get(projectId);
-            pool.setNpjfs(year.getPjfs());
-        }
-        double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRpjfs).average().orElse(0);
-        double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYpjfs).average().orElse(0);
-        double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNpjfs).average().orElse(0);
-        if (CollUtil.isNotEmpty(pools2)) {
-            pools2.get(0).setRpjfs(v1);
-            pools2.get(0).setYpjfs(v2);
-            pools2.get(0).setNpjfs(v3);
-            reportIndicatorPoolService.saveOrUpdateBatch(pools2);
+
+        if (!pools.isEmpty()){
+            for (ProEconReportIndicatorPool pool : pools) {
+                projectId = pool.getProjectId();
+                day = dayMap.get(projectId);
+                pool.setRpjfs(day.getPjfs());
+                month = monthMap.get(projectId);
+                pool.setYpjfs(month.getPjfs());
+                year = yearMap.get(projectId);
+                pool.setNpjfs(year.getPjfs());
+            }
+            double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRpjfs).average().orElse(0);
+            double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYpjfs).average().orElse(0);
+            double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNpjfs).average().orElse(0);
+            if (CollUtil.isNotEmpty(pools2)) {
+                pools2.get(0).setRpjfs(v1);
+                pools2.get(0).setYpjfs(v2);
+                pools2.get(0).setNpjfs(v3);
+                reportIndicatorPoolService.saveOrUpdateBatch(pools2);
+            }
+            reportIndicatorPoolService.saveOrUpdateBatch(pools);
+        }else {
+            List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
+            for (TurbineInfoDay day2 : days) {
+                ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
+                pool.setRecordDate(time0.toLocalDateTime().toLocalDate());
+                pool.setForeignKeyId(day2.getStationId());
+                poolList.add(pool);
+            }
+            reportIndicatorPoolService.saveOrUpdateBatch(poolList);
+
         }
-        reportIndicatorPoolService.saveOrUpdateBatch(pools);
+
     }