|
|
@ -27,10 +27,13 @@ import org.dromara.system.domain.SysRole; |
|
|
import org.dromara.system.domain.SysUser; |
|
|
import org.dromara.system.domain.SysUser; |
|
|
import org.dromara.system.domain.bo.SysDeptBo; |
|
|
import org.dromara.system.domain.bo.SysDeptBo; |
|
|
import org.dromara.system.domain.vo.SysDeptVo; |
|
|
import org.dromara.system.domain.vo.SysDeptVo; |
|
|
|
|
|
import org.dromara.system.domain.vo.SysDictDataVo; |
|
|
import org.dromara.system.mapper.SysDeptMapper; |
|
|
import org.dromara.system.mapper.SysDeptMapper; |
|
|
import org.dromara.system.mapper.SysRoleMapper; |
|
|
import org.dromara.system.mapper.SysRoleMapper; |
|
|
import org.dromara.system.mapper.SysUserMapper; |
|
|
import org.dromara.system.mapper.SysUserMapper; |
|
|
import org.dromara.system.service.ISysDeptService; |
|
|
import org.dromara.system.service.ISysDeptService; |
|
|
|
|
|
import org.dromara.system.service.ISysDictTypeService; |
|
|
|
|
|
import org.dromara.system.service.ISysDictTypeService; |
|
|
import org.springframework.cache.annotation.CacheEvict; |
|
|
import org.springframework.cache.annotation.CacheEvict; |
|
|
import org.springframework.cache.annotation.Cacheable; |
|
|
import org.springframework.cache.annotation.Cacheable; |
|
|
import org.springframework.cache.annotation.Caching; |
|
|
import org.springframework.cache.annotation.Caching; |
|
|
@ -39,6 +42,8 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.function.Function; |
|
|
import java.util.function.Function; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 部门管理 服务实现 |
|
|
* 部门管理 服务实现 |
|
|
@ -52,6 +57,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { |
|
|
private final SysDeptMapper baseMapper; |
|
|
private final SysDeptMapper baseMapper; |
|
|
private final SysRoleMapper roleMapper; |
|
|
private final SysRoleMapper roleMapper; |
|
|
private final SysUserMapper userMapper; |
|
|
private final SysUserMapper userMapper; |
|
|
|
|
|
private final ISysDictTypeService dictTypeService; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 分页查询部门管理数据 |
|
|
* 分页查询部门管理数据 |
|
|
@ -105,6 +111,108 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { |
|
|
return buildDeptTreeSelect(depts); |
|
|
return buildDeptTreeSelect(depts); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 查询部门树结构信息(按zone重建,包含深圳市根节点和区市直层级) |
|
|
|
|
|
* <p> |
|
|
|
|
|
* 树结构:深圳市 → 市直/区 → 各部门,区下设区直虚拟节点 |
|
|
|
|
|
* </p> |
|
|
|
|
|
* |
|
|
|
|
|
* @param bo 部门信息 |
|
|
|
|
|
* @param zones 区域标识列表 |
|
|
|
|
|
* @return 部门树信息集合 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public List<Tree<String>> selectDeptTreeListReBuildByZone(SysDeptBo bo, List<Integer> zones) { |
|
|
|
|
|
LambdaQueryWrapper<SysDept> lqw = buildQueryWrapper(bo); |
|
|
|
|
|
List<SysDeptVo> depts = new ArrayList<>(baseMapper.selectDeptList(lqw, zones)); |
|
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(depts)) { |
|
|
|
|
|
return CollUtil.newArrayList(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 1. 添加深圳市根节点(插入到头部,确保排在第一位)
|
|
|
|
|
|
SysDeptVo rootNode = new SysDeptVo(); |
|
|
|
|
|
rootNode.setDeptId("0"); |
|
|
|
|
|
rootNode.setParentId("_root_"); |
|
|
|
|
|
rootNode.setDeptName("深圳市"); |
|
|
|
|
|
rootNode.setOrderNum(0); |
|
|
|
|
|
rootNode.setStatus(SystemConstants.NORMAL); |
|
|
|
|
|
depts.add(0, rootNode); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 获取字典数据 role_tree_zone
|
|
|
|
|
|
List<SysDictDataVo> dictDataList = dictTypeService.selectDictDataByType("role_tree_zone"); |
|
|
|
|
|
if (CollUtil.isNotEmpty(dictDataList)) { |
|
|
|
|
|
// 2.1 添加市直(1)和区(2)虚拟节点,父节点为深圳市
|
|
|
|
|
|
List<SysDeptVo> zoneNodes = dictDataList.stream() |
|
|
|
|
|
.filter(item -> "1".equals(item.getDictValue()) || "2".equals(item.getDictValue())) |
|
|
|
|
|
.map(item -> { |
|
|
|
|
|
SysDeptVo node = new SysDeptVo(); |
|
|
|
|
|
node.setDeptId(item.getDictValue()); |
|
|
|
|
|
node.setParentId("0"); |
|
|
|
|
|
node.setDeptName(item.getDictLabel()); |
|
|
|
|
|
node.setOrderNum(Integer.parseInt(item.getDictValue())); |
|
|
|
|
|
node.setStatus(SystemConstants.NORMAL); |
|
|
|
|
|
return node; |
|
|
|
|
|
}) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
depts.addAll(zoneNodes); |
|
|
|
|
|
|
|
|
|
|
|
// 3. 绑定部门到市直/区节点
|
|
|
|
|
|
// zone=1/2 → 父节点设为对应zone值;zone=15/16 → 父节点设为市直("1")
|
|
|
|
|
|
depts.forEach(d -> { |
|
|
|
|
|
if (Objects.equals(d.getZone(), 1) || Objects.equals(d.getZone(), 2)) { |
|
|
|
|
|
d.setParentId(String.valueOf(d.getZone())); |
|
|
|
|
|
} |
|
|
|
|
|
if (Objects.equals(d.getZone(), 15) || Objects.equals(d.getZone(), 16)) { |
|
|
|
|
|
d.setParentId("1"); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 4. 收集区(zone=2)的 id->name 映射
|
|
|
|
|
|
Map<String, String> districtMap = depts.stream() |
|
|
|
|
|
.filter(d -> Objects.equals(d.getZone(), 2)) |
|
|
|
|
|
.collect(Collectors.toMap(SysDeptVo::getDeptId, SysDeptVo::getDeptName)); |
|
|
|
|
|
|
|
|
|
|
|
// 收集zone=3/5/6的部门ID(用于判断父部门是否也是区直类型)
|
|
|
|
|
|
List<String> checkDeptIds = depts.stream() |
|
|
|
|
|
.filter(d -> Objects.equals(d.getZone(), 3) || Objects.equals(d.getZone(), 5) || Objects.equals(d.getZone(), 6)) |
|
|
|
|
|
.map(SysDeptVo::getDeptId) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
// 5. 为每个区创建“区直”虚拟节点,并将zone=3/5/6的部门挂到对应区直下
|
|
|
|
|
|
List<SysDeptVo> finalDepts = depts; |
|
|
|
|
|
districtMap.forEach((pid, districtName) -> { |
|
|
|
|
|
// 创建区直虚拟节点
|
|
|
|
|
|
SysDeptVo quzhiNode = new SysDeptVo(); |
|
|
|
|
|
quzhiNode.setDeptId(pid + "3"); |
|
|
|
|
|
quzhiNode.setParentId(pid); |
|
|
|
|
|
quzhiNode.setDeptName("区直"); |
|
|
|
|
|
quzhiNode.setOrderNum(0); |
|
|
|
|
|
quzhiNode.setStatus(SystemConstants.NORMAL); |
|
|
|
|
|
finalDepts.add(quzhiNode); |
|
|
|
|
|
|
|
|
|
|
|
// 将zone=3/5/6的部门挂到对应区直节点下
|
|
|
|
|
|
for (SysDeptVo dept : finalDepts) { |
|
|
|
|
|
if (Objects.equals(dept.getZone(), 3) || Objects.equals(dept.getZone(), 6) || Objects.equals(dept.getZone(), 5)) { |
|
|
|
|
|
if (checkDeptIds.contains(dept.getParentId())) { |
|
|
|
|
|
// 父部门也是区直类型(zone=3/5/6),保持原有父子关系
|
|
|
|
|
|
} else if (StringUtils.isNotEmpty(dept.getAncestors()) && dept.getAncestors().contains(pid)) { |
|
|
|
|
|
dept.setParentId(quzhiNode.getDeptId()); |
|
|
|
|
|
} else if (StringUtils.isEmpty(dept.getAncestors()) |
|
|
|
|
|
|| districtMap.values().stream().noneMatch(v -> dept.getAncestors().contains(v))) { |
|
|
|
|
|
if (dept.getDeptName() != null && districtName.length() >= 2 |
|
|
|
|
|
&& dept.getDeptName().contains(districtName.substring(0, 2))) { |
|
|
|
|
|
dept.setParentId(quzhiNode.getDeptId()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return buildDeptTreeSelect(depts); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private LambdaQueryWrapper<SysDept> buildQueryWrapper(SysDeptBo bo) { |
|
|
private LambdaQueryWrapper<SysDept> buildQueryWrapper(SysDeptBo bo) { |
|
|
Map<String, Object> params = bo.getParams(); |
|
|
Map<String, Object> params = bo.getParams(); |
|
|
LambdaQueryWrapper<SysDept> lqw = Wrappers.lambdaQuery(); |
|
|
LambdaQueryWrapper<SysDept> lqw = Wrappers.lambdaQuery(); |
|
|
@ -116,7 +224,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { |
|
|
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysDept::getStatus, bo.getStatus()); |
|
|
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysDept::getStatus, bo.getStatus()); |
|
|
lqw.between(params.get("beginTime") != null && params.get("endTime") != null, |
|
|
lqw.between(params.get("beginTime") != null && params.get("endTime") != null, |
|
|
SysDept::getCreateTime, params.get("beginTime"), params.get("endTime")); |
|
|
SysDept::getCreateTime, params.get("beginTime"), params.get("endTime")); |
|
|
lqw.orderByAsc(SysDept::getAncestors); |
|
|
//lqw.orderByAsc(SysDept::getAncestors);
|
|
|
lqw.orderByAsc(SysDept::getParentId); |
|
|
lqw.orderByAsc(SysDept::getParentId); |
|
|
lqw.orderByAsc(SysDept::getOrderNum); |
|
|
lqw.orderByAsc(SysDept::getOrderNum); |
|
|
lqw.orderByAsc(SysDept::getDeptId); |
|
|
lqw.orderByAsc(SysDept::getDeptId); |
|
|
@ -141,7 +249,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { |
|
|
if (CollUtil.isEmpty(depts)) { |
|
|
if (CollUtil.isEmpty(depts)) { |
|
|
return CollUtil.newArrayList(); |
|
|
return CollUtil.newArrayList(); |
|
|
} |
|
|
} |
|
|
return TreeBuildUtils.buildMultiRoot( |
|
|
return TreeBuildUtils.buildMultiRootUseLinkedHashSet( |
|
|
depts, |
|
|
depts, |
|
|
SysDeptVo::getDeptId, |
|
|
SysDeptVo::getDeptId, |
|
|
SysDeptVo::getParentId, |
|
|
SysDeptVo::getParentId, |
|
|
|