Kaynağa Gözat

楼宇接口无数据显示优化

yangbq 1 ay önce
ebeveyn
işleme
9d2f953434

+ 224 - 37
project-zcustom/src/main/java/com/project/zcustom/service/service/smart/impl/PlatBuildingServiceImpl.java

@@ -27,11 +27,13 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
         String json = platBuildingMapper.getPowerAndWaterMonth();
         if (StringUtils.isEmpty(json)){
-            Map<String, Object> data = new HashMap<>();
-            data.put("name", "water");
-            data.put("value", 0);
-            resultList.add(data);
-            return resultList;
+            json = "[{\n" +
+                    "\t\"key\": \"water\",\n" +
+                    "\t\"value\": \"0\"\n" +
+                    "}, {\n" +
+                    "\t\"key\": \"power\",\n" +
+                    "\t\"value\": \"0\"\n" +
+                    "}]";
         }
         JSONArray dataArray = JSONArray.parseArray(json);
         for (int i = 0; i < dataArray.size(); i++) {
@@ -51,12 +53,27 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
         String json = platBuildingMapper.getAirCondition();
         if (StringUtils.isEmpty(json)){
-            Map<String, Object> data = new HashMap<>();
-            data.put("name", "温度");
-            data.put("valueIn", 0);
-            data.put("valueOut", 0);
-            resultList.add(data);
-            return resultList;
+           json = "[{\n" +
+                   "\t\"name\": \"温度\",\n" +
+                   "\t\"value\": \"0.00\",\n" +
+                   "\t\"value1\": \"0.00\"\n" +
+                   "}, {\n" +
+                   "\t\"name\": \"湿度\",\n" +
+                   "\t\"value\": \"0.00\",\n" +
+                   "\t\"value1\": \"0.00\"\n" +
+                   "}, {\n" +
+                   "\t\"name\": \"二氧化碳\",\n" +
+                   "\t\"value\": \"0.00\",\n" +
+                   "\t\"value1\": \"0.00\"\n" +
+                   "}, {\n" +
+                   "\t\"name\": \"PM2.5\",\n" +
+                   "\t\"value\": \"0.00\",\n" +
+                   "\t\"value1\": \"0.00\"\n" +
+                   "}, {\n" +
+                   "\t\"name\": \"PM10\",\n" +
+                   "\t\"value\": \"0.00\",\n" +
+                   "\t\"value1\": \"0.00\"\n" +
+                   "}]";
         }
         JSONArray dataArray = JSONArray.parseArray(json);
         for (int i = 0; i < dataArray.size(); i++) {
@@ -78,7 +95,43 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
         String json = platBuildingMapper.getTarget();
         if (StringUtils.isEmpty(json)){
-            return resultList;
+            json = "[{\n" +
+                    "\t\"guideValue\": 0.00,\n" +
+                    "\t\"datumValue\": 0.00,\n" +
+                    "\t\"tieValue\": 0.00,\n" +
+                    "\t\"value\": \"0.00\",\n" +
+                    "\t\"name\": \"单位建筑面积电耗(kW·h)\"\n" +
+                    "}, {\n" +
+                    "\t\"guideValue\": 0.00,\n" +
+                    "\t\"datumValue\": 0.00,\n" +
+                    "\t\"tieValue\": 0.00,\n" +
+                    "\t\"value\": \"\",\n" +
+                    "\t\"name\": \"单位建筑面积水耗(m³)\"\n" +
+                    "}, {\n" +
+                    "\t\"guideValue\": 0.00,\n" +
+                    "\t\"datumValue\": 0.00,\n" +
+                    "\t\"tieValue\": 0.00,\n" +
+                    "\t\"value\": \"0.00\",\n" +
+                    "\t\"name\": \"单位建筑面积综合能耗(kgce)\"\n" +
+                    "}, {\n" +
+                    "\t\"guideValue\": 0.00,\n" +
+                    "\t\"datumValue\": 0.00,\n" +
+                    "\t\"tieValue\": 0.00,\n" +
+                    "\t\"value\": \"0.00\",\n" +
+                    "\t\"name\": \"人均电耗(kW·h)\"\n" +
+                    "}, {\n" +
+                    "\t\"guideValue\": 0.00,\n" +
+                    "\t\"datumValue\": 0.00,\n" +
+                    "\t\"tieValue\": 0.00,\n" +
+                    "\t\"value\": \"0.00\",\n" +
+                    "\t\"name\": \"人均水耗(m³)\"\n" +
+                    "}, {\n" +
+                    "\t\"guideValue\": 0.00,\n" +
+                    "\t\"datumValue\": 0.00,\n" +
+                    "\t\"tieValue\": 0.00,\n" +
+                    "\t\"value\": \"0.00\",\n" +
+                    "\t\"name\": \"人均综合能耗(kgce)\"\n" +
+                    "}]";
         }
         JSONArray dataArray = JSONArray.parseArray(json);
         for (int i = 0; i < dataArray.size(); i++) {
@@ -130,7 +183,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         String json = platBuildingMapper.greenElectricity();
         if (StringUtils.isEmpty(json)){
             data.put("publicEnergy", 0);
-            data.put("grennEnergy", 0);
+            data.put("grennEnergy", 100);
             return data;
         }
         JSONObject jsonObject = JSONObject.parseObject(json);
@@ -319,9 +372,57 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         Map<String, Object> map = new HashMap<>();
         LargeBuildingControl largeBuildingControl = platBuildingMapper.getThisWeekElectricity();
         if (Objects.isNull(largeBuildingControl)) {
-            JSONArray array = new JSONArray();
-            map.put("total", array);
-            map.put("room", array);
+            String total = "[{\n" +
+                    "\t\"name\": \"光伏用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"楼外设备用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"充电桩用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"地下室用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"制冷机组用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"消防用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"电梯用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"办公用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"公共照明用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"供热设备用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"厨房用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"机房总用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"生活水泵用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"冷源泵用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"热源泵用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}, {\n" +
+                    "\t\"name\": \"通信辅助设备用电量\",\n" +
+                    "\t\"num\": 0.0\n" +
+                    "}]";
+            map.put("total", JSONArray.parseArray(total));
+            map.put("room", "");
             return map;
         }
         JSONArray weekElectricity = JSONArray.parseArray(largeBuildingControl.getWeekElectricity());
@@ -333,6 +434,9 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
     public JSONObject getControlElevator(){
         String result = platBuildingMapper.getControlElevator();
+        if (StringUtils.isBlank(result)){
+            result = "{\"weekTotal\":0.00}";
+        }
         return JSONObject.parseObject(result);
     }
 
@@ -347,7 +451,25 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
     public List<Map<String, Object>> getTodayElectricity(){
         String json = platBuildingMapper.getTodayElectricity();
         if (StringUtils.isBlank(json)) {
-            return new ArrayList<>();
+            json = "[{\n" +
+                    "\t\"time\": \"00\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"01\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"02\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"03\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"04\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"05\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}]";
         }
         JSONArray jsonArray = JSONArray.parseArray(json);
         return repeatElectricity(jsonArray);
@@ -357,11 +479,47 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         LargeBuildingControl largeBuildingControl = platBuildingMapper.getMonthElectricity();
         Map<String, Object> map = new HashMap<>();
         if (Objects.isNull(largeBuildingControl)) {
-            List<Map<String, Object>> list = new ArrayList<>();
-            map.put("first", list);
-            map.put("second", list);
-            map.put("third", list);
-            return map;
+            largeBuildingControl = new LargeBuildingControl();
+            String one = "[{\n" +
+                    "\t\"time\": \"2025-01\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-02\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-03\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-04\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-05\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-06\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-07\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-08\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-09\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-10\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-11\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}, {\n" +
+                    "\t\"time\": \"2025-12\",\n" +
+                    "\t\"Kwh\": \"0.0\"\n" +
+                    "}]";
+            largeBuildingControl.setMonthElectricityOne(one);
+            largeBuildingControl.setMonthElectricityTwo(one);
+            largeBuildingControl.setMonthElectricityThree(one);
         }
         JSONArray x = JSONArray.parseArray(largeBuildingControl.getMonthElectricityOne());
         JSONArray y = JSONArray.parseArray(largeBuildingControl.getMonthElectricityTwo());
@@ -380,11 +538,21 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         LargeBuildingControl largeBuildingControl = platBuildingMapper.getRoomLoad();
         Map<String, Object> map = new HashMap<>();
         if (Objects.isNull(largeBuildingControl)) {
-            List<Integer> list = new ArrayList<>();
-            map.put("first", list);
-            map.put("second", list);
-            map.put("third", list);
-            return map;
+            largeBuildingControl = new LargeBuildingControl();
+            String json = "[{\n" +
+                    "\t\"kz\": 0\n" +
+                    "}, {\n" +
+                    "\t\"qz\": 0\n" +
+                    "}, {\n" +
+                    "\t\"zc\": 0\n" +
+                    "}, {\n" +
+                    "\t\"zz\": 0\n" +
+                    "}, {\n" +
+                    "\t\"gz\": 0\n" +
+                    "}]";
+            largeBuildingControl.setRoomLoadOne(json);
+            largeBuildingControl.setRoomLoadTwo(json);
+            largeBuildingControl.setRoomLoadThree(json);
         }
         JSONArray x = JSONArray.parseArray(largeBuildingControl.getRoomLoadOne());
         JSONArray y = JSONArray.parseArray(largeBuildingControl.getRoomLoadTwo());
@@ -418,12 +586,29 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
         Map<String, Object> map = new HashMap<>();
         if (Objects.isNull(largeBuildingControl)) {
-            JSONObject db = new JSONObject();
-            map.put("db", db);
-            map.put("ywj", db);
-            map.put("sj", db);
-            map.put("yw", db);
-            return map;
+            String warnDevice = "{\n" +
+                    "\t\"db\": {\n" +
+                    "\t\t\"zcdw\": \"0\",\n" +
+                    "\t\t\"ycdw\": \"0\"\n" +
+                    "\t},\n" +
+                    "\t\"ywj\": {\n" +
+                    "\t\t\"zcdw\": \"0\",\n" +
+                    "\t\t\"ycdw\": \"0\"\n" +
+                    "\t},\n" +
+                    "\t\"sj\": {\n" +
+                    "\t\t\"zcdw\": \"0\",\n" +
+                    "\t\t\"ycdw\": \"0\"\n" +
+                    "\t},\n" +
+                    "\t\"yw\": {\n" +
+                    "\t\t\"zcdw\": \"0\",\n" +
+                    "\t\t\"ycdw\": \"0\"\n" +
+                    "\t}\n" +
+                    "}";
+            largeBuildingControl = new LargeBuildingControl();
+            largeBuildingControl.setWarnDevice(warnDevice);
+            largeBuildingControl.setWaterControlAbnormalNum(0L);
+            largeBuildingControl.setWaterControlNormalNum(0L);
+            largeBuildingControl.setWaterDeviceAirNum(0L);
         }
         JSONObject jsonObject = JSONObject.parseObject(largeBuildingControl.getWarnDevice());
         JSONObject water = jsonObject.getJSONObject("sj");
@@ -458,6 +643,9 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
 
     public JSONArray getWarnEvent(){
         String json = platBuildingMapper.getWarnEvent();
+        if (StringUtils.isBlank(json)) {
+            json = "[{\"db\":\"0\",\"sj\":\"0\",\"yw\":\"0\",\"ywj\":\"0\",\"month\":\"1\"},{\"db\":\"0\",\"sj\":\"0\",\"yw\":\"0\",\"ywj\":\"0\",\"month\":\"2\"},{\"db\":\"0\",\"sj\":\"0\",\"yw\":\"0\",\"ywj\":\"0\",\"month\":\"3\"},{\"db\":\"0\",\"sj\":\"0\",\"yw\":\"0\",\"ywj\":\"0\",\"month\":\"4\"},{\"db\":\"0\",\"sj\":\"0\",\"yw\":\"0\",\"ywj\":\"0\",\"month\":\"5\"},{\"db\":\"0\",\"sj\":\"0\",\"yw\":\"0\",\"ywj\":\"0\",\"month\":\"6\"}]";
+        }
         return JSONArray.parseArray(json);
     }
 
@@ -465,9 +653,8 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         LargeBuildingControl largeBuildingControl = platBuildingMapper.getWarnState();
         Map<String, Object> map = new HashMap<>();
         if (Objects.isNull(largeBuildingControl)) {
-            List<Map<String, Object>> list = new ArrayList<>();
-            map.put("twentyThree", list);
-            map.put("minusTwo", list);
+            map.put("twentyThree", JSONObject.parseObject("{\"shsx\":[{\"dqsw\":\"0m\"},{\"zdsw\":\"0m\"},{\"zgsw\":\"00m\"}],\"xfsx\":[{\"dqsw\":\"0m\"},{\"zdsw\":\"0m\"},{\"zgsw\":\"0m\"}]}"));
+            map.put("minusTwo", JSONObject.parseObject("{\"gqsx\":[{\"dqsw\":\"0m\"},{\"zdsw\":\"0m\"},{\"zgsw\":\"0m\"}],\"dqsx\":[{\"dqsw\":\"0m\"},{\"zdsw\":\"0m\"},{\"zgsw\":\"0m\"}]}"));
             return map;
         }
         map.put("twentyThree", JSONObject.parseObject(largeBuildingControl.getWaterStateOne()));
@@ -497,7 +684,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
         return list;
     }
 
-    private static String[] getLastSixMonths() {
+    private String[] getLastSixMonths() {
         LocalDate currentDate = LocalDate.now();
         // 自定义格式化模式,确保月份没有前导零并附加“月”字
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M'月'");