From e8ff379d1a31f09e4d024e96eb788e5b65e0931d Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期二, 01 三月 2022 16:58:13 +0800
Subject: [PATCH] fix

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java |   76 +++++++++++++++++++++++++++++++------
 1 files changed, 63 insertions(+), 13 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 bc8b7a7..b2fe1a5 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
@@ -35,6 +35,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -110,10 +111,10 @@
      *
      * @return
      */
-    public List<Pole> queryStatesAndList(Integer pageNo,Integer pageSize) {
+    public List<Pole> queryStatesAndList(Integer pageNo, Integer pageSize) {
         // List<LampPost> list = list(Wrappers.lambdaQuery(LampPost.class).eq(LampPost::getClientId, SecurityUtils.getUserId()));
         //List<Pole> list = list(Wrappers.lambdaQuery(Pole.class));
-        PageHelper.startPage(pageNo,pageSize);
+        PageHelper.startPage(pageNo, pageSize);
         List<Pole> list = new ArrayList<>();
         if (SecurityUtils.getClientId() == null) {
             list = list(Wrappers.lambdaQuery(Pole.class));
@@ -154,6 +155,15 @@
             throw new BusinessException("鏈壘鍒拌鐏潌");
         }
         return poleBindingService.bindPole(poleId, param);
+    }
+
+    /**
+     * 鐏潌瑙g粦缁戝畾璁惧
+     *
+     * @return 鏄惁鎴愬姛
+     */
+    public boolean unBindPole(String deviceCode) {
+        return poleBindingService.unBindPole(deviceCode);
     }
 
 
@@ -205,16 +215,15 @@
     /**
      * 缁欑伅鏉嗘敞鍐屼笁鍏冪爜
      */
-
-
-    public boolean setMac(Long poleId) {
-        Pole pole = getById(poleId);
-        if (pole == null) {
+    public boolean setMac(String baseMac) {
+        // public boolean setMac() {
+        //Pole pole = getById(poleId);
+       /* if (pole == null) {
             throw new BusinessException("鏈壘鍒拌鐏潌");
-        }
+        }*/
 
         boolean setMac = false;
-        String baseMac = "baseDevice";
+        //String baseMac = "baseDevice";
         A1Frame a1Frame = new A1Frame(A1OrderEnum.REQUEST_READ_DEVICE_UNIQUE_MAC.getCode(), new EmptyRequestInnerFrame());
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance()
                 .sendRRPC(baseMac, a1Frame);
@@ -225,6 +234,10 @@
         log.info(commonFrame.toString());
         String uniqueMac = a1DeviceMacRespInnerFrame.getMac();
         uniqueMac = uniqueMac.toLowerCase();
+
+        if (uniqueMac.isEmpty()) {
+            throw new BusinessException("璇诲彇璁惧鍞竴ID澶辫触!");
+        }
         log.info("鍞竴鐮亄}", uniqueMac);
 
         // 2  浠庨樋閲屾敞鍐�
@@ -277,17 +290,28 @@
                         FrameBuilder.builderA2().innerFrame(new EmptyRequestInnerFrame())
                                 .orderType(A2OrderEnum.REQUEST_MAIN_BOARD_RESET.getCode()).build());
         if ("00".equals(rebootFrame.getPayload())) {
-            pole.setDeviceCode(uniqueMac);
+            //  pole.setDeviceCode(uniqueMac);
 
-            setMac = updateById(pole);
+            // setMac = updateById(pole);
 
             System.out.println("閲嶅惎鎴愬姛");
         }
+
+        Pole pole = new Pole();
+        String strh = uniqueMac.substring(uniqueMac.length() - 2, uniqueMac.length());
+        pole.setDeviceCode(strh);
+        pole.setPoleName(strh);
+        String strm = uniqueMac.substring(0, uniqueMac.length() - 2);
+        int i = Integer.parseInt(strm);
+        pole.setPoleCode(generatePoleCode());
+        pole.setDeviceType(i);
+        setMac = save(pole);
+
         return setMac;
     }
 
     public List<String> listDeviceCodeByIds(List<Long> poleIdList) {
-        if(CollectionUtil.isEmpty(poleIdList)){
+        if (CollectionUtil.isEmpty(poleIdList)) {
             return null;
         }
         List<Pole> list = list(Wrappers.lambdaQuery(Pole.class).in(Pole::getId, poleIdList).select(Pole::getDeviceCode));
@@ -297,6 +321,7 @@
 
     /**
      * 鎵归噺鑾峰彇闃块噷浜戣澶囩殑鐘舵��
+     *
      * @param deviceCodeList 闃块噷浜戣澶囩爜
      * @return 璁惧鐘舵�佸垪琛�
      */
@@ -306,7 +331,7 @@
         List<DeviceStatus> statusList = new ArrayList<>();
         for (List<String> list : split) {
             List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses = MainBoardInvokeSyncService.getInstance().batchGetDeviceState(list);
-            if(CollectionUtil.isNotEmpty(deviceStatuses)){
+            if (CollectionUtil.isNotEmpty(deviceStatuses)) {
                 for (BatchGetDeviceStateResponse.DeviceStatus d : deviceStatuses) {
                     DeviceStatus deviceStatus = new DeviceStatus();
                     deviceStatus.setDeviceCode(d.getDeviceName());
@@ -317,4 +342,29 @@
         }
         return statusList;
     }
+
+    /**
+     * 鐢ㄦ埛缁戝畾鐏潌
+     *
+     * @param clientId 鐢ㄦ埛ID
+     * @param poleIds  鐏潌ID
+     * @return
+     */
+    public boolean ClientBindingPole(long clientId, int[] poleIds) {
+        boolean r = false;
+        for (int poleId : poleIds) {
+            Pole pole = getById(poleId);
+            if (pole == null) {
+                throw new BusinessException("鐏潌涓嶅瓨鍦�");
+            }
+            pole.setClientId(clientId);
+            r = updateById(pole);
+
+            if (!r) {
+                throw new BusinessException("鐏潌ID涓�" + poleId + "璁剧疆澶辫触,鑷姩鍋滄");
+            }
+
+        }
+        return r;
+    }
 }

--
Gitblit v1.9.3