|
|
@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.constant.Constants;
|
|
|
+import com.xunmei.common.core.domain.OrgTreeReq;
|
|
|
+import com.xunmei.common.core.domain.OrgTreeResp;
|
|
|
import com.xunmei.common.core.exception.ServiceException;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
@@ -72,7 +74,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
// org.setParentId(null);
|
|
|
//查询条件
|
|
|
// QueryWrapper<SysOrg> query = new QueryWrapper<>(org);
|
|
|
- if(sysOrg!=null) {
|
|
|
+ if (sysOrg != null) {
|
|
|
//下穿
|
|
|
if (org.getCheckSub()) {
|
|
|
org.setParentId(null);
|
|
|
@@ -119,7 +121,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
|
|
|
@Override
|
|
|
public List<SysOrg> listByTypes(Long topId, List<String> types) {
|
|
|
- List<SysOrg> top = sysOrgMapper.selectList(new LambdaQueryWrapper<SysOrg>().eq(SysOrg::getId,topId).select(SysOrg::getPath));
|
|
|
+ List<SysOrg> top = sysOrgMapper.selectList(new LambdaQueryWrapper<SysOrg>().eq(SysOrg::getId, topId).select(SysOrg::getPath));
|
|
|
if (CollectionUtil.isEmpty(top)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
@@ -132,14 +134,14 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<SysOrg> listByParentIdAndType(Long parentId, Integer type,String path) {
|
|
|
- QueryWrapper queryWrapper=new QueryWrapper();
|
|
|
- queryWrapper.eq("type",type);
|
|
|
- if (null!=parentId){
|
|
|
- queryWrapper.eq("parent_id",parentId);
|
|
|
+ public List<SysOrg> listByParentIdAndType(Long parentId, Integer type, String path) {
|
|
|
+ QueryWrapper queryWrapper = new QueryWrapper();
|
|
|
+ queryWrapper.eq("type", type);
|
|
|
+ if (null != parentId) {
|
|
|
+ queryWrapper.eq("parent_id", parentId);
|
|
|
}
|
|
|
- queryWrapper.likeRight("path",path);
|
|
|
- queryWrapper.eq("deleted",0);
|
|
|
+ queryWrapper.likeRight("path", path);
|
|
|
+ queryWrapper.eq("deleted", 0);
|
|
|
List list = baseMapper.selectList(queryWrapper);
|
|
|
return list;
|
|
|
}
|
|
|
@@ -228,7 +230,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
LambdaQueryWrapper<SysOrg> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(SysOrg::getParentId, orgId);
|
|
|
List<SysOrg> selectList = sysOrgMapper.selectList(wrapper);
|
|
|
- if (selectList.size()>0){
|
|
|
+ if (selectList.size() > 0) {
|
|
|
return selectList.get(0);
|
|
|
}
|
|
|
return null;
|
|
|
@@ -243,9 +245,9 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<SysOrg> selectByOrgPathAndOrgType(String orgPath,Integer orgType) {
|
|
|
+ public List<SysOrg> selectByOrgPathAndOrgType(String orgPath, Integer orgType) {
|
|
|
LambdaQueryWrapper<SysOrg> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.likeRight(SysOrg::getPath,orgPath);
|
|
|
+ wrapper.likeRight(SysOrg::getPath, orgPath);
|
|
|
wrapper.eq(SysOrg::getType, orgType);
|
|
|
wrapper.eq(SysOrg::getDeleted, 0);
|
|
|
return sysOrgMapper.selectList(wrapper);
|
|
|
@@ -260,10 +262,12 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
public List<Long> selectOrgTypeByIdList(List<Long> execOrgIdList) {
|
|
|
return sysOrgMapper.selectOrgTypeByIdList(execOrgIdList);
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public List<SysOrg> findByOrgTypeAndParent(Integer orgType, String path) {
|
|
|
return sysOrgMapper.findByOrgTypeAndParent(orgType, path);
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public List<SysOrg> selectDeptTreeList(SysOrg dept) {
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
@@ -293,7 +297,6 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void clearOrgCache() {
|
|
|
RedisUtils.deleteObject(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
@@ -311,9 +314,9 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
//修改前的原始机构对象
|
|
|
final SysOrg originalOrg = getById(org.getId());
|
|
|
//仅系统新增的机构可以修改层级,同步到系统的机构不允许修改机构层级
|
|
|
- if(ObjectUtil.equal(originalOrg.getSource(),0)) {
|
|
|
+ if (ObjectUtil.equal(originalOrg.getSource(), 0)) {
|
|
|
//父级机构发生变化后,修改机构path ,以及下级机构path
|
|
|
- if(!ObjectUtil.equal(originalOrg.getParentId(),org.getParentId())){
|
|
|
+ if (!ObjectUtil.equal(originalOrg.getParentId(), org.getParentId())) {
|
|
|
//获取选择的父机构数据
|
|
|
SysOrg parentOrg = getById(org.getParentId());
|
|
|
//更新机构对应的业务path
|
|
|
@@ -323,7 +326,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
org.setTreeShowParentId(parentOrg.getId());
|
|
|
|
|
|
//ToDo 刷新当前机构下所有子机构 path
|
|
|
- List<SysOrg> allChildOrgList= reSetOrgAllChildOrgPath(org,originalOrg);
|
|
|
+ List<SysOrg> allChildOrgList = reSetOrgAllChildOrgPath(org, originalOrg);
|
|
|
this.saveOrUpdateBatch(allChildOrgList);
|
|
|
}
|
|
|
}
|
|
|
@@ -359,34 +362,30 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
return rel;
|
|
|
}
|
|
|
|
|
|
- private List<SysOrg> getAllChildOrgList(String path)
|
|
|
- {
|
|
|
+ private List<SysOrg> getAllChildOrgList(String path) {
|
|
|
return sysOrgMapper.selectList(new LambdaQueryWrapper<SysOrg>()
|
|
|
.likeRight(SysOrg::getPath, path)
|
|
|
.eq(SysOrg::getDeleted, 0));
|
|
|
}
|
|
|
|
|
|
- private List<SysOrg> reSetOrgAllChildOrgPath(SysOrg newOrg,SysOrg originalOrg)
|
|
|
- {
|
|
|
+ private List<SysOrg> reSetOrgAllChildOrgPath(SysOrg newOrg, SysOrg originalOrg) {
|
|
|
final List<SysOrg> allChildOrgList = getAllChildOrgList(originalOrg.getPath());
|
|
|
- if(ObjectUtil.isEmpty(allChildOrgList))
|
|
|
- {
|
|
|
- return allChildOrgList;
|
|
|
+ if (ObjectUtil.isEmpty(allChildOrgList)) {
|
|
|
+ return allChildOrgList;
|
|
|
}
|
|
|
- reSetOrgPath(newOrg,allChildOrgList);
|
|
|
+ reSetOrgPath(newOrg, allChildOrgList);
|
|
|
return allChildOrgList;
|
|
|
}
|
|
|
|
|
|
- private void reSetOrgPath(SysOrg parentOrg,List<SysOrg> allChildOrgList)
|
|
|
- {
|
|
|
+ private void reSetOrgPath(SysOrg parentOrg, List<SysOrg> allChildOrgList) {
|
|
|
final List<SysOrg> chillOrgList = allChildOrgList.stream().filter(child -> ObjectUtil.equal(parentOrg.getId(), child.getParentId())).collect(Collectors.toList());
|
|
|
- if(ObjectUtil.isEmpty(chillOrgList)){
|
|
|
+ if (ObjectUtil.isEmpty(chillOrgList)) {
|
|
|
return;
|
|
|
}
|
|
|
- chillOrgList.stream().forEach(child->{
|
|
|
- child.setPath(parentOrg.getPath()+child.getId()+"-");
|
|
|
- child.setTreeShowPath(parentOrg.getTreeShowPath()+child.getId()+"-");
|
|
|
- reSetOrgPath(child,allChildOrgList);
|
|
|
+ chillOrgList.stream().forEach(child -> {
|
|
|
+ child.setPath(parentOrg.getPath() + child.getId() + "-");
|
|
|
+ child.setTreeShowPath(parentOrg.getTreeShowPath() + child.getId() + "-");
|
|
|
+ reSetOrgPath(child, allChildOrgList);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -443,4 +442,39 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
public List<SysOrg> findAllOrg() {
|
|
|
return this.list();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrgTreeResp getOrgTreeReq(OrgTreeReq req) {
|
|
|
+ OrgTreeResp resp = new OrgTreeResp();
|
|
|
+ Long curOrgId = SecurityUtils.getLoginUser().getOrgId();
|
|
|
+ Long queryOrgId = req.getOrgId();
|
|
|
+ Map<Long, String> idPathMap = lambdaQuery().in(SysOrg::getId, Arrays.asList(curOrgId, queryOrgId))
|
|
|
+ .select(SysOrg::getId, SysOrg::getPath).list().stream().collect(Collectors.toMap(SysOrg::getId, SysOrg::getPath));
|
|
|
+ String curOrgPath = idPathMap.get(curOrgId);
|
|
|
+ String queryOrgPath = idPathMap.get(queryOrgId);
|
|
|
+ if (req.getCheckSub()) {
|
|
|
+ //1.如果当前机构是查询机构的上级机构,那么应查询当前机构到 查询机构之间的所有机构id,与当前机构的所有下级
|
|
|
+ if (curOrgPath.startsWith(queryOrgPath)){
|
|
|
+ List<Long> list = Arrays.stream(queryOrgPath.split("-")).map(Long::valueOf).collect(Collectors.toList());
|
|
|
+ //移除当前机构id,当前机构的数据以path字段查询
|
|
|
+ list.remove(curOrgId);
|
|
|
+ resp.setOrgIdList(list);
|
|
|
+ resp.setOrgPath(queryOrgPath);
|
|
|
+ }else {
|
|
|
+ resp.setOrgPath(curOrgPath);
|
|
|
+ }
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+ //不下穿查询:
|
|
|
+ if (queryOrgPath.startsWith(curOrgPath)){
|
|
|
+ //查询父机构: 返回当前机构至查询机构之间的所有机构id
|
|
|
+ List<Long> list = Arrays.stream(queryOrgPath.split("-")).map(Long::valueOf).collect(Collectors.toList());
|
|
|
+ resp.setOrgIdList(list);
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+ //查询的是下级机构,返回下级机构id
|
|
|
+ resp.setOrgId(queryOrgId);
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
}
|