Przeglądaj źródła

能耗乱七八糟的东西

Levi.u 4 lat temu
rodzic
commit
3e209bd804

+ 1 - 1
src/main/java/com/ebei/screen/common/util/EnergyUtils.java

@@ -243,7 +243,7 @@ public class EnergyUtils {
         if (MapUtil.isNotEmpty(map)) {
             Map obj = ((List<Map>) map.get("data")).get(day - 1);
             if (MapUtil.isNotEmpty(obj)) {
-                return Double.valueOf((obj.get(key).toString()));
+                return Double.valueOf((obj.get(key) == null ? "0" : obj.get(key).toString()));
             }
             return 0.0;
         }

+ 12 - 4
src/main/java/com/ebei/screen/controller/energy/EnergyPlatformController.java

@@ -1,10 +1,13 @@
 package com.ebei.screen.controller.energy;
 
 import com.ebei.screen.common.response.ResponseBean;
+import com.ebei.screen.common.response.ResponseBuilder;
+import com.ebei.screen.common.util.EnergyUtils;
 import com.ebei.screen.service.EnergyPlatformService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -31,10 +34,15 @@ public class EnergyPlatformController {
         energyPlatformService.initData();
     }
 
-    @ApiOperation("获取能耗大屏除预警外全部数据")
-    @PostMapping("/getAllInOne")
-    public ResponseBean getAllInOne() {
-        return energyPlatformService.getAllInOne();
+    @ApiOperation("获取盒子列表")
+    @PostMapping("/getBoxList")
+    public ResponseBean getBoxList() {
+        return ResponseBuilder.ok(EnergyUtils.boxIds);
     }
 
+    @ApiOperation("获取能耗大屏除预警外全部数据")
+    @PostMapping("/getAllInOne/{boxId}")
+    public ResponseBean getAllInOne(@PathVariable String boxId) {
+        return energyPlatformService.getAllInOne(boxId);
+    }
 }

+ 1 - 1
src/main/java/com/ebei/screen/service/EnergyPlatformService.java

@@ -44,6 +44,6 @@ public interface EnergyPlatformService {
      *
      * @return
      */
-    ResponseBean getAllInOne();
+    ResponseBean getAllInOne(String boxId);
 
 }

+ 104 - 110
src/main/java/com/ebei/screen/service/impl/EnergyPlatformServiceImpl.java

@@ -198,8 +198,7 @@ public class EnergyPlatformServiceImpl implements EnergyPlatformService {
      * @return
      */
     @Override
-    public ResponseBean getAllInOne() {
-        List<Map> results = new ArrayList<>();
+    public ResponseBean getAllInOne(String boxId) {
         LocalDateTime now = LocalDateTime.now();
         int year = now.getYear();
         int month = now.getMonthValue();
@@ -212,116 +211,111 @@ public class EnergyPlatformServiceImpl implements EnergyPlatformService {
         int lastHour = lastYearNow.getHour();
         LocalDateTime lastMonthNow = now.minus(1, ChronoUnit.MONTHS);
         int dayOfMonth = lastMonthNow.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
-        // 获取所有盒子id
-        List<String> boxIds = EnergyUtils.boxIds;
         // 封装本月用电构成
-        boxIds.forEach(boxId -> {
-            Map thisBoxDmonMap = mongoTemplate.findById(boxId + "_" + year + "_" + month, Map.class, "boxDmonLists");
-            Map thisBoxDmonMapL = mongoTemplate.findById(boxId + "_" + ((month) == 1 ? lastYear : year) + "_" + ((month == 1) ? 12 : month - 1), Map.class, "boxDmonLists");
-            boolean flag = MapUtil.isNotEmpty(thisBoxDmonMap);
-            boolean flagL = MapUtil.isNotEmpty(thisBoxDmonMapL);
-            Double zj1 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj1").toString()) : 0.0;
-            Double zj2 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj2").toString()) : 0.0;
-            Double zj3 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj3").toString()) : 0.0;
-            Double zj4 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj4").toString()) : 0.0;
-            Double zj5 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj5").toString()) : 0.0;
-            Double zj6 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj6").toString()) : 0.0;
-            Double all = flag ? Double.parseDouble(thisBoxDmonMap.get("all").toString()) : 0.0;
-            List<Map> byydgc = Arrays.asList(Levi.by("name", DmonDeviceCode.ONE.getName()).set("value", zj1).set("percent", EnergyUtils.getPercent(zj1, all)),
-                    Levi.by("name", DmonDeviceCode.TWO.getName()).set("value", zj2).set("percent", EnergyUtils.getPercent(zj2, all)),
-                    Levi.by("name", DmonDeviceCode.THREE.getName()).set("value", zj3).set("percent", EnergyUtils.getPercent(zj3, all)),
-                    Levi.by("name", DmonDeviceCode.FOUR.getName()).set("value", zj4).set("percent", EnergyUtils.getPercent(zj4, all)),
-                    Levi.by("name", DmonDeviceCode.FIVE.getName()).set("value", zj5).set("percent", EnergyUtils.getPercent(zj5, all)),
-                    Levi.by("name", DmonDeviceCode.SIX.getName()).set("value", zj6).set("percent", EnergyUtils.getPercent(zj6, all)),
-                    Levi.by("name", DmonDeviceCode.ALL.getName()).set("value", all));
-            double ndlj = 0.0, by = 0.0, jrss = 0.0, first = 0.0, second = 0.0, third = 0.0;
-            double ndljL = 0.0, byL = 0.0, jrssL = 0.0, firstL = 0.0, secondL = 0.0, thirdL = 0.0;
-            String ndljP = "0%", byP = "0%", jrssP = "0%", firstP = "0%", secondP = "0%", thirdP = "0%";
-            String firstName = "", secondName = "", thirdName = "";
-            // 封装年度用量环比
-            List<Map> monthList = new ArrayList<>();
-            for (int i = 1; i <= 12; i++) {
-                // 遍历今年和去年每个月的数据
-                Map map = mongoTemplate.findById(boxId + "_" + year + "_" + i, Map.class, "boxDmonLists");
-                Map lastMap = mongoTemplate.findById(boxId + "_" + lastYear + "_" + i, Map.class, "boxDmonLists");
-                Double aDouble = MapUtil.isNotEmpty(map) ? Double.parseDouble(map.get("all").toString()) : 0.0;
-                Double aDoubleL = MapUtil.isNotEmpty(lastMap) ? Double.parseDouble(lastMap.get("all").toString()) : 0.0;
-                monthList.add(Levi.by("year", year).set("month", i).set("value", aDouble).set("yearL", lastYear).set("valueL", aDoubleL));
-                // 累计今年和去年总数
-                ndlj = Double.sum(ndlj, aDouble);
-                ndljL = Double.sum(ndljL, aDoubleL);
+        Map thisBoxDmonMap = mongoTemplate.findById(boxId + "_" + year + "_" + month, Map.class, "boxDmonLists");
+        Map thisBoxDmonMapL = mongoTemplate.findById(boxId + "_" + ((month) == 1 ? lastYear : year) + "_" + ((month == 1) ? 12 : month - 1), Map.class, "boxDmonLists");
+        boolean flag = MapUtil.isNotEmpty(thisBoxDmonMap);
+        boolean flagL = MapUtil.isNotEmpty(thisBoxDmonMapL);
+        Double zj1 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj1").toString()) : 0.0;
+        Double zj2 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj2").toString()) : 0.0;
+        Double zj3 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj3").toString()) : 0.0;
+        Double zj4 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj4").toString()) : 0.0;
+        Double zj5 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj5").toString()) : 0.0;
+        Double zj6 = flag ? Double.parseDouble(thisBoxDmonMap.get("zj6").toString()) : 0.0;
+        Double all = flag ? Double.parseDouble(thisBoxDmonMap.get("all").toString()) : 0.0;
+        List<Map> byydgc = Arrays.asList(Levi.by("name", DmonDeviceCode.ONE.getName()).set("value", zj1).set("percent", EnergyUtils.getPercent(zj1, all)),
+                Levi.by("name", DmonDeviceCode.TWO.getName()).set("value", zj2).set("percent", EnergyUtils.getPercent(zj2, all)),
+                Levi.by("name", DmonDeviceCode.THREE.getName()).set("value", zj3).set("percent", EnergyUtils.getPercent(zj3, all)),
+                Levi.by("name", DmonDeviceCode.FOUR.getName()).set("value", zj4).set("percent", EnergyUtils.getPercent(zj4, all)),
+                Levi.by("name", DmonDeviceCode.FIVE.getName()).set("value", zj5).set("percent", EnergyUtils.getPercent(zj5, all)),
+                Levi.by("name", DmonDeviceCode.SIX.getName()).set("value", zj6).set("percent", EnergyUtils.getPercent(zj6, all)),
+                Levi.by("name", DmonDeviceCode.ALL.getName()).set("value", all));
+        double ndlj = 0.0, by = 0.0, jrss = 0.0, first = 0.0, second = 0.0, third = 0.0;
+        double ndljL = 0.0, byL = 0.0, jrssL = 0.0, firstL = 0.0, secondL = 0.0, thirdL = 0.0;
+        String ndljP = "0%", byP = "0%", jrssP = "0%", firstP = "0%", secondP = "0%", thirdP = "0%";
+        String firstName = "", secondName = "", thirdName = "";
+        // 封装年度用量环比
+        List<Map> monthList = new ArrayList<>();
+        for (int i = 1; i <= 12; i++) {
+            // 遍历今年和去年每个月的数据
+            Map map = mongoTemplate.findById(boxId + "_" + year + "_" + i, Map.class, "boxDmonLists");
+            Map lastMap = mongoTemplate.findById(boxId + "_" + lastYear + "_" + i, Map.class, "boxDmonLists");
+            Double aDouble = MapUtil.isNotEmpty(map) ? Double.parseDouble(map.get("all").toString()) : 0.0;
+            Double aDoubleL = MapUtil.isNotEmpty(lastMap) ? Double.parseDouble(lastMap.get("all").toString()) : 0.0;
+            monthList.add(Levi.by("year", year).set("month", i).set("value", aDouble).set("yearL", lastYear).set("valueL", aDoubleL));
+            // 累计今年和去年总数
+            ndlj = Double.sum(ndlj, aDouble);
+            ndljL = Double.sum(ndljL, aDoubleL);
+        }
+        // 计算年度累计总用量百分比
+        ndljP = EnergyUtils.getPercent(ndlj, ndljL);
+        // 计算本月总用量
+        by = Double.valueOf(monthList.get(month - 1).get("value").toString());
+        byL = Double.valueOf(monthList.get(month - 1).get("valueL").toString());
+        byP = EnergyUtils.getPercent(by, byL);
+        // 计算今日实时用量
+        jrss = EnergyUtils.getDayInfo("all", thisBoxDmonMap, day);
+        jrssL = EnergyUtils.getDayInfo("all", thisBoxDmonMapL, day);
+        jrssP = EnergyUtils.getPercent(jrss, jrssL);
+        // 用量第一、第二、第三
+        Double d1 = EnergyUtils.getDayInfo("zj1", thisBoxDmonMap, day);
+        Double d2 = EnergyUtils.getDayInfo("zj2", thisBoxDmonMap, day);
+        Double d3 = EnergyUtils.getDayInfo("zj3", thisBoxDmonMap, day);
+        Double d4 = EnergyUtils.getDayInfo("zj4", thisBoxDmonMap, day);
+        Double d5 = EnergyUtils.getDayInfo("zj5", thisBoxDmonMap, day);
+        Double d6 = EnergyUtils.getDayInfo("zj6", thisBoxDmonMap, day);
+        Map<Double, List<String>> dmonMaps = new HashMap(16);
+        dmonMaps.put(d1, EnergyUtils.addSameList(dmonMaps.get(d1), DmonDeviceCode.ONE.getName()));
+        dmonMaps.put(d2, EnergyUtils.addSameList(dmonMaps.get(d2), DmonDeviceCode.TWO.getName()));
+        dmonMaps.put(d3, EnergyUtils.addSameList(dmonMaps.get(d3), DmonDeviceCode.THREE.getName()));
+        dmonMaps.put(d4, EnergyUtils.addSameList(dmonMaps.get(d4), DmonDeviceCode.FOUR.getName()));
+        dmonMaps.put(d5, EnergyUtils.addSameList(dmonMaps.get(d5), DmonDeviceCode.FIVE.getName()));
+        dmonMaps.put(d6, EnergyUtils.addSameList(dmonMaps.get(d6), DmonDeviceCode.SIX.getName()));
+        List<Double> doubles = Arrays.asList(d1, d2, d3, d4, d5, d6);
+        Collections.sort(doubles);
+        first = doubles.get(doubles.size() - 1);
+        firstName = String.join(",", dmonMaps.get(first));
+        firstL = EnergyUtils.getDayInfo(firstName.replace("主机", "zj"), (day == 1 ? thisBoxDmonMapL : thisBoxDmonMap), (day == 1 ? dayOfMonth : day - 1));
+        firstP = EnergyUtils.getPercent(first, firstL);
+        second = doubles.get(doubles.size() - 2);
+        secondName = String.join(",", dmonMaps.get(second));
+        secondL = EnergyUtils.getDayInfo(secondName.replace("主机", "zj"), (day == 1 ? thisBoxDmonMapL : thisBoxDmonMap), (day == 1 ? dayOfMonth : day - 1));
+        secondP = EnergyUtils.getPercent(second, secondL);
+        third = doubles.get(doubles.size() - 3);
+        thirdName = String.join(",", dmonMaps.get(third));
+        thirdL = EnergyUtils.getDayInfo(thirdName.replace("主机", "zj"), (day == 1 ? thisBoxDmonMapL : thisBoxDmonMap), (day == 1 ? dayOfMonth : day - 1));
+        thirdP = EnergyUtils.getPercent(third, thirdL);
+        List<Map> byhxzb = Arrays.asList(Levi.by("name", "年度累计总用量").set("value1", ndlj).set("value2", ndljP),
+                Levi.by("name", "本月总用量").set("value1", by).set("value2", byP),
+                Levi.by("name", "今日实时用量").set("value1", jrss).set("value2", jrssP),
+                Levi.by("name", "业态用量第一:" + firstName).set("value1", first).set("value2", firstP),
+                Levi.by("name", "业态用量第二:" + secondName).set("value1", second).set("value2", secondP),
+                Levi.by("name", "业态用量第三:" + thirdName).set("value1", third).set("value2", thirdP)
+        );
+        // 计算本日用量环比
+        List<Map> dayHbList = new ArrayList<>();
+        List<Map> dataHb = flag ? (List<Map>) ((List<Map>) thisBoxDmonMap.get("data")).get(day - 1).get("data") : null;
+        List<Map> dataHbL = flag ? (List<Map>) ((List<Map>) (day == 1 ? thisBoxDmonMapL : thisBoxDmonMap).get("data")).get(day == 1 ? dayOfMonth - 1 : day - 2).get("data") : null;
+        for (int i = 0; i < 8; i++) {
+            dayHbList.add(Levi.by("time", String.format("%02d", i * 3) + ":00").set("today", dataHb.get(i * 3).get("all") == null ? 0.0 : dataHb.get(i * 3).get("all")).set("lastDay", dataHbL.get(i * 3).get("all") == null ? 0.0 : dataHbL.get(i * 3).get("all")));
+        }
+        dayHbList.add(Levi.by("time", "23:59").set("today", dataHb.get(23).get("all") == null ? 0.0 : dataHb.get(23).get("all")).set("lastDay", dataHbL.get(23).get("all") == null ? 0.0 : dataHbL.get(23).get("all")));
+        // 计算月度用量环比
+        List<Map> monthHbList = new ArrayList<>();
+        for (int i = 1; i <= 31; i++) {
+            double x1 = 0.0;
+            double x2 = 0.0;
+            if (flag) {
+                List<Map> l1 = (List<Map>) thisBoxDmonMap.get("data");
+                x1 = l1.get(i - 1).get("all") == null ? 0.0 : Double.valueOf((l1.get(i - 1) == null ? "0" : l1.get(i - 1).get("all").toString()));
             }
-            // 计算年度累计总用量百分比
-            ndljP = EnergyUtils.getPercent(ndlj, ndljL);
-            // 计算本月总用量
-            by = Double.valueOf(monthList.get(month - 1).get("value").toString());
-            byL = Double.valueOf(monthList.get(month - 1).get("valueL").toString());
-            byP = EnergyUtils.getPercent(by, byL);
-            // 计算今日实时用量
-            jrss = EnergyUtils.getDayInfo("all", thisBoxDmonMap, day);
-            jrssL = EnergyUtils.getDayInfo("all", thisBoxDmonMapL, day);
-            jrssP = EnergyUtils.getPercent(jrss, jrssL);
-            // 用量第一、第二、第三
-            Double d1 = EnergyUtils.getDayInfo("zj1", thisBoxDmonMap, day);
-            Double d2 = EnergyUtils.getDayInfo("zj2", thisBoxDmonMap, day);
-            Double d3 = EnergyUtils.getDayInfo("zj3", thisBoxDmonMap, day);
-            Double d4 = EnergyUtils.getDayInfo("zj4", thisBoxDmonMap, day);
-            Double d5 = EnergyUtils.getDayInfo("zj5", thisBoxDmonMap, day);
-            Double d6 = EnergyUtils.getDayInfo("zj6", thisBoxDmonMap, day);
-            Map<Double, List<String>> dmonMaps = new HashMap(16);
-            dmonMaps.put(d1, EnergyUtils.addSameList(dmonMaps.get(d1), DmonDeviceCode.ONE.getName()));
-            dmonMaps.put(d2, EnergyUtils.addSameList(dmonMaps.get(d2), DmonDeviceCode.TWO.getName()));
-            dmonMaps.put(d3, EnergyUtils.addSameList(dmonMaps.get(d3), DmonDeviceCode.THREE.getName()));
-            dmonMaps.put(d4, EnergyUtils.addSameList(dmonMaps.get(d4), DmonDeviceCode.FOUR.getName()));
-            dmonMaps.put(d5, EnergyUtils.addSameList(dmonMaps.get(d5), DmonDeviceCode.FIVE.getName()));
-            dmonMaps.put(d6, EnergyUtils.addSameList(dmonMaps.get(d6), DmonDeviceCode.SIX.getName()));
-            List<Double> doubles = Arrays.asList(d1, d2, d3, d4, d5, d6);
-            Collections.sort(doubles);
-            first = doubles.get(doubles.size() - 1);
-            firstName = String.join(",", dmonMaps.get(first));
-            firstL = EnergyUtils.getDayInfo(firstName.replace("主机", "zj"), (day == 1 ? thisBoxDmonMapL : thisBoxDmonMap), (day == 1 ? dayOfMonth : day - 1));
-            firstP = EnergyUtils.getPercent(first, firstL);
-            second = doubles.get(doubles.size() - 2);
-            secondName = String.join(",", dmonMaps.get(second));
-            secondL = EnergyUtils.getDayInfo(secondName.replace("主机", "zj"), (day == 1 ? thisBoxDmonMapL : thisBoxDmonMap), (day == 1 ? dayOfMonth : day - 1));
-            secondP = EnergyUtils.getPercent(second, secondL);
-            third = doubles.get(doubles.size() - 3);
-            thirdName = String.join(",", dmonMaps.get(third));
-            thirdL = EnergyUtils.getDayInfo(thirdName.replace("主机", "zj"), (day == 1 ? thisBoxDmonMapL : thisBoxDmonMap), (day == 1 ? dayOfMonth : day - 1));
-            thirdP = EnergyUtils.getPercent(third, thirdL);
-            List<Map> byhxzb = Arrays.asList(Levi.by("name", "年度累计总用量").set("value1", ndlj).set("value2", ndljP),
-                    Levi.by("name", "本月总用量").set("value1", by).set("value2", byP),
-                    Levi.by("name", "今日实时用量").set("value1", jrss).set("value2", jrssP),
-                    Levi.by("name", "业态用量第一:" + firstName).set("value1", first).set("value2", firstP),
-                    Levi.by("name", "业态用量第二:" + secondName).set("value1", second).set("value2", secondP),
-                    Levi.by("name", "业态用量第三:" + thirdName).set("value1", third).set("value2", thirdP)
-            );
-            // 计算本日用量环比
-            List<Map> dayHbList = new ArrayList<>();
-            List<Map> dataHb = flag ? (List<Map>) ((List<Map>) thisBoxDmonMap.get("data")).get(day - 1).get("data") : null;
-            List<Map> dataHbL = flag ? (List<Map>) ((List<Map>) (day == 1 ? thisBoxDmonMapL : thisBoxDmonMap).get("data")).get(day == 1 ? dayOfMonth - 1 : day - 2).get("data") : null;
-            for (int i = 0; i < 8; i++) {
-                dayHbList.add(Levi.by("time", String.format("%02d", i * 3) + ":00").set("today", dataHb.get(i * 3).get("all") == null ? 0.0 : dataHb.get(i * 3).get("all")).set("lastDay", dataHbL.get(i * 3).get("all") == null ? 0.0 : dataHbL.get(i * 3).get("all")));
+            if (flagL) {
+                List<Map> l2 = (List<Map>) thisBoxDmonMapL.get("data");
+                x2 = l2.get(i - 1).get("all") == null ? 0.0 : Double.valueOf((l2.get(i - 1) == null ? "0" : l2.get(i - 1).get("all").toString()));
             }
-            dayHbList.add(Levi.by("time", "23:59").set("today", dataHb.get(23).get("all") == null ? 0.0 : dataHb.get(23).get("all")).set("lastDay", dataHbL.get(23).get("all") == null ? 0.0 : dataHbL.get(23).get("all")));
-            // 计算月度用量环比
-            List<Map> monthHbList = new ArrayList<>();
-            for (int i = 1; i <= 31; i++) {
-                double x1 = 0.0;
-                double x2 = 0.0;
-                if (flag) {
-                    List<Map> l1 = (List<Map>) thisBoxDmonMap.get("data");
-                    x1 = l1.get(i - 1).get("all") == null ? 0.0 : Double.valueOf((l1.get(i - 1) == null ? "0" : l1.get(i - 1).get("all").toString()));
-                }
-                if (flagL) {
-                    List<Map> l2 = (List<Map>) thisBoxDmonMapL.get("data");
-                    x2 = l2.get(i - 1).get("all") == null ? 0.0 : Double.valueOf((l2.get(i - 1) == null ? "0" : l2.get(i - 1).get("all").toString()));
-                }
-                monthHbList.add(Levi.by("day", i + "号").set("this", x1).set("last", x2));
-            }
-            // 封装所有数据
-            results.add(Levi.by("boxId", boxId).set("byydgc", byydgc).set("byhxzb", byhxzb).set("ndylhb", monthList).set("brylhb", dayHbList).set("ydylhb", monthHbList));
-        });
-        return ResponseBuilder.ok(results);
+            monthHbList.add(Levi.by("day", i + "号").set("this", x1).set("last", x2));
+        }
+        // 封装所有数据
+        return ResponseBuilder.ok(Levi.by("boxId", boxId).set("byydgc", byydgc).set("byhxzb", byhxzb).set("ndylhb", monthList).set("brylhb", dayHbList).set("ydylhb", monthHbList));
     }
 }