From dc590d026e1130a98c70181fb65f8ed09414e787 Mon Sep 17 00:00:00 2001
From: yuxc <653031404@qq.com>
Date: 星期五, 14 七月 2023 17:48:11 +0800
Subject: [PATCH] 1、主要解决获取当前用户信息等问题,使用AuthUtil来进行获取,对生成token等信息进行了修改增加。

---
 Source/UBCS/ubcs-service/ubcs-user/src/main/java/com/vci/ubcs/system/user/service/impl/UserServiceImpl.java |   71 +++++++++++++++++++++++++++++++----
 1 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-user/src/main/java/com/vci/ubcs/system/user/service/impl/UserServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-user/src/main/java/com/vci/ubcs/system/user/service/impl/UserServiceImpl.java
index 9072185..4eceb7b 100644
--- a/Source/UBCS/ubcs-service/ubcs-user/src/main/java/com/vci/ubcs/system/user/service/impl/UserServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-user/src/main/java/com/vci/ubcs/system/user/service/impl/UserServiceImpl.java
@@ -19,6 +19,7 @@
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.vci.ubcs.system.cache.DictCache;
@@ -44,6 +45,7 @@
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
+import org.springblade.core.secure.BladeUser;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tenant.BladeTenantProperties;
 import org.springblade.core.tool.api.R;
@@ -56,6 +58,8 @@
 import org.springframework.util.DigestUtils;
 
 import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import static com.vci.ubcs.common.constant.CommonConstant.DEFAULT_PARAM_PASSWORD;
 
@@ -77,13 +81,16 @@
 	//鎷垮埌閰嶇疆鐨勮秴绠d
 	@Value("${user-info.id}")
 	private String adminUserId;
-
+	@Value("${user-info.tenant-id}")
+	private String tenantId;
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public boolean submit(User user) {
 		if (StringUtil.isBlank(user.getTenantId())) {
-			user.setTenantId(BladeConstant.ADMIN_TENANT_ID);
+			// user.setTenantId(BladeConstant.ADMIN_TENANT_ID);
+			// 榛樿璁剧疆涓虹鐞嗙粍涓嬬殑鐢ㄦ埛
+			user.setTenantId(this.tenantId);
 		}
 		String tenantId = user.getTenantId();
 		//Tenant tenant = SysCache.getTenant(tenantId);
@@ -161,6 +168,13 @@
 	}
 
 	@Override
+	public List<User> selectAllUser(User user, Long deptId){
+		List<Long> deptIdList = SysCache.getDeptChildIds(deptId);
+		List<User> users = baseMapper.selectUserPage(user, deptIdList, (AuthUtil.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? StringPool.EMPTY : AuthUtil.getTenantId()));
+		return users;
+	}
+
+	@Override
 	public IPage<UserVO> selectUserSearch(UserVO user, Query query) {
 		LambdaQueryWrapper<User> queryWrapper = Wrappers.<User>query().lambda();
 		String tenantId = AuthUtil.getTenantId();
@@ -205,13 +219,20 @@
 
 	@Override
 	public UserInfo userInfo(String tenantId, String account) {
-		User user = baseMapper.getUser(tenantId, account);
+		User user = baseMapper.getUser(tenantId, account,null);
 		return buildUserInfo(user);
 	}
 
 	@Override
+	public UserInfo userInfo(String tenantId, String account,String name) {
+		User user = baseMapper.getUser(tenantId, account,name);
+		UserInfo userInfo = buildUserInfo(user);
+		return null;
+	}
+
+	@Override
 	public UserInfo userInfo(String tenantId, String account, UserEnum userEnum) {
-		User user = baseMapper.getUser(tenantId, account);
+		User user = baseMapper.getUser(tenantId, account,null);
 		return buildUserInfo(user, userEnum);
 	}
 
@@ -223,6 +244,7 @@
 		if (ObjectUtil.isEmpty(user)) {
 			return null;
 		}
+		user.setDeptName(Func.join(SysCache.getDeptNames(user.getDeptId())));
 		UserInfo userInfo = new UserInfo();
 		userInfo.setUser(user);
 		if (Func.isNotEmpty(user)) {
@@ -308,6 +330,10 @@
 		}
 		//鑾峰彇鐢ㄦ埛閲囩敤鐨勫瘑鐮佺瓥鐣�
 		Strategy strategy = sysClient.getByUserId(userId).getData();
+		// 鍑犱箮涓嶄細鍑虹幇杩欑鎯呭喌
+		if(ObjectUtil.isEmpty(strategy)) {
+			throw new ServiceException("褰撳墠鐢ㄦ埛鏈簲鐢ㄥ瘑鐮佺瓥鐣ワ紒");
+		}
 		//瀵嗙爜闀垮害鏍¢獙
 		if(newPassword1.length() < strategy.getMinPwdLen() || newPassword1.length() > strategy.getMaxPwdLen()){
 			throw new ServiceException("瀵嗙爜涓繀椤诲惈鏈夈��"+strategy.getCombinationNames()+"銆戜腑鐨勩��"+strategy.getRequiredType()+"銆戠瀵嗙爜缁勫悎鏂瑰紡锛屼笖瀵嗙爜闀垮害蹇呴』鍦ㄣ��"+strategy.getMinPwdLen()+"-"+strategy.getMaxPwdLen()+"銆戣寖鍥村唴");
@@ -319,7 +345,7 @@
 			if(reqType>=strategy.getRequiredType()){
 				break;
 			}
-			if(!Func.isEmpty(RegexUtil.findResult(regexs.get(i),newPassword1))){
+			if(RegexUtil.find(regexs.get(i),newPassword1)){
 				reqType++;
 			}
 		}
@@ -327,12 +353,13 @@
 		if(reqType<strategy.getRequiredType()){
 			throw new ServiceException(resException);
 		}
-		// 鏄惁灞炰簬缁勫悎鏂瑰紡涓殑绫诲瀷
+		// 鏄惁灞炰簬缁勫悎鏂瑰紡涓殑绫诲瀷,浠ュ墠鏄瘑鐮佸繀椤绘槸鍖呭惈鍦ㄧ粍鍚堟柟寮忎腑鐨勭被鍨�
 		String regex = sysClient.getRegex(Arrays.asList(strategy.getCombinationIds().split(","))).getData();
 		regex = "^"+regex+"{"+strategy.getRequiredType()+",}$";
 		boolean result = RegexUtil.find(regex, newPassword1);
 		if(!result){
-			throw new ServiceException(resException);
+			throw new ServiceException("瀵嗙爜涓彧鑳藉瓨鍦ㄣ��"+strategy.getCombinationNames()+"銆戜腑鍖呭惈鐨勫瓧绗︼紒");
+			//throw new ServiceException(resException);
 		}
 		//淇敼瀵嗙爜鍚屾椂锛屾敼鍙樼敤鎴蜂俊鎭腑鐨勫瘑鐮佷慨鏀圭姸鎬佸瓧娈�,瀵嗙爜淇敼鏃堕棿
 		return this.update(Wrappers.<User>update().lambda()
@@ -418,6 +445,7 @@
 		boolean oauthTemp = userOauthService.updateById(userOauth);
 		return (userTemp && oauthTemp);
 	}
+
 	@Override
 	public boolean updatePlatform(Long userId, Integer userType, String userExt) {
 		if (userType.equals(UserEnum.WEB.getCategory())) {
@@ -482,8 +510,9 @@
 		if(adminUserId.equals(userId)){
 			return 0L;
 		}
+		QueryWrapper<User> wrapper = Wrappers.<User>query().eq("ID", userId);
 		//鑾峰彇鍒板瘑鐮佷慨鏀规椂闂�
-		Date pwdUpdateTime = this.getOne(Wrappers.<User>query().eq("ID", userId)).getPwdUpdateTime();
+		Date pwdUpdateTime = this.getOne(wrapper).getPwdUpdateTime();
 		Long pwdupdateday = 0L;
 		if(!Func.isEmpty(pwdUpdateTime)){
 			pwdupdateday = dateToDay(pwdUpdateTime);
@@ -510,7 +539,31 @@
 	}
 
 	/**
-	 * 鏃堕棿鏍煎紡杞ぉ
+	 * 鑾峰彇鍒版寚瀹氳韩浠芥潈闄愮殑鐢ㄦ埛鍒楄〃
+	 * @param user 鐢ㄦ埛鏌ヨ鐨勭敤鎴蜂俊鎭紝濡傜鎴蜂俊鎭紝閫氬父涓鸿嚜鍔ㄦ敞鍏ワ紝鍓嶇鍙�夋嫨涓嶄紶
+	 * @param roleName 瑕佹煡璇㈢殑瑙掕壊韬唤
+	 * @return
+	 */
+	@Override
+	public List<Map<String,String>> getByRoleUserList(BladeUser user, String roleName) {
+		// 鑰冭檻鍒颁竴涓敤鎴峰彲浠ユ嫢鏈夊绉嶈鑹叉潈闄愶紝鑰岀敤鎴峰叧鑱旇鑹叉潈闄愭槸鐢╮ole_id瀛楁鐢ㄩ�楀彿鍒嗛殧瑙掕壊id鐨勶紝鐩存帴閲囩敤瀛愭煡璇㈡潵in鏌ヨ涓嶈兘瀹炵幇锛屾墍浠ュ厛鏌ヨ瑙掕壊id
+		R<String> roleIds = sysClient.getRoleIds(user.getTenantId(), roleName);
+		if(roleIds.getCode() != 200){
+			throw new ServiceException("绯荤粺鏈嶅姟feign鎺ュ彛璋冪敤閿欒锛�");
+		}
+		if(Func.isBlank(roleIds.getData())){
+			return new ArrayList<>();
+		}
+		List<Map<String,String>> list = new ArrayList<>();
+		Arrays.stream(roleIds.getData().split(",")).forEach(item->{
+			list.addAll(this.baseMapper.getUserMap(item,user.getUserId().toString()));
+		});
+		// 鍘婚櫎閲嶅
+		return list.stream().distinct().collect(Collectors.toList());
+	}
+
+	/**
+	 * 鏃ユ湡鏃堕棿鏍煎紡杞ぉ
 	 * @param date
 	 * @return
 	 */

--
Gitblit v1.9.3