|
|
@ -9,6 +9,8 @@ |
|
|
|
package com.elink.esua.epdc.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|
|
@ -313,8 +315,21 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
return new Result().ok(list); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<DeptOption> getUserDeptOption() { |
|
|
|
Long userId = SecurityUser.getUserId(); |
|
|
|
String deptOptionKey = RedisKeys.getAdminUserDeptOptionKey(userId); |
|
|
|
Object obj = redisUtils.get(deptOptionKey); |
|
|
|
if (null == obj) { |
|
|
|
this.packageUserDeptOption(userId); |
|
|
|
obj = redisUtils.get(deptOptionKey); |
|
|
|
} |
|
|
|
return new Result<DeptOption>().ok((DeptOption) obj); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void packageUserDeptOption(Long userId) { |
|
|
|
|
|
|
|
UserDetail userDetail = userDetailRedis.get(userId); |
|
|
|
// 用户拥有的所有部门权限
|
|
|
|
List<Long> dataScopeDeptList = userDetail.getDeptIdList(); |
|
|
@ -326,140 +341,119 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
if (CollUtil.isEmpty(headDepts)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
String label = "label"; |
|
|
|
String value = "value"; |
|
|
|
String children = "children"; |
|
|
|
// 某个部门id 声明变量,方便操作数据
|
|
|
|
Long deptId; |
|
|
|
|
|
|
|
// 存放上级节点的主键,查询下级节点用
|
|
|
|
List<Long> parentDeptIdList = Lists.newArrayList(); |
|
|
|
Long deptId; |
|
|
|
// 一级节点
|
|
|
|
List<DeptNode> headNodeList = Lists.newArrayList(); |
|
|
|
DeptNode<DeptNode> node; |
|
|
|
// 一级节点 相当于市区,此处虽然组装,但并没有应用第一级节点
|
|
|
|
JSONArray NodeListLevel_1 = new JSONArray(); |
|
|
|
JSONObject node; |
|
|
|
for (int i = 0; i < headDepts.size(); i++) { |
|
|
|
// 父节点主键
|
|
|
|
deptId = headDepts.get(i).getId(); |
|
|
|
parentDeptIdList.add(deptId); |
|
|
|
|
|
|
|
node = new DeptNode(); |
|
|
|
node.setLabel(headDepts.get(i).getName()); |
|
|
|
node.setValue(String.valueOf(deptId)); |
|
|
|
headNodeList.add(node); |
|
|
|
node = new JSONObject(); |
|
|
|
node.put(label, headDepts.get(i).getName()); |
|
|
|
node.put(value, String.valueOf(deptId)); |
|
|
|
NodeListLevel_1.add(node); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询所有一级节点的下级部门,用于组装 二级节点
|
|
|
|
List<SysDeptEntity> childDepts = baseDao.selectChildrenDeptNode(dataScopeDeptList, parentDeptIdList); |
|
|
|
if (CollUtil.isEmpty(childDepts)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
parentDeptIdList = Lists.newArrayList(); |
|
|
|
|
|
|
|
// 所有上级节点下 所有下级节点
|
|
|
|
List<DeptNode> allChildrenNodeList = Lists.newArrayList(); |
|
|
|
// 单个上级节点下 所有下级节点
|
|
|
|
List<DeptNode> childrenNodeList; |
|
|
|
// 单个 下级节点
|
|
|
|
DeptNode<DeptNode> childrenNode; |
|
|
|
// 单个 上级节点
|
|
|
|
DeptNode parentNode; |
|
|
|
|
|
|
|
for (int i = 0; i < headNodeList.size(); i++) { |
|
|
|
// 父节点
|
|
|
|
parentNode = headNodeList.get(i); |
|
|
|
childrenNodeList = Lists.newArrayList(); |
|
|
|
// 所有二级节点 相当于街道
|
|
|
|
JSONArray NodeListLevel_2 = new JSONArray(); |
|
|
|
// 某个一级节点下所有的二级节点
|
|
|
|
JSONArray childrenNodeList; |
|
|
|
// 单个 二级节点
|
|
|
|
JSONObject nodeChild; |
|
|
|
// 单个 一级节点
|
|
|
|
JSONObject nodeParent; |
|
|
|
|
|
|
|
for (int i = 0; i < NodeListLevel_1.size(); i++) { |
|
|
|
// 一个父节点
|
|
|
|
nodeParent = NodeListLevel_1.getJSONObject(i); |
|
|
|
// 一个父节点的所有下级节点
|
|
|
|
childrenNodeList = new JSONArray(); |
|
|
|
|
|
|
|
for (int j = 0; j < childDepts.size(); j++) { |
|
|
|
deptId = childDepts.get(j).getId(); |
|
|
|
|
|
|
|
if (parentNode.getValue().equals(String.valueOf(childDepts.get(j).getPid()))) { |
|
|
|
childrenNode = new DeptNode<>(); |
|
|
|
childrenNode.setLabel(childDepts.get(j).getName()); |
|
|
|
childrenNode.setValue(String.valueOf(deptId)); |
|
|
|
childrenNodeList.add(childrenNode); |
|
|
|
if (nodeParent.get(value).equals(String.valueOf(childDepts.get(j).getPid()))) { |
|
|
|
nodeChild = new JSONObject(); |
|
|
|
nodeChild.put(label, childDepts.get(j).getName()); |
|
|
|
nodeChild.put(value, String.valueOf(deptId)); |
|
|
|
childrenNodeList.add(nodeChild); |
|
|
|
|
|
|
|
allChildrenNodeList.add(childrenNode); |
|
|
|
NodeListLevel_2.add(nodeChild); |
|
|
|
parentDeptIdList.add(deptId); |
|
|
|
} |
|
|
|
} |
|
|
|
parentNode.setChildren(childrenNodeList); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询所有二级节点的下级部门,用于组装 三级节点
|
|
|
|
childDepts = baseDao.selectChildrenDeptNode(dataScopeDeptList, parentDeptIdList); |
|
|
|
|
|
|
|
|
|
|
|
parentDeptIdList = Lists.newArrayList(); |
|
|
|
|
|
|
|
// 所有上级节点下 所有下级节点
|
|
|
|
List<DeptNode<DeptNodeLast>> allChildrenBeforeLast = Lists.newArrayList(); |
|
|
|
// 单个上级节点下 所有下级节点
|
|
|
|
List<DeptNode> childrenBeforeLastList; |
|
|
|
|
|
|
|
DeptNode<DeptNodeLast> childrenBeforeLast; |
|
|
|
|
|
|
|
for (int i = 0; i < allChildrenNodeList.size(); i++) { |
|
|
|
// 父节点
|
|
|
|
parentNode = allChildrenNodeList.get(i); |
|
|
|
childrenBeforeLastList = Lists.newArrayList(); |
|
|
|
// 所有三级节点 相当于社区
|
|
|
|
JSONArray NodeListLevel_3 = new JSONArray(); |
|
|
|
for (int i = 0; i < NodeListLevel_2.size(); i++) { |
|
|
|
// 一个父节点
|
|
|
|
nodeParent = NodeListLevel_2.getJSONObject(i); |
|
|
|
// 一个父节点的所有下级节点
|
|
|
|
childrenNodeList = new JSONArray(); |
|
|
|
|
|
|
|
for (int j = 0; j < childDepts.size(); j++) { |
|
|
|
deptId = childDepts.get(j).getId(); |
|
|
|
|
|
|
|
if (parentNode.getValue().equals(String.valueOf(childDepts.get(j).getPid()))) { |
|
|
|
childrenBeforeLast = new DeptNode<>(); |
|
|
|
childrenBeforeLast.setLabel(childDepts.get(j).getName()); |
|
|
|
childrenBeforeLast.setValue(String.valueOf(deptId)); |
|
|
|
childrenBeforeLastList.add(childrenBeforeLast); |
|
|
|
if (nodeParent.get(value).equals(String.valueOf(childDepts.get(j).getPid()))) { |
|
|
|
nodeChild = new JSONObject(); |
|
|
|
nodeChild.put(label, childDepts.get(j).getName()); |
|
|
|
nodeChild.put(value, String.valueOf(deptId)); |
|
|
|
childrenNodeList.add(nodeChild); |
|
|
|
|
|
|
|
allChildrenBeforeLast.add(childrenBeforeLast); |
|
|
|
NodeListLevel_3.add(nodeChild); |
|
|
|
parentDeptIdList.add(deptId); |
|
|
|
} |
|
|
|
} |
|
|
|
parentNode.setChildren(childrenBeforeLastList); |
|
|
|
if(childrenNodeList.size() > 0){ |
|
|
|
nodeParent.put(children, childrenNodeList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 查询所有三级节点的下级部门,用于组装 四级节点
|
|
|
|
childDepts = baseDao.selectChildrenDeptNode(dataScopeDeptList, parentDeptIdList); |
|
|
|
if (CollUtil.isEmpty(childDepts)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 单个上级节点下 所有下级节点
|
|
|
|
List<DeptNodeLast> childrenLastList; |
|
|
|
|
|
|
|
DeptNodeLast childrenLast; |
|
|
|
|
|
|
|
for (int i = 0; i < allChildrenBeforeLast.size(); i++) { |
|
|
|
for (int i = 0; i < NodeListLevel_3.size(); i++) { |
|
|
|
// 父节点
|
|
|
|
parentNode = allChildrenBeforeLast.get(i); |
|
|
|
childrenLastList = Lists.newArrayList(); |
|
|
|
nodeParent = NodeListLevel_3.getJSONObject(i); |
|
|
|
childrenNodeList = new JSONArray(); |
|
|
|
|
|
|
|
for (int j = 0; j < childDepts.size(); j++) { |
|
|
|
deptId = childDepts.get(j).getId(); |
|
|
|
|
|
|
|
if (parentNode.getValue().equals(String.valueOf(childDepts.get(j).getPid()))) { |
|
|
|
childrenLast = new DeptNodeLast(); |
|
|
|
childrenLast.setLabel(childDepts.get(j).getName()); |
|
|
|
childrenLast.setValue(String.valueOf(deptId)); |
|
|
|
childrenLastList.add(childrenLast); |
|
|
|
if (nodeParent.get(value).equals(String.valueOf(childDepts.get(j).getPid()))) { |
|
|
|
nodeChild = new JSONObject(); |
|
|
|
nodeChild.put(label, childDepts.get(j).getName()); |
|
|
|
nodeChild.put(value, String.valueOf(deptId)); |
|
|
|
childrenNodeList.add(nodeChild); |
|
|
|
} |
|
|
|
} |
|
|
|
if(childrenNodeList.size() > 0){ |
|
|
|
nodeParent.put(children, childrenNodeList); |
|
|
|
} |
|
|
|
parentNode.setChildren(childrenLastList); |
|
|
|
} |
|
|
|
|
|
|
|
DeptOption option = new DeptOption(); |
|
|
|
option.setOptions(allChildrenNodeList); |
|
|
|
option.setOptions(NodeListLevel_2); |
|
|
|
|
|
|
|
redisUtils.set(RedisKeys.getAdminUserDeptOptionKey(userId), option); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<DeptOption> getUserDeptOption() { |
|
|
|
Long userId = SecurityUser.getUserId(); |
|
|
|
String deptOptionKey = RedisKeys.getAdminUserDeptOptionKey(userId); |
|
|
|
Object obj = redisUtils.get(deptOptionKey); |
|
|
|
if (null == obj) { |
|
|
|
this.packageUserDeptOption(userId); |
|
|
|
obj = redisUtils.get(deptOptionKey); |
|
|
|
} |
|
|
|
return new Result<DeptOption>().ok((DeptOption) obj); |
|
|
|
} |
|
|
|
} |
|
|
|