From 4e76b9737e036c18e8a9e840dc443615ffcec348 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期四, 20 十月 2022 12:20:18 +0800
Subject: [PATCH] 大气农耕

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java |   32 ++++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java
index 911d98d..b0fc52b 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java
@@ -17,6 +17,7 @@
 import lombok.AllArgsConstructor;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -34,6 +35,10 @@
      * 娣诲姞涓绘満
      */
     public boolean addHost(InterphoneHostParam interphoneHostParam) {
+        List<InterphoneHost> list = list(Wrappers.lambdaQuery(InterphoneHost.class).eq(InterphoneHost::getHostMac, interphoneHostParam.getHostMac()));
+        if (list.size() > 0) {
+            throw new BusinessException("璇ヨ澶囧凡瀛樺湪");
+        }
         InterphoneHost interphoneHost = new InterphoneHost();
         BeanUtils.copyProperties(interphoneHostParam, interphoneHost);
         boolean save = save(interphoneHost);
@@ -56,18 +61,19 @@
     /**
      * 淇敼涓绘満
      */
+    @Transactional(rollbackFor = Exception.class)
     public boolean updateHost(Integer id, InterphoneHostParam interphoneHostParam) {
         InterphoneHost byId = getById(id);
         if (byId == null) {
             return false;
         }
 
-       if(SecurityUtils.getClientId()!=null){
-           boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getHostMac(), PoleBindingEnums.FOR_HELP);
-           if (!belong) {
-               throw new BusinessException("璇ヨ澶囦笉灞炰簬鎮�,涓嶈兘淇敼璁惧淇℃伅");
-           }
-       }
+        if (SecurityUtils.getClientId() != null) {
+            boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getHostMac(), PoleBindingEnums.FOR_HELP);
+            if (!belong) {
+                throw new BusinessException("璇ヨ澶囦笉灞炰簬鎮�,涓嶈兘淇敼璁惧淇℃伅");
+            }
+        }
         InterphoneHost interphoneHost = new InterphoneHost();
         interphoneHost.setHostId(id);
         BeanUtils.copyProperties(interphoneHostParam, interphoneHost);
@@ -84,7 +90,12 @@
         /**
          * 缂栬緫涓�閿眰鍔╀富鏈� 鏃ュ織璁板綍缁撴潫
          */
-        return updateById(interphoneHost);
+        boolean b = updateById(interphoneHost);
+        List<InterphoneHost> list = list(Wrappers.lambdaQuery(InterphoneHost.class).eq(InterphoneHost::getHostMac, interphoneHostParam.getHostMac()));
+        if (list.size() > 1) {
+            throw new BusinessException("璇锋鏌ヨ澶噈ac鏄惁閲嶅");
+        }
+        return b;
     }
 
     /**
@@ -96,12 +107,13 @@
     public boolean deleteHost(Integer id) {
         InterphoneHost byId = getById(id);
 
+        if (byId == null) {
+            throw new BusinessException("涓绘満涓嶅瓨鍦紒");
+        }
+
         InterphoneHostSubPole one = interphoneHostSubService.getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getHostId, id));
         if (one != null) {
             throw new BusinessException("璇ヤ富鏈哄瓨鍦ㄧ粦瀹氬叧绯伙紝涓嶈兘鍒犻櫎");
-        }
-        if (byId == null) {
-            return false;
         }
 
         /**

--
Gitblit v1.9.3