From d7a83f1396425c4e47da9b95f287b26cd5bb3344 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期三, 12 四月 2023 10:18:53 +0800
Subject: [PATCH] 后端代码整合

---
 Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/StrategyServiceImpl.java |   61 +++++++++++++++++++++++++-----
 1 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/StrategyServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/StrategyServiceImpl.java
index d73d658..45fd332 100644
--- a/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/StrategyServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/StrategyServiceImpl.java
@@ -4,15 +4,17 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.vci.ubcs.common.constant.CommonConstant;
+import com.vci.ubcs.system.entity.Strategy;
 import com.vci.ubcs.system.mapper.StrategyMapper;
 import com.vci.ubcs.system.service.IStrategyService;
+import com.vci.ubcs.system.user.feign.IUserClient;
 import org.springblade.core.cache.utils.CacheUtil;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.utils.Func;
-import com.vci.ubcs.system.entity.Strategy;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.Date;
@@ -31,6 +33,12 @@
 
 	@Resource
 	private StrategyMapper strategyMapper;
+
+	@Resource
+	private UserPwdstrategyServiceImpl userPwdstrategyService;
+
+	@Resource
+	private IUserClient userClient;
 
 	/**
 	 * 閫氳繃ID鏌ヨ鍗曟潯鏁版嵁
@@ -71,7 +79,10 @@
 	 * @return 瀹炰緥瀵硅薄
 	 */
 	@Override
+	@Transactional(rollbackFor = Exception.class)
 	public boolean submit(Strategy strategy) {
+		//鑰佺殑榛樿瀵嗙爜绛栫暐
+		Long oldIsDefaultStrategy = null;
 		//鍒ゆ柇鏄惁鎼哄甫id
 		if(Func.isEmpty(strategy.getId())){
 			//鎵ц鏂板
@@ -85,23 +96,26 @@
 			checkPwdStrategy(strategy);
 			//濡傛灉褰撳墠鏂板璁剧疆涓洪粯璁ゅ瘑鐮佺瓥鐣ワ紝闇�瑕佸皢宸插瓨鍦ㄩ粯璁ゅ瘑鐮佺瓥鐣ヤ慨鏀逛负闈為粯璁�
 			if(strategy.getIsDefault().equals("1") || strategy.getIsDefault() == 1){
+				//鏌ヨ鑰佺殑榛樿瀵嗙爜绛栫暐锛屼究浜庝笅闈慨鏀�
+				oldIsDefaultStrategy = this.queryByIsDefault().getId();
 				this.update(Wrappers.<Strategy>update().lambda()
 					.set(Strategy::getIsDefault, CommonConstant.NOT_DEFAULT)
 					.eq(Strategy::getIsDefault, CommonConstant.IS_DEFAULT));
 			}
-			if(Func.isEmpty(strategy.getCreateTime())){
+			//鍒涘缓鏃堕棿鍜屼慨鏀规椂闂存坊鍔�
+			if(Func.isEmpty(strategy.getCreateTime())||Func.isEmpty(strategy.getUpdateTime())){
 				strategy.setCreateTime(new Date());
-			}
-			if(Func.isEmpty(strategy.getUpdateTime())){
 				strategy.setUpdateTime(new Date());
 			}
 			boolean temp = super.saveOrUpdate(strategy);
-			return temp;
+			return temp && updateUserStrategyDefault(temp,oldIsDefaultStrategy);
 		}else {
 			//妫�楠屽瘑鐮佺瓥鐣ユ槸鍚︾鍚堣姹�
 			checkPwdStrategy(strategy);
 			//濡傛灉褰撳墠淇敼璁剧疆涓洪粯璁ゅ瘑鐮佺瓥鐣ワ紝闇�瑕佸皢宸插瓨鍦ㄩ粯璁ゅ瘑鐮佺瓥鐣ヤ慨鏀逛负闈為粯璁�
 			if(strategy.getIsDefault().equals("1") || strategy.getIsDefault() == 1){
+				//鏌ヨ鑰佺殑榛樿瀵嗙爜绛栫暐锛屼究浜庝笅闈慨鏀�
+				oldIsDefaultStrategy = this.queryByIsDefault().getId();
 				this.update(Wrappers.<Strategy>update().lambda()
 					.set(Strategy::getIsDefault,CommonConstant.NOT_DEFAULT)
 					.eq(Strategy::getIsDefault,CommonConstant.IS_DEFAULT));
@@ -110,28 +124,53 @@
 					throw new ServiceException("榛樿瀵嗙爜绛栫暐蹇呴』鏈変笖浠呮湁涓�鏉�!");
 				}
 			}
-			if(Func.isEmpty(strategy.getUpdateTime())){
-				strategy.setUpdateTime(new Date());
-			}
+			strategy.setUpdateTime(new Date());
 			CacheUtil.clear(SYS_CACHE, Boolean.FALSE);
-			return super.saveOrUpdate(strategy);
+			boolean temp1 = super.saveOrUpdate(strategy);
+			boolean temp2 = false;
+			if(Func.isNotEmpty(oldIsDefaultStrategy)){
+				temp2 = updateUserStrategyDefault(temp1, oldIsDefaultStrategy);
+			}
+			return temp1 && temp2;
 		}
+	}
+
+	/**
+	 * 淇敼浣跨敤榛樿瀵嗙爜绛栫暐鐨勭敤鎴风姸鎬�
+	 * @param oldIsDefaultStrategy
+	 */
+	private boolean updateUserStrategyDefault(boolean temp,Long oldIsDefaultStrategy){
+		boolean resBoolean = false;
+		/**
+		 * 浜х敓鏂扮殑榛樿瀵嗙爜绛栫暐锛岄渶瑕佸皢浠ュ墠閲囩敤榛樿瀵嗙爜绛栫暐鐨勭敤鎴峰仛涓�涓洿鏀规彁閱掞紝鐢变簬鏈嚭鐜板湪鍏宠仈琛ㄤ腑鐨勭敤鎴烽兘鏄噰鐢ㄧ殑榛樿瀵嗙爜绛栫暐锛屾墍浠ラ渶瑕佸仛涓�涓繛鎺ユ煡璇㈠嚭鐢ㄦ埛id
+		 */
+		if(temp && Func.isNotEmpty(oldIsDefaultStrategy)){
+			List<Long> userIds = userPwdstrategyService.queryByUseISDefault(oldIsDefaultStrategy);
+			if (Func.isNotEmpty(userIds)){
+				resBoolean = userClient.updateStrategyStatus(userIds).getData();
+			}
+		}
+		return resBoolean;
 	}
 
 	/**
 	 * 	妫�楠屽瘑鐮佺瓥鐣ユ槸鍚︾鍚堣姹�
 	 * @param strategy
 	 */
-	public void checkPwdStrategy(Strategy strategy){
+	private void checkPwdStrategy(Strategy strategy){
 		if(strategy.getRequiredType() > strategy.getCombinationIds().split(",").length){
 			throw new ServiceException("蹇呭~绉嶇被涓嶈兘澶т簬鎵�閫夋嫨鐨勫瘑鐮佺粍鍚堟柟寮忕殑涓暟!");
 		}
 		if(strategy.getMaxPwdLen() < strategy.getMinPwdLen()){
 			throw new ServiceException("瀵嗙爜鏈�澶ч暱搴︿笉鑳藉皬浜庢渶灏忛暱搴�!");
 		}
-		if(strategy.getMinPwdLen() < strategy.getRequiredType() || strategy.getMaxPwdLen() < strategy.getRequiredType()){
+		if(Func.isNotEmpty(strategy.getRequiredType()) && (strategy.getMinPwdLen() < strategy.getRequiredType() || strategy.getMaxPwdLen() < strategy.getRequiredType())){
 			throw new ServiceException("瀵嗙爜鏈�灏忛暱搴︿笉鑳藉皬浜庡繀濉绫荤殑鍊�!");
 		}
+		//鍒ゆ柇鍓嶇鏄惁鏈彁浜わ紝鏄惁榛樿瀛楁
+		if(Func.isEmpty(strategy.getIsDefault())){
+			strategy.setIsDefault(0L);
+		}
 	}
 
 	/**

--
Gitblit v1.9.3