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