From 5e94332935da62448c17f89a807acf46a5ae3e75 Mon Sep 17 00:00:00 2001
From: Van333 <van666666@foxmail.com>
Date: 星期四, 15 十二月 2022 10:08:22 +0800
Subject: [PATCH] 本地诺瓦调整

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java |   71 +++++++++++++++++++++--------------
 1 files changed, 43 insertions(+), 28 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 998120c..825e07d 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
@@ -51,6 +51,7 @@
 import java.util.*;
 import java.util.stream.Collectors;
 
+
 /**
  * @author chenjiantian
  * @date 2021/12/13 16:00
@@ -86,6 +87,14 @@
                 light.setLight2Percent(heartBeatDataPackage.getLight2Percent());
                 save(light);
                 log.info("鏂板璺伅");
+                Pole pole = new Pole();
+                pole.setDeviceCode(deviceName);
+                pole.setPoleName(deviceName);
+                pole.setDeviceType(0);
+                pole.setPoleCode(SpringContextHolder.getBean(PoleService.class).generatePoleCode());
+
+                boolean result = SpringContextHolder.getBean(PoleService.class).saveOrUpdate(pole);
+                log.info("鏂板鐏潌锛�"+result);
             }
             redisService.set(LightKey.REPORT_MAC.key(deviceName), 1, LightKey.REPORT_MAC.expireSeconds());
         } else {
@@ -144,7 +153,8 @@
 
         // 鑾峰彇鏈�杩戠殑涓婃姤鏃堕棿
         List<String> deviceCodeList = listLight.stream().map(Light::getDeviceCode).collect(Collectors.toList());
-        //鎷嗗垎list
+
+//        //鎷嗗垎list
         List<List<String>> split = CollectionUtil.split(deviceCodeList, 100);
 
         List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses = null;
@@ -265,13 +275,17 @@
 
         List<Map<String, Object>> resultList = new ArrayList<>();
         for (LightControlParam param : paramList) {
-            A5LightBrightnessReqInnerFrame lightControlFrame = new A5LightBrightnessReqInnerFrame(param.getBrightness(), param.getLightAddress());
-            A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_LIGHT_DATA.getCode(), lightControlFrame);
+            A5LightBrightnessReqInnerFrame
+                    lightControlFrame = new A5LightBrightnessReqInnerFrame(param.getBrightness(), param.getLightAddress());
+            A5Frame a5Frame = new A5Frame(
+                    A5OrderEnum.REQUEST_LIGHT_DATA.getCode(),
+                    lightControlFrame);
             Map<String, Object> map = new HashMap<>();
             try {
                 map.put("deviceCode", param.getDeviceCode());
                 WrapResponseCommonFrame<A5LightBrightnessRespInnerFrame> frame
-                        = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a5Frame, A5LightBrightnessRespInnerFrame.class);
+                        = MainBoardInvokeSyncService.getInstance().sendRRPC
+                        (param.getDeviceCode(), a5Frame, A5LightBrightnessRespInnerFrame.class);
                 //瀛樺偍鎺у埗甯ф寚浠�
                 StoreOperationRecordsUtils.storeInnerFrameData(param.getDeviceCode(), "鍗曠伅甯�-浜害鎺у埗", a5Frame, frame);
 
@@ -1006,9 +1020,7 @@
         A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_LIGHT_DATA.getCode(), setCalendarReqInnerFrame);
         System.out.println(a5Frame + "            -----a5Frame");
 
-        CommonFrame commonFrame;
-
-        commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(one.getDeviceCode(), a5Frame);
+        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(one.getDeviceCode(), a5Frame);
         StoreOperationRecordsUtils.storeInnerFrameData(one.getDeviceCode(), "鍗曠伅甯�-璁剧疆鏃ュ巻", a5Frame, commonFrame);
 
         System.out.println(commonFrame + "            -----commonFrame");
@@ -1032,17 +1044,17 @@
             return;
         }
         //鍗曠伅浠诲姟淇℃伅
-        LightTaskPoleRelation lightTaskPoleRelation = SpringContextHolder.getBean(LightTaskPoleRelationService.class)
-                .getOne(Wrappers.lambdaQuery(LightTaskPoleRelation.class)
-                        .eq(LightTaskPoleRelation::getDeviceCode, deviceCode).eq(LightTaskPoleRelation::getLightAddress, lightAddress));
+//        LightTaskPoleRelation lightTaskPoleRelation = SpringContextHolder.getBean(LightTaskPoleRelationService.class)
+//                .getOne(Wrappers.lambdaQuery(LightTaskPoleRelation.class)
+//                        .eq(LightTaskPoleRelation::getDeviceCode, deviceCode).eq(LightTaskPoleRelation::getLightAddress, lightAddress));
 
         LightTask lightTask = null;
-        //鐏ご娌℃湁浠诲姟
-        if (lightTaskPoleRelation != null) {
-            if (lightTaskPoleRelation.getDeviceScheduled() != null) {
-                lightTask = JSONObject.parseObject(lightTaskPoleRelation.getDeviceScheduled(), LightTask.class);
-            }
-        }
+//        //鐏ご娌℃湁浠诲姟
+//        if (lightTaskPoleRelation != null) {
+//            if (lightTaskPoleRelation.getDeviceScheduled() != null) {
+//                lightTask = JSONObject.parseObject(lightTaskPoleRelation.getDeviceScheduled(), LightTask.class);
+//            }
+//        }
 
         timeSynchronization(light, lightAddress, lightTask);
 
@@ -1055,16 +1067,18 @@
      * @param lightTask 鍗曠伅浠诲姟瀹炰綋锛堜负绌烘爣璇嗗崟鐏病鏈夊畾鏃朵换鍔★級
      */
     public void timeSynchronization(Light light, String lightAddress, LightTask lightTask) {
+        lightTask = null;
+        LightTask finalLightTask = lightTask;
         new Thread(new Runnable() {
             @Override
             public void run() {
                 //鑾峰彇褰撳墠鏃堕棿鏃躲�佸垎
                 Calendar cal = Calendar.getInstance();
 
-                if (lightTask != null) {
-                    String closeOrder = lightTask.getCloseOrder();
-                    String openOrder = lightTask.getOpenOrder();
-                    String controlOrder = lightTask.getControlOrder() == null ? null : lightTask.getControlOrder();
+                if (finalLightTask != null) {
+                    String closeOrder = finalLightTask.getCloseOrder();
+                    String openOrder = finalLightTask.getOpenOrder();
+                    String controlOrder = finalLightTask.getControlOrder() == null ? null : finalLightTask.getControlOrder();
 
                     List<String> timeList = new ArrayList<>();
                     timeList.add(openOrder.substring(0, 4));
@@ -1089,14 +1103,15 @@
                         count++;
                     }
                     if (haveTime) {
-                        try {
-                            long longTime = cal.getTimeInMillis() - System.currentTimeMillis();
-                            log.error("鐫$湢鏃堕棿锛堟绉掞級锛�" + longTime);
-                            Thread.sleep(longTime);
-                            SetCalendar(light.getLightId(), lightAddress);
-                        } catch (InterruptedException e) {
-                            e.printStackTrace();
-                        }
+                        log.error("瀛樺湪瀹氭椂浠诲姟锛�" + light.getLightId()+","+light.getDeviceCode());
+//                        try {
+//                            long longTime = cal.getTimeInMillis() - System.currentTimeMillis();
+//                            log.error("鐫$湢鏃堕棿锛堟绉掞級锛�" + longTime);
+//                            Thread.sleep(longTime);
+//                            SetCalendar(light.getLightId(), lightAddress);
+//                        } catch (InterruptedException e) {
+//                            e.printStackTrace();
+//                        }
                     } else {
                         log.error("鐏潌ID涓猴細" + light.getLightId() + "锛岀伅澶村湴鍧�涓猴細" + lightAddress + "娌℃湁鎵惧埌鍙悓姝ョ殑鏃堕棿锛岃妫�鏌ヤ换鍔★紒");
                     }

--
Gitblit v1.9.3