From cfb17d6e329f3cc7afe3018d6cc8784ebafd5965 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期三, 14 九月 2022 16:08:57 +0800
Subject: [PATCH] changes

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java |   49 ++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 40 insertions(+), 9 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 9cf84ce..c65a4ff 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
@@ -643,10 +643,13 @@
         boolean result = saveOrUpdate(pole);
 
         if (result) {
-            Light light = new Light();
-            light.setDeviceCode(uniqueMac);
-            light.setLightCount(2);
-            SpringContextHolder.getBean(LightService.class).save(light);
+            Light light = SpringContextHolder.getBean(LightService.class).getOne(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, pole.getDeviceCode()).last("limit 1"));
+            if (light == null) {
+                light = new Light();
+                light.setDeviceCode(uniqueMac);
+                light.setLightCount(2);
+                SpringContextHolder.getBean(LightService.class).save(light);
+            }
         }
 
         /**
@@ -713,10 +716,36 @@
             if (pole == null) {
                 throw new BusinessException("鐏潌涓嶅瓨鍦�");
             }
-            pole.setUserId(clientId);
-            if (!clientService.findClientId(clientId)) {
-                pole.setClientId(clientService.getClientId(clientId));
+            pole.setClientId(clientId);
+            if (clientService.findClientId(clientId)) {
+                pole.setUserId(clientService.getClientId(clientId));
+
             }
+            r = updateById(pole);
+
+            if (!r) {
+                throw new BusinessException("鐏潌ID涓�" + poleId + "璁剧疆澶辫触,鑷姩鍋滄");
+            }
+
+        }
+        return r;
+    }
+
+    /**
+     * 鐢ㄦ埛瑙g粦鐏潌
+     *
+     * @param clientId
+     * @param poleIds
+     * @return
+     */
+    public boolean ClientUnBindingPole(long clientId, int[] poleIds) {
+        boolean r = false;
+        for (int poleId : poleIds) {
+            Pole pole = getById(poleId);
+            if (pole == null) {
+                throw new BusinessException("鐏潌涓嶅瓨鍦�");
+            }
+            pole.setClientId(-1L);
             r = updateById(pole);
 
             if (!r) {
@@ -899,8 +928,10 @@
             throw new BusinessException("璁惧涓嶅瓨鍦�");
         }
         //鍏抽棴鎺ㄩ��
-        SpringContextHolder.getBean(LightemitUtils.class).clear(xixun.getDeviceCode());
-
+        String clear = SpringContextHolder.getBean(LightemitUtils.class).clear(xixun.getDeviceCode());
+        if (clear.contains("is not") || clear.contains("does not")) {
+            throw new BusinessException("璁惧涓嶅湪绾挎垨璁惧鏈瓨鍦ㄤ簬鏈嶅姟鍣�");
+        }
     }
 
     /**

--
Gitblit v1.9.3