|
|
@ -598,63 +598,7 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
public void packageAllUserDeptOption(Long userId) { |
|
|
|
packageDeptOptionByUser(userId, true); |
|
|
|
} |
|
|
|
private void packageWorkLogsUserDeptOption(Long userId) { |
|
|
|
packageWorkLogDeptOptionByUser(userId); |
|
|
|
} |
|
|
|
private void packageWorkLogDeptOptionByUser(Long userId) { |
|
|
|
UserDetail userDetail = userDetailRedis.get(userId); |
|
|
|
// 用户拥有的所有部门权限
|
|
|
|
List<Long> dataScopeDeptList = userDetail.getDeptIdList(); |
|
|
|
if (CollUtil.isEmpty(dataScopeDeptList)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
// 通过用户部门权限 获取第一级部门节点
|
|
|
|
List<SysDeptEntity> headDepts = baseDao.selectListHeadDeptNode(dataScopeDeptList); |
|
|
|
|
|
|
|
|
|
|
|
// 某个部门id 声明变量,方便操作数据
|
|
|
|
Long deptId; |
|
|
|
|
|
|
|
// 存放上级节点的主键,查询下级节点用
|
|
|
|
List<Long> parentDeptIdList = Lists.newArrayList(); |
|
|
|
// 所有父级节点 此处为第一次获取,为顶级节点,相当于市区
|
|
|
|
JSONArray parentNodeArray = new JSONArray(); |
|
|
|
JSONObject node; |
|
|
|
for (int i = 0; i < headDepts.size(); i++) { |
|
|
|
// 父节点主键
|
|
|
|
deptId = headDepts.get(i).getId(); |
|
|
|
parentDeptIdList.add(deptId); |
|
|
|
|
|
|
|
node = new JSONObject(); |
|
|
|
node.put("label", headDepts.get(i).getName()); |
|
|
|
node.put("typeKey", headDepts.get(i).getTypeKey()); |
|
|
|
node.put("value", String.valueOf(deptId)); |
|
|
|
parentNodeArray.add(node); |
|
|
|
} |
|
|
|
// 用于存放 每次组装好的 某一级节点。页面只需展示三级,所以没有存放顶级节点(市区)
|
|
|
|
List<JSONArray> cache = Lists.newArrayList(); |
|
|
|
//判断用户所属部门是否属于一级部门 属于则添加头
|
|
|
|
SysDeptEntity sysDeptEntity = baseDao.selectById(SecurityUser.getDeptId()); |
|
|
|
if(0L == sysDeptEntity.getPid()){ |
|
|
|
cache.add(parentNodeArray); |
|
|
|
} |
|
|
|
Map<String, Object> object; |
|
|
|
while (CollUtil.isNotEmpty(dataScopeDeptList) && CollUtil.isNotEmpty(parentDeptIdList)) { |
|
|
|
// 通过上级节点组装所有下级节点
|
|
|
|
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.getWorkLogUserDeptOptionKey(userId), option); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 组装部门层级结构 |
|
|
|
* |
|
|
@ -1242,10 +1186,10 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
@Override |
|
|
|
public Result<DeptOption> getUserDeptOptionByUserId(String userId) { |
|
|
|
Long realUserId = Long.parseLong(userId); |
|
|
|
String deptOptionKey = RedisKeys.getWorkLogUserDeptOptionKey(realUserId); |
|
|
|
String deptOptionKey = RedisKeys.getAdminUserDeptOptionKey(realUserId); |
|
|
|
Object obj = redisUtils.get(deptOptionKey); |
|
|
|
if (null == obj) { |
|
|
|
this.packageWorkLogsUserDeptOption(realUserId); |
|
|
|
this.packageUserDeptOption(realUserId); |
|
|
|
obj = redisUtils.get(deptOptionKey); |
|
|
|
} |
|
|
|
return new Result<DeptOption>().ok((DeptOption) obj); |
|
|
|