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/InterphoneSubService.java |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneSubService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneSubService.java
index 1bf629f..890dcd3 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneSubService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneSubService.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;
@@ -32,6 +33,10 @@
      * 鏂板瀛愯澶�
      */
     public boolean addSub(InterphoneSubParam interphoneSubParam) {
+        List<InterphoneSub> list = list(Wrappers.lambdaQuery(InterphoneSub.class).eq(InterphoneSub::getSubMac, interphoneSubParam.getSubMac()));
+        if (list.size() > 0) {
+            throw new BusinessException("璇ヨ澶囧凡瀛樺湪");
+        }
         InterphoneSub interphoneSub = new InterphoneSub();
         BeanUtils.copyProperties(interphoneSubParam, interphoneSub);
         boolean save = save(interphoneSub);
@@ -53,14 +58,17 @@
     /**
      * 淇敼瀛愯澶�
      */
+    @Transactional(rollbackFor = Exception.class)
     public boolean updateSub(Integer id, InterphoneSubParam interphoneSubParam) {
         InterphoneSub byId = getById(id);
         if (byId == null) {
             return false;
         }
-        boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getSubMac(), PoleBindingEnums.FOR_HELP);
-        if (!belong) {
-            throw new BusinessException("璇ヨ澶囦笉灞炰簬鎮�,涓嶈兘淇敼璁惧淇℃伅");
+        if (SecurityUtils.getClientId() != null) {
+            boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getSubMac(), PoleBindingEnums.FOR_HELP);
+            if (!belong) {
+                throw new BusinessException("璇ヨ澶囦笉灞炰簬鎮�,涓嶈兘淇敼璁惧淇℃伅");
+            }
         }
         InterphoneSub interphoneSub = new InterphoneSub();
         BeanUtils.copyProperties(interphoneSubParam, interphoneSub);
@@ -75,11 +83,15 @@
                 "}";
 
         StoreOperationRecordsUtils.storeOperationData(listCode, null, "缂栬緫涓�閿眰鍔╁瓙璁惧", content);
+        boolean b = updateById(interphoneSub);
         /**
          * 缂栬緫涓�閿眰鍔╁瓙璁惧 鏃ュ織璁板綍缁撴潫
          */
-
-        return updateById(interphoneSub);
+        List<InterphoneSub> list = list(Wrappers.lambdaQuery(InterphoneSub.class).eq(InterphoneSub::getSubMac, interphoneSubParam.getSubMac()));
+        if (list.size() > 1) {
+            throw new BusinessException("璇锋鏌ヨ澶噈ac鏄惁閲嶅");
+        }
+        return b;
     }
 
     /**
@@ -136,6 +148,13 @@
         } else {
             list = interphoneSubMapper.getInterphoneSubList(keyword, SecurityUtils.getUserId());
         }
+        list.forEach(interphoneSubBo -> {
+            InterphoneHostSubPole one = SpringContextHolder.getBean(InterphoneHostSubService.class).getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class)
+                    .eq(InterphoneHostSubPole::getSubId, interphoneSubBo.getSubId()));
+            if (one != null) {
+                interphoneSubBo.setHostId(one.getHostId());
+            }
+        });
         return list;
     }
 }

--
Gitblit v1.9.3