From d9a9d8a2dad1d1e57b184bf8f972a03d654d883a Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 22 七月 2022 15:07:01 +0800
Subject: [PATCH] 优化

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/ClientService.java |   61 +++++++++++++++++++++++++-----
 1 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/ClientService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/ClientService.java
index 9938ac1..3e9aecd 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/ClientService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/ClientService.java
@@ -15,16 +15,15 @@
 import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
 import com.sandu.ximon.dao.bo.MenuNode;
 import com.sandu.ximon.dao.domain.*;
-import com.sandu.ximon.dao.mapper.AdminMapper;
+import com.sandu.ximon.dao.enums.AdministratorEnums;
 import com.sandu.ximon.dao.mapper.ClientMapper;
 import lombok.AllArgsConstructor;
-import org.springframework.beans.BeanUtils;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.stream.Collectors;
 
 @Service
 @AllArgsConstructor
@@ -74,8 +73,8 @@
         if (role == null) {
             throw new BusinessException("瑙掕壊涓嶅瓨鍦�");
         }
-        if (!RoleLevelStatus.NORMAL.getCode().equals(role.getLevel())) {
-            throw new BusinessException("鏃犳硶娣诲姞瓒呯骇绠$悊鍛樻垨鐢ㄦ埛绠$悊鍛�");
+        if (RoleLevelStatus.SUPER.getCode().equals(role.getLevel())) {
+            throw new BusinessException("鏃犳硶娣诲姞瓒呯骇绠$悊鍛�");
         }
 
 
@@ -97,12 +96,12 @@
         }
 
         /**
-         * 娣诲姞绠$悊鍛樻棩蹇楄褰曞紑濮�
+         * 娣诲姞鏅�氱敤鎴� 鏃ュ織璁板綍寮�濮�
          */
         String content = "鏂版敞鍐岀敤鎴凤細" + addClientPrarm.getClientName();
         StoreOperationRecordsUtils.storeOperationData(null, null, "娣诲姞鏅�氱敤鎴�", content);
         /**
-         * 娣诲姞绠$悊鍛樻棩蹇楄褰曠粨鏉�
+         * 娣诲姞鏅�氱敤鎴� 鏃ュ織璁板綍缁撴潫
          */
 
         return flag;
@@ -157,6 +156,14 @@
         client.setLinkMan(updateClientPrarm.getLinkMan());
         client.setMobile(updateClientPrarm.getMobile());
 
+        /**
+         * 缂栬緫鏅�氱敤鎴� 鏃ュ織璁板綍寮�濮�
+         */
+        String content = "缂栬緫鏅�氱敤鎴凤細" + client.getClientName() + "鐢ㄦ埛id锛�" + id;
+        StoreOperationRecordsUtils.storeOperationData(null, null, "缂栬緫鏅�氱敤鎴�", content);
+        /**
+         * 缂栬緫鏅�氱敤鎴� 鏃ュ織璁板綍缁撴潫
+         */
         return updateById(client);
     }
 
@@ -202,11 +209,21 @@
         return updateById(client);
     }
 
+    @Transactional(rollbackFor = Exception.class)
     public boolean deleteClient(Long id) {
+        boolean flag = false;
         //鍒ゆ柇鍒犻櫎鐢ㄦ埛鏄惁瀛樺湪
-        Client one = getById(id);
-        if (one == null) {
+        Client client = getById(id);
+        if (client == null) {
             throw new BusinessException("璇ュ鎴蜂笉瀛樺湪");
+        }
+
+        //鍙湁瓒呯鑳藉垹闄�  鎴�  涓婄骇瀹㈡埛鍒犻櫎鑷繁鐨勪笅绾х敤鎴�
+        if (!AdministratorEnums.ADMIN.getCode().equals(SecurityUtils.getUserDetails().getAdministratorType())) {
+            Client temp = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getSuperiorId, SecurityUtils.getUserId()).eq(Client::getId, id));
+            if (temp == null) {
+                throw new BusinessException("鍒犻櫎鐨勭敤鎴蜂笉瀛樺湪鎴栬鐢ㄦ埛涓嶆槸浣犵殑涓嬬骇鐢ㄦ埛");
+            }
         }
 
         //鍒ゆ柇鍒犻櫎鐨勭敤鎴锋湁鏃犱笅绾х敤鎴�
@@ -216,7 +233,31 @@
             throw new BusinessException("鍒犻櫎鐨勭敤鎴蜂笅鏈変笅绾х敤鎴凤紝涓嶅厑璁稿垹闄�");
         }
 
-        return removeById(id);
+        //绠$悊鍛樿鑹插叧绯昏〃
+        ClientRoleRelationService clientRoleRelationService = SpringContextHolder.getBean(ClientRoleRelationService.class);
+        //鏈夌敤鎴峰繀瀹氭湁鐢ㄦ埛涓庤鑹茬殑鍏崇郴鏁版嵁
+        ClientRoleRelation one = clientRoleRelationService.getOne(Wrappers.lambdaQuery(ClientRoleRelation.class).eq(ClientRoleRelation::getClientId, client.getId()));
+
+        //鍒犵敤鎴�
+        if (removeById(id)) {
+            //鍒犺鑹插叧绯昏〃淇℃伅
+            flag = clientRoleRelationService.removeById(one);
+            //鍒犻櫎澶辫触鍥炴粴鏁版嵁
+            if (!flag) {
+                throw new BusinessException("鍒犻櫎鐢ㄦ埛澶辫触锛�");
+            }
+        }
+
+        /**
+         * 鍒犻櫎鏅�氱敤鎴� 鏃ュ織璁板綍寮�濮�
+         */
+        String content = "鍒犻櫎鏅�氱敤鎴凤細" + client.getClientName() + "鐢ㄦ埛id锛�" + id;
+        StoreOperationRecordsUtils.storeOperationData(null, null, "鍒犻櫎鏅�氱敤鎴�", content);
+        /**
+         * 鍒犻櫎鏅�氱敤鎴� 鏃ュ織璁板綍缁撴潫
+         */
+
+        return flag;
     }
 
     public List<Client> clientList(Long userId, BaseConditionVO baseConditionVO) {

--
Gitblit v1.9.3