|
|
@@ -16,10 +16,12 @@ import com.xunmei.common.core.utils.StringUtils;
|
|
|
import com.xunmei.common.datascope.annotation.DataScope;
|
|
|
import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
+import com.xunmei.system.api.Eto.SysOrgTreeRequestDto;
|
|
|
import com.xunmei.system.api.domain.SysDept;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
import com.xunmei.system.api.domain.SysRole;
|
|
|
import com.xunmei.system.api.domain.SysUser;
|
|
|
+import com.xunmei.system.api.model.LoginUser;
|
|
|
import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
import com.xunmei.system.domain.vo.TreeSelect;
|
|
|
import com.xunmei.system.mapper.SysDeptMapper;
|
|
|
@@ -146,6 +148,42 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
return generateTree(hangshelist, sysOrg);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<SysOrgVO> selectBusinessTreeList(String excludeOrgCode) {
|
|
|
+ SysOrg sysOrg = null;
|
|
|
+ SysOrgVO excludeOrg = null;
|
|
|
+ sysOrg = getLoginUserOrg();
|
|
|
+ List<SysOrgVO> cacheList = getOrgCache();
|
|
|
+ List<SysOrgVO> orgs = new ArrayList<>();
|
|
|
+ if(StringUtils.isNotEmpty(excludeOrgCode)){
|
|
|
+ final Optional<SysOrgVO> first = cacheList.stream().filter(x -> ObjectUtil.equal(x.getCode(), excludeOrgCode)).findFirst();
|
|
|
+ if(first.isPresent())
|
|
|
+ {
|
|
|
+ excludeOrg=first.get();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (SysOrgVO org : cacheList) {
|
|
|
+ String path = org.getPath();
|
|
|
+ if (StringUtils.isEmpty(path) || !path.startsWith(sysOrg.getPath())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String treeShowPath = org.getTreeShowPath();
|
|
|
+ if (ObjectUtil.isNotEmpty(excludeOrg) && treeShowPath.startsWith(excludeOrg.getTreeShowPath())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(org.getShortName())) {
|
|
|
+ org.setShortName(org.getName());
|
|
|
+ }
|
|
|
+ if (org.getSort() == null) {
|
|
|
+ org.setSort(100000);
|
|
|
+ }
|
|
|
+ orgs.add(org);
|
|
|
+ }
|
|
|
+ return generateTree(orgs, sysOrg);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取缓存的行社及行社上级机构
|
|
|
*
|
|
|
@@ -200,6 +238,69 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
return orgVOS;
|
|
|
}
|
|
|
|
|
|
+ @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()))
|
|
|
+ {
|
|
|
+ orgId = loginUser.getOrgId();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ orgId =request.getOrgId();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysOrgVO> cacheList = getOrgCache();
|
|
|
+ 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(ObjectUtil.isEmpty(sysOrg))
|
|
|
+ {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ final List<SysOrgVO> orgList = getWholePathTreeOrgFromCache(sysOrg, cacheList,request.getIncludeSub());
|
|
|
+
|
|
|
+ return generateTree(orgList,null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据业务机构path 获取指定机构的所有下级以及所有直接上级机构
|
|
|
+ * @param orgVO
|
|
|
+ * @param cacheList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<SysOrgVO> getWholePathTreeOrgFromCache(SysOrgVO orgVO,List<SysOrgVO> cacheList,Boolean includeSub) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ selfAndAllChildOrglist.addAll(cacheList.stream()
|
|
|
+ .filter(o -> parentIds.contains(o.getId()))
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+
|
|
|
+ return selfAndAllChildOrglist;
|
|
|
+ }
|
|
|
+
|
|
|
private SysOrg getLoginUserOrg() {
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
SysOrg sysOrg = orgMapper.selectSysOrgByUserId(userId);
|
|
|
@@ -223,11 +324,12 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
|
|
|
private List<SysOrgVO> generateTree(List<SysOrgVO> orgs, SysOrg sysOrg) {
|
|
|
Long parentId = Constants.TOP_ORG_PARENT_ID;
|
|
|
- if (ObjectUtil.notEqual(Constants.TOP_ORG_PARENT_ID, sysOrg.getParentId())) {
|
|
|
+ if (ObjectUtil.isNotEmpty(sysOrg) && ObjectUtil.notEqual(Constants.TOP_ORG_PARENT_ID, sysOrg.getParentId())) {
|
|
|
parentId = sysOrg.getParentId();
|
|
|
}
|
|
|
|
|
|
- final List<Long> parentIds = orgs.stream().filter(x -> !orgs.stream().anyMatch(y -> x.getTreeShowParentId().equals(y.getParentId()))).map(SysOrgVO::getTreeShowParentId).collect(Collectors.toList());
|
|
|
+ // 顶级机构存在多个的情况
|
|
|
+ final 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);
|
|
|
}
|