@ -92,51 +92,135 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
@Override
public TreeDataVO selectOrganizationChart ( String virtualType ) {
public TreeDataVO selectOrganizationChart ( OrgTreeParam orgTreeParam ) {
RecordSet rs = new RecordSet ( ) ;
BaseBean bb = new BaseBean ( ) ;
String virtualType = orgTreeParam . getVirtualType ( ) ;
String root = orgTreeParam . getRoot ( ) ;
String level = orgTreeParam . getLevel ( ) ;
TreeDataVO build ;
String roleId = bb . getPropValue ( "sship" , "roleId" ) ;
String rolelevel = bb . getPropValue ( "sship" , "rolelevel" ) ;
boolean isExsit = selectIdsByRole ( roleId , rolelevel ) ;
String id = "" ;
if ( isExsit | | ( user . getUID ( ) = = 1 ) ) {
//ShareHolder唯一
rs . executeQuery ( "select id,departmentmark from hrmdepartmentvirtual where supdepid = 0 and virtualtype = ? order by showorder" , virtualType ) ;
rs . next ( ) ;
String id = Util . null2String ( rs . getString ( "id" ) ) ;
if ( StringUtils . isBlank ( root ) ) {
rs . executeQuery ( "select a.id,departmentmark,bmfzrid from hrmdepartmentvirtual a " +
"left join uf_xnbmfzr on a.id =xnzzid where supdepid = 0 and virtualtype = ? order by showorder" , virtualType ) ;
rs . next ( ) ;
id = rs . getString ( "id" ) ;
} else {
rs . executeQuery ( "select departmentmark from hrmdepartmentvirtual where id = ? and virtualtype = ? order by showorder" , root . substring ( 3 ) , virtualType ) ;
rs . next ( ) ;
id = root . substring ( 3 ) ;
}
build = TreeDataVO . builder ( )
. id ( id )
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) )
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) +"(" + Util . null2String ( rs . getString ( "bmfzrid" ) ) + ")" )
. build ( ) ;
if ( isVirtualSubDepartment ( id , virtualType ) ) {
build . setChildrens ( getVirtualSubDept ( id , virtualType ) ) ;
}
// 根据id查询对应建模的虚拟部门领导
rs . executeQuery ( "select bmfzrid from uf_xnbmfzr where xnzzid = ? " , id ) ;
build . setLastName ( rs . getString ( "bmfzrid" ) ) ;
//level等于1
if ( StringUtils . isNotBlank ( level ) ) {
if ( Integer . parseInt ( level ) = = 1 ) {
build . setChildrens ( null ) ;
} else {
build . setChildrens ( setTreeStructure ( build . getChildrens ( ) , Integer . parseInt ( level ) ) ) ;
}
}
} else {
String departmentId = "" ;
//获取当前部门
rs . executeQuery ( "select departmentid from hrmresourcevirtual where resourceid = ? and virtualtype = ?" , user . getUID ( ) , virtualType ) ;
rs . next ( ) ;
String departmentId = Util . null2String ( rs . getString ( "departmentid" ) ) ;
rs . executeQuery ( "select departmentmark from hrmdepartmentvirtual where id = ? and virtualtype = ? order by showorder" , departmentId , virtualType ) ;
if ( StringUtils . isBlank ( root ) ) {
rs . executeQuery ( "select departmentid from hrmresourcevirtual where resourceid = ? and virtualtype = ?" , user . getUID ( ) , virtualType ) ;
rs . next ( ) ;
departmentId = rs . getString ( "departmentid" ) ;
} else {
departmentId = root . substring ( 3 ) ;
}
rs . executeQuery ( "select departmentmark,bmfzrid from hrmdepartmentvirtual a left join uf_xnbmfzr on a.id =xnzzid where a.id = ? and virtualtype = ? order by showorder" , departmentId , virtualType ) ;
rs . next ( ) ;
build = TreeDataVO . builder ( )
. id ( departmentId )
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) )
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) +"(" + Util . null2String ( rs . getString ( "bmfzrid" ) ) + ")" )
. build ( ) ;
if ( isVirtualSubDepartment ( departmentId , virtualType ) ) {
build . setChildrens ( getVirtualSubDept ( departmentId , virtualType ) ) ;
}
// 根据id查询对应建模的虚拟部门领导
rs . executeQuery ( "select bmfzrid from uf_xnbmfzr where xnzzid = ? " , departmentId ) ;
build . setLastName ( rs . getString ( "bmfzrid" ) ) ;
//level等于1
if ( StringUtils . isNotBlank ( level ) ) {
if ( Integer . parseInt ( level ) = = 1 ) {
build . setChildrens ( null ) ;
} else {
build . setChildrens ( setTreeStructure ( build . getChildrens ( ) , Integer . parseInt ( level ) ) ) ;
}
}
}
return build ;
}
/ * *
* 根 据 层 级 修 改 树 结 构
* @param childrens
* /
public static List < ChartChildrensVO > setTreeStructure ( List < ChartChildrensVO > childrens , int level ) {
switch ( level ) {
case 2 :
childrens . forEach ( childrensVO - > childrensVO . setChildrens ( null ) ) ;
break ;
case 3 :
childrens . forEach ( childrensVO - > childrensVO . getChildrens ( ) . forEach ( childrensVO1 - > childrensVO1 . setChildrens ( null ) ) ) ;
break ;
case 4 :
childrens . forEach ( childrensVO - > childrensVO . getChildrens ( ) . forEach ( childrensVO1 - >
childrensVO1 . getChildrens ( ) . forEach ( childrensVO2 - > childrensVO2 . setChildrens ( null ) ) ) ) ;
break ;
case 5 :
childrens . forEach ( childrensVO - > childrensVO . getChildrens ( ) . forEach ( childrensVO1 - >
childrensVO1 . getChildrens ( ) . forEach ( childrensVO2 - > childrensVO2 . getChildrens ( ) . forEach ( childrensVO3 - >
childrensVO3 . setChildrens ( null ) ) ) ) ) ;
break ;
case 6 :
childrens . forEach ( childrensVO - > childrensVO . getChildrens ( ) . forEach ( childrensVO1 - >
childrensVO1 . getChildrens ( ) . forEach ( childrensVO2 - > childrensVO2 . getChildrens ( ) . forEach ( childrensVO3 - >
childrensVO3 . getChildrens ( ) . forEach ( childrensVO4 - > childrensVO4 . setChildrens ( null ) ) ) ) ) ) ;
break ;
case 7 :
childrens . forEach ( childrensVO - > childrensVO . getChildrens ( ) . forEach ( childrensVO1 - >
childrensVO1 . getChildrens ( ) . forEach ( childrensVO2 - > childrensVO2 . getChildrens ( ) . forEach ( childrensVO3 - >
childrensVO3 . getChildrens ( ) . forEach ( childrensVO4 - > childrensVO4 . getChildrens ( ) .
forEach ( childrensVO5 - > childrensVO5 . setChildrens ( null ) ) ) ) ) ) ) ;
break ;
case 8 :
childrens . forEach ( childrensVO - > childrensVO . getChildrens ( ) . forEach ( childrensVO1 - >
childrensVO1 . getChildrens ( ) . forEach ( childrensVO2 - > childrensVO2 . getChildrens ( ) . forEach ( childrensVO3 - >
childrensVO3 . getChildrens ( ) . forEach ( childrensVO4 - > childrensVO4 . getChildrens ( ) .
forEach ( childrensVO5 - > childrensVO5 . getChildrens ( ) . forEach ( childrensVO6 - > childrensVO6 . setChildrens ( null ) ) ) ) ) ) ) ) ;
break ;
case 9 :
childrens . forEach ( childrensVO - > childrensVO . getChildrens ( ) . forEach ( childrensVO1 - >
childrensVO1 . getChildrens ( ) . forEach ( childrensVO2 - > childrensVO2 . getChildrens ( ) . forEach ( childrensVO3 - >
childrensVO3 . getChildrens ( ) . forEach ( childrensVO4 - > childrensVO4 . getChildrens ( ) .
forEach ( childrensVO5 - > childrensVO5 . getChildrens ( ) . forEach ( childrensVO6 - >
childrensVO6 . getChildrens ( ) . forEach ( childrensVO7 - > childrensVO7 . setChildrens ( null ) ) ) ) ) ) ) ) ) ;
break ;
case 10 :
childrens . forEach ( childrensVO - > childrensVO . getChildrens ( ) . forEach ( childrensVO1 - >
childrensVO1 . getChildrens ( ) . forEach ( childrensVO2 - > childrensVO2 . getChildrens ( ) . forEach ( childrensVO3 - >
childrensVO3 . getChildrens ( ) . forEach ( childrensVO4 - > childrensVO4 . getChildrens ( ) .
forEach ( childrensVO5 - > childrensVO5 . getChildrens ( ) . forEach ( childrensVO6 - >
childrensVO6 . getChildrens ( ) . forEach ( childrensVO7 - >
childrensVO7 . getChildrens ( ) . forEach ( childrensVO8 - > childrensVO8 . setChildrens ( null ) ) ) ) ) ) ) ) ) ) ;
break ;
default :
childrens . forEach ( childrensVO - > childrensVO . setChildrens ( null ) ) ;
}
return childrens ;
}
/ * *
* 遍 历 n 叉 树 最 大 深 度
* @param root
@ -154,11 +238,29 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
return num ;
}
private List < ChartChildrensVO > getVirtualSubDept ( String supdepid , String virtualType ) {
RecordSet rs = new RecordSet ( ) ;
List < ChartChildrensVO > voList = new ArrayList < > ( ) ;
rs . executeQuery ( "select id,departmentmark from hrmdepartmentvirtual where supdepid <> '' and supdepid = ? and virtualtype = ? order by showorder" , supdepid , virtualType ) ;
rs . executeQuery ( "select a.id,departmentmark,bmfzrid from hrmdepartmentvirtual a left join uf_xnbmfzr on a.id =xnzzid where supdepid <> '' and supdepid = ? and virtualtype = ? order by showorder" , supdepid , virtualType ) ;
while ( rs . next ( ) ) {
String id = Util . null2String ( rs . getString ( "id" ) ) ;
ChartChildrensVO build = ChartChildrensVO . builder ( )
. pid ( supdepid )
. id ( id )
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) + "(" + Util . null2String ( rs . getString ( "bmfzrid" ) ) + ")" )
. build ( ) ;
if ( isVirtualSubDepartment ( id , virtualType ) ) {
build . setChildrens ( getVirtualSubDept ( id , virtualType ) ) ;
}
voList . add ( build ) ;
}
return voList ;
}
private List < ChartChildrensVO > getVirtualSub ( String supdepid , String virtualType ) {
RecordSet rs = new RecordSet ( ) ;
List < ChartChildrensVO > voList = new ArrayList < > ( ) ;
rs . executeQuery ( "select id,departmentmark from hrmdepartmentvirtual where supdepid <> '' and supdepid = ? and virtualtype = ? order by showorder" , supdepid , virtualType ) ;
while ( rs . next ( ) ) {
String id = Util . null2String ( rs . getString ( "id" ) ) ;
ChartChildrensVO build = ChartChildrensVO . builder ( )
@ -166,17 +268,13 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
. id ( id )
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) )
. build ( ) ;
if ( isVirtualSubDepartment ( id , virtualType ) ) {
build . setChildrens ( getVirtualSub Dept ( id , virtualType ) ) ;
if ( isVirtualSubDepartment ( id , virtualType ) ) {
build . setChildrens ( getVirtualSub ( id , virtualType ) ) ;
}
// 根据id查询对应建模的虚拟部门领导
rs . executeQuery ( "select bmfzrid from uf_xnbmfzr where xnzzid = ? " , id ) ;
build . setLastName ( rs . getString ( "bmfzrid" ) ) ;
voList . add ( build ) ;
}
return voList ;
}
private List < DropTreeDataVO > getVirtualSubDeptData ( String supdepid , String virtualType ) {
RecordSet rs = new RecordSet ( ) ;
List < DropTreeDataVO > voList = new ArrayList < > ( ) ;
@ -324,7 +422,7 @@ public List<DropTreeDataVO> selectVirtualTopTwo(String virtualType) {
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) )
. build ( ) ;
if ( isVirtualSubDepartment ( virtualTopParam . getId ( ) , virtualTopParam . getVirtualType ( ) ) ) {
build . setChildrens ( getVirtualSub Dept ( virtualTopParam . getId ( ) , virtualTopParam . getVirtualType ( ) ) ) ;
build . setChildrens ( getVirtualSub ( virtualTopParam . getId ( ) , virtualTopParam . getVirtualType ( ) ) ) ;
}
if ( null ! = build . getChildrens ( ) & & build . getChildrens ( ) . size ( ) > 0 ) {
for ( ChartChildrensVO children : build . getChildrens ( ) ) {