From 0d2e4e6b8954d77dd34664f861135ae41f7eb828 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 13 五月 2022 10:31:34 +0800
Subject: [PATCH] 单灯数据直接下载

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/ClientService.java |  139 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 133 insertions(+), 6 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 0fef97e..06b6be0 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
@@ -7,7 +7,9 @@
 import com.sandu.common.object.BaseConditionVO;
 import com.sandu.common.service.impl.BaseServiceImpl;
 import com.sandu.ximon.admin.param.AddClientPrarm;
+import com.sandu.ximon.admin.param.PwdParam;
 import com.sandu.ximon.admin.param.UpdateClientPrarm;
+import com.sandu.ximon.admin.param.UserPwsParm;
 import com.sandu.ximon.admin.security.SecurityUtils;
 import com.sandu.ximon.dao.domain.Client;
 import com.sandu.ximon.dao.domain.ClientRoleRelation;
@@ -34,12 +36,30 @@
         if (getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, addClientPrarm.getClientName().trim())) != null) {
             throw new BusinessException("璇ョ敤鎴峰悕宸插瓨鍦紒");
         }
+        Long userId = SecurityUtils.getUserId();
+        boolean clientId = findClientId();
+        //鍒ゆ柇鏄惁涓轰簩绾у鎴�  濡傛灉鏄簩绾у鎴峰垯涓嶈兘缁х画娣诲姞   涓�绾у鎴蜂负FALSE
+        if (SecurityUtils.getClientId() != null && clientId) {
+            throw new BusinessException("鏉冮檺涓嶈冻,浜岀骇瀹㈡埛涓嶈兘鏂板鐢ㄦ埛锛�");
+        }
+
 
         Client client = new Client();
-        if (addClientPrarm.getClientSuperior() != null && !"".equals(addClientPrarm.getClientSuperior())) {
+
+        if (SecurityUtils.getClientId() != null && !clientId) {
+            //涓�绾у鎴锋柊澧炵敤鎴锋椂 榛樿涓鸿嚜宸卞悕涓嬬殑浜岀骇瀹㈡埛
+            client.setSuperiorId(SecurityUtils.getUserId());
+            client.setClientSuperior(addClientPrarm.getClientSuperior());
+        } else if (addClientPrarm.getClientSuperior() != null && !"".equals(addClientPrarm.getClientSuperior())) {
+            //瓒呯
             Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, addClientPrarm.getClientSuperior()));
             if (one != null) {
-                client.setSuperiorId(one.getId());
+                if (one.getSuperiorId() == null) {
+                    client.setSuperiorId(one.getId());
+                    client.setClientSuperior(addClientPrarm.getClientSuperior());
+                } else {
+                    throw new BusinessException("涓婄骇瀹㈡埛涓嶈兘涓轰簩绾х敤鎴�");
+                }
             } else {
                 throw new BusinessException("涓婄骇瀹㈡埛涓嶅瓨鍦�");
             }
@@ -56,8 +76,11 @@
 
         client.setClientName(addClientPrarm.getClientName());
         client.setLinkMan(addClientPrarm.getLinkMan());
+//        client.setClientSuperior(addClientPrarm.getClientSuperior());
         client.setMobile(addClientPrarm.getMobile());
-        client.setClientSuperior(addClientPrarm.getClientSuperior());
+        if (SecurityUtils.getClientId() != null && clientId) {
+            client.setClientSuperior(SecurityUtils.getUsername());
+        }
         client.setPassword(passwordEncoder.encode(addClientPrarm.getPassword()));
         boolean flag = save(client);
 
@@ -84,9 +107,25 @@
         if (client1 != null && !client1.getId().equals(one.getId())) {
             throw new BusinessException("璇ョ敤鎴峰悕宸插瓨鍦紒");
         }
+
         //鍒ゆ柇涓婄骇鐢ㄦ埛鏄惁瀛樺湪
+        boolean clientId = findClientId();
+        Long userId = SecurityUtils.getUserId();
+        //鍒ゆ柇鏇存敼鐨勭敤鎴锋槸鍚︽槸灞炰簬鑷繁鍚嶄笅鐨勪簩绾у鎴�
+        if (SecurityUtils.getClientId() != null && !clientId) {
+            if (SecurityUtils.getUserId() != one.getSuperiorId()) {
+                throw new BusinessException("鏉冮檺涓嶈冻锛屼笉鑳芥洿鏀瑰叾浠栧鎴风殑鎵�灞炲鎴蜂俊鎭紒");
+            }
+        }
+
         Client client = new Client();
-        if (updateClientPrarm.getClientSuperior() != null && updateClientPrarm.getClientSuperior().trim().length() != 0) {
+        client.setClientName(updateClientPrarm.getClientName());
+        if (SecurityUtils.getClientId() != null && clientId) {
+            //涓�绾у鎴锋柊澧炵敤鎴锋椂 榛樿涓鸿嚜宸卞悕涓嬬殑浜岀骇瀹㈡埛
+            client.setSuperiorId(SecurityUtils.getUserId());
+            client.setClientSuperior(updateClientPrarm.getClientSuperior());
+        } else if (updateClientPrarm.getClientSuperior() != null && updateClientPrarm.getClientSuperior().trim().length() != 0) {
+            //瓒呯
             Client superior = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, updateClientPrarm.getClientSuperior()));
             if (superior != null) {
                 if (superior.getId().equals(one.getId())) {
@@ -100,11 +139,52 @@
             }
         }
         client.setId(id);
-        client.setClientName(updateClientPrarm.getClientName());
+//        client.setClientName(updateClientPrarm.getClientName());
         client.setLinkMan(updateClientPrarm.getLinkMan());
         client.setMobile(updateClientPrarm.getMobile());
 
-        // update(client);
+        return updateById(client);
+    }
+
+    /**
+     * 淇敼褰撳墠鐧诲綍鐢ㄦ埛瀵嗙爜
+     *
+     * @param param
+     * @return
+     */
+    public boolean resetPassword(PwdParam param) {
+
+        Client client = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, SecurityUtils.getUserDetails().getUserId()));
+
+        if (client == null) {
+            throw new BusinessException("璇ョ敤鎴蜂笉瀛樺湪锛�");
+        }
+
+        //鍒ゆ柇鏃у瘑鐮佷笌鏁版嵁搴撴槸鍚︿竴鑷�
+        if (passwordEncoder.matches(param.getOldPass(), client.getPassword())) {
+            //鍔犲瘑鏂板瘑鐮�
+            String encode = passwordEncoder.encode(param.getNewPass());
+            client.setPassword(encode);
+            return updateById(client);
+        } else {
+            throw new BusinessException("鏃у瘑鐮佷笉姝g‘锛岃閲嶆柊纭瀵嗙爜锛�");
+        }
+    }
+
+    /**
+     * 淇敼绠$悊鍛樼殑瀵嗙爜
+     *
+     * @param param
+     * @return
+     */
+    public boolean updateAdminPassword(UserPwsParm param) {
+        Client client = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, param.getUserid()));
+        if (client == null) {
+            throw new BusinessException("鐢ㄦ埛涓嶅瓨鍦�");
+        }
+
+        //鍔犲瘑鏂板瘑鐮�
+        client.setPassword(passwordEncoder.encode(param.getNewPass()));
         return updateById(client);
     }
 
@@ -152,6 +232,23 @@
     }
 
     /**
+     * \
+     * 鍏朵粬绫荤敤鏉ユ煡鎵惧鎴穒d浣跨敤  濡傛灉娌℃湁涓婄骇瀹㈡埛 杩欒繑鍥炵敤鎴稩D
+     *
+     * @param
+     * @return
+     */
+    public Long getClientId(Long userId) {
+        Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, userId));
+        if (one != null && one.getSuperiorId() != null) {
+            return one.getSuperiorId();
+        } else {
+            return userId;
+        }
+
+    }
+
+    /**
      * 涓�绾у鎴疯繑鍥瀎alse  浜岀骇瀹㈡埛杩斿洖true
      *
      * @return
@@ -166,4 +263,34 @@
         }
 
     }
+
+    /**
+     * 涓�绾у鎴疯繑鍥瀎alse  浜岀骇瀹㈡埛杩斿洖true
+     *
+     * @return
+     */
+    public boolean findClientId(Long userId) {
+        Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, userId));
+        if (one != null && one.getSuperiorId() != null) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 淇敼鏅�氱敤鎴峰ご鍍�
+     *
+     * @param userId
+     * @param IconUrl
+     * @return
+     */
+    public boolean updateIcon(Long userId, String IconUrl) {
+        Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, userId));
+        if (one == null) {
+            throw new BusinessException("鐢ㄦ埛涓嶅瓨鍦�");
+        }
+        one.setIcon(IconUrl);
+        return updateById(one);
+    }
 }

--
Gitblit v1.9.3