From 383b33fdfb1a01b27b8ecda7a46fd8e5e5d4d0f2 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期二, 17 五月 2022 17:07:28 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java |   85 +++++++++++++++++++++++++++++++-----------
 1 files changed, 62 insertions(+), 23 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 ee55573..aa11e70 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
@@ -3,6 +3,7 @@
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.HexUtil;
 import cn.hutool.core.util.StrUtil;
+import com.aliyuncs.iot.model.v20180120.BatchGetDeviceStateResponse;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.pagehelper.PageHelper;
 import com.sandu.common.domain.CommonPage;
@@ -41,10 +42,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;
 
 /**
@@ -100,12 +100,37 @@
     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);
 
         // 鑾峰彇鏈�杩戠殑涓婃姤鏃堕棿
         List<String> deviceCodeList = listLight.stream().map(Light::getDeviceCode).collect(Collectors.toList());
+        //鎷嗗垎list
+        List<List<String>> split = CollectionUtil.split(deviceCodeList, 100);
+
+        List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses=null;
+        for (List<String> splist : split) {
+            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()) ){
+                                lightBo.setOnlineStatus(0);
+                            }else if("OFFLINE".equals(deviceStatus.getStatus())){
+                                lightBo.setOnlineStatus(1);
+                            }else {
+                                lightBo.setOnlineStatus(2);
+                            }
+
+                        }
+                    }
+
+                }
+            }
+        }
         if (CollectionUtil.isNotEmpty(deviceCodeList)) {
             List<LightReportData> reportDataList = lightReportDataService.getNewestReportByDeviceCode(deviceCodeList);
             for (LightBo lightBo : listLight) {
@@ -205,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);
@@ -250,7 +277,7 @@
      *
      * @return
      */
-    public Map controlEnergySaving() {
+    public List controlEnergySaving() {
         //鑾峰彇鍒版鍦ㄦ墽琛岀殑浠诲姟鍒楄〃
         List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask();
         LocalDateTime now = LocalDateTime.now();
@@ -265,7 +292,6 @@
 
         for (LightTaskDto lightTaskDto : lightTaskDtos) {
             List<Integer> weekList = lightTaskDto.getWeekList();
-            System.out.println(weekList + "===========================");
             for (Integer one : weekList) {
                 switch (one) {
                     case 1:
@@ -294,21 +320,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;
     }
 
 
@@ -317,7 +351,7 @@
      *
      * @return
      */
-    public Map controlEnergy() {
+    public List controlEnergy() {
         //鑾峰彇鍒版鍦ㄦ墽琛岀殑浠诲姟鍒楄〃
         List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask();
         LocalDateTime now = LocalDateTime.now();
@@ -361,21 +395,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;
     }
 
 

--
Gitblit v1.9.3