From e879e9776519490bd633c73d314bf2cf00d82dc4 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 22 七月 2022 13:53:51 +0800
Subject: [PATCH] 优化

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java       |   23 ++++++++++++-----------
 ximon-admin/src/main/java/com/sandu/ximon/admin/controller/PoleController.java |   22 +++++++++++++---------
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/controller/PoleController.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/controller/PoleController.java
index 881bef7..058ce00 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/controller/PoleController.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/controller/PoleController.java
@@ -7,6 +7,7 @@
 import com.sandu.common.domain.CommonPage;
 import com.sandu.common.domain.ResponseVO;
 import com.sandu.common.object.BaseConditionVO;
+import com.sandu.common.security.annotation.AnonymousAccess;
 import com.sandu.common.util.ResponseUtil;
 import com.sandu.ximon.admin.dto.DeviceStatus;
 import com.sandu.ximon.admin.param.PoleBindParam;
@@ -127,22 +128,24 @@
     /**
      * 璁剧疆涓夊厓鐮�
      */
+    @AnonymousAccess
     @PostMapping("/setMac/{baseMac}")
     public ResponseVO<Object> setMac(@PathVariable String baseMac) {
-        if (!permissionConfig.check(MenuEnum.POLE_REAL_ADD.getCode())) {
-            return ResponseUtil.fail("缂哄皯瀵瑰簲鐢ㄦ埛鏉冮檺");
-        }
+//        if (!permissionConfig.check(MenuEnum.POLE_REAL_ADD.getCode())) {
+//            return ResponseUtil.fail("缂哄皯瀵瑰簲鐢ㄦ埛鏉冮檺");
+//        }
         return ResponseUtil.success(poleService.setMac(baseMac));
     }
 
     /**
      * 鎭㈠鐏潌鍑哄巶璁剧疆
      */
+    @AnonymousAccess
     @PostMapping("/poleReset/{poleId}")
     public ResponseVO<Object> poleReset(@PathVariable Long poleId) {
-        if (!permissionConfig.check(MenuEnum.POLE_REAL_RESET.getCode())) {
-            return ResponseUtil.fail("缂哄皯瀵瑰簲鐢ㄦ埛鏉冮檺");
-        }
+//        if (!permissionConfig.check(MenuEnum.POLE_REAL_RESET.getCode())) {
+//            return ResponseUtil.fail("缂哄皯瀵瑰簲鐢ㄦ埛鏉冮檺");
+//        }
         return ResponseUtil.success(poleService.poleReset(poleId));
     }
 
@@ -254,11 +257,12 @@
         }
     }
 
+    @AnonymousAccess
     @PostMapping("/listStatusByDeviceCode")
     public ResponseVO<Object> getStatusById(@RequestBody String[] deviceCodeList) {
-        if (!permissionConfig.check(MenuEnum.GET_STATE_BY_DEVICECODE.getCode())) {
-            return ResponseUtil.fail("缂哄皯瀵瑰簲鐢ㄦ埛鏉冮檺");
-        }
+//        if (!permissionConfig.check(MenuEnum.GET_STATE_BY_DEVICECODE.getCode())) {
+//            return ResponseUtil.fail("缂哄皯瀵瑰簲鐢ㄦ埛鏉冮檺");
+//        }
         for (String s : deviceCodeList) {
             if (s == null) {
                 return ResponseUtil.fail("鍙傛暟涓嶈兘涓虹┖");
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 1a0cc11..c41fbda 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.*;
@@ -605,6 +606,7 @@
     /**
      * 缁欑伅鏉嗘敞鍐屼笁鍏冪爜
      */
+    @Transactional(rollbackFor = Exception.class)
     public Map setMac(String baseMac) {
 
         A1Frame a1Frame = new A1Frame(A1OrderEnum.REQUEST_READ_DEVICE_UNIQUE_MAC.getCode(), new EmptyRequestInnerFrame());
@@ -676,10 +678,6 @@
         StoreOperationRecordsUtils.storeInnerFrameData(baseMac, "閲嶅惎璁惧", build4, rebootFrame);
 
         if ("00".equals(rebootFrame.getPayload())) {
-            //  pole.setDeviceCode(uniqueMac);
-
-            // setMac = updateById(pole);
-
             System.out.println("閲嶅惎鎴愬姛");
         }
 
@@ -688,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())) {
@@ -700,20 +695,26 @@
         }
 
         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);
+        }
 
         /**
          * 瀹炰綋鐏潌娉ㄥ唽鏃ュ織璁板綍寮�濮�
          */
-        String content = "{鐏潌ID锛�" + pole.getId() + ",鐏潌缂栧彿锛�" + pole.getPoleCode() + ",鐏潌鍚嶇О锛�" + pole.getPoleName() + ",鐏潌绫诲瀷锛�" + pole.getDeviceType() + ",鐏潌MAC锛�" + pole.getDeviceCode() + " }";
-        StoreOperationRecordsUtils.storeOperationData(null, null, "瀹炰綋鐏潌娉ㄥ唽", content);
+//        String content = "{鐏潌ID锛�" + pole.getId() + ",鐏潌缂栧彿锛�" + pole.getPoleCode() + ",鐏潌鍚嶇О锛�" + pole.getPoleName() + ",鐏潌绫诲瀷锛�" + pole.getDeviceType() + ",鐏潌MAC锛�" + pole.getDeviceCode() + " }";
+//        StoreOperationRecordsUtils.storeOperationData(null, null, "瀹炰綋鐏潌娉ㄥ唽", content);
         /**
          * 瀹炰綋鐏潌娉ㄥ唽鏃ュ織璁板綍缁撴潫
          */
         Map map = new HashMap();
-        if (result) {
+        if (true) {
             map.put("mac", uniqueMac);
         } else {
             map.put("mac", -1);

--
Gitblit v1.9.3