@ -684,6 +684,61 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
redisUtils . set ( RedisKeys . getAllDeptOptionKeyWithTypeKey ( ) , option ) ;
}
private void packgeAllOrgOption ( ) {
List < DeptTreeWithTypeKeyDTO > deptList = baseDao . selectListOrgTree ( ) ;
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 . getAllOrgOptionKey ( ) , option ) ;
}
List < DeptTreeDTO > getOtherDept ( List < DeptTreeDTO > deptList , JSONArray parent ) {
List < Long > already = Lists . newArrayList ( ) ;
@ -748,6 +803,17 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
return new Result < DeptOption > ( ) . ok ( ( DeptOption ) obj ) ;
}
@Override
public Result < DeptOption > getOrgTree ( ) {
String deptKey = RedisKeys . getAllOrgOptionKey ( ) ;
Object obj = redisUtils . get ( deptKey ) ;
if ( null = = obj ) {
this . packgeAllOrgOption ( ) ;
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 >