From db617099d629961796774821d1dbdb0a3ddd16b5 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期三, 18 五月 2022 14:58:30 +0800
Subject: [PATCH] 日志记录

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java |   75 +++++++++++++++++++++++++------------
 1 files changed, 51 insertions(+), 24 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 f314146..03d895a 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
@@ -41,10 +41,9 @@
 
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.time.LocalTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -205,7 +204,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);
@@ -228,6 +229,20 @@
             }
         }
 
+        /**
+         * 鏈嶅姟绔壒閲忔帶鐏棩蹇楄褰曞紑濮�
+         */
+        String content = "{鎺х伅璇锋眰锛�" + paramList.toString()
+                + "锛� 鎺х伅缁撴灉锛�" + resultList.toString() + "}";
+        List<String> codeList = new ArrayList<>();
+        for (LightControlParam bean : paramList) {
+            codeList.add(bean.getDeviceCode());
+        }
+        StoreOperationRecordsUtils.storeOperationData(codeList, null, "鏈嶅姟绔壒閲忔帶鐏�", content);
+        /**
+         * 鏈嶅姟绔壒閲忔帶鐏棩蹇楄褰曠粨鏉�
+         */
+
         return resultList;
     }
 
@@ -236,7 +251,7 @@
      *
      * @return
      */
-    public Map controlEnergySaving() {
+    public List controlEnergySaving() {
         //鑾峰彇鍒版鍦ㄦ墽琛岀殑浠诲姟鍒楄〃
         List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask();
         LocalDateTime now = LocalDateTime.now();
@@ -251,7 +266,6 @@
 
         for (LightTaskDto lightTaskDto : lightTaskDtos) {
             List<Integer> weekList = lightTaskDto.getWeekList();
-            System.out.println(weekList + "===========================");
             for (Integer one : weekList) {
                 switch (one) {
                     case 1:
@@ -280,21 +294,29 @@
             }
         }
 
-        Integer week = now.getDayOfWeek().getValue();
 
-        Map map = new HashMap();
+        //鑾峰彇褰撳墠鏄熸湡鍑� 1-7
+
+        int currentWeekValue = now.getDayOfWeek().getValue();
+        Map map;
+        List<Map> temp = new ArrayList<>();
+        //鑾峰彇鏃ユ湡 绮剧‘鍒板ぉ
+        LocalDateTime localDateTime = now.with(LocalTime.MIN);
 
 
         for (int i = 1; i < 8; i++) {
-            week--;
-            if (week < 1) {
-                week = 7;
+            currentWeekValue--;
+            if (currentWeekValue < 1) {
+                currentWeekValue = 7;
             }
-            map.put(i, getlist(week));
+            map = new LinkedHashMap();
+            map.put("time",localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+            map.put("value", getlist(currentWeekValue));
+            temp.add(map);
         }
 
 
-        return map;
+        return temp;
     }
 
 
@@ -303,7 +325,7 @@
      *
      * @return
      */
-    public Map controlEnergy() {
+    public List controlEnergy() {
         //鑾峰彇鍒版鍦ㄦ墽琛岀殑浠诲姟鍒楄〃
         List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask();
         LocalDateTime now = LocalDateTime.now();
@@ -347,21 +369,26 @@
             }
         }
 
-        Integer week = now.getDayOfWeek().getValue();
-
-        Map map = new HashMap();
+        Integer currentWeekValue = now.getDayOfWeek().getValue();
+        Map map;
+        List<Map> temp = new ArrayList<>();
+        //鑾峰彇褰撳墠鏃ユ湡  鏍煎紡涓簓yyy-MM-dd
+        LocalDateTime localDateTime = now.with(LocalTime.MIN);
 
 
         for (int i = 1; i < 8; i++) {
-            week--;
-            if (week < 1) {
-                week = 7;
+            currentWeekValue--;
+            if (currentWeekValue < 1) {
+                currentWeekValue = 7;
             }
-            map.put(i, getlistEnergy(week));
+            map = new LinkedHashMap();
+            map.put("time",localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+            map.put("value", getlistEnergy(currentWeekValue));
+            temp.add(map);
         }
 
 
-        return map;
+        return temp;
     }
 
 
@@ -693,11 +720,11 @@
             min = 0;
         }
         //璁$畻鏃堕暱
-        BigDecimal totalTime = BigDecimal.valueOf(hour*60+min);
+        BigDecimal totalTime = BigDecimal.valueOf(hour * 60 + min);
 
         //璁$畻鑺傝兘鐜� ( (1-v1.getBrightness()/100)*totalTime/3600 )   淇濈暀涓や綅灏忔暟
         BigDecimal energySaving = BigDecimal.valueOf((1 - v1.getBrightness() / 100) * totalTime.doubleValue() / 3600).setScale(2, BigDecimal.ROUND_HALF_UP);
-        System.out.println(energySaving+"鑺傝兘鐜�");
+        System.out.println(energySaving + "鑺傝兘鐜�");
         return energySaving;
     }
 

--
Gitblit v1.9.3