Browse Source

首页问题修复

wangb 1 month ago
parent
commit
2026fb21ec

+ 7 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/model/vo/GeneratingCapacityVo.java

@@ -11,8 +11,15 @@ import java.math.BigDecimal;
  */
 @Data
 public class GeneratingCapacityVo {
+
     private String name;
+
     private Double value;
+
+    /**
+     * 理论发电量
+     */
     private Double total;
+
     private Double bfb;
 }

+ 56 - 88
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/homepage/EconomyPointHomePageService.java

@@ -132,10 +132,6 @@ public class EconomyPointHomePageService {
 
     private List<Map<String, Object>> stainfo = null;//场站性息
 
-    /**
-     * 15分钟发电量
-     */
-    private Map<String, GeneratingCapacityVo> generatingCapacity15min = new HashMap<>();
     private Map<String, BigDecimal> yfdlCal = new HashMap<>();
     private Map<String, BigDecimal> yllfdlCal = new HashMap<>();
     private Map<Integer, BigDecimal> nfdlCal = new HashMap<>();
@@ -1697,12 +1693,12 @@ public class EconomyPointHomePageService {
 
 
     public Map<String, Object> getHomeMiddle(String companyId) throws ParseException {
-        double rfdl = generatingCapacity15min.get("日发电量").getValue();
+        Double rfdl = dayFdlCal(LocalDate.now());
         Integer month = LocalDate.now().getMonthValue();
         int year = LocalDate.now().getYear();
         Map<String, Object> allmap = new HashMap<>();
         PlanDataVo pd = new PlanDataVo();
-        Double week = getWeekFdlCal();
+        Double week = weekFdlCal();
         pd.setZfdlsj(week);
         String s = year + "-" + month;
         BigDecimal monCache = yfdlCal.get(s);
@@ -1910,21 +1906,8 @@ public class EconomyPointHomePageService {
 
 
     public Map<String, Object> getGeneratingCapacity(String companyId) {
+        LocalDate now = LocalDate.now();
         Map<String, Object> allmap = new HashMap<>();
-        QueryWrapper<StationInfoMin> qw = new QueryWrapper<>();
-        qw.lambda().ge(StationInfoMin::getRecordDate, LocalDateTime.now().toLocalDate().atStartOfDay())
-                .le(StationInfoMin::getRecordDate, LocalDateTime.now())
-                .orderByDesc(StationInfoMin::getRecordDate)
-                .last("LIMIT 1")
-                .eq(StationInfoMin::getStationId, companyId);
-
-        QueryWrapper<StationInfoMin> qw2 = new QueryWrapper<>();
-        qw2.lambda().ge(StationInfoMin::getRecordDate, LocalDateTime.now().minusYears(1).toLocalDate().atStartOfDay())
-                .le(StationInfoMin::getRecordDate, LocalDateTime.now().minusYears(1).toLocalDate())
-                .orderByDesc(StationInfoMin::getRecordDate)
-                .last("LIMIT 1")
-                .eq(StationInfoMin::getStationId, companyId);
-
         Map<String, Object> zbtqdb = new HashMap<>();
         List<ColumnVo> ls1 = new ArrayList<>();
         ColumnVo cl1 = new ColumnVo();
@@ -1944,63 +1927,35 @@ public class EconomyPointHomePageService {
         ls1.add(cl3);
         ls1.add(cl4);
 
-        List<StationInfoMin> day1s = iStationInfoMinService.list(qw);
         List<GeneratingCapacityVo> ls = new ArrayList<>();
-        if (null == day1s || day1s.isEmpty()) {
-            GeneratingCapacityVo rfdl = new GeneratingCapacityVo();
-            rfdl.setName("日发电量");
-            rfdl.setValue(0.0);
-            rfdl.setTotal(0.0);
-            rfdl.setBfb(0.0);
-            ls.add(rfdl);
-            generatingCapacity15min.put(rfdl.getName(), rfdl);
-            GeneratingCapacityVo yfdl = new GeneratingCapacityVo();
-            yfdl.setName("月发电量");
-            yfdl.setValue(0.0);
-            yfdl.setTotal(0.0);
-            yfdl.setBfb(0.0);
-            ls.add(yfdl);
-            generatingCapacity15min.put(yfdl.getName(), yfdl);
-            GeneratingCapacityVo nfdl = new GeneratingCapacityVo();
-            nfdl.setName("年发电量");
-            nfdl.setValue(0.0);
-            nfdl.setTotal(0.0);
-            nfdl.setBfb(0.0);
-            ls.add(nfdl);
-            generatingCapacity15min.put(nfdl.getName(), nfdl);
-        } else {
-            StationInfoMin day1 = day1s.get(0);
-            GeneratingCapacityVo rfdl = new GeneratingCapacityVo();
-            rfdl.setName("日发电量");
-            rfdl.setValue(Double.valueOf(String.format("%.2f", day1.getRfdl() / 1000)));
-            Double llgl = day1.getLlgl() / 1000;
-            rfdl.setTotal(calDivide(llgl / 1000, 4.0));
-            Double rbfb = calDivide(rfdl.getValue(), rfdl.getTotal());
-            rfdl.setBfb(new BigDecimal(rbfb * 100).setScale(2, RoundingMode.HALF_UP).doubleValue());
-            ls.add(rfdl);
-            generatingCapacity15min.put(rfdl.getName(), rfdl);
-
-            GeneratingCapacityVo yfdl = new GeneratingCapacityVo();
-            yfdl.setName("月发电量");
-            String s = LocalDate.now().getYear() + "-" + LocalDate.now().getMonthValue();
-            BigDecimal monCache = yfdlCal.get(s);
-            yfdl.setValue(monCache.add(BigDecimal.valueOf(rfdl.getValue())).setScale(2, RoundingMode.HALF_UP).doubleValue());
-            yfdl.setTotal(calDivide(yllfdlCal.get(s).add(BigDecimal.valueOf(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.get(LocalDate.now().getYear()).add(BigDecimal.valueOf(rfdl.getValue())).setScale(2, RoundingMode.HALF_UP).doubleValue());
-            nfdl.setTotal(calDivide(nllfdlCal.get(LocalDate.now().getYear()).add(BigDecimal.valueOf(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);
-            generatingCapacity15min.put(nfdl.getName(), nfdl);
-        }
-        List<StationInfoMin> day2s = iStationInfoMinService.list(qw2);
+        Double dayFdl = dayFdlCal(now);
+        Double dayLlfdl = dayLldlCal(now);
+        GeneratingCapacityVo rfdl = new GeneratingCapacityVo();
+        rfdl.setName("日发电量");
+        rfdl.setValue(Double.valueOf(String.format("%.2f", dayFdl)));
+        rfdl.setTotal(dayLlfdl);
+        Double rbfb = calDivide(dayFdl, dayLlfdl);
+        rfdl.setBfb(new BigDecimal(rbfb * 100).setScale(2, RoundingMode.HALF_UP).doubleValue());
+        ls.add(rfdl);
+
+        GeneratingCapacityVo yfdl = new GeneratingCapacityVo();
+        yfdl.setName("月发电量");
+        String s = LocalDate.now().getYear() + "-" + LocalDate.now().getMonthValue();
+        BigDecimal monCache = yfdlCal.get(s);
+        yfdl.setValue(monCache.add(BigDecimal.valueOf(rfdl.getValue())).setScale(2, RoundingMode.HALF_UP).doubleValue());
+        yfdl.setTotal(calDivide(yllfdlCal.get(s).add(BigDecimal.valueOf(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);
+
+        GeneratingCapacityVo nfdl = new GeneratingCapacityVo();
+        nfdl.setName("年发电量");
+        nfdl.setValue(nfdlCal.get(LocalDate.now().getYear()).add(BigDecimal.valueOf(rfdl.getValue())).setScale(2, RoundingMode.HALF_UP).doubleValue());
+        nfdl.setTotal(calDivide(nllfdlCal.get(LocalDate.now().getYear()).add(BigDecimal.valueOf(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);
+
         QueryWrapper<StationInfoDay> thisYear = new QueryWrapper<>();
         thisYear.select("station_id,max(record_date) as record_date,sum(swdl) as swdl,sum(gwdl) as gwdl,sum(cydl) as cydl,sum(zhcydl) as zhcydl")
                 .apply("to_char(record_date,'yyyy') = '" + (LocalDate.now().getYear()) + "'")
@@ -2022,15 +1977,7 @@ public class EconomyPointHomePageService {
         cv2.setWtId("年购网电量");
         ComparetqVo cv4 = new ComparetqVo();
         cv4.setWtId("年厂用电量");
-        cv.setRecodedate(generatingCapacity15min.get("年发电量").getValue());
-
-        if (null == day2s || day2s.isEmpty()) {
-            cv.setRecodedate2(0);
-            cv.setOperation(100);
-        } else {
-            cv.setRecodedate2(day2s.get(0).getRfdl() / 1000);
-            cv.setOperation(calDivide(cv.getRecodedate() - cv.getRecodedate2(), cv.getRecodedate2()));
-        }
+        cv.setRecodedate(nfdl.getValue());
 
         if (null == list2 || list2.isEmpty()) {
             cv1.setRecodedate2(0);
@@ -2113,11 +2060,11 @@ public class EconomyPointHomePageService {
     }
 
 
-    private Double getWeekFdlCal() {
+    private Double weekFdlCal() {
         LocalDate week = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
         LocalDate yesterday = LocalDate.now().atStartOfDay().toLocalDate();
         if (week.equals(LocalDate.now())) {
-            return generatingCapacity15min.get("日发电量").getValue();
+            return dayFdlCal(LocalDate.now());
         }
         QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
         currentqw.select("station_id,SUM(rfdl) AS rfdl")
@@ -2129,7 +2076,28 @@ public class EconomyPointHomePageService {
             return 0.0;
         }
         Double weekfdlc = calDivide(weekData.get(0).getRfdl(), 1000.0);
-        return weekfdlc + generatingCapacity15min.get("日发电量").getValue();
+        Double dayFdl = dayFdlCal(LocalDate.now());
+        return weekfdlc + dayFdl;
+    }
+
+    private Double dayFdlCal(LocalDate now) {
+        QueryWrapper<TurbineInfoDay> qw = new QueryWrapper<>();
+        qw.select("station_id,SUM(rfdl) AS rfdl").eq("record_date", now).groupBy("station_id");
+        List<TurbineInfoDay> dayData = iTurbineInfoDayService.list(qw);
+        if (null == dayData || dayData.isEmpty()) {
+            return 0.0;
+        }
+        return calDivide(dayData.get(0).getRfdl(), 1000.0);
+    }
+
+    private Double dayLldlCal(LocalDate now) {
+        QueryWrapper<TurbineInfoDay> qw = new QueryWrapper<>();
+        qw.select("station_id,SUM(llfdl) AS llfdl").eq("record_date", now).groupBy("station_id");
+        List<TurbineInfoDay> dayData = iTurbineInfoDayService.list(qw);
+        if (null == dayData || dayData.isEmpty()) {
+            return 0.0;
+        }
+        return calDivide(dayData.get(0).getLlfdl(), 1000.0);
     }
 
 }