|
|
|
@ -35,6 +35,7 @@ import com.elink.esua.epdc.feign.GroupFeignClient; |
|
|
|
import com.elink.esua.epdc.service.SysDeptService; |
|
|
|
import com.elink.esua.epdc.service.SysUserService; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.google.common.collect.Maps; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -249,22 +250,30 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
if (null == deptId) { |
|
|
|
return new Result().error("参数格式异常"); |
|
|
|
} |
|
|
|
CompleteDeptDTO completeDept = this.baseDao.getCompleteDept(deptIdL); |
|
|
|
CompleteDeptDTO completeDept = this.baseDao.getParentAndAllDept(deptIdL); |
|
|
|
ParentAndAllDeptDTO parentAndAllDeptDTO = new ParentAndAllDeptDTO(); |
|
|
|
parentAndAllDeptDTO.setGrid(completeDept.getGrid()); |
|
|
|
parentAndAllDeptDTO.setGridId(completeDept.getGridId()); |
|
|
|
// 父所有部门(包含街道、社区)
|
|
|
|
String deptNames = (StringUtils.isNotEmpty(completeDept.getStreet()) ? completeDept.getStreet() : ""); |
|
|
|
deptNames += (StringUtils.isNotEmpty(completeDept.getCommunity()) ? "-"+completeDept.getCommunity() : ""); |
|
|
|
String deptIds = (completeDept.getStreetId()!=null && completeDept.getStreetId()!= 0 ? completeDept.getStreetId().toString() : ""); |
|
|
|
deptIds += (completeDept.getCommunityId()!=null && completeDept.getCommunityId()!= 0 ? ","+completeDept.getCommunityId().toString() : ""); |
|
|
|
parentAndAllDeptDTO.setParentDeptIds(deptIds); |
|
|
|
parentAndAllDeptDTO.setParentDeptNames(deptNames); |
|
|
|
// 所有部门(包含街道、社区、网格)
|
|
|
|
deptNames += (StringUtils.isNotEmpty(completeDept.getGrid()) ? "-"+completeDept.getGrid() : ""); |
|
|
|
deptIds += (completeDept.getGridId()!=null && completeDept.getGridId()!= 0 ? ","+completeDept.getGridId().toString() : ""); |
|
|
|
parentAndAllDeptDTO.setAllDeptIds(deptIds); |
|
|
|
parentAndAllDeptDTO.setAllDeptNames(deptNames); |
|
|
|
|
|
|
|
if(completeDept != null){ |
|
|
|
parentAndAllDeptDTO.setGrid(StringUtils.isNotEmpty(completeDept.getGrid()) ? completeDept.getGrid() : ""); |
|
|
|
parentAndAllDeptDTO.setGridId(completeDept.getGridId()!=null && completeDept.getGridId()!= 0 ? completeDept.getGridId() : null); |
|
|
|
// 父所有部门(包含街道、社区)
|
|
|
|
String deptNames = (StringUtils.isNotEmpty(completeDept.getDistrict()) ? completeDept.getDistrict() : ""); |
|
|
|
deptNames += (StringUtils.isNotEmpty(completeDept.getStreet()) ? "-"+completeDept.getStreet() : ""); |
|
|
|
deptNames += (StringUtils.isNotEmpty(completeDept.getCommunity()) ? "-"+completeDept.getCommunity() : ""); |
|
|
|
String deptIds = (completeDept.getDistrictId()!=null && completeDept.getDistrictId()!= 0 ? completeDept.getDistrictId().toString() : ""); |
|
|
|
deptIds += (completeDept.getStreetId()!=null && completeDept.getStreetId()!= 0 ? ","+ completeDept.getStreetId().toString() : ""); |
|
|
|
deptIds += (completeDept.getCommunityId()!=null && completeDept.getCommunityId()!= 0 ? ","+ completeDept.getCommunityId().toString() : ""); |
|
|
|
parentAndAllDeptDTO.setParentDeptIds(deptIds); |
|
|
|
parentAndAllDeptDTO.setParentDeptNames(deptNames); |
|
|
|
// 所有部门(包含街道、社区、网格)
|
|
|
|
deptNames += (StringUtils.isNotEmpty(completeDept.getGrid()) ? "-"+completeDept.getGrid() : ""); |
|
|
|
deptIds += (completeDept.getGridId()!=null && completeDept.getGridId()!= 0 ? ","+completeDept.getGridId().toString() : ""); |
|
|
|
parentAndAllDeptDTO.setAllDeptIds(deptIds); |
|
|
|
parentAndAllDeptDTO.setAllDeptNames(deptNames); |
|
|
|
} else { |
|
|
|
return new Result().error("部门Id错误"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new Result().ok(parentAndAllDeptDTO); |
|
|
|
} |
|
|
|
@ -329,7 +338,6 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
|
|
|
|
@Override |
|
|
|
public void packageUserDeptOption(Long userId) { |
|
|
|
|
|
|
|
UserDetail userDetail = userDetailRedis.get(userId); |
|
|
|
// 用户拥有的所有部门权限
|
|
|
|
List<Long> dataScopeDeptList = userDetail.getDeptIdList(); |
|
|
|
@ -341,16 +349,13 @@ 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(); |
|
|
|
// 一级节点 相当于市区,此处虽然组装,但并没有应用第一级节点
|
|
|
|
JSONArray NodeListLevel_1 = new JSONArray(); |
|
|
|
// 所有父级节点 此处为第一次获取,为顶级节点,相当于市区
|
|
|
|
JSONArray parentNodeArray = new JSONArray(); |
|
|
|
JSONObject node; |
|
|
|
for (int i = 0; i < headDepts.size(); i++) { |
|
|
|
// 父节点主键
|
|
|
|
@ -358,102 +363,93 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
parentDeptIdList.add(deptId); |
|
|
|
|
|
|
|
node = new JSONObject(); |
|
|
|
node.put(label, headDepts.get(i).getName()); |
|
|
|
node.put(value, String.valueOf(deptId)); |
|
|
|
NodeListLevel_1.add(node); |
|
|
|
node.put("label", headDepts.get(i).getName()); |
|
|
|
node.put("value", String.valueOf(deptId)); |
|
|
|
parentNodeArray.add(node); |
|
|
|
} |
|
|
|
// 用于存放 每次组装好的 某一级节点。页面只需展示三级,所以没有存放顶级节点(市区)
|
|
|
|
List<JSONArray> cache = Lists.newArrayList(); |
|
|
|
Map<String, Object> object; |
|
|
|
while (CollUtil.isNotEmpty(dataScopeDeptList)) { |
|
|
|
// 通过上级节点组装所有下级节点
|
|
|
|
object = this.packageChildrenNodeArray(parentNodeArray, dataScopeDeptList, parentDeptIdList); |
|
|
|
|
|
|
|
dataScopeDeptList = (List<Long>) object.get("scope"); |
|
|
|
parentDeptIdList = (List<Long>) object.get("pids"); |
|
|
|
|
|
|
|
parentNodeArray = (JSONArray) object.get("node"); |
|
|
|
cache.add(parentNodeArray); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询所有一级节点的下级部门,用于组装 二级节点
|
|
|
|
DeptOption option = new DeptOption(); |
|
|
|
option.setOptions(cache.get(0)); |
|
|
|
|
|
|
|
redisUtils.set(RedisKeys.getAdminUserDeptOptionKey(userId), option); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组装下级结构节点 |
|
|
|
* |
|
|
|
* @param allParentNode 所有的上级机构节点 |
|
|
|
* @param dataScopeDeptList 拥有数据权限的部门 |
|
|
|
* @param parentDeptIdList 上级部门id |
|
|
|
* @return java.util.Map<java.lang.String, java.lang.Object> |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/11/29 10:27 |
|
|
|
*/ |
|
|
|
private Map<String, Object> packageChildrenNodeArray(JSONArray allParentNode, List<Long> dataScopeDeptList, List<Long> parentDeptIdList) { |
|
|
|
|
|
|
|
List<SysDeptEntity> childDepts = baseDao.selectChildrenDeptNode(dataScopeDeptList, parentDeptIdList); |
|
|
|
|
|
|
|
parentDeptIdList = Lists.newArrayList(); |
|
|
|
|
|
|
|
// 所有二级节点 相当于街道
|
|
|
|
JSONArray NodeListLevel_2 = new JSONArray(); |
|
|
|
// 某个一级节点下所有的二级节点
|
|
|
|
// 用于存储所有子节点
|
|
|
|
JSONArray allChildrenNode = 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 (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); |
|
|
|
|
|
|
|
NodeListLevel_2.add(nodeChild); |
|
|
|
parentDeptIdList.add(deptId); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 单个 父节点
|
|
|
|
JSONObject nodeParent; |
|
|
|
Long deptId; |
|
|
|
|
|
|
|
// 查询所有二级节点的下级部门,用于组装 三级节点
|
|
|
|
childDepts = baseDao.selectChildrenDeptNode(dataScopeDeptList, parentDeptIdList); |
|
|
|
parentDeptIdList = Lists.newArrayList(); |
|
|
|
for (int i = 0; i < allParentNode.size(); i++) { |
|
|
|
|
|
|
|
// 所有三级节点 相当于社区
|
|
|
|
JSONArray NodeListLevel_3 = new JSONArray(); |
|
|
|
for (int i = 0; i < NodeListLevel_2.size(); i++) { |
|
|
|
// 一个父节点
|
|
|
|
nodeParent = NodeListLevel_2.getJSONObject(i); |
|
|
|
// 一个父节点的所有下级节点
|
|
|
|
nodeParent = allParentNode.getJSONObject(i); |
|
|
|
// 用于存储 一个父节点的所有下级节点
|
|
|
|
childrenNodeList = new JSONArray(); |
|
|
|
|
|
|
|
for (int j = 0; j < childDepts.size(); j++) { |
|
|
|
deptId = childDepts.get(j).getId(); |
|
|
|
|
|
|
|
if (nodeParent.get(value).equals(String.valueOf(childDepts.get(j).getPid()))) { |
|
|
|
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)); |
|
|
|
nodeChild.put("label", childDepts.get(j).getName()); |
|
|
|
nodeChild.put("value", String.valueOf(deptId)); |
|
|
|
childrenNodeList.add(nodeChild); |
|
|
|
|
|
|
|
NodeListLevel_3.add(nodeChild); |
|
|
|
allChildrenNode.add(nodeChild); |
|
|
|
parentDeptIdList.add(deptId); |
|
|
|
} |
|
|
|
} |
|
|
|
if(childrenNodeList.size() > 0){ |
|
|
|
nodeParent.put(children, childrenNodeList); |
|
|
|
if (childrenNodeList.size() > 0) { |
|
|
|
nodeParent.put("children", childrenNodeList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 查询所有三级节点的下级部门,用于组装 四级节点
|
|
|
|
childDepts = baseDao.selectChildrenDeptNode(dataScopeDeptList, parentDeptIdList); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < NodeListLevel_3.size(); i++) { |
|
|
|
// 父节点
|
|
|
|
nodeParent = NodeListLevel_3.getJSONObject(i); |
|
|
|
childrenNodeList = new JSONArray(); |
|
|
|
|
|
|
|
for (int j = 0; j < childDepts.size(); j++) { |
|
|
|
deptId = childDepts.get(j).getId(); |
|
|
|
|
|
|
|
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); |
|
|
|
List<Long> newDataScopeList = Lists.newArrayList(); |
|
|
|
for (int i = 0; i < dataScopeDeptList.size(); i++) { |
|
|
|
deptId = dataScopeDeptList.get(i); |
|
|
|
if (!parentDeptIdList.contains(deptId)) { |
|
|
|
newDataScopeList.add(deptId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
DeptOption option = new DeptOption(); |
|
|
|
option.setOptions(NodeListLevel_2); |
|
|
|
|
|
|
|
redisUtils.set(RedisKeys.getAdminUserDeptOptionKey(userId), option); |
|
|
|
dataScopeDeptList = newDataScopeList; |
|
|
|
Map<String, Object> result = Maps.newHashMap(); |
|
|
|
result.put("node", allChildrenNode); |
|
|
|
result.put("scope", dataScopeDeptList); |
|
|
|
result.put("pids", parentDeptIdList); |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|