更新子账号也更新工作流的部门和人员的缓存
This commit is contained in:
parent
17f331dfd7
commit
5cc62689f0
@ -28,10 +28,10 @@ import java.util.stream.Collectors;
|
||||
public class MemoryOrgOwnershipServiceImpl implements OrgOwnershipService {
|
||||
|
||||
//用户ID与其所有层级所属部门ID级联映射
|
||||
private static final Map<String, Set<String>> userDeptMap = new ConcurrentHashMap<>();
|
||||
private static Map<String, Set<String>> userDeptMap = new ConcurrentHashMap<>();
|
||||
|
||||
//部门ID与其所有父级部门ID级联关系映射
|
||||
private static final Map<String, Set<String>> deptAndDeptMap = new ConcurrentHashMap<>();
|
||||
private static Map<String, Set<String>> deptAndDeptMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Autowired
|
||||
private OrgRepositoryService orgRepositoryService;
|
||||
@ -96,32 +96,34 @@ public class MemoryOrgOwnershipServiceImpl implements OrgOwnershipService {
|
||||
* 实例化时从数据库加载组织架构关系
|
||||
*/
|
||||
@PostConstruct
|
||||
public void loadByDbToCatch(){
|
||||
public void loadByDbToCatch() {
|
||||
//查询全量数据
|
||||
log.info("开始加载全量组织架构关系数据");
|
||||
List<UserDeptDo> userDepartments = orgRepositoryService.getSysAllUserDepts();
|
||||
List<DeptDo> departments = orgRepositoryService.getSysAllDepts();
|
||||
userDeptMap.clear();
|
||||
deptAndDeptMap.clear();
|
||||
|
||||
//先加载部门级联关系,部门map化
|
||||
// 构建新的临时 Map
|
||||
Map<String, Set<String>> newDeptAndDeptMap = new ConcurrentHashMap<>();
|
||||
Map<String, DeptDo> deptMap = departments.stream().collect(Collectors.toMap(DeptDo::getId, v -> v));
|
||||
deptMap.forEach((k, v) -> {
|
||||
Set<String> set = new LinkedHashSet<>();
|
||||
loadCascade(set, deptMap, v);
|
||||
deptAndDeptMap.put(k, set);
|
||||
newDeptAndDeptMap.put(k, set);
|
||||
});
|
||||
//再加载用户与所属部门的级联关系
|
||||
Map<String, Set<String>> newUserDeptMap = new ConcurrentHashMap<>();
|
||||
userDepartments.forEach(ud -> {
|
||||
if (ud.getDeptId() != null) {
|
||||
Set<String> userDeptSet = userDeptMap.get(ud.getUserId());
|
||||
if (CollectionUtil.isEmpty(userDeptSet)){
|
||||
userDeptSet = new LinkedHashSet<>();
|
||||
userDeptMap.put(ud.getUserId(), userDeptSet);
|
||||
}
|
||||
Set<String> userDeptSet = newUserDeptMap.computeIfAbsent(ud.getUserId(), k -> new LinkedHashSet<>());
|
||||
userDeptSet.add(ud.getDeptId());
|
||||
userDeptSet.addAll(deptAndDeptMap.getOrDefault(ud.getDeptId(), new HashSet<>()));
|
||||
userDeptSet.addAll(newDeptAndDeptMap.getOrDefault(ud.getDeptId(), new HashSet<>()));
|
||||
}
|
||||
});
|
||||
|
||||
// 原子替换引用
|
||||
deptAndDeptMap = newDeptAndDeptMap;
|
||||
userDeptMap = newUserDeptMap;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user