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 | 126 ++++++++++++++++++++++++++++++++++++++----
1 files changed, 114 insertions(+), 12 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 376c204..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,15 +7,15 @@
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.ResetClientPasswordPrarm;
+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;
import com.sandu.ximon.dao.domain.Role;
import com.sandu.ximon.dao.mapper.ClientMapper;
import lombok.AllArgsConstructor;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
@@ -36,13 +36,27 @@
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) {
if (one.getSuperiorId() == null) {
client.setSuperiorId(one.getId());
+ client.setClientSuperior(addClientPrarm.getClientSuperior());
} else {
throw new BusinessException("涓婄骇瀹㈡埛涓嶈兘涓轰簩绾х敤鎴�");
}
@@ -62,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);
@@ -90,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())) {
@@ -106,31 +139,53 @@
}
}
client.setId(id);
- client.setClientName(updateClientPrarm.getClientName());
+// client.setClientName(updateClientPrarm.getClientName());
client.setLinkMan(updateClientPrarm.getLinkMan());
client.setMobile(updateClientPrarm.getMobile());
- // update(client);
return updateById(client);
}
- public boolean resetPassword(ResetClientPasswordPrarm resetClientPasswordPrarm) {
- Client client = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, resetClientPasswordPrarm.getId()));
+ /**
+ * 淇敼褰撳墠鐧诲綍鐢ㄦ埛瀵嗙爜
+ *
+ * @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("璇ョ敤鎴蜂笉瀛樺湪锛�");
}
- PasswordEncoder pw = new BCryptPasswordEncoder();
//鍒ゆ柇鏃у瘑鐮佷笌鏁版嵁搴撴槸鍚︿竴鑷�
- if (pw.matches(resetClientPasswordPrarm.getOldPassword(), client.getPassword())) {
+ if (passwordEncoder.matches(param.getOldPass(), client.getPassword())) {
//鍔犲瘑鏂板瘑鐮�
- String encode = pw.encode(resetClientPasswordPrarm.getNewPassword());
+ 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);
}
public boolean deleteClient(Long id) {
@@ -177,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
@@ -191,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