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/InterphoneHostService.java |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 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 9389921..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;
     }
 
     /**

--
Gitblit v1.9.3