2023-07-26 10:52:10 +08:00
package com.engine.organization.entity.chart ;
import lombok.AllArgsConstructor ;
import lombok.Builder ;
import lombok.Data ;
import lombok.NoArgsConstructor ;
import org.apache.commons.collections.CollectionUtils ;
2023-07-27 17:45:02 +08:00
import org.apache.commons.lang3.StringUtils ;
2023-07-26 10:52:10 +08:00
import weaver.conn.RecordSet ;
import java.util.ArrayList ;
import java.util.List ;
/ * *
* @author : dxfeng
* @createTime : 2023 / 07 / 25
* @version : 1 . 0
* /
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
2023-07-27 14:32:07 +08:00
public class TreeSelect {
2023-07-27 17:45:02 +08:00
public static final String COMPANY = " 0 " ;
public static final String SUB_COMPANY = " 1 " ;
public static final String DEPARTMENT = " 2 " ;
2023-07-26 10:52:10 +08:00
private String key ;
private String id ;
private String title ;
private String type ;
2023-07-27 17:45:02 +08:00
private String canceled ;
2023-07-27 14:32:07 +08:00
private List < TreeSelect > children ;
2023-07-31 10:02:38 +08:00
private boolean disabled ;
2023-07-26 10:52:10 +08:00
2023-07-27 17:45:02 +08:00
private String cancelSql ;
2023-07-27 14:32:07 +08:00
public List < TreeSelect > getChildren ( ) {
2023-07-26 10:52:10 +08:00
if ( null ! = children ) {
return children ;
}
children = new ArrayList < > ( ) ;
RecordSet rs = new RecordSet ( ) ;
2023-07-27 14:32:07 +08:00
if ( COMPANY . equals ( type ) ) {
2023-07-31 09:29:10 +08:00
String sql = " select id ,subcompanyname ,canceled from hrmsubcompany where " + getCancelSqlStr ( ) + " and (supsubcomid is null or supsubcomid = 0) and companyid = ? order by showorder " ;
2023-07-27 14:32:07 +08:00
rs . executeQuery ( sql , key ) ;
while ( rs . next ( ) ) {
2023-07-27 17:45:02 +08:00
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( " id " ) ) . title ( rs . getString ( " subcompanyname " ) ) . canceled ( rs . getString ( " canceled " ) ) . type ( SUB_COMPANY ) . cancelSql ( cancelSql ) . build ( ) ) ;
2023-07-27 14:32:07 +08:00
}
} else if ( SUB_COMPANY . equals ( type ) ) {
2023-07-31 09:29:10 +08:00
String sql = " select id ,subcompanyname ,canceled from hrmsubcompany where " + getCancelSqlStr ( ) + " and supsubcomid = ? order by showorder " ;
2023-07-26 10:52:10 +08:00
rs . executeQuery ( sql , key ) ;
while ( rs . next ( ) ) {
2023-07-27 17:45:02 +08:00
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( " id " ) ) . title ( rs . getString ( " subcompanyname " ) ) . canceled ( rs . getString ( " canceled " ) ) . type ( SUB_COMPANY ) . cancelSql ( cancelSql ) . build ( ) ) ;
2023-07-26 10:52:10 +08:00
}
2023-07-31 09:29:10 +08:00
sql = " select id,departmentname ,canceled from hrmdepartment where " + getCancelSqlStr ( ) + " and (supdepid is null or supdepid =0) and subcompanyid1 = ? order by showorder " ;
2023-07-26 10:52:10 +08:00
rs . executeQuery ( sql , key ) ;
while ( rs . next ( ) ) {
2023-07-27 17:45:02 +08:00
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( " id " ) ) . title ( rs . getString ( " departmentname " ) ) . canceled ( rs . getString ( " canceled " ) ) . type ( DEPARTMENT ) . cancelSql ( cancelSql ) . build ( ) ) ;
2023-07-26 10:52:10 +08:00
}
} else if ( DEPARTMENT . equals ( type ) ) {
2023-07-31 09:29:10 +08:00
String sql = " select id,departmentname ,canceled from hrmdepartment where " + getCancelSqlStr ( ) + " and supdepid = ? order by showorder " ;
2023-07-26 10:52:10 +08:00
rs . executeQuery ( sql , key ) ;
while ( rs . next ( ) ) {
2023-07-27 17:45:02 +08:00
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( " id " ) ) . title ( rs . getString ( " departmentname " ) ) . canceled ( rs . getString ( " canceled " ) ) . type ( DEPARTMENT ) . cancelSql ( cancelSql ) . build ( ) ) ;
2023-07-26 10:52:10 +08:00
}
}
return CollectionUtils . isEmpty ( children ) ? null : children ;
}
public String getKey ( ) {
switch ( type ) {
2023-07-27 14:32:07 +08:00
case COMPANY :
return " c " + key ;
2023-07-26 10:52:10 +08:00
case SUB_COMPANY :
return " s " + key ;
case DEPARTMENT :
return " d " + key ;
default :
break ;
}
return key ;
}
public String getId ( ) {
return key ;
}
2023-07-27 17:45:02 +08:00
public String getCanceled ( ) {
if ( StringUtils . isBlank ( canceled ) ) {
return " 0 " ;
}
return canceled ;
}
public String getCancelSql ( ) {
return null ;
}
private String getCancelSqlStr ( ) {
if ( StringUtils . isNotBlank ( cancelSql ) & & " 1 " . equals ( cancelSql ) ) {
return " 1=1 " ;
} else {
return " (canceled is null or canceled != 1) " ;
}
}
2023-07-26 10:52:10 +08:00
}