From 35d46e7981e91fcab730d3a2331c583e6405b460 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 20 五月 2022 13:57:40 +0800
Subject: [PATCH] 日志

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java |   99 ++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 81 insertions(+), 18 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
index 02bb51e..9e83af9 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
@@ -100,7 +100,7 @@
     public List<LightBo> listLight(int pageNo, int pageSize, String keyword) {
         Long clientId = SecurityUtils.getClientId();
 
-      //  PageHelper.startPage(pageNo, pageSize);
+        PageHelper.startPage(pageNo, pageSize);
 
         List<LightBo> listLight = baseMapper.listLight(clientId, keyword);
 
@@ -109,19 +109,19 @@
         //鎷嗗垎list
         List<List<String>> split = CollectionUtil.split(deviceCodeList, 100);
 
-        List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses=null;
+        List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses = null;
         for (List<String> splist : split) {
-            deviceStatuses=MainBoardInvokeSyncService.getInstance().batchGetDeviceState(splist);
+            deviceStatuses = MainBoardInvokeSyncService.getInstance().batchGetDeviceState(splist);
             if (deviceStatuses != null) {
                 for (LightBo lightBo : listLight) {
                     for (BatchGetDeviceStateResponse.DeviceStatus deviceStatus : deviceStatuses) {
 
                         if (lightBo.getDeviceCode() != null && lightBo.getDeviceCode().equals(deviceStatus.getDeviceName())) {
-                            if("ONLINE".equals(deviceStatus.getStatus()) ){
+                            if ("ONLINE".equals(deviceStatus.getStatus())) {
                                 lightBo.setOnlineStatus(0);
-                            }else if("OFFLINE".equals(deviceStatus.getStatus())){
+                            } else if ("OFFLINE".equals(deviceStatus.getStatus())) {
                                 lightBo.setOnlineStatus(1);
-                            }else {
+                            } else {
                                 lightBo.setOnlineStatus(2);
                             }
 
@@ -230,7 +230,9 @@
                 map.put("deviceCode", param.getDeviceCode());
                 WrapResponseCommonFrame<A5LightBrightnessRespInnerFrame> frame
                         = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a5Frame, A5LightBrightnessRespInnerFrame.class);
+                //瀛樺偍鎺у埗甯ф寚浠�
                 StoreOperationRecordsUtils.storeInnerFrameData(param.getDeviceCode(), "鍗曠伅甯�-浜害鎺у埗", a5Frame, frame);
+
                 if (frame == null) {
                     map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                     resultList.add(map);
@@ -334,7 +336,7 @@
                 currentWeekValue = 7;
             }
             map = new LinkedHashMap();
-            map.put("time",localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+            map.put("time", localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
             map.put("value", getlist(currentWeekValue));
             temp.add(map);
         }
@@ -406,7 +408,7 @@
                 currentWeekValue = 7;
             }
             map = new LinkedHashMap();
-            map.put("time",localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+            map.put("time", localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
             map.put("value", getlistEnergy(currentWeekValue));
             temp.add(map);
         }
@@ -598,6 +600,60 @@
          */
     }
 
+    /**
+     * 鍗曚釜浠诲姟涓�澶╃殑鑺傝兘鐜�
+     *
+     * @return
+     */
+    public BigDecimal jisuan(LightTaskDto Task) {
+        final BigDecimal[] bigDecimalResult = {new BigDecimal(0.00)};
+        /**
+         * 鑺傝兘鐜囪绠楀紑濮�
+         */
+        //TODO
+      //鑾峰彇鏄ㄥぉ鐨勬槦鏈熸暟
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime yesterday = now.minusDays(1);
+        int week = yesterday.getDayOfWeek().getValue();
+
+        //鍒ゆ柇Task.getWeekList()鏄惁鍖呭惈鏄ㄥぉ鐨勬槦鏈熸暟   涓嶅寘鍚洿鎺ヨ繑鍥�0  涓嶈繘琛岃绠�
+        if (Task.getWeekList() != null && !Task.getWeekList().isEmpty()) {
+            if (!Task.getWeekList().contains(week)) {
+                new BigDecimal(0.00);
+            }
+        }
+
+
+        ControlLightCommandVO startTime = parseSwitchLightCommand(Task.getOpenOrder());
+        ControlLightCommandVO endTime = parseSwitchLightCommand(Task.getCloseOrder());
+        //瀛樻斁鑺傝兘鐜�
+        //鑾峰彇鍒板崟鐏换鍔$殑鑺傝兘鐜�
+        if (Task.getControlOrder() != null && !Task.getControlOrder().isEmpty()) {//鏈夋帶绛夋寚浠� 鎷嗗垎璁$畻
+            List<ControlLightCommandVO> controlLightCommandVOS = parseControlLightCommand(Task.getControlOrder());
+
+            for (int i = 0; i < controlLightCommandVOS.size(); i++) {
+                BigDecimal bigDecimal = calculateEnergySaving(startTime, controlLightCommandVOS.get(i));
+                bigDecimalResult[0] = bigDecimalResult[0].add(bigDecimal);
+                if (controlLightCommandVOS.size() == (i + 1)) {
+                    BigDecimal bigDecimal1 = calculateEnergySaving(controlLightCommandVOS.get(i), endTime);
+                    bigDecimalResult[0] = bigDecimalResult[0].add(bigDecimal1);
+                    break;
+                }
+                startTime = controlLightCommandVOS.get(i);
+//                    saving.add(bigDecimal);
+            }
+        } else {//鏃犳帶鐏寚浠� 鐩存帴璁$畻
+            BigDecimal bigDecimal = calculateEnergySaving(startTime, endTime);
+//                saving.add(bigDecimal);
+            bigDecimalResult[0] = bigDecimalResult[0].add(bigDecimal);
+        }
+        return bigDecimalResult[0];
+
+        /**
+         * 鑺傝兘鐜囪绠楃粨鏉�
+         */
+    }
+
 
     /**
      * 涓�澶╃殑鑳借��
@@ -623,20 +679,22 @@
                 for (int i = 0; i < controlLightCommandVOS.size(); i++) {
                     //寰楀埌鏃堕暱*浜害
                     BigDecimal bigEnergy1 = calculateEnergyConsumption(startTime, controlLightCommandVOS.get(i));
-//                    //璁$畻鑳借��(鎬�   鏃堕暱*浜害*鍔熺巼)
-                    BigDecimal totalEnergy = totalEnergy(bigEnergy1, Task.getLightAdress(), poleTaskLightPowerBos);
-                    bigEnergy[0] = bigEnergy[0].add(totalEnergy);
-//                    BigDecimal totalEnergy4 = totalEnergy(bigEnergy1, Task.getLightAdress(), poleTaskLightPowerBos);
-//                    bigEnergy[0] = bigEnergy[0].add(totalEnergy4);
+                    //鍒ゆ柇 Energy==0 鍒欎笉璁$畻
+                    if (bigEnergy1.compareTo(new BigDecimal(0)) != 0) {
+                        //璁$畻鑳借��(鎬�   鏃堕暱*浜害*鍔熺巼)
+                        BigDecimal totalEnergy = totalEnergy(bigEnergy1, Task.getLightAdress(), poleTaskLightPowerBos);
+                        bigEnergy[0] = bigEnergy[0].add(totalEnergy);
+                    }
                     if (controlLightCommandVOS.size() == (i + 1)) {
                         BigDecimal bigEnergy2 = calculateEnergyConsumption(controlLightCommandVOS.get(i), endTime);
 
                         System.out.println(bigEnergy2 + "鏃堕暱*浜害===========================");
 
                         //璁$畻鑳借��(鎬�   鏃堕暱*浜害*鍔熺巼)
-                        BigDecimal totalEnergy3 = totalEnergy(bigEnergy2, Task.getLightAdress(), poleTaskLightPowerBos);
-//                        saving.add(bigDecimal1);
-                        bigEnergy[0] = bigEnergy[0].add(totalEnergy3);
+                        if (bigEnergy2.compareTo(new BigDecimal(0)) != 0) {
+                            BigDecimal totalEnergy3 = totalEnergy(bigEnergy2, Task.getLightAdress(), poleTaskLightPowerBos);
+                            bigEnergy[0] = bigEnergy[0].add(totalEnergy3);
+                        }
                         break;
                     }
                     startTime = controlLightCommandVOS.get(i);
@@ -646,9 +704,14 @@
                 //璁$畻鑳借��(閮ㄥ垎   鏃堕暱*浜害)
                 BigDecimal Energy = calculateEnergyConsumption(startTime, endTime);
                 //璁$畻鑳借��(鎬�   鏃堕暱*浜害*鍔熺巼)
-                BigDecimal totalEnergy = totalEnergy(Energy, Task.getLightAdress(), poleTaskLightPowerBos);
+                //鍒ゆ柇 Energy==0 鍒欎笉璁$畻
+                if (Energy.compareTo(new BigDecimal(0)) != 0) {
+                    BigDecimal totalEnergy = totalEnergy(Energy, Task.getLightAdress(), poleTaskLightPowerBos);
+                    bigEnergy[0] = bigEnergy[0].add(totalEnergy);
+                }
+
 //                saving.add(bigDecimal);
-                bigEnergy[0] = bigEnergy[0].add(totalEnergy);
+
             }
         });
         return bigEnergy[0];

--
Gitblit v1.9.3