Browse Source

公司指标,理论发电量

malijun 5 tháng trước cách đây
mục cha
commit
9ae41df010

+ 87 - 0
ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java

@@ -1910,6 +1910,93 @@ public class JavaFunctionJobHandler extends IJobHandler {
 
     }
 
+    //公司指标,累加风机理论发电量
+    public void writeReportPoolLLFDL(Date date) {
+        //date当天零点
+        DateTime time = DateUtil.beginOfDay(date);
+        //date昨天零点
+        DateTime time0 = DateUtil.offsetDay(time, -1);
+        DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
+        DateTime beginOfYear = DateUtil.beginOfYear(time0);
+
+        QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
+        wrapper.select("avg(llfdl) llfdl,project_id")
+                .eq("record_date", time0)
+                .groupBy("project_id");
+        List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
+        Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
+        wrapper = new QueryWrapper<>();
+        wrapper.select("avg(llfdl) llfdl,project_id")
+                .between("record_date", beginOfMonth, time0)
+                .groupBy("project_id");
+        List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
+        Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
+        wrapper = new QueryWrapper<>();
+        wrapper.select("avg(llfdl) llfdl,project_id")
+                .between("record_date", beginOfYear, time0)
+                .groupBy("project_id");
+        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)
+                .in("foreign_key_id", days.stream().map(TurbineInfoDay::getProjectId).collect(Collectors.toList()));
+        List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
+
+
+
+        QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
+        wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
+        ProEconReportIndicatorPool pools2 = reportIndicatorPoolService.getOne(wrapperrp2);
+
+        if (pools2 == null){
+            ProEconReportIndicatorPool GSPJFS = new ProEconReportIndicatorPool();
+            GSPJFS.setRecordDate(time0.toLocalDateTime().toLocalDate());
+            GSPJFS.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
+            GSPJFS.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
+            reportIndicatorPoolService.saveOrUpdate(GSPJFS);
+        }
+
+
+        TurbineInfoDay day, month, year;
+        String projectId;
+
+        if (!pools.isEmpty()) {
+            for (ProEconReportIndicatorPool pool : pools) {
+                projectId = pool.getForeignKeyId();
+                day = dayMap.get(projectId);
+                pool.setRllfdl(day.getPjfs());
+                month = monthMap.get(projectId);
+                pool.setYllfdl(month.getPjfs());
+                year = yearMap.get(projectId);
+                pool.setNllfdl(year.getPjfs());
+            }
+            double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRllfdl).average().orElse(0);
+            double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYllfdl).average().orElse(0);
+            double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNllfdl).average().orElse(0);
+            if (pools2 != null) {
+                pools2.setRpjfs(v1);
+                pools2.setYpjfs(v2);
+                pools2.setNpjfs(v3);
+                reportIndicatorPoolService.saveOrUpdate(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.getProjectId());
+                poolList.add(pool);
+            }
+            reportIndicatorPoolService.saveOrUpdateBatch(poolList);
+
+        }
+
+    }
+
+
 
     public void calcRealtimeTurbineZt() {
         DateTime date = DateUtil.date();