@ -349,8 +349,41 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
public DeptOption getUserDeptOption ( ) {
return getUserDeptOption ( SecurityUser . getUserId ( ) ) ;
}
@Override
public DeptOption getDeptAuthByUser ( ) {
return getDeptAuthByUser ( SecurityUser . getUserId ( ) ) ;
}
@Override
public List < DeptGridDTO > getGridAuthByUser ( ) {
// 用户拥有的所有部门权限
List < Long > deptList = SecurityUser . getUser ( ) . getDeptIdList ( ) ;
List < DeptGridDTO > list ;
if ( deptList ! = null & & deptList . size ( ) > 0 ) {
list = baseDao . getGridAuthByUser ( deptList ) ;
} else {
return null ;
}
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取出用户部门层级关系 ( 街道 - 社区 - 网格 )
*
@ -506,6 +539,10 @@ 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 ) ;
}
@ -576,6 +613,43 @@ 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 ) ;
}
/ * *
* 组装下级结构节点
@ -642,7 +716,79 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
result . put ( "pids" , parentDeptIdList ) ;
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 ( ) ;