|
|
@ -29,6 +29,7 @@ import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.TreeUtils; |
|
|
|
import com.elink.esua.epdc.dao.SysDeptDao; |
|
|
|
import com.elink.esua.epdc.dto.*; |
|
|
|
import com.elink.esua.epdc.dto.epdc.DeptTreeWithTypeKeyDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.GridForLeaderRegisterDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.UserSysDeptInfoFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.result.UserSysDeptInfoResultDTO; |
|
|
@ -606,6 +607,62 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
redisUtils.set(RedisKeys.getAllDeptOptionKey(), option); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void packgeAllDeptOptionWithTypeKey() { |
|
|
|
List<DeptTreeWithTypeKeyDTO> deptList = baseDao.selectListDeptTreeWithTypeKey(); |
|
|
|
JSONObject node; |
|
|
|
JSONArray headNodes = new JSONArray(); |
|
|
|
for (DeptTreeWithTypeKeyDTO deptItemDto : deptList) { |
|
|
|
if (deptItemDto.getPid().longValue() == NumConstant.ZERO_L) { |
|
|
|
node = new JSONObject(); |
|
|
|
node.put("value", deptItemDto.getId()); |
|
|
|
node.put("label", deptItemDto.getName()); |
|
|
|
node.put("typeKey", deptItemDto.getTypeKey()); |
|
|
|
headNodes.add(node); |
|
|
|
} |
|
|
|
} |
|
|
|
// 用于存放所有父级节点
|
|
|
|
JSONArray parent; |
|
|
|
parent = headNodes; |
|
|
|
// 用于存放所有子级节点
|
|
|
|
JSONArray allChildren = new JSONArray(); |
|
|
|
JSONArray children; |
|
|
|
// 用于存放单个子级节点
|
|
|
|
JSONObject childNode; |
|
|
|
// 存放其余未处理的类别(节点)
|
|
|
|
List<DeptTreeWithTypeKeyDTO> others = this.getOtherDeptWithTypeKey(deptList, parent); |
|
|
|
|
|
|
|
while (!others.isEmpty()) { |
|
|
|
for (int i = 0; i < parent.size(); i++) { |
|
|
|
node = parent.getJSONObject(i); |
|
|
|
children = new JSONArray(); |
|
|
|
for (DeptTreeWithTypeKeyDTO categoryTreeDto : others) { |
|
|
|
if (categoryTreeDto.getPid().equals(node.get("value"))) { |
|
|
|
childNode = new JSONObject(); |
|
|
|
childNode.put("value", categoryTreeDto.getId()); |
|
|
|
childNode.put("label", categoryTreeDto.getName()); |
|
|
|
childNode.put("typeKey", categoryTreeDto.getTypeKey()); |
|
|
|
children.add(childNode); |
|
|
|
allChildren.add(childNode); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!children.isEmpty()) { |
|
|
|
node.put("children", children); |
|
|
|
} |
|
|
|
} |
|
|
|
parent = allChildren; |
|
|
|
|
|
|
|
others = this.getOtherDeptWithTypeKey(others, parent); |
|
|
|
|
|
|
|
} |
|
|
|
//存放到redis中
|
|
|
|
List<JSONArray> cache = Lists.newArrayList(); |
|
|
|
cache.add(headNodes); |
|
|
|
DeptOption option = new DeptOption(); |
|
|
|
option.setOptions(cache.get(0)); |
|
|
|
redisUtils.set(RedisKeys.getAllDeptOptionKeyWithTypeKey(), option); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<DeptTreeDTO> getOtherDept(List<DeptTreeDTO> deptList, JSONArray parent) { |
|
|
|
List<Long> already = Lists.newArrayList(); |
|
|
@ -623,6 +680,22 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
} |
|
|
|
return others; |
|
|
|
} |
|
|
|
List<DeptTreeWithTypeKeyDTO> getOtherDeptWithTypeKey(List<DeptTreeWithTypeKeyDTO> deptList, JSONArray parent) { |
|
|
|
List<Long> already = Lists.newArrayList(); |
|
|
|
for (int i = 0; i < parent.size(); i++) { |
|
|
|
already.add((Long) parent.getJSONObject(i).get("value")); |
|
|
|
} |
|
|
|
|
|
|
|
List<DeptTreeWithTypeKeyDTO> others = Lists.newArrayList(); |
|
|
|
|
|
|
|
for (DeptTreeWithTypeKeyDTO categoryTreeDto : deptList) { |
|
|
|
Long categoryTreeDtoId = categoryTreeDto.getId(); |
|
|
|
if (!already.contains(categoryTreeDtoId)) { |
|
|
|
others.add(categoryTreeDto); |
|
|
|
} |
|
|
|
} |
|
|
|
return others; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
@ -643,6 +716,17 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
return new Result<DeptOption>().ok((DeptOption) obj); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<DeptOption> getDeptTreeWithTypeKey() { |
|
|
|
String deptKey = RedisKeys.getAllDeptOptionKeyWithTypeKey(); |
|
|
|
Object obj = redisUtils.get(deptKey); |
|
|
|
if (null == obj) { |
|
|
|
this.packgeAllDeptOptionWithTypeKey(); |
|
|
|
obj = redisUtils.get(deptKey); |
|
|
|
} |
|
|
|
return new Result<DeptOption>().ok((DeptOption) obj); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param |
|
|
|
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.DeptOption> |
|
|
|