From 3a8545610608eaece0702a1fca82d09956fdd66d Mon Sep 17 00:00:00 2001
From: xiejun <xj@2023>
Date: 星期四, 14 十二月 2023 17:08:19 +0800
Subject: [PATCH] 集成统一接口管理模块控制接口完善
---
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/StrategyServiceImpl.java | 137 ++++++++++++++++++++++++++++++++++-----------
1 files changed, 104 insertions(+), 33 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 8673d59..dfb7c75 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
@@ -1,18 +1,22 @@
package com.vci.ubcs.system.service.impl;
+import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.cache.NacosConfigCache;
+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.secure.utils.AuthUtil;
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;
@@ -32,6 +36,12 @@
@Resource
private StrategyMapper strategyMapper;
+ @Resource
+ private UserPwdstrategyServiceImpl userPwdstrategyService;
+
+ @Resource
+ private IUserClient userClient;
+
/**
* 閫氳繃ID鏌ヨ鍗曟潯鏁版嵁
*
@@ -49,7 +59,13 @@
*/
@Override
public Strategy queryByIsDefault() {
- return this.strategyMapper.queryByIsDefault();
+ return this.strategyMapper.queryByIsDefault(AuthUtil.getTenantId()
+ .equals(
+ NacosConfigCache
+ .getAdminUserInfo()
+ .getTenantId()
+ ) ? null:AuthUtil.getTenantId()
+ );
}
/**
@@ -59,9 +75,20 @@
* @return 鏌ヨ缁撴灉
*/
@Override
- public PageImpl<Strategy> queryAllByPage(Query query) {
+ public IPage<Strategy> queryAllByPage(Query query) {
Page<Strategy> strategyPage = new Page<>(query.getCurrent(), query.getSize());
- return new PageImpl<>(this.strategyMapper.queryAllByPage(strategyPage));
+ // 娣诲姞绉熸埛鏌ヨ鏉′欢
+ IPage<Strategy> strategyIPage = this.strategyMapper.queryAllByPage(
+ strategyPage,
+ AuthUtil.getTenantId()
+ .equals(
+ NacosConfigCache
+ .getAdminUserInfo()
+ .getTenantId()
+ )
+ ? null:AuthUtil.getTenantId()
+ );
+ return strategyIPage;
}
/**
@@ -71,8 +98,11 @@
* @return 瀹炰緥瀵硅薄
*/
@Override
+ @Transactional(rollbackFor = Exception.class)
public boolean submit(Strategy strategy) {
- //鍒ゆ柇鏄惁鎼哄甫id
+ //鑰佺殑榛樿瀵嗙爜绛栫暐
+ Long oldIsDefaultStrategy = null;
+ //鍒ゆ柇鏄惁鎼哄甫id锛屼笉鎼哄甫id涓烘柊澧炴搷浣�
if(Func.isEmpty(strategy.getId())){
//鎵ц鏂板
Strategy dbstrategy = this.getOne(Wrappers.<Strategy>query().lambda()
@@ -81,48 +111,89 @@
if(!Func.isEmpty(dbstrategy)){
throw new ServiceException("璇ュ瘑鐮佺瓥鐣ュ凡瀛樺湪!");
}
+ //妫�楠屽瘑鐮佺瓥鐣ユ槸鍚︾鍚堣姹�
+ 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_SEALED_ID)
- .eq(Strategy::getIsDefault, CommonConstant.DATA_SCOPE_CATEGORY));
+ .set(Strategy::getIsDefault, CommonConstant.NOT_DEFAULT)
+ .eq(Strategy::getIsDefault, CommonConstant.IS_DEFAULT));
}
- if(strategy.getRequiredType() > 0){
- throw new ServiceException("蹇呭~绉嶇被涓嶈兘灏忎簬绛変簬0!");
- }
- if(strategy.getRequiredType() > strategy.getCombinationIds().split(",").length){
- throw new ServiceException("蹇呭~绉嶇被涓嶈兘澶т簬鎵�閫夋嫨鐨勫瘑鐮佺粍鍚堟柟寮忕殑涓暟!");
- }
- if(strategy.getMaxPwdLen() > strategy.getMinPwdLen()){
- throw new ServiceException("瀵嗙爜鏈�澶ч暱搴︿笉鑳藉皬浜庢渶灏忛暱搴�!");
- }
- if(strategy.getMinPwdLen() < strategy.getCombinationIds().split(",").length || strategy.getMaxPwdLen() < strategy.getCombinationIds().split(",").length){
- throw new ServiceException("瀵嗙爜鏈�灏忛暱搴︿笉鑳藉皬浜庣瀵嗙瓥鐣ョ殑鍊�!");
- }
- 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){
- this.update(Wrappers.<Strategy>update().lambda()
- .set(Strategy::getIsDefault,CommonConstant.NOT_SEALED_ID)
- .eq(Strategy::getIsDefault,CommonConstant.DATA_SCOPE_CATEGORY));
+ if((strategy.getIsDefault().toString()).equals("1")){
+ //鏌ヨ鑰佺殑榛樿瀵嗙爜绛栫暐锛屼究浜庝笅闈慨鏀�
+ Strategy strategyDefault = this.queryByIsDefault();
+ // 鍦ㄦ暟鎹笉鍑虹幇闂鐨勬儏鍐典笅涓嶄細鍑虹幇strategyDefault涓虹┖鐨勬儏鍐�
+ if(Func.isNotEmpty(strategyDefault)){
+ oldIsDefaultStrategy = strategyDefault.getId();
+ this.update(Wrappers.<Strategy>update().lambda()
+ .set(Strategy::getIsDefault,CommonConstant.NOT_DEFAULT)
+ .eq(Strategy::getIsDefault,CommonConstant.IS_DEFAULT));
+ }
}else {
+ // 閬垮厤鐢ㄦ埛灏嗗敮涓�鐨勯粯璁ゅ瘑鐮佺瓥鐣ユ敼涓洪潪榛樿
if(Func.isEmpty(queryByIsDefault())){
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 = this.update(strategy,Wrappers.<Strategy>update().lambda().eq(Strategy::getId,strategy.getId()));
+ 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
+ */
+ private void checkPwdStrategy(Strategy strategy){
+ if(strategy.getRequiredType() > strategy.getCombinationIds().split(",").length){
+ throw new ServiceException("蹇呭~绉嶇被涓嶈兘澶т簬鎵�閫夋嫨鐨勫瘑鐮佺粍鍚堟柟寮忕殑涓暟!");
+ }
+ if(strategy.getMaxPwdLen() < strategy.getMinPwdLen()){
+ throw new ServiceException("瀵嗙爜鏈�澶ч暱搴︿笉鑳藉皬浜庢渶灏忛暱搴�!");
+ }
+ if(Func.isNotEmpty(strategy.getRequiredType()) && (strategy.getMinPwdLen() < strategy.getRequiredType() || strategy.getMaxPwdLen() < strategy.getRequiredType())){
+ throw new ServiceException("瀵嗙爜鏈�灏忛暱搴︿笉鑳藉皬浜庡繀濉绫荤殑鍊�!");
+ }
+ //鍒ゆ柇鍓嶇鏄惁鏈彁浜わ紝鏄惁榛樿瀛楁
+ if(Func.isEmpty(strategy.getIsDefault())){
+ strategy.setIsDefault(0L);
}
}
@@ -136,7 +207,7 @@
public boolean deleteByIds(List<String> ids) {
Strategy strategy = this.getOne(Wrappers.<Strategy>query().lambda()
.in(Strategy::getId,ids)
- .eq(Strategy::getIsDefault, CommonConstant.DATA_SCOPE_CATEGORY));
+ .eq(Strategy::getIsDefault, CommonConstant.IS_DEFAULT));
//濡傛灉瀛樺湪榛樿绛栫暐鐨刬d锛屽氨涓嶈兘鐩存帴鍒犻櫎缁欏嚭鎻愮ず
if(!Func.isEmpty(strategy)){
throw new ServiceException("涓嶈兘鍒犻櫎榛樿瀵嗙爜绛栫暐!");
--
Gitblit v1.9.3