|
|
@@ -135,22 +135,29 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
orgs.add(org);
|
|
|
}
|
|
|
if (dept.getRemoveId() != null) {
|
|
|
- orgs.removeIf(d -> d.getTreeShowPath().endsWith(dept.getId()+"-"));
|
|
|
+ orgs.removeIf(d -> d.getTreeShowPath().endsWith(dept.getId() + "-"));
|
|
|
}
|
|
|
return generateTree(orgs, sysOrg);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取指定机构类型及其上级机构
|
|
|
+ * 获取用户机构下的指定机构类型及其上级机构
|
|
|
+ *
|
|
|
* @param orgType
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<SysOrgVO> selectTreeByOrgType(OrgTypeEnum orgType) {
|
|
|
+ public List<SysOrgVO> selectTreeByOrgType(Boolean includeUp, OrgTypeEnum orgType) {
|
|
|
+ String path="";
|
|
|
SysOrg sysOrg = getLoginUserOrg();
|
|
|
- List<SysOrgVO> hangshelist = getWholeTreeInCache(sysOrg.getPath(),orgType);
|
|
|
+ path=sysOrg.getPath();
|
|
|
+ if(includeUp){
|
|
|
+ sysOrg=null;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysOrgVO> orglist = getWholePathInCache(path, orgType);
|
|
|
|
|
|
- return generateTree(hangshelist, sysOrg);
|
|
|
+ return generateTree(orglist, sysOrg);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -160,11 +167,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
sysOrg = getLoginUserOrg();
|
|
|
List<SysOrgVO> cacheList = getOrgCache();
|
|
|
List<SysOrgVO> orgs = new ArrayList<>();
|
|
|
- if(StringUtils.isNotEmpty(request.getExcludeOrgCode())){
|
|
|
+ if (StringUtils.isNotEmpty(request.getExcludeOrgCode())) {
|
|
|
final Optional<SysOrgVO> first = cacheList.stream().filter(x -> ObjectUtil.equal(x.getCode(), request.getExcludeOrgCode())).findFirst();
|
|
|
- if(first.isPresent())
|
|
|
- {
|
|
|
- excludeOrg=first.get();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ excludeOrg = first.get();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -186,9 +192,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
}
|
|
|
orgs.add(org);
|
|
|
}
|
|
|
- if(!StringUtils.isEmpty(request.getExcludeOrgName()))
|
|
|
- {
|
|
|
- orgs= excludeOrgByOrgName(orgs,request.getExcludeOrgName());
|
|
|
+ if (!StringUtils.isEmpty(request.getExcludeOrgName())) {
|
|
|
+ orgs = excludeOrgByOrgName(orgs, request.getExcludeOrgName());
|
|
|
}
|
|
|
|
|
|
return generateTree(orgs, sysOrg);
|
|
|
@@ -196,22 +201,20 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
|
|
|
/**
|
|
|
* 排除指定机构名称的机构以及该机构的下级机构
|
|
|
- * @param orgs 待排出机构列表
|
|
|
+ *
|
|
|
+ * @param orgs 待排出机构列表
|
|
|
* @param excludeOrgName 需排出机构的名称
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<SysOrgVO> excludeOrgByOrgName(List<SysOrgVO> orgs,String excludeOrgName)
|
|
|
- {
|
|
|
+ private List<SysOrgVO> excludeOrgByOrgName(List<SysOrgVO> orgs, String excludeOrgName) {
|
|
|
List<SysOrgVO> result = new ArrayList<>();
|
|
|
|
|
|
final List<SysOrgVO> excludeOrgList = orgs.stream().filter(x -> ObjectUtil.equal(x.getName(), excludeOrgName)).collect(Collectors.toList());
|
|
|
- if(ObjectUtil.isEmpty(excludeOrgList))
|
|
|
- {
|
|
|
+ if (ObjectUtil.isEmpty(excludeOrgList)) {
|
|
|
return orgs;
|
|
|
}
|
|
|
for (SysOrgVO org : orgs) {
|
|
|
- if(excludeOrgList.stream().anyMatch(e-> org.getPath().startsWith(e.getPath())))
|
|
|
- {
|
|
|
+ if (excludeOrgList.stream().anyMatch(e -> org.getPath().startsWith(e.getPath()))) {
|
|
|
continue;
|
|
|
}
|
|
|
result.add(org);
|
|
|
@@ -226,10 +229,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<SysOrgVO> getWholeTreeInCache(String path, OrgTypeEnum orgType) {
|
|
|
+ public List<SysOrgVO> getWholePathInCache(String path, OrgTypeEnum orgType) {
|
|
|
List<SysOrgVO> cacheList = getOrgCache();
|
|
|
List<SysOrgVO> hangshelist = cacheList.stream().filter(c -> ObjectUtil.equal(c.getType(), orgType.getCode())
|
|
|
- && ObjectUtil.isNotEmpty(c.getPath()) && c.getPath().startsWith(path))
|
|
|
+ && ObjectUtil.isNotEmpty(c.getPath()) && c.getPath().startsWith(path))
|
|
|
.collect(Collectors.toList());
|
|
|
Set<Long> hangsheSet = hangshelist.stream().map(o -> o.getId()).collect(Collectors.toSet());
|
|
|
Set<Long> parentIds = new HashSet<>();
|
|
|
@@ -243,7 +246,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
});
|
|
|
});
|
|
|
hangshelist.addAll(cacheList.stream()
|
|
|
- .filter(o -> parentIds.contains(o.getId()) && ObjectUtil.isNotEmpty(o.getPath()) && o.getPath().startsWith(path))
|
|
|
+ .filter(o -> parentIds.contains(o.getId()))
|
|
|
.collect(Collectors.toList()));
|
|
|
|
|
|
return hangshelist;
|
|
|
@@ -257,7 +260,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
*/
|
|
|
@Override
|
|
|
public List<SysOrgVO> hangsheWholePathTree(Long orgId) {
|
|
|
- List<SysOrgVO> orgs = getWholeTreeInCache("", OrgTypeEnum.HANG_SHE);
|
|
|
+ List<SysOrgVO> orgs = getWholePathInCache("", OrgTypeEnum.HANG_SHE);
|
|
|
Map<Long, SysOrgVO> orgMap = orgs.stream().collect(Collectors.toMap(o -> o.getId(), o -> o));
|
|
|
if (!orgMap.containsKey(orgId)) {
|
|
|
return new ArrayList<>();
|
|
|
@@ -274,73 +277,65 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public List<SysOrgVO> orgWholePathTree(SysOrgTreeRequestDto request) {
|
|
|
SysOrgVO sysOrg = null;
|
|
|
Long orgId = null;
|
|
|
- LoginUser loginUser=SecurityUtils.getLoginUser();
|
|
|
- if(ObjectUtil.isEmpty(request) || ObjectUtil.isEmpty(request.getOrgId()))
|
|
|
- {
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
+ if (ObjectUtil.isEmpty(request) || ObjectUtil.isEmpty(request.getOrgId())) {
|
|
|
orgId = loginUser.getOrgId();
|
|
|
- }
|
|
|
- else {
|
|
|
- orgId =request.getOrgId();
|
|
|
+ } else {
|
|
|
+ orgId = request.getOrgId();
|
|
|
}
|
|
|
|
|
|
List<SysOrgVO> cacheList = getOrgCache();
|
|
|
- if(ObjectUtil.isNotEmpty(orgId)){
|
|
|
+ if (ObjectUtil.isNotEmpty(orgId)) {
|
|
|
Long finalOrgId = orgId;
|
|
|
final Optional<SysOrgVO> first = cacheList.stream().filter(x -> ObjectUtil.equal(x.getId(), finalOrgId)).findFirst();
|
|
|
- if(first.isPresent())
|
|
|
- {
|
|
|
- sysOrg=first.get();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ sysOrg = first.get();
|
|
|
}
|
|
|
}
|
|
|
- if(ObjectUtil.isEmpty(sysOrg))
|
|
|
- {
|
|
|
+ if (ObjectUtil.isEmpty(sysOrg)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
- final List<SysOrgVO> orgList = getWholePathTreeOrgFromCache(sysOrg, cacheList,request.getIncludeSub(),request.getExcludeOrgName());
|
|
|
+ final List<SysOrgVO> orgList = getWholePathTreeOrgFromCache(sysOrg, cacheList, request.getIncludeSub(), request.getExcludeOrgName());
|
|
|
|
|
|
- return generateTree(orgList,null);
|
|
|
+ return generateTree(orgList, null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据业务机构path 获取指定机构的所有下级以及所有直接上级机构
|
|
|
+ *
|
|
|
* @param orgVO
|
|
|
* @param cacheList
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<SysOrgVO> getWholePathTreeOrgFromCache(SysOrgVO orgVO,List<SysOrgVO> cacheList,Boolean includeSub,String excludeOrgName) {
|
|
|
- List<SysOrgVO> selfAndAllChildOrglist =null;
|
|
|
- if(includeSub)
|
|
|
- {
|
|
|
- selfAndAllChildOrglist=cacheList.stream().filter(c ->ObjectUtil.isNotEmpty(c.getPath()) && c.getPath().startsWith(orgVO.getPath())).collect(Collectors.toList());
|
|
|
- }
|
|
|
- else {
|
|
|
- selfAndAllChildOrglist=cacheList.stream().filter(c ->ObjectUtil.equal(orgVO.getId(),c.getId())).collect(Collectors.toList());
|
|
|
+ public List<SysOrgVO> getWholePathTreeOrgFromCache(SysOrgVO orgVO, List<SysOrgVO> cacheList, Boolean includeSub, String excludeOrgName) {
|
|
|
+ List<SysOrgVO> selfAndAllChildOrglist = null;
|
|
|
+ if (includeSub) {
|
|
|
+ selfAndAllChildOrglist = cacheList.stream().filter(c -> ObjectUtil.isNotEmpty(c.getPath()) && c.getPath().startsWith(orgVO.getPath())).collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ selfAndAllChildOrglist = cacheList.stream().filter(c -> ObjectUtil.equal(orgVO.getId(), c.getId())).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
Set<Long> parentIds = new HashSet<>();
|
|
|
- Arrays.stream(orgVO.getPath().split("-")).map(p -> Long.parseLong(p))
|
|
|
- .collect(Collectors.toList())
|
|
|
- .forEach(id -> {
|
|
|
- if (!ObjectUtil.equal(orgVO.getId(),id)) {
|
|
|
- parentIds.add(id);
|
|
|
- }
|
|
|
- });
|
|
|
+ Arrays.stream(orgVO.getPath().split("-")).map(p -> Long.parseLong(p))
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ .forEach(id -> {
|
|
|
+ if (!ObjectUtil.equal(orgVO.getId(), id)) {
|
|
|
+ parentIds.add(id);
|
|
|
+ }
|
|
|
+ });
|
|
|
selfAndAllChildOrglist.addAll(cacheList.stream()
|
|
|
.filter(o -> parentIds.contains(o.getId()))
|
|
|
.collect(Collectors.toList()));
|
|
|
|
|
|
// 排除指定机构名称的机构以及该机构的下级机构
|
|
|
- if(StringUtils.isNotEmpty(excludeOrgName))
|
|
|
- {
|
|
|
- selfAndAllChildOrglist= excludeOrgByOrgName(selfAndAllChildOrglist,excludeOrgName);
|
|
|
+ if (StringUtils.isNotEmpty(excludeOrgName)) {
|
|
|
+ selfAndAllChildOrglist = excludeOrgByOrgName(selfAndAllChildOrglist, excludeOrgName);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -378,9 +373,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
List<Long> parentIds = orgs.stream().filter(x -> !orgs.stream().anyMatch(y -> x.getTreeShowParentId().equals(y.getId()))).map(SysOrgVO::getTreeShowParentId).collect(Collectors.toList());
|
|
|
if (parentIds.size() == 0) {
|
|
|
parentIds.add(parentId);
|
|
|
- }
|
|
|
- else {
|
|
|
- parentIds=parentIds.stream().distinct().collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ parentIds = parentIds.stream().distinct().collect(Collectors.toList());
|
|
|
}
|
|
|
final Map<Long, List<SysOrgVO>> collect = orgs.stream().collect(Collectors.groupingBy(SysOrgVO::getTreeShowParentId));
|
|
|
List<SysOrgVO> result = new ArrayList<>();
|