From 52eb3f0befcb397d2fdd645c8d7471d6ee477f87 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期一, 09 五月 2022 16:36:38 +0800
Subject: [PATCH] 权限

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 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 4716a7e..d43f65a 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
@@ -1,13 +1,19 @@
 package com.sandu.ximon.admin.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.sandu.common.execption.BusinessException;
 import com.sandu.common.service.impl.BaseServiceImpl;
+import com.sandu.common.util.SpringContextHolder;
 import com.sandu.ximon.admin.param.PoleBindingParam;
+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;
 
 /**
  * @author chenjiantian
@@ -30,6 +36,16 @@
         Integer deviceType = param.getDeviceType();
 //        if (PoleBindingEnums.LIGHT.getCode().equals(deviceType)) {
 //        }
+        LambdaQueryWrapper<PoleBinding> eq = Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getPoleId, poleId);
+        List<PoleBinding> list = list(eq);
+        if (list.size() != 0) {
+            for (PoleBinding poleBinding : list) {
+                //鍏呯數妗╃殑缁戝畾鏄綉缁滆姹傛槸甯﹁繃鏉ョ殑鐏潌淇℃伅锛岃鍏佽鐩存帴淇敼
+                if (poleBinding.getDeviceType().equals(deviceType) && deviceType != 2) {
+                    throw new BusinessException("璇ョ伅鏉嗗凡缁戝畾杩囩浉鍚岀被鍨嬭澶�");
+                }
+            }
+        }
 
         PoleBinding one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, param.getDeviceCode()));
         if (one == null) {
@@ -40,7 +56,22 @@
             poleBinding.setDeviceCode(param.getDeviceCode());
             return save(poleBinding);
         } else {
-            throw new BusinessException("璇ヨ澶囧凡缁戝畾杩�");
+            //淇敼鍗曠伅鐨勭粦瀹氬叧绯荤殑鏃跺�欒棰濆澶勭悊鐨勪簨鍔�
+            // 鍒犻櫎鐏潌鐨刣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);
+            one.setDeviceType(param.getDeviceType());
+            one.setDeviceName(param.getDeviceName());
+            one.setDeviceCode(param.getDeviceCode());
+            return updateById(one);
         }
     }
 
@@ -86,7 +117,7 @@
         }
     }
 
-    public PoleBinding getPoleIdByMac(String deviceCode){
-       return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
+    public PoleBinding getPoleIdByMac(String deviceCode) {
+        return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
     }
 }

--
Gitblit v1.9.3