From 0d2e4e6b8954d77dd34664f861135ae41f7eb828 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 13 五月 2022 10:31:34 +0800
Subject: [PATCH] 单灯数据直接下载

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java |   48 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java
index 1b9f5df..a72f3e7 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java
@@ -6,13 +6,13 @@
 import com.sandu.common.service.impl.BaseServiceImpl;
 import com.sandu.common.util.SpringContextHolder;
 import com.sandu.ximon.admin.param.PoleBindingParam;
+import com.sandu.ximon.admin.security.SecurityUtils;
 import com.sandu.ximon.dao.domain.Pole;
 import com.sandu.ximon.dao.domain.PoleBinding;
 import com.sandu.ximon.dao.mapper.PoleBindingMapper;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
-import javax.swing.*;
 import java.util.List;
 
 /**
@@ -56,12 +56,15 @@
             poleBinding.setDeviceCode(param.getDeviceCode());
             return save(poleBinding);
         } else {
-            //鍒犻櫎鐏潌鐨刣evicescode
-            PoleService poleService = SpringContextHolder.getBean(PoleService.class);
-            Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, one.getPoleId()));
-            if (pole != null) {
-                pole.setDeviceCode(null);
-                poleService.updateById(pole);
+            //淇敼鍗曠伅鐨勭粦瀹氬叧绯荤殑鏃跺�欒棰濆澶勭悊鐨勪簨鍔�
+            // 鍒犻櫎鐏潌鐨刣evicescode
+            if (param.getDeviceType() == 0) {
+                PoleService poleService = SpringContextHolder.getBean(PoleService.class);
+                Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, one.getPoleId()));
+                if (pole != null) {
+                    pole.setDeviceCode(null);
+                    poleService.updateById(pole);
+                }
             }
 
             one.setPoleId(poleId);
@@ -87,16 +90,6 @@
             one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
         } else {
             one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode).eq(PoleBinding::getPoleId, poleId));
-
-            //鍒犻櫎鐏潌鐨刣evicescode
-            PoleService poleService = SpringContextHolder.getBean(PoleService.class);
-            Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, poleId));
-            if (pole != null) {
-                pole.setDeviceCode(null);
-                poleService.updateById(pole);
-            }
-
-
         }
         if (one != null) {
             return removeById(one.getId());
@@ -127,4 +120,25 @@
     public PoleBinding getPoleIdByMac(String deviceCode) {
         return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
     }
+
+
+    /**
+     * 鍒ゆ柇璁惧褰掑睘
+     *
+     * @param deviceCode 璁惧缂栧彿
+     * @param type       璁惧绫诲瀷
+     * @return 宸茬粦瀹氳繑鍥瀟rue锛屾湭缁戝畾杩斿洖false
+     */
+    public boolean isBelong(String deviceCode, String type) {
+        if (type.isEmpty() || deviceCode.isEmpty()) {
+            throw new BusinessException("璁惧缂栧彿鎴栫被鍨嬩笉鑳戒负绌�");
+        }
+        Long userId = SecurityUtils.getClientId();
+        Pole binding = baseMapper.getPoleByBinding(type, deviceCode, userId);
+        if (binding != null) {
+            return true;
+        } else {
+            return false;
+        }
+    }
 }

--
Gitblit v1.9.3