@ -14,10 +14,7 @@ import weaver.conn.RecordSet;
import weaver.hrm.company.DepartmentComInfo ;
import weaver.hrm.resource.ResourceComInfo ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.List ;
import java.util.* ;
import java.util.stream.Collectors ;
@ -29,8 +26,7 @@ import java.util.stream.Collectors;
* /
public class OrgChartServiceImpl extends Service implements OrgChartService {
private HrmCommonService hrmCommonService = new HrmCommonServiceImpl ( ) ;
private final HrmCommonService hrmCommonService = new HrmCommonServiceImpl ( ) ;
@Override
public boolean selectIdsByRole ( String roleId , String rolelevel ) {
String roleMemberIds = hrmCommonService . getRoleMemberIds ( roleId , rolelevel ) ;
@ -115,12 +111,16 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
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" ) ) ;
} else {
//获取当前部门
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 = ? ", departmentId , virtualType ) ;
rs . executeQuery ( "select departmentmark from hrmdepartmentvirtual where id = ? and virtualtype = ? order by showorder ", departmentId , virtualType ) ;
rs . next ( ) ;
build = TreeDataVO . builder ( )
. id ( departmentId )
@ -129,11 +129,111 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
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" ) ) ;
}
return build ;
}
public static void main ( String [ ] args ) {
List < SelectVO > voList = assembleSelectVOList ( ) ;
// 判断是否满足删除条件
for ( int i = voList . size ( ) - 1 ; i > = 0 ; i - - ) {
if ( Integer . parseInt ( voList . get ( i ) . getValue ( ) ) > 5 ) {
voList . remove ( i ) ;
}
}
List < SelectVO > collect = voList . stream ( ) . filter ( SelectVO - > Integer . parseInt ( SelectVO . getValue ( ) ) > 5 ) . collect ( Collectors . toList ( ) ) ;
TreeDataVO build ;
int num = 1 ;
List < Integer > list = new ArrayList < > ( ) ;
list . add ( num ) ;
List < ChartChildrensVO > childList4 = new ArrayList < > ( ) ;
ChartChildrensVO chart5 = null ;
chart5 = chart5 . builder ( ) . id ( "1111" ) . label ( "aaaa" ) . pid ( "11111" ) . childrens ( null ) . build ( ) ;
ChartChildrensVO chart6 = null ;
chart6 = chart6 . builder ( ) . id ( "2222" ) . label ( "bbbb" ) . pid ( "22222" ) . childrens ( null ) . build ( ) ;
ChartChildrensVO chart7 = null ;
chart7 = chart7 . builder ( ) . id ( "2222" ) . label ( "bbbb" ) . pid ( "22222" ) . childrens ( null ) . build ( ) ;
childList4 . add ( chart5 ) ;
childList4 . add ( chart6 ) ;
childList4 . add ( chart7 ) ;
List < ChartChildrensVO > childList3 = new ArrayList < > ( ) ;
ChartChildrensVO chart3 = null ;
chart3 = chart3 . builder ( ) . id ( "1111" ) . label ( "aaaa" ) . pid ( "11111" ) . childrens ( null ) . build ( ) ;
ChartChildrensVO chart4 = null ;
chart4 = chart4 . builder ( ) . id ( "2222" ) . label ( "bbbb" ) . pid ( "22222" ) . childrens ( null ) . build ( ) ;
childList3 . add ( chart3 ) ;
childList3 . add ( chart4 ) ;
List < ChartChildrensVO > childList2 = new ArrayList < > ( ) ;
ChartChildrensVO chart1 = null ;
chart1 = chart1 . builder ( ) . id ( "111" ) . label ( "aaa" ) . pid ( "1111" ) . childrens ( childList3 ) . build ( ) ;
ChartChildrensVO chart2 = null ;
chart2 = chart2 . builder ( ) . id ( "222" ) . label ( "bbb" ) . pid ( "2222" ) . childrens ( childList3 ) . build ( ) ;
childList2 . add ( chart1 ) ;
childList2 . add ( chart2 ) ;
List < ChartChildrensVO > childList1 = new ArrayList < > ( ) ;
ChartChildrensVO chartChildrensVO1 = null ;
chartChildrensVO1 = chartChildrensVO1 . builder ( ) . id ( "11" ) . label ( "aa" ) . pid ( "111" ) . childrens ( childList2 ) . build ( ) ;
ChartChildrensVO chartChildrensVO2 = null ;
chartChildrensVO2 = chartChildrensVO2 . builder ( ) . id ( "22" ) . label ( "bb" ) . pid ( "222" ) . childrens ( childList2 ) . build ( ) ;
ChartChildrensVO chartChildrensVO3 = null ;
chartChildrensVO3 = chartChildrensVO3 . builder ( ) . id ( "33" ) . label ( "cc" ) . pid ( "333" ) . childrens ( childList2 ) . build ( ) ;
ChartChildrensVO chartChildrensVO4 = null ;
chartChildrensVO4 = chartChildrensVO4 . builder ( ) . id ( "44" ) . label ( "dd" ) . pid ( "444" ) . childrens ( childList2 ) . build ( ) ;
childList1 . add ( chartChildrensVO1 ) ;
childList1 . add ( chartChildrensVO2 ) ;
childList1 . add ( chartChildrensVO3 ) ;
childList1 . add ( chartChildrensVO4 ) ;
build = TreeDataVO . builder ( )
. id ( "11" )
. label ( "aa" )
. childrens ( childList1 )
. build ( ) ;
if ( null ! = build . getChildrens ( ) & & build . getChildrens ( ) . size ( ) > 0 ) {
for ( ChartChildrensVO children : build . getChildrens ( ) ) {
num = maxDepth ( children ) + 1 ;
list . add ( num ) ;
}
build . setNum ( Collections . max ( list ) + 1 ) ;
} else {
build . setNum ( num ) ;
}
}
/ * *
* 遍 历 n 叉 树 最 大 深 度
* @param root
* /
public static int maxDepth ( ChartChildrensVO root ) {
if ( CollectionUtils . isEmpty ( root . getChildrens ( ) ) ) {
return 0 ;
}
int num = 0 ;
if ( ! CollectionUtils . isEmpty ( root . getChildrens ( ) ) ) {
for ( int i = 0 ; i < root . getChildrens ( ) . size ( ) ; i + + ) {
num = Math . max ( num , 1 + maxDepth ( root . getChildrens ( ) . get ( i ) ) ) ;
}
}
return num ;
}
private List < ChartChildrensVO > getVirtualSubDept ( String supdepid , String virtualType ) {
RecordSet rs = new RecordSet ( ) ;
@ -149,11 +249,43 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
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" ) ) ;
voList . add ( build ) ;
}
return voList ;
}
private List < ChartChildrensVO > getVirtualSubDeptData ( 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 ( )
. pid ( supdepid )
. id ( getRandomData ( ) + id )
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) )
. build ( ) ;
if ( isVirtualSubDepartment ( id , virtualType ) ) {
build . setChildrens ( getVirtualSubDeptData ( id , virtualType ) ) ;
}
voList . add ( build ) ;
}
return voList ;
}
private String getRandomData ( ) {
String name = "" ; //先定义空字符串
for ( int i = 0 ; i < 3 ; i + + ) {
char n = ( char ) ( new Random ( ) . nextInt ( 26 ) + 97 ) ;
name + = n ; //name=name+n;
}
return name ;
}
@Override
public boolean isVirtualSubDepartment ( String supdepid , String virtualType ) {
RecordSet rs = new RecordSet ( ) ;
@ -215,6 +347,97 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
return voList ;
}
@Override
public TreeDataVO selectVirtualTopTwo ( String virtualType ) {
RecordSet rs = new RecordSet ( ) ;
BaseBean bb = new BaseBean ( ) ;
TreeDataVO build ;
String roleId = bb . getPropValue ( "sship" , "roleId" ) ;
String rolelevel = bb . getPropValue ( "sship" , "rolelevel" ) ;
boolean isExsit = selectIdsByRole ( roleId , rolelevel ) ;
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" ) ) ;
build = TreeDataVO . builder ( )
. id ( getRandomData ( ) + id )
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) )
. build ( ) ;
if ( isVirtualSubDepartment ( id , virtualType ) ) {
build . setChildrens ( getVirtualSubDeptData ( id , virtualType ) ) ;
}
} else {
//获取当前部门
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 ) ;
rs . next ( ) ;
build = TreeDataVO . builder ( )
. id ( getRandomData ( ) + departmentId )
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) )
. build ( ) ;
if ( isVirtualSubDepartment ( departmentId , virtualType ) ) {
build . setChildrens ( getVirtualSubDeptData ( departmentId , virtualType ) ) ;
}
}
return build ;
}
@Override
public List < SelectVO > selectVirtualTopThree ( VirtualTopParam virtualTopParam ) {
RecordSet rs = new RecordSet ( ) ;
List < SelectVO > voList = assembleSelectVOList ( ) ;
TreeDataVO build ;
int num = 1 ;
List < Integer > list = new ArrayList < > ( ) ;
list . add ( num ) ;
rs . executeQuery ( "select departmentmark from hrmdepartmentvirtual where id = ? and virtualtype = ? order by showorder" , virtualTopParam . getId ( ) , virtualTopParam . getVirtualType ( ) ) ;
rs . next ( ) ;
build = TreeDataVO . builder ( )
. id ( virtualTopParam . getId ( ) )
. label ( Util . null2String ( rs . getString ( "departmentmark" ) ) )
. build ( ) ;
if ( isVirtualSubDepartment ( virtualTopParam . getId ( ) , virtualTopParam . getVirtualType ( ) ) ) {
build . setChildrens ( getVirtualSubDept ( virtualTopParam . getId ( ) , virtualTopParam . getVirtualType ( ) ) ) ;
}
if ( null ! = build . getChildrens ( ) & & build . getChildrens ( ) . size ( ) > 0 ) {
for ( ChartChildrensVO children : build . getChildrens ( ) ) {
num = maxDepth ( children ) + 1 ;
list . add ( num ) ;
}
build . setNum ( Collections . max ( list ) + 1 ) ;
} else {
build . setNum ( num ) ;
}
// 判断是否满足删除条件
for ( int i = voList . size ( ) - 1 ; i > = 0 ; i - - ) {
if ( Integer . parseInt ( voList . get ( i ) . getValue ( ) ) > build . getNum ( ) ) {
voList . remove ( i ) ;
}
}
//MAP.entrySet().removeIf(entry -> Integer.parseInt(entry.getKey()) > build.getNum());
return voList ;
}
private static List < SelectVO > assembleSelectVOList ( ) {
List < SelectVO > voList = new ArrayList < > ( ) ;
voList . add ( SelectVO . builder ( ) . value ( "1" ) . label ( "一级" ) . build ( ) ) ;
voList . add ( SelectVO . builder ( ) . value ( "2" ) . label ( "二级" ) . build ( ) ) ;
voList . add ( SelectVO . builder ( ) . value ( "3" ) . label ( "三级" ) . build ( ) ) ;
voList . add ( SelectVO . builder ( ) . value ( "4" ) . label ( "四级" ) . build ( ) ) ;
voList . add ( SelectVO . builder ( ) . value ( "5" ) . label ( "五级" ) . build ( ) ) ;
voList . add ( SelectVO . builder ( ) . value ( "6" ) . label ( "六级" ) . build ( ) ) ;
voList . add ( SelectVO . builder ( ) . value ( "7" ) . label ( "七级" ) . build ( ) ) ;
voList . add ( SelectVO . builder ( ) . value ( "8" ) . label ( "八级" ) . build ( ) ) ;
voList . add ( SelectVO . builder ( ) . value ( "9" ) . label ( "九级" ) . build ( ) ) ;
voList . add ( SelectVO . builder ( ) . value ( "10" ) . label ( "十级" ) . build ( ) ) ;
return voList ;
}
private List < PersonTablePO > selectByLevel ( Integer level ) {
RecordSet rs = new RecordSet ( ) ;