fix(REQ-20240731): 同步优化
This commit is contained in:
parent
a355be301b
commit
abe48655b7
@ -26,6 +26,7 @@ import cn.azxo.framework.common.constatns.Constants;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
@ -35,11 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@ -131,12 +128,16 @@ public class FeatureResourceSyncServiceImpl implements FeatureResourceSyncServic
|
|||||||
//TODO:@Zhan 并发处理;同一个parent下同批查询
|
//TODO:@Zhan 并发处理;同一个parent下同批查询
|
||||||
//处理数据缓存:避免同级节点上级重复处理 - 上级code查询
|
//处理数据缓存:避免同级节点上级重复处理 - 上级code查询
|
||||||
final Map<Long, String> codeCache = new ConcurrentHashMap<>();
|
final Map<Long, String> codeCache = new ConcurrentHashMap<>();
|
||||||
|
Set<Long> syncedRoleFeatureResourceIds = Sets.newConcurrentHashSet();
|
||||||
|
try {
|
||||||
for (Long id : req.getIds()) {
|
for (Long id : req.getIds()) {
|
||||||
//获取基准环境配置数据:同步某个ID的数据 需要同步处理它所有上级及下级组件
|
//获取基准环境配置数据:同步某个ID的数据 需要同步处理它所有上级及下级组件
|
||||||
List<FeatureResourceTreeNode> syncList = RpcInternalUtil.rpcProcessor(() -> baseFeatureResourceApi.getSyncTreeById(id),
|
List<FeatureResourceTreeNode> syncList = RpcInternalUtil.rpcProcessor(() -> baseFeatureResourceApi.getSyncTreeById(id),
|
||||||
"get base sync tree by id", id).getData();
|
"get base sync tree by id", id).getData();
|
||||||
syncResourceProcess(syncList, codeCache, req.getOperatorId(), operateDos);
|
syncResourceProcess(syncList, codeCache, req.getOperatorId(), operateDos, syncedRoleFeatureResourceIds);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("do sync from base error", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 记录操作日志
|
// 记录操作日志
|
||||||
@ -177,7 +178,8 @@ public class FeatureResourceSyncServiceImpl implements FeatureResourceSyncServic
|
|||||||
return featureResourceIdCodeMap;
|
return featureResourceIdCodeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncResourceProcess(List<FeatureResourceTreeNode> syncList, Map<Long, String> codeCache, Long operatorId, List<RelationOperateLogResourceBindRoleDO> operateDos) {
|
private void syncResourceProcess(List<FeatureResourceTreeNode> syncList, Map<Long, String> codeCache, Long operatorId,
|
||||||
|
List<RelationOperateLogResourceBindRoleDO> operateDos, Set<Long> syncedRoleFeatureResourceIds) {
|
||||||
|
|
||||||
for (FeatureResourceTreeNode treeNode : syncList) {
|
for (FeatureResourceTreeNode treeNode : syncList) {
|
||||||
if (codeCache.containsKey(treeNode.getId())) {
|
if (codeCache.containsKey(treeNode.getId())) {
|
||||||
@ -185,7 +187,7 @@ public class FeatureResourceSyncServiceImpl implements FeatureResourceSyncServic
|
|||||||
log.info("already sync resource:{}", treeNode.getId());
|
log.info("already sync resource:{}", treeNode.getId());
|
||||||
//递归子节点
|
//递归子节点
|
||||||
if (CollectionUtils.isNotEmpty(treeNode.getChildren())) {
|
if (CollectionUtils.isNotEmpty(treeNode.getChildren())) {
|
||||||
syncResourceProcess(treeNode.getChildren(), codeCache, operatorId, operateDos);
|
syncResourceProcess(treeNode.getChildren(), codeCache, operatorId, operateDos, syncedRoleFeatureResourceIds);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -220,14 +222,14 @@ public class FeatureResourceSyncServiceImpl implements FeatureResourceSyncServic
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理资源关联的权限
|
// 处理资源关联的权限
|
||||||
RelationOperateLogResourceBindRoleDO logResourceBindRoleDO = doFeatureResourceRole(baseResource, treeNode.getRoleCodes(), operatorId);
|
RelationOperateLogResourceBindRoleDO logResourceBindRoleDO = doFeatureResourceRole(baseResource, treeNode.getRoleCodes(), operatorId, syncedRoleFeatureResourceIds);
|
||||||
if (Objects.nonNull(logResourceBindRoleDO)) {
|
if (Objects.nonNull(logResourceBindRoleDO)) {
|
||||||
operateDos.add(logResourceBindRoleDO);
|
operateDos.add(logResourceBindRoleDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
//递归子节点
|
//递归子节点
|
||||||
if (CollectionUtils.isNotEmpty(treeNode.getChildren())) {
|
if (CollectionUtils.isNotEmpty(treeNode.getChildren())) {
|
||||||
syncResourceProcess(treeNode.getChildren(), codeCache, operatorId, operateDos);
|
syncResourceProcess(treeNode.getChildren(), codeCache, operatorId, operateDos, syncedRoleFeatureResourceIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,10 +253,17 @@ public class FeatureResourceSyncServiceImpl implements FeatureResourceSyncServic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RelationOperateLogResourceBindRoleDO doFeatureResourceRole(SaasFeatureResource featureResource, List<String> roleCodes, Long operatorId) {
|
private RelationOperateLogResourceBindRoleDO doFeatureResourceRole(SaasFeatureResource featureResource, List<String> roleCodes,
|
||||||
|
Long operatorId, Set<Long> syncedRoleFeatureResourceIds) {
|
||||||
if (Objects.isNull(featureResource)) {
|
if (Objects.isNull(featureResource)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// 同一FeatureResource如果已经处理过角色同步,不再进行再次处理。
|
||||||
|
if (syncedRoleFeatureResourceIds.contains(featureResource.getId())) {
|
||||||
|
log.warn("sync role bind has handled,feature resource id:{}", featureResource.getId());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
syncedRoleFeatureResourceIds.add(featureResource.getId());
|
||||||
|
|
||||||
// 先清除资源绑定的角色 @20240723 产品武艳华要求资源绑定的角色以PRE角色为准;
|
// 先清除资源绑定的角色 @20240723 产品武艳华要求资源绑定的角色以PRE角色为准;
|
||||||
List<SaasPgroupPermissionRelation> existPermissionRelations = saasPgroupPermissionRelationDao.lambdaQuery()
|
List<SaasPgroupPermissionRelation> existPermissionRelations = saasPgroupPermissionRelationDao.lambdaQuery()
|
||||||
@ -291,7 +300,7 @@ public class FeatureResourceSyncServiceImpl implements FeatureResourceSyncServic
|
|||||||
return logResourceBindRoleDO;
|
return logResourceBindRoleDO;
|
||||||
}
|
}
|
||||||
List<SaasPgroupRoleRelation> saasPgroupRoleRelations = saasPgroupRoleRelationDao.findByRoleIds(saasRoles.stream().map(BaseEntity::getId).collect(Collectors.toList()));
|
List<SaasPgroupRoleRelation> saasPgroupRoleRelations = saasPgroupRoleRelationDao.findByRoleIds(saasRoles.stream().map(BaseEntity::getId).collect(Collectors.toList()));
|
||||||
List<Long> groupIds = saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList());
|
Set<Long> groupIds = saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toSet());
|
||||||
List<Long> existRoleIds = saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getRoleId).collect(Collectors.toList());
|
List<Long> existRoleIds = saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getRoleId).collect(Collectors.toList());
|
||||||
if (CollectionUtils.isNotEmpty(groupIds)) {
|
if (CollectionUtils.isNotEmpty(groupIds)) {
|
||||||
List<SaasPgroupPermissionRelation> insertRelation = groupIds.stream()
|
List<SaasPgroupPermissionRelation> insertRelation = groupIds.stream()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user