From 28a9dc3f52b879053c79feb216fa868be906cd02 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期三, 06 十二月 2023 13:57:29 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 Source/UBCS/ubcs-service/ubcs-user/src/main/java/com/vci/ubcs/system/user/service/impl/UserServiceImpl.java |   92 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 79 insertions(+), 13 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 785cf67..b1de27c 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
@@ -20,8 +20,10 @@
 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.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.vci.ubcs.starter.web.util.VciBaseUtil;
 import com.vci.ubcs.system.cache.DictCache;
 import com.vci.ubcs.system.cache.NacosConfigCache;
 import com.vci.ubcs.system.cache.ParamCache;
@@ -34,6 +36,7 @@
 import com.vci.ubcs.system.user.cache.UserCache;
 import com.vci.ubcs.system.user.entity.*;
 import com.vci.ubcs.system.user.enums.UserEnum;
+import com.vci.ubcs.system.user.enums.UserStatus;
 import com.vci.ubcs.system.user.excel.UserExcel;
 import com.vci.ubcs.system.user.mapper.UserMapper;
 import com.vci.ubcs.system.user.service.IUserDeptService;
@@ -42,6 +45,7 @@
 import com.vci.ubcs.system.user.vo.UserVO;
 import com.vci.ubcs.system.user.wrapper.UserWrapper;
 import lombok.RequiredArgsConstructor;
+import org.springblade.core.log.annotation.GrantLog;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.mp.support.Condition;
@@ -53,15 +57,12 @@
 import org.springblade.core.tool.constant.BladeConstant;
 import org.springblade.core.tool.support.Kv;
 import org.springblade.core.tool.utils.*;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 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;
 
@@ -80,21 +81,21 @@
 	private final IUserOauthService userOauthService;
 	private final ISysClient sysClient;
 	private final BladeTenantProperties tenantProperties;
-	//鎷垮埌閰嶇疆鐨勮秴绠�
-	private final NacosConfigCache nacosConfigCache;
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public boolean submit(User user) {
 		if (StringUtil.isBlank(user.getTenantId())) {
-			// user.setTenantId(BladeConstant.ADMIN_TENANT_ID);
 			// 榛樿璁剧疆涓虹鐞嗙粍涓嬬殑鐢ㄦ埛
-			user.setTenantId(nacosConfigCache.getAdminUserInfo().getTenantId());
+			user.setTenantId(NacosConfigCache.getAdminUserInfo().getTenantId());
 		}
 		String tenantId = user.getTenantId();
 		//Tenant tenant = SysCache.getTenant(tenantId);
 		if (Func.isNotEmpty(user.getPassword())) {
 			user.setPassword(DigestUtil.encrypt(user.getPassword()));
+		}
+		if(Func.isEmpty(user.getUserStatus())){
+			user.setUserStatus(UserStatus.Enable.getValue());
 		}
 		Long userCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, user.getAccount()));
 		if (userCount > 0L && Func.isEmpty(user.getId())) {
@@ -109,7 +110,7 @@
 		Boolean flag = true;
 		for (User user : users){
 			if (StringUtil.isBlank(user.getTenantId())) {
-				user.setTenantId(BladeConstant.ADMIN_TENANT_ID);
+				user.setTenantId(NacosConfigCache.getAdminUserInfo().getTenantId());
 			}
 			String tenantId = user.getTenantId();
 			if (Func.isNotEmpty(user.getPassword())) {
@@ -127,6 +128,7 @@
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
+	@GrantLog("grantUser")
 	public boolean updateUser(User user) {
 		String tenantId = user.getTenantId();
 		Long userCount = baseMapper.selectCount(
@@ -135,6 +137,7 @@
 				.eq(User::getAccount, user.getAccount())
 				.notIn(User::getId, user.getId())
 		);
+		// 鍒ゆ柇鏄惁琚慨鏀逛负宸插瓨鍦ㄧ殑鐢ㄦ埛鍚�
 		if (userCount > 0L) {
 			throw new ServiceException(StringUtil.format("褰撳墠鐢ㄦ埛 [{}] 宸插瓨鍦�!", user.getAccount()));
 		}
@@ -147,8 +150,41 @@
 		return updateById(user);
 	}
 
+	/**
+	 * 鏍规嵁鏃ц处鍙凤紝淇敼涓烘柊璐﹀彿鍚�
+	 * @param oldAccount
+	 * @param newAccount
+	 * @return
+	 */
+	@Override
+	public boolean updateByAccount(String oldAccount,String newAccount) {
+		User user = this.userByAccount(AuthUtil.getTenantId(), oldAccount);
+		if(Func.isEmpty(user)){
+			return true;
+		}
+		user.setAccount(newAccount);
+		return this.updateUser(user);
+	}
+
+	/**
+	 * 鎹处鍙凤紝淇敼涓虹敤鎴风姸鎬�
+	 * @param accounts
+	 * @param status
+	 * @return
+	 */
+	@Override
+	public boolean updateStatusByAccount(String accounts, String status) {
+		LambdaUpdateWrapper<User> updateWrapper = Wrappers.<User>update()
+			.lambda().in(User::getAccount, accounts)
+			.set(User::getUserStatus, status);
+		return this.update(updateWrapper);
+	}
+
 	private boolean submitUserDept(User user) {
 		List<Long> deptIdList = Func.toLongList(user.getDeptId());
+		if(deptIdList.isEmpty()){
+			return true;
+		}
 		List<UserDept> userDeptList = new ArrayList<>();
 		deptIdList.forEach(deptId -> {
 			UserDept userDept = new UserDept();
@@ -169,7 +205,7 @@
 	@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()));
+		List<User> users = baseMapper.selectUserPage(user, deptIdList, (VciBaseUtil.checkAdminTenant() ? StringPool.EMPTY : AuthUtil.getTenantId()));
 		return users;
 	}
 
@@ -318,6 +354,16 @@
 		return this.update(user, Wrappers.<User>update().lambda().in(User::getId, Func.toLongList(userIds)));
 	}
 
+	/**
+	 * 鎺堟潈鏃ュ織鎻掑叆鎿嶄綔
+	 * @param res
+	 */
+	@Override
+	@GrantLog("grantUser")
+	public boolean grantLog(String res, boolean isException){
+		return true;
+	}
+
 	@Override
 	public boolean resetPassword(String userIds) {
 		User user = new User();
@@ -332,9 +378,6 @@
 		if (!newPassword.equals(newPassword1)) {
 			throw new ServiceException("璇疯緭鍏ユ纭殑纭瀵嗙爜!");
 		}
-		if (!user.getPassword().equals(DigestUtil.hex(oldPassword))) {
-			throw new ServiceException("鍘熷瘑鐮佷笉姝g‘!");
-		}
 		//鑾峰彇鐢ㄦ埛閲囩敤鐨勫瘑鐮佺瓥鐣�
 		Strategy strategy = sysClient.getByUserId(userId).getData();
 		// 鍑犱箮涓嶄細鍑虹幇杩欑鎯呭喌
@@ -344,6 +387,11 @@
 		//瀵嗙爜闀垮害鏍¢獙
 		if(newPassword1.length() < strategy.getMinPwdLen() || newPassword1.length() > strategy.getMaxPwdLen()){
 			throw new ServiceException("瀵嗙爜涓繀椤诲惈鏈夈��"+strategy.getCombinationNames()+"銆戜腑鐨勩��"+strategy.getRequiredType()+"銆戠瀵嗙爜缁勫悎鏂瑰紡锛屼笖瀵嗙爜闀垮害蹇呴』鍦ㄣ��"+strategy.getMinPwdLen()+"-"+strategy.getMaxPwdLen()+"銆戣寖鍥村唴");
+		}
+
+		oldPassword = DigestUtil.hex(DigestUtils.md5DigestAsHex((oldPassword).getBytes()));
+		if (!user.getPassword().equals(oldPassword)) {
+			throw new ServiceException("鍘熷瘑鐮佷笉姝g‘!");
 		}
 		List<String> regexs = sysClient.getRegexByList(Arrays.asList(strategy.getCombinationIds().split(","))).getData();
 		//鍒ゆ柇鏄惁婊¤冻缁勫悎鏂瑰紡涓殑蹇呭~绉嶇被鏁�
@@ -517,7 +565,7 @@
 	@Override
 	public Long checkRenAndExpr(Long userId) {
 		//瓒呯骇绠$悊鍛樼洿鎺ヨ繑鍥炰笉闇�瑕佹彁閱掑瘑鐮佷慨鏀�
-		if(nacosConfigCache.getAdminUserInfo().getUserId().equals(userId)){
+		if(NacosConfigCache.getAdminUserInfo().getUserId().equals(userId)){
 			return 0L;
 		}
 		QueryWrapper<User> wrapper = Wrappers.<User>query().eq("ID", userId);
@@ -529,6 +577,9 @@
 			pwdupdateday = dateToDay(pwdUpdateTime);
 		}
 		Strategy strategy = sysClient.getByUserId(userId).getData();
+		if(Func.isEmpty(strategy)){
+			throw new ServiceException("瀵嗙爜绛栫暐鏌ヨ涓虹┖锛岃妫�鏌ュ綋鍓嶇鎴蜂笅鏄惁瀛樺湪榛樿瀵嗙爜绛栫暐锛�");
+		}
 		//鏄惁鎻愰啋閫氳繃鏈�鍚庝竴娆′慨鏀瑰瘑鐮佺殑鏃堕棿鍔犱笂杩囨湡鏃堕棿鍑忓幓褰撳墠鏃堕棿锛屽鏋滃皬浜庤繃鏈熸彁閱掓椂闂村氨杩涜鎻愰啋锛屽鏋�<=0灏辨彁閱掑繀椤讳慨鏀瑰瘑鐮�
 		long reminder = pwdupdateday+strategy.getExpirationTime()-dateToDay(new Date());
 		//鎻愰啋鐢ㄦ埛蹇呴』淇敼瀵嗙爜
@@ -573,6 +624,21 @@
 		return list.stream().distinct().collect(Collectors.toList());
 	}
 
+	/***
+	 * 鏇存柊鐢ㄦ埛鍚敤鍋滅敤鐘舵��
+	 * @param userIds
+	 * @param status
+	 * @return
+	 */
+	@Override
+	public boolean updateUserStatus(String userIds, boolean status) {
+		Integer userStatus = 0;
+		if(!status){
+			userStatus = 1;
+		}
+		return this.update(Wrappers.<User>lambdaUpdate().in(User::getId, Func.toLongList(userIds)).set(User::getUserStatus,userStatus));
+	}
+
 	/**
 	 * 鏃ユ湡鏃堕棿鏍煎紡杞ぉ
 	 * @param date

--
Gitblit v1.9.3