From dda268997ca8f8a364f7c19b45d7a43a50a98efe Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期二, 25 十月 2022 18:00:11 +0800
Subject: [PATCH] changes

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java |   64 +++++++++++++++++++++++++++-----
 1 files changed, 54 insertions(+), 10 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 7e7e050..f46f4a7 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
@@ -34,8 +34,6 @@
      */
     public boolean bindPole(Long poleId, PoleBindingParam param) {
         Integer deviceType = param.getDeviceType();
-//        if (PoleBindingEnums.LIGHT.getCode().equals(deviceType)) {
-//        }
 
         int size = 0;
         switch (deviceType.toString()) {
@@ -49,7 +47,24 @@
                 size = SpringContextHolder.getBean(C3ChargingService.class).list(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, param.getDeviceCode())).size();
                 break;
             case PoleBindingEnums.ATMOSPHERIC:
-                size = SpringContextHolder.getBean(AirEquipmentService.class).list(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, param.getDeviceCode())).size();
+                Pole byId = SpringContextHolder.getBean(PoleService.class).getById(poleId);
+                if (byId == null) {
+                    throw new BusinessException("鏈壘鍒扮伅鏉�");
+                }
+                if (byId.getDeviceCode() != null || !byId.getDeviceCode().isEmpty()) {
+                    if (!param.getDeviceCode().equals(byId.getDeviceCode())) {
+                        throw new BusinessException("鐏潌mac鍜屽ぇ姘攎ac涓嶄竴鑷�, 鏃犳硶缁戝畾");
+                    }
+                } else {
+                    throw new BusinessException("鐏潌mac涓虹┖,鏃犳硶缁戝畾澶ф皵璁惧");
+                }
+
+                int size1 = SpringContextHolder.getBean(AirEquipmentService.class).list(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, param.getDeviceCode())).size();
+                int size2 = SpringContextHolder.getBean(AirEquipmentNongGengService.class).list(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, param.getDeviceCode())).size();
+                //涓�閿眰鍔╀袱绫荤‖浠�
+                if (size1 > 0 || size2 > 0) {
+                    size = 1;
+                }
                 break;
             case PoleBindingEnums.WATER:
                 size = SpringContextHolder.getBean(WaterQualityEquipmentService.class).list(Wrappers.lambdaQuery(WaterQualityEquipment.class).eq(WaterQualityEquipment::getWaterQualityEquipmentCode, param.getDeviceCode())).size();
@@ -67,10 +82,10 @@
                 size = SpringContextHolder.getBean(LightPoleHeelingEquipmentService.class).list(Wrappers.lambdaQuery(LightPoleHeelingEquipment.class).eq(LightPoleHeelingEquipment::getMac, param.getDeviceCode())).size();
                 break;
             case PoleBindingEnums.FOR_HELP:
-                int size1 = SpringContextHolder.getBean(InterphoneHostService.class).list(Wrappers.lambdaQuery(InterphoneHost.class).eq(InterphoneHost::getHostMac, param.getDeviceCode())).size();
-                int size2 = SpringContextHolder.getBean(InterphoneSubService.class).list(Wrappers.lambdaQuery(InterphoneSub.class).eq(InterphoneSub::getSubMac, param.getDeviceCode())).size();
+                int size3 = SpringContextHolder.getBean(InterphoneHostService.class).list(Wrappers.lambdaQuery(InterphoneHost.class).eq(InterphoneHost::getHostMac, param.getDeviceCode())).size();
+                int size4 = SpringContextHolder.getBean(InterphoneSubService.class).list(Wrappers.lambdaQuery(InterphoneSub.class).eq(InterphoneSub::getSubMac, param.getDeviceCode())).size();
                 //涓�閿眰鍔╀袱绫荤‖浠�
-                if (size1 > 0 || size2 > 0) {
+                if (size3 > 0 || size4 > 0) {
                     size = 1;
                 }
                 break;
@@ -101,12 +116,24 @@
 
         PoleBinding one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, param.getDeviceCode()));
         if (one == null) {
+            //鍏呯數妗╀繚瀛樼粦瀹氬叧绯婚渶瑕佸厛鍒ゆ柇鏄笉鏄纭殑鐏潌
+            if (deviceType == 2) {
+                C3mCharging mCharging = SpringContextHolder.getBean(C3ChargingService.class).
+                        getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, param.getDeviceCode()));
+                Pole poleInfo = SpringContextHolder.getBean(PoleService.class).getById(poleId);
+
+                if (!mCharging.getPoleDevicesCode().equals(poleInfo.getDeviceCode())) {
+                    throw new BusinessException("缁戝畾鍑洪敊锛佽鍏呯數妗╃‖浠剁粦瀹氱殑鐏潌mac涓猴細" + mCharging.getPoleDevicesCode());
+                }
+
+            }
             PoleBinding poleBinding = new PoleBinding();
             poleBinding.setPoleId(poleId);
             poleBinding.setDeviceType(deviceType);
             poleBinding.setDeviceName(param.getDeviceName());
             poleBinding.setDeviceCode(param.getDeviceCode());
             return save(poleBinding);
+
         } else {
             //淇敼鍗曠伅鐨勭粦瀹氬叧绯荤殑鏃跺�欒棰濆澶勭悊鐨勪簨鍔�
             // 鍒犻櫎鐏潌鐨刣evicescode
@@ -119,11 +146,24 @@
                 }
             }
 
+            //鍏呯數妗╀繚瀛樼粦瀹氬叧绯婚渶瑕佸厛鍒ゆ柇鏄笉鏄纭殑鐏潌
+            if (deviceType == 2) {
+                C3mCharging mCharging = SpringContextHolder.getBean(C3ChargingService.class).
+                        getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, param.getDeviceCode()));
+                Pole poleInfo = SpringContextHolder.getBean(PoleService.class).getById(poleId);
+
+                if (!mCharging.getPoleDevicesCode().equals(poleInfo.getDeviceCode())) {
+                    throw new BusinessException("缁戝畾鍑洪敊锛佽鍏呯數妗╃‖浠剁粦瀹氱殑鐏潌mac涓猴細" + mCharging.getPoleDevicesCode());
+                }
+
+            }
+
             one.setPoleId(poleId);
             one.setDeviceType(param.getDeviceType());
             one.setDeviceName(param.getDeviceName());
             one.setDeviceCode(param.getDeviceCode());
             return updateById(one);
+
         }
     }
 
@@ -159,6 +199,13 @@
         if (deviceCode == null) {
             throw new BusinessException("璁惧缂栧彿涓嶈兘涓虹┖");
         }
+        if (SecurityUtils.getClientId() != null) {
+            //鏌ョ伅鏉嗗綊灞炲叧绯�
+            boolean belong = isBelong(deviceCode, null);
+            if (!belong) {
+                throw new BusinessException("璇ョ伅鏉嗕笉灞炰簬鎮紝鏃犳硶瑙g粦锛�");
+            }
+        }
         //鐩存帴鍒犻櫎璁惧涓嶉渶瑕佺伅鏉咺D
         PoleBinding one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
 
@@ -179,12 +226,9 @@
      *
      * @param deviceCode 璁惧缂栧彿
      * @param type       璁惧绫诲瀷
-     * @return 宸茬粦瀹氳繑鍥瀟rue锛屾湭缁戝畾杩斿洖false
+     * @return 灞炰簬璇ョ敤鎴疯繑鍥瀟rue锛屼笉鏄繑鍥瀎alse
      */
     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) {

--
Gitblit v1.9.3