wangb 2 kuukautta sitten
vanhempi
commit
54a12a089d

+ 3 - 2
runeconomy-xk/src/main/java/com/gyee/runeconomy/controller/homepage/EconomyHomePageController.java

@@ -139,7 +139,7 @@ public class EconomyHomePageController {
     @GetMapping(value = "/generating-capacity")
     @ApiOperation(value = "首页-发电量", notes = "首页-发电量")
     public ResultMsg getHomeGeneratingCapacity2(@RequestParam(value = "companyId", required = false) String companyId) throws Exception {
-
+        economyPointHomePageService.calFdl();
         Map<String, Object> map = economyPointHomePageService.getGeneratingCapacity(companyId);
         if (null != map) {
             return ResultMsg.ok(map);
@@ -167,7 +167,7 @@ public class EconomyHomePageController {
     @GetMapping(value = "/home-right")
     @ApiOperation(value = "首页-右侧模块", notes = "首页-右侧模块")
     public ResultMsg getHomeRight(@RequestParam(value = "companyId", required = false) String companyId) throws Exception {
-
+        economyPointHomePageService.calFdl();
         Map<String, Object> map = economyPointHomePageService.getHomeRight(companyId);
         if (null != map) {
             return ResultMsg.ok(map);
@@ -184,6 +184,7 @@ public class EconomyHomePageController {
     @ApiOperation(value = "首页-中间模块", notes = "首页-中间模块")
     public ResultMsg getHomeMiddle(@RequestParam(value = "companyId", required = false) String companyId) throws Exception {
 
+        economyPointHomePageService.calFdl();
         Map<String, Object> map = economyPointHomePageService.getHomeMiddle(companyId);
         if (null != map) {
             return ResultMsg.ok(map);

+ 77 - 59
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/homepage/EconomyPointHomePageService.java

@@ -136,12 +136,10 @@ public class EconomyPointHomePageService {
      * 15分钟发电量
      */
     private Map<String, GeneratingCapacityVo> generatingCapacity15min = new HashMap<>();
-
-    private BigDecimal weekFdlCal = null;
-    private BigDecimal yfdlCal = null;
-    private BigDecimal yllfdlCal = null;
-    private BigDecimal nfdlCal = null;
-    private BigDecimal nllfdlCal = null;
+    private Map<String, BigDecimal> yfdlCal = new HashMap<>();
+    private Map<String, BigDecimal> yllfdlCal = new HashMap<>();
+    private Map<Integer, BigDecimal> nfdlCal = new HashMap<>();
+    private Map<Integer, BigDecimal> nllfdlCal = new HashMap<>();
     private LocalDate lastCalDate;
 
     private Map<LocalDate, BigDecimal> fnlyl = new HashMap<>();
@@ -1685,13 +1683,18 @@ public class EconomyPointHomePageService {
 
 
     public Map<String, Object> getHomeMiddle(String companyId) throws ParseException {
+        double rfdl = generatingCapacity15min.get("日发电量").getValue();
         Integer month = LocalDate.now().getMonthValue();
         int year = LocalDate.now().getYear();
         Map<String, Object> allmap = new HashMap<>();
         PlanDataVo pd = new PlanDataVo();
-        pd.setZfdlsj(weekFdlCal.add(new BigDecimal(generatingCapacity15min.get("日发电量").getValue())).doubleValue());
-        pd.setYfdlsj(yfdlCal.add(new BigDecimal(generatingCapacity15min.get("月发电量").getValue())).doubleValue());
-        pd.setNfdlsj(nfdlCal.add(new BigDecimal(generatingCapacity15min.get("年发电量").getValue())).doubleValue());
+        Double week = getWeekFdlCal();
+        pd.setZfdlsj(week);
+        String s = year + "-" + month;
+        BigDecimal monCache = yfdlCal.get(s);
+        pd.setYfdlsj(monCache.add(new BigDecimal(rfdl)).doubleValue());
+        BigDecimal yearCache = nfdlCal.get(year);
+        pd.setNfdlsj(yearCache.add(new BigDecimal(rfdl)).doubleValue());
         //计划发电量
         List<ProBasicProjectPlan> list = iProBasicProjectPlanService.list();
         List<ProBasicProjectPlan> pp = list.stream()
@@ -1803,15 +1806,15 @@ public class EconomyPointHomePageService {
         ptxdl.setYAxisIndex(0);
         ptssdl.setYAxisIndex(0);
         ptfdl.setYAxisIndex(0);
-        if (null == lastYear || lastYear.isEmpty()) {
+        if (lastYear.isEmpty()) {
             List<ValueVo> value = value(year - 1, month);
             ptxdl2.setValue(value);
             ptssdl2.setValue(value);
             ptfdl2.setValue(value);
         } else {
-            List<ValueVo> vxdl2 = value(year, 12);
-            List<ValueVo> vssdl2 = value(year, 12);
-            List<ValueVo> vfdl2 = value(year, 12);
+            List<ValueVo> vxdl2 = value(year - 1, 12);
+            List<ValueVo> vssdl2 = value(year - 1, 12);
+            List<ValueVo> vfdl2 = value(year - 1, 12);
             Map<Integer, List<TurbineInfoDay>> day1sMap2 = lastYear.stream().collect(Collectors.groupingBy(record -> record.getRecordDate().getMonth() + 1));
             for (Integer mon2 : day1sMap2.keySet()) {
                 List<TurbineInfoDay> day1s3 = day1sMap2.get(mon2);
@@ -1819,24 +1822,27 @@ public class EconomyPointHomePageService {
                 LocalDate localDate = day1s3.get(0).getRecordDate().toInstant().atZone(ZoneOffset.UTC).toLocalDate();
                 int year1 = localDate.getYear();
                 String text = year1 + "-" + mon2;
-                ValueVo vexdl2 = new ValueVo();
-                ValueVo vessdl2 = new ValueVo();
-                ValueVo vefdl2 = new ValueVo();
-                vexdl2.setText(text);
-                vessdl2.setText(text);
-                vefdl2.setText(text);
-                vexdl2.setValue(day1s4.stream().map(TurbineInfoDay::getXdss).reduce(BigDecimal.ZERO, BigDecimal::add));
-                vessdl2.setValue(day1s4.stream().map(TurbineInfoDay::getXdss).reduce(BigDecimal.ZERO, BigDecimal::add)
-                        .add(day1s4.stream().map(TurbineInfoDay::getJhjxss).reduce(BigDecimal.ZERO, BigDecimal::add)
-                                .add(day1s4.stream().map(TurbineInfoDay::getFjhjxss).reduce(BigDecimal.ZERO, BigDecimal::add)
-                                        .add(day1s4.stream().map(TurbineInfoDay::getSlss).reduce(BigDecimal.ZERO, BigDecimal::add))
-                                        .add(day1s4.stream().map(TurbineInfoDay::getXnss).reduce(BigDecimal.ZERO, BigDecimal::add))
-                                        .add(day1s4.stream().map(TurbineInfoDay::getDjss).reduce(BigDecimal.ZERO, BigDecimal::add))
-                                        .add(day1s4.stream().map(TurbineInfoDay::getGzss).reduce(BigDecimal.ZERO, BigDecimal::add)))));
-                vefdl2.setValue(day1s4.stream().map(TurbineInfoDay::getRfdl).reduce(BigDecimal.ZERO, BigDecimal::add));
-                vxdl2.add(vexdl2);
-                vssdl2.add(vessdl2);
-                vfdl2.add(vefdl2);
+                for (ValueVo vv : vxdl2) {
+                    if (vv.getText().equals(text)) {
+                        vv.setValue(day1s4.stream().map(TurbineInfoDay::getXdss).reduce(BigDecimal.ZERO, BigDecimal::add));
+                    }
+                }
+                for (ValueVo vv : vssdl2) {
+                    if (vv.getText().equals(text)) {
+                        vv.setValue(day1s4.stream().map(TurbineInfoDay::getXdss).reduce(BigDecimal.ZERO, BigDecimal::add)
+                                .add(day1s4.stream().map(TurbineInfoDay::getJhjxss).reduce(BigDecimal.ZERO, BigDecimal::add)
+                                        .add(day1s4.stream().map(TurbineInfoDay::getFjhjxss).reduce(BigDecimal.ZERO, BigDecimal::add)
+                                                .add(day1s4.stream().map(TurbineInfoDay::getSlss).reduce(BigDecimal.ZERO, BigDecimal::add))
+                                                .add(day1s4.stream().map(TurbineInfoDay::getXnss).reduce(BigDecimal.ZERO, BigDecimal::add))
+                                                .add(day1s4.stream().map(TurbineInfoDay::getDjss).reduce(BigDecimal.ZERO, BigDecimal::add))
+                                                .add(day1s4.stream().map(TurbineInfoDay::getGzss).reduce(BigDecimal.ZERO, BigDecimal::add)))));
+                    }
+                }
+                for (ValueVo vv : vfdl2) {
+                    if (vv.getText().equals(text)) {
+                        vv.setValue(day1s4.stream().map(TurbineInfoDay::getRfdl).reduce(BigDecimal.ZERO, BigDecimal::add));
+                    }
+                }
             }
             ptxdl2.setValue(vxdl2);
             ptssdl2.setValue(vssdl2);
@@ -1886,7 +1892,6 @@ public class EconomyPointHomePageService {
     public Map<String, Object> getGeneratingCapacity(String companyId) {
         Map<String, Object> allmap = new HashMap<>();
         QueryWrapper<StationInfoMin> qw = new QueryWrapper<>();
-        DecimalFormat df = new DecimalFormat("#.##");
         qw.lambda().ge(StationInfoMin::getRecordDate, LocalDateTime.now().toLocalDate().atStartOfDay())
                 .le(StationInfoMin::getRecordDate, LocalDateTime.now())
                 .orderByDesc(StationInfoMin::getRecordDate)
@@ -1944,13 +1949,10 @@ public class EconomyPointHomePageService {
             ls.add(nfdl);
             generatingCapacity15min.put(nfdl.getName(), nfdl);
         } else {
-            if (null == lastCalDate || !lastCalDate.equals(LocalDate.now()) || null == yfdlCal) {
-                calFdl();
-            }
             StationInfoMin day1 = day1s.get(0);
             GeneratingCapacityVo rfdl = new GeneratingCapacityVo();
             rfdl.setName("日发电量");
-            rfdl.setValue(new BigDecimal(day1.getRfdl()).setScale(2, RoundingMode.HALF_UP).doubleValue());
+            rfdl.setValue(Double.valueOf(String.format("%.2f", day1.getRfdl())));
             Double llgl = day1.getLlgl();
             rfdl.setTotal(calDivide(llgl, 4.0));
             Double rbfb = calDivide(rfdl.getValue(), rfdl.getTotal());
@@ -1959,17 +1961,19 @@ public class EconomyPointHomePageService {
             generatingCapacity15min.put(rfdl.getName(), rfdl);
             GeneratingCapacityVo yfdl = new GeneratingCapacityVo();
             yfdl.setName("月发电量");
-            yfdl.setValue(yfdlCal.add(new BigDecimal(rfdl.getValue())).setScale(2, RoundingMode.HALF_UP).doubleValue());
-            yfdl.setTotal(calDivide(yllfdlCal.add(new BigDecimal(rfdl.getTotal())).doubleValue(), 4.0));
+
+            String s = LocalDate.now().getYear() + "-" + LocalDate.now().getMonthValue();
+            BigDecimal monCache = yfdlCal.get(s);
+            yfdl.setValue(monCache.add(new BigDecimal(rfdl.getValue())).setScale(2, RoundingMode.HALF_UP).doubleValue());
+            yfdl.setTotal(calDivide(yllfdlCal.get(s).add(new BigDecimal(rfdl.getTotal())).doubleValue(), 4.0));
             Double ybfb = calDivide(yfdl.getValue(), yfdl.getTotal());
             yfdl.setBfb(new BigDecimal(ybfb).setScale(2, RoundingMode.HALF_UP).doubleValue());
             ls.add(yfdl);
             generatingCapacity15min.put(yfdl.getName(), yfdl);
             GeneratingCapacityVo nfdl = new GeneratingCapacityVo();
             nfdl.setName("年发电量");
-//            nfdl.setValue(nfdlCal.add(new BigDecimal(yfdl.getValue())).doubleValue());
-            nfdl.setValue(nfdlCal.add(new BigDecimal(yfdl.getValue())).setScale(2, RoundingMode.HALF_UP).doubleValue());
-            nfdl.setTotal(calDivide(nllfdlCal.add(new BigDecimal(yfdl.getTotal())).doubleValue(), 4.0));
+            nfdl.setValue(nfdlCal.get(LocalDate.now().getYear()).add(new BigDecimal(rfdl.getValue())).setScale(2, RoundingMode.HALF_UP).doubleValue());
+            nfdl.setTotal(calDivide(nllfdlCal.get(LocalDate.now().getYear()).add(new BigDecimal(rfdl.getTotal())).doubleValue(), 4.0));
             Double nbfb = calDivide(nfdl.getValue(), nfdl.getTotal());
             nfdl.setBfb(new BigDecimal(nbfb).setScale(2, RoundingMode.HALF_UP).doubleValue());
             ls.add(nfdl);
@@ -2054,39 +2058,53 @@ public class EconomyPointHomePageService {
     /**
      * 缓存月、年发电量
      */
-    private void calFdl() {
+    public void calFdl() {
+        if (null != lastCalDate || LocalDate.now().equals(lastCalDate) || !yfdlCal.isEmpty()) {
+            return;
+        }
         DecimalFormat df = new DecimalFormat("#.##");
+        LocalDate yesterday = LocalDate.now().atStartOfDay().toLocalDate();
         QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
         currentqw.select("station_id,SUM(rfdl) AS rfdl,sum(llfdl) as llfdl")
                 .ge("record_date", LocalDate.now().with(TemporalAdjusters.firstDayOfYear())) // 大于等于今年的第一天
-                .lt("record_date", LocalDate.now().atStartOfDay().toLocalDate()) // 小于今天0点的日期
-                .like("station_id", "_FDC_%") // 模糊查询 station_id
+                .lt("record_date", yesterday) // 小于今天0点的日期
+                .like("station_id", "_FDC_%")
                 .groupBy("station_id");
-        List<TurbineInfoDay> monthData = iTurbineInfoDayService.list(currentqw);
-        yfdlCal = new BigDecimal(df.format(monthData.get(0).getRfdl()));
-        yllfdlCal = new BigDecimal(df.format(monthData.get(0).getLlfdl()));
+        List<TurbineInfoDay> yearData = iTurbineInfoDayService.list(currentqw);
+        Integer intYear = LocalDate.now().getYear();
+        nfdlCal.put(intYear, new BigDecimal(df.format(yearData.get(0).getRfdl())));
+        nllfdlCal.put(intYear, new BigDecimal(df.format(yearData.get(0).getLlfdl())));
         currentqw.clear();
         currentqw.select("station_id,MAX(record_date) AS record_date,SUM(rfdl) AS rfdl,SUM(llfdl) as llfdl")
                 .ge("record_date", LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()))  // 大于等于本月的第一天
-                .lt("record_date", LocalDate.now().plusDays(1).atStartOfDay().toLocalDate())  // 小于明天0点的日期
-                .like("station_id", "_FDC_%")  // 模糊查询 station_id
+                .lt("record_date", yesterday)  // 小于今天0点的日期
+                .like("station_id", "_FDC_%")
                 .groupBy("station_id");
-        List<TurbineInfoDay> yearData = iTurbineInfoDayService.list(currentqw);
-        nfdlCal = new BigDecimal(df.format(yearData.get(0).getRfdl()));
-        nllfdlCal = new BigDecimal(df.format(yearData.get(0).getLlfdl()));
+        List<TurbineInfoDay> monthData = iTurbineInfoDayService.list(currentqw);
+        String yearAndMonth = LocalDate.now().getYear() + "-" + LocalDate.now().getMonthValue();
+        yfdlCal.put(yearAndMonth, new BigDecimal(df.format(monthData.get(0).getRfdl())));
+        yllfdlCal.put(yearAndMonth, new BigDecimal(df.format(monthData.get(0).getLlfdl())));
         currentqw.clear();
-        currentqw.select("station_id,SUM(rfdl) AS rfdl,sum(llfdl) as llfdl")
+        lastCalDate = LocalDate.now();
+    }
+
+
+    private Double getWeekFdlCal() {
+        LocalDate week = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
+        LocalDate yesterday = LocalDate.now().atStartOfDay().toLocalDate();
+        if (week.equals(LocalDate.now())) {
+            return generatingCapacity15min.get("日发电量").getValue();
+        }
+        QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
+        currentqw.select("station_id,SUM(rfdl) AS rfdl")
                 .ge("record_date", LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)))  // 大于等于本周一的日期
-                .lt("record_date", LocalDate.now().atStartOfDay().toLocalDate())  // 小于今天0点的日期
-                .like("station_id", "_FDC_")  // 模糊查询 station_id
+                .lt("record_date", yesterday)
                 .groupBy("station_id");
         List<TurbineInfoDay> weekData = iTurbineInfoDayService.list(currentqw);
         if (null == weekData || weekData.isEmpty()) {
-            weekFdlCal = new BigDecimal("0");
-        } else {
-            weekFdlCal = new BigDecimal(df.format(weekData.get(0).getRfdl()));
+            return 0.0;
         }
-        lastCalDate = LocalDate.now();
+        return weekData.get(0).getRfdl().add(new BigDecimal(generatingCapacity15min.get("日发电量").getValue())).doubleValue();
     }
 
 }