@ -8,6 +8,7 @@
package com.elink.esua.epdc.service.impl ;
package com.elink.esua.epdc.service.impl ;
import cn.hutool.core.collection.CollUtil ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl ;
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl ;
import com.elink.esua.epdc.commons.tools.constant.Constant ;
import com.elink.esua.epdc.commons.tools.constant.Constant ;
@ -16,15 +17,16 @@ import com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant;
import com.elink.esua.epdc.commons.tools.enums.SuperAdminEnum ;
import com.elink.esua.epdc.commons.tools.enums.SuperAdminEnum ;
import com.elink.esua.epdc.commons.tools.exception.ErrorCode ;
import com.elink.esua.epdc.commons.tools.exception.ErrorCode ;
import com.elink.esua.epdc.commons.tools.exception.RenException ;
import com.elink.esua.epdc.commons.tools.exception.RenException ;
import com.elink.esua.epdc.commons.tools.redis.RedisKeys ;
import com.elink.esua.epdc.commons.tools.redis.RedisUtils ;
import com.elink.esua.epdc.commons.tools.redis.UserDetailRedis ;
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser ;
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser ;
import com.elink.esua.epdc.commons.tools.security.user.UserDetail ;
import com.elink.esua.epdc.commons.tools.security.user.UserDetail ;
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils ;
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils ;
import com.elink.esua.epdc.commons.tools.utils.Result ;
import com.elink.esua.epdc.commons.tools.utils.Result ;
import com.elink.esua.epdc.commons.tools.utils.TreeUtils ;
import com.elink.esua.epdc.commons.tools.utils.TreeUtils ;
import com.elink.esua.epdc.dao.SysDeptDao ;
import com.elink.esua.epdc.dao.SysDeptDao ;
import com.elink.esua.epdc.dto.CompleteDeptDTO ;
import com.elink.esua.epdc.dto.* ;
import com.elink.esua.epdc.dto.SysDeptDTO ;
import com.elink.esua.epdc.dto.SysSimpleDeptDTO ;
import com.elink.esua.epdc.dto.epdc.GridForLeaderRegisterDTO ;
import com.elink.esua.epdc.dto.epdc.GridForLeaderRegisterDTO ;
import com.elink.esua.epdc.entity.SysDeptEntity ;
import com.elink.esua.epdc.entity.SysDeptEntity ;
import com.elink.esua.epdc.feign.GroupFeignClient ;
import com.elink.esua.epdc.feign.GroupFeignClient ;
@ -57,6 +59,12 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
@Autowired
@Autowired
private GroupFeignClient groupFeignClient ;
private GroupFeignClient groupFeignClient ;
@Autowired
private UserDetailRedis userDetailRedis ;
@Autowired
private RedisUtils redisUtils ;
@Override
@Override
public List < SysDeptDTO > list ( Map < String , Object > params ) {
public List < SysDeptDTO > list ( Map < String , Object > params ) {
//普通管理员,只能查询所属部门及子部门的数据
//普通管理员,只能查询所属部门及子部门的数据
@ -273,4 +281,149 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
list . add ( completeDept . getGrid ( ) ) ;
list . add ( completeDept . getGrid ( ) ) ;
return new Result ( ) . ok ( list ) ;
return new Result ( ) . ok ( list ) ;
}
}
@Override
public void packageUserDeptOption ( Long userId ) {
UserDetail userDetail = userDetailRedis . get ( userId ) ;
// 用户拥有的所有部门权限
List < Long > dataScopeDeptList = userDetail . getDeptIdList ( ) ;
if ( CollUtil . isEmpty ( dataScopeDeptList ) ) {
return ;
}
// 通过用户部门权限 获取第一级部门节点
List < SysDeptEntity > headDepts = baseDao . selectListHeadDeptNode ( dataScopeDeptList ) ;
if ( CollUtil . isEmpty ( headDepts ) ) {
return ;
}
// 存放上级节点的主键,查询下级节点用
List < Long > parentDeptIdList = Lists . newArrayList ( ) ;
Long deptId ;
// 一级节点
List < DeptNode > headNodeList = Lists . newArrayList ( ) ;
DeptNode < DeptNode > 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 ) ;
}
// 查询所有一级节点的下级部门,用于组装 二级节点
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 ( ) ;
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 ) ;
allChildrenNodeList . add ( childrenNode ) ;
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 ( ) ;
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 ) ;
allChildrenBeforeLast . add ( childrenBeforeLast ) ;
parentDeptIdList . add ( deptId ) ;
}
}
parentNode . setChildren ( childrenBeforeLastList ) ;
}
// 查询所有三级节点的下级部门,用于组装 四级节点
childDepts = baseDao . selectChildrenDeptNode ( dataScopeDeptList , parentDeptIdList ) ;
if ( CollUtil . isEmpty ( childDepts ) ) {
return ;
}
// 单个上级节点下 所有下级节点
List < DeptNodeLast > childrenLastList ;
DeptNodeLast childrenLast ;
for ( int i = 0 ; i < allChildrenBeforeLast . size ( ) ; i + + ) {
// 父节点
parentNode = allChildrenBeforeLast . get ( i ) ;
childrenLastList = Lists . newArrayList ( ) ;
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 ) ;
}
}
parentNode . setChildren ( childrenLastList ) ;
}
DeptOption option = new DeptOption ( ) ;
option . setOptions ( allChildrenNodeList ) ;
redisUtils . set ( RedisKeys . getAdminUserDeptOptionKey ( userId ) , option ) ;
}
@Override
public Result < DeptOption > getUserDeptOption ( ) {
Long userId = SecurityUser . getUserId ( ) ;
DeptOption option = ( DeptOption ) redisUtils . get ( RedisKeys . getAdminUserDeptOptionKey ( userId ) ) ;
return new Result < DeptOption > ( ) . ok ( option ) ;
}
}
}