From 74e253770f0c321ad47bb68e490e4a118f35fd35 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 22 七月 2022 16:29:40 +0800
Subject: [PATCH] 优化

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
index b3dd9de..bd65b3b 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
@@ -44,6 +44,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -140,7 +141,7 @@
         StringBuilder sb = new StringBuilder();
         String date = new SimpleDateFormat("yyMMdd").format(new Date());
         sb.append(date);
-        String key = LightKey.POLE_SN.key(null);
+        String key = LightKey.POLE_SN.key(date);
         Long increment = redisService.incr(key, 1);
         String incrementStr = increment.toString();
         if (incrementStr.length() <= 4) {
@@ -568,10 +569,10 @@
      */
     public boolean poleReset(Long id) {
         Pole byId = getById(id);
-        String deviceName = byId.getDeviceCode();
         if (byId == null) {
             throw new BusinessException("鏈壘鍒拌鐏潌");
         }
+        String deviceName = byId.getDeviceCode();
         if (deviceName.isEmpty()) {
             throw new BusinessException("璇ョ伅鏉哅ca涓虹┖");
         }
@@ -605,9 +606,9 @@
     /**
      * 缁欑伅鏉嗘敞鍐屼笁鍏冪爜
      */
-    public boolean setMac(String baseMac) {
-        boolean setMac = false;
-        //String baseMac = "baseDevice";
+    @Transactional(rollbackFor = Exception.class)
+    public Map setMac(String baseMac) {
+
         A1Frame a1Frame = new A1Frame(A1OrderEnum.REQUEST_READ_DEVICE_UNIQUE_MAC.getCode(), new EmptyRequestInnerFrame());
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(baseMac, a1Frame);
         //瀛樺偍鎸褰�
@@ -677,10 +678,6 @@
         StoreOperationRecordsUtils.storeInnerFrameData(baseMac, "閲嶅惎璁惧", build4, rebootFrame);
 
         if ("00".equals(rebootFrame.getPayload())) {
-            //  pole.setDeviceCode(uniqueMac);
-
-            // setMac = updateById(pole);
-
             System.out.println("閲嶅惎鎴愬姛");
         }
 
@@ -689,11 +686,8 @@
         if (pole == null) {
             pole = new Pole();
         }
-      /*  String type = uniqueMac.substring(uniqueMac.length() - 2, uniqueMac.length());
-        String Code = uniqueMac.substring(0, uniqueMac.length() - 2);*/
         pole.setDeviceCode(uniqueMac);
         pole.setPoleName(uniqueMac);
-        /*  int i = Integer.parseInt(strm);*/
         if ("00".equals(a1DeviceMacRespInnerFrame.getType())) {
             pole.setDeviceType(0);
         } else if ("01".equals(a1DeviceMacRespInnerFrame.getType())) {
@@ -701,9 +695,15 @@
         }
 
         pole.setPoleCode(generatePoleCode());
-//        setMac = save(pole);
 
         boolean result = saveOrUpdate(pole);
+
+        if (result) {
+            Light light = new Light();
+            light.setDeviceCode(uniqueMac);
+            light.setLightCount(2);
+            SpringContextHolder.getBean(LightService.class).save(light);
+        }
 
         /**
          * 瀹炰綋鐏潌娉ㄥ唽鏃ュ織璁板綍寮�濮�
@@ -713,8 +713,14 @@
         /**
          * 瀹炰綋鐏潌娉ㄥ唽鏃ュ織璁板綍缁撴潫
          */
+        Map map = new HashMap();
+        if (true) {
+            map.put("mac", uniqueMac);
+        } else {
+            map.put("mac", -1);
+        }
 
-        return result;
+        return map;
     }
 
     public List<String> listDeviceCodeByIds(List<Long> poleIdList) {

--
Gitblit v1.9.3