Browse Source

update

feature/yujt_vim
yujt 5 years ago
parent
commit
d0bf2217e5
  1. 53
      epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/SysDeptService.java
  2. 298
      epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/impl/SysDeptServiceImpl.java
  3. 2
      epdc-cloud-client-yushan
  4. 2
      epdc-cloud-commons-yushan

53
epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/SysDeptService.java

@ -156,17 +156,6 @@ public interface SysDeptService extends BaseService<SysDeptEntity> {
*/
void packageUserDeptOption(Long userId);
/**
* 从缓存中读取用户部门层级结构
*
* @return com.elink.esua.epdc.dto.DeptOption
* @author work@yujt.net.cn
* @date 2019/11/28 11:13
*/
DeptOption getUserDeptOption();
DeptOption getDeptAuthByUser();
List<DeptGridDTO> getGridAuthByUser();
/**
@ -214,14 +203,6 @@ public interface SysDeptService extends BaseService<SysDeptEntity> {
**/
PageData<CompleteDeptDTO> listCompleteDeptDTO(Map<String, Object> params);
/**
* 获取用户部门多层结构完整层级结构包括顶级部门用户前端显示请求需携带token
*
* @author work@yujt.net.cn
* @date 2020/1/28 10:40
*/
DeptOption getAllDeptOptionByLoginUser();
/***
* 获取所有网格
* @param
@ -243,24 +224,6 @@ public interface SysDeptService extends BaseService<SysDeptEntity> {
*/
Result<List<Long>> pageDeptIdByTypeKey(String typeKey, Integer pageSize, Integer pageIndex);
/**
* pc端页面获取用户街道-社区层级关系前端显示请求需携带token
*
* @return com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO
* @author work@yujt.net.cn
* @date 2019/12/18 11:05
*/
DeptOption getMiddleByLoginUser();
/**
* 获取用户部门层级结构街道用户前端显示请求需携带token
*
* @return com.elink.esua.epdc.dto.DeptOption
* @author work@yujt.net.cn
* @date 2020/2/11 11:31
*/
DeptOption getStreetByLoginUser();
DeptLevelAndLeaderDTO getDeptInfoById(Long deptId, String leaderFlag);
/**
@ -272,15 +235,6 @@ public interface SysDeptService extends BaseService<SysDeptEntity> {
*/
List<UserSysDeptInfoResultDTO> listAllDeptInfo(UserSysDeptInfoFormDTO formDTO);
/**
* 展示三级机构层级街道-社区-网格不包括区级不包括科室科室和没有下属网格的社区
*
* @return com.elink.esua.epdc.dto.DeptOption
* @author work@yujt.net.cn
* @date 2020/5/14 10:11
*/
DeptOption getBusinessDeptByUser();
/**
* 获取产品端areaCode
*
@ -290,12 +244,13 @@ public interface SysDeptService extends BaseService<SysDeptEntity> {
* @date 2021/1/11 18:01
*/
List getEpmetAreaCode(UserSysDeptAreaCodeFormDTO dto);
/**
* @Description 获取用户部门多层结构用户前端显示请求需携带token - 工作日志使用
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.DeptOption>
* @Description 获取用户部门多层结构用户前端显示请求需携带token - 工作日志使用
* @Author songyunpeng
* @Date 2021/1/27
* @Date 2021/1/27
* @Param [userId]
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.DeptOption>
**/
Result<DeptOption> getUserDeptOptionByUserId(String userId);
}

298
epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/impl/SysDeptServiceImpl.java

@ -49,8 +49,6 @@ 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -87,8 +85,6 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
@Autowired
private EpmetUtils epmetUtils;
private static final Logger logger = LoggerFactory.getLogger(SysDeptServiceImpl.class);
@Override
public List<SysDeptDTO> list(Map<String, Object> params) {
//普通管理员,只能查询所属部门及子部门的数据
@ -349,16 +345,6 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
return new Result().ok(list);
}
@Override
public DeptOption getUserDeptOption() {
return getUserDeptOption(SecurityUser.getUserId());
}
@Override
public DeptOption getDeptAuthByUser() {
return getDeptAuthByUser(SecurityUser.getUserId());
}
@Override
public List<DeptGridDTO> getGridAuthByUser() {
// 用户拥有的所有部门权限
@ -372,170 +358,6 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
return list;
}
/**
* 根据userId从redis取出用户部门层级关系街道-社区-网格
*
* @param userId
* @return com.elink.esua.epdc.dto.DeptOption
* @author work@yujt.net.cn
* @date 2020/2/11 11:18
*/
private DeptOption getDeptAuthByUser(Long userId) {
String deptOptionKey = RedisKeys.getAdminUserDeptAuthOptionKey(userId);
Object obj = redisUtils.get(deptOptionKey);
if (null == obj) {
this.packageDeptAuthByUser(userId);
obj = redisUtils.get(deptOptionKey);
}
return (DeptOption) obj;
}
/**
* 根据userId从redis取出用户部门层级关系街道-社区-网格
*
* @param userId
* @return com.elink.esua.epdc.dto.DeptOption
* @author work@yujt.net.cn
* @date 2020/2/11 11:18
*/
private DeptOption getUserDeptOption(Long userId) {
String deptOptionKey = RedisKeys.getAdminUserDeptOptionKey(userId);
Object obj = redisUtils.get(deptOptionKey);
if (null == obj) {
this.packageUserDeptOption(userId);
obj = redisUtils.get(deptOptionKey);
}
return (DeptOption) obj;
}
@Override
public DeptOption getAllDeptOptionByLoginUser() {
Long userId = SecurityUser.getUserId();
String deptOptionKey = RedisKeys.getAllAdminUserDeptOptionKey(userId);
Object obj = redisUtils.get(deptOptionKey);
if (null == obj) {
this.packageAllUserDeptOption(userId);
obj = redisUtils.get(deptOptionKey);
}
return (DeptOption) obj;
}
@Override
public DeptOption getBusinessDeptByUser() {
DeptOption result = getUserDeptOption(SecurityUser.getUserId());
List<JSONObject> options = result.getOptions();
if (options.isEmpty()) {
return result;
}
// 代表存在子级机构的json key
String childJsonOptionKey = "children";
// 一个街道机构
JSONObject streetOption;
// 一个街道下所有社区机构
JSONArray communityOptionArray;
// 一个社区机构
JSONObject communityOption;
// 循环所有街道
for (int i = options.size() - NumConstant.ONE; i >= NumConstant.ZERO; i--) {
// 取出一个街道
streetOption = options.get(i);
// 街道没有children,代表没有下级社区(没有children的,其实是区直)
if (null == streetOption.get(childJsonOptionKey)) {
// 移除区直机构
options.remove(i);
continue;
}
// 获取该街道的所有社区
communityOptionArray = streetOption.getJSONArray(childJsonOptionKey);
if (communityOptionArray.isEmpty()) {
// 移除区直机构
options.remove(i);
continue;
}
// 社区不为空,循环所有社区
for (int j = communityOptionArray.size() - 1; j >= 0; j--) {
// 取出一个社区
communityOption = communityOptionArray.getJSONObject(j);
if (null == communityOption.get(childJsonOptionKey) || communityOption.getJSONArray(childJsonOptionKey).isEmpty()) {
// 若街道有下级机构(社区),移除社区
communityOptionArray.remove(j);
}
}
}
return result;
}
@Override
public DeptOption getMiddleByLoginUser() {
DeptOption result = getUserDeptOption(SecurityUser.getUserId());
List<JSONObject> options = result.getOptions();
if (options.isEmpty()) {
return result;
}
// 代表存在子级机构的json key
String childJsonOptionKey = "children";
// 一个街道机构
JSONObject streetOption;
// 一个街道下所有社区机构
JSONArray communityOptionArray;
// 一个社区机构
JSONObject communityOption;
// 循环所有街道
for (int i = options.size() - NumConstant.ONE; i >= NumConstant.ZERO; i--) {
// 取出一个街道
streetOption = options.get(i);
// 街道有children,代表有下级社区(没有children的,其实是区直)
if (null != streetOption.get(childJsonOptionKey)) {
// 获取该街道的所有社区
communityOptionArray = streetOption.getJSONArray(childJsonOptionKey);
if (!communityOptionArray.isEmpty()) {
// 社区不为空,循环所有社区
for (int j = 0; j < communityOptionArray.size(); j++) {
// 取出一个社区
communityOption = communityOptionArray.getJSONObject(j);
// 社区有children,代表有下级网格,
if (null != communityOption.get(childJsonOptionKey)) {
// 移除网格
communityOption.remove(childJsonOptionKey);
}
}
}
} else {
// 移除区直机构
options.remove(i);
}
}
return result;
}
@Override
public DeptOption getStreetByLoginUser() {
DeptOption result = getUserDeptOption(SecurityUser.getUserId());
if (null == result || result.getOptions().isEmpty()) {
return result;
}
List<JSONObject> options = result.getOptions();
// 代表存在子级机构的json key
String childJsonOptionKey = "children";
// 一个街道机构
JSONObject streetOption;
// 循环所有街道
for (int i = options.size() - NumConstant.ONE; i >= NumConstant.ZERO; i--) {
// 取出一个街道
streetOption = options.get(i);
// 街道有children,代表有下级社区(没有children的,其实是区直)
if (null != streetOption.get(childJsonOptionKey)) {
// 若街道有下级机构(社区),移除社区
streetOption.remove(childJsonOptionKey);
} else {
// 移除区直机构(有些街道还没创建社区,也被移除)
options.remove(i);
}
}
return result;
}
/**
* @param formDTO
* @return java.util.List<com.elink.esua.epdc.dto.epdc.result.UserSysDeptInfoResultDTO>
@ -591,14 +413,6 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
packageDeptOptionByUser(userId, false);
}
public void packageDeptAuthByUser(Long userId) {
packageDeptOptionAuthByUser(userId);
}
public void packageAllUserDeptOption(Long userId) {
packageDeptOptionByUser(userId, true);
}
/**
* 组装部门层级结构
*
@ -666,43 +480,6 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
}
/**
* 组装部门层级结构
*
* @param userId 用户id
* @return void
* @author work@yujt.net.cn
* @date 2020/1/28 10:49
*/
private void packageDeptOptionAuthByUser(long userId) {
UserDetail userDetail = userDetailRedis.get(userId);
// 用户拥有的所有部门权限
List<Long> dataScopeDeptList = userDetail.getDeptIdList();
if (CollUtil.isEmpty(dataScopeDeptList)) {
return;
}
// 某个部门id 声明变量,方便操作数据
Long deptId;
// 所有父级节点 此处为第一次获取,为顶级节点,相当于市区
JSONArray parentNodeArray = new JSONArray();
// 用于存放 每次组装好的 某一级节点。页面只需展示三级,所以没有存放顶级节点(市区)
List<JSONArray> cache = Lists.newArrayList();
Map<String, Object> object;
while (CollUtil.isNotEmpty(dataScopeDeptList)) {
// 通过上级节点组装所有下级节点
object = this.packageChildrenNodeAuth(parentNodeArray, dataScopeDeptList);
dataScopeDeptList = (List<Long>) object.get("scope");
parentNodeArray = (JSONArray) object.get("node");
cache.add(parentNodeArray);
}
DeptOption option = new DeptOption();
option.setOptions(cache.get(0));
redisUtils.set(RedisKeys.getAdminUserDeptAuthOptionKey(userId), option);
}
/**
* 组装下级结构节点
@ -770,80 +547,6 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
return result;
}
/**
* 组装下级结构节点
*
* @param allParentNode 所有的上级机构节点
* @param dataScopeDeptList 拥有数据权限的部门
* @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> packageChildrenNodeAuth(JSONArray allParentNode, List<Long> dataScopeDeptList) {
List<SysDeptEntity> childDepts = baseDao.selectChildrenDeptAuth(dataScopeDeptList);
List<Long> parentDeptIdList = Lists.newArrayList();
// 用于存储所有子节点
JSONArray allChildrenNode = new JSONArray();
// 某个父节点下所有的子节点
JSONArray childrenNodeList;
// 单个 子节点
JSONObject nodeChild;
// 单个 父节点
JSONObject nodeParent;
Long deptId;
for (int i = 0; i < allParentNode.size(); 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()))) {
nodeChild = new JSONObject();
nodeChild.put("label", childDepts.get(j).getName());
nodeChild.put("value", String.valueOf(deptId));
childrenNodeList.add(nodeChild);
allChildrenNode.add(nodeChild);
parentDeptIdList.add(deptId);
}
}
if (childrenNodeList.size() > 0) {
nodeParent.put("children", childrenNodeList);
}
}
if (allParentNode.size() == 0) {
for (int index = 0; index < childDepts.size(); index++) {
JSONObject node = new JSONObject();
node.put("label", childDepts.get(index).getName());
node.put("value", String.valueOf(childDepts.get(index).getId()));
allParentNode.add(node);
parentDeptIdList.add(childDepts.get(index).getId());
allChildrenNode.add(node);
}
}
List<Long> newDataScopeList = Lists.newArrayList();
for (int i = 0; i < dataScopeDeptList.size(); i++) {
deptId = dataScopeDeptList.get(i);
if (!parentDeptIdList.contains(deptId)) {
newDataScopeList.add(deptId);
}
}
dataScopeDeptList = newDataScopeList;
Map<String, Object> result = Maps.newHashMap();
result.put("node", allChildrenNode);
result.put("scope", dataScopeDeptList);
return result;
}
@Override
public void packgeAllDeptOption() {
List<DeptTreeDTO> deptList = baseDao.selectListDeptTree();
@ -1183,6 +886,7 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
dto.getId().toString(), JSONObject.toJSONString(body));
}
}
@Override
public Result<DeptOption> getUserDeptOptionByUserId(String userId) {
Long realUserId = Long.parseLong(userId);

2
epdc-cloud-client-yushan

@ -1 +1 @@
Subproject commit 139c18ffc1c83b68353fe711fdaf60deff83b453
Subproject commit 6658103da6140f7e012742e90f68da59f0613d3e

2
epdc-cloud-commons-yushan

@ -1 +1 @@
Subproject commit 6fe5ff2df365caeb02b1fbb842ec90e73d29a16a
Subproject commit 5033dafdc2bca43924d2b37a8db63b50b5ea4b84
Loading…
Cancel
Save