@ -5,6 +5,7 @@ import lombok.Builder;
import lombok.Data ;
import lombok.NoArgsConstructor ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang3.StringUtils ;
import weaver.conn.RecordSet ;
import java.util.ArrayList ;
@ -20,17 +21,19 @@ import java.util.List;
@NoArgsConstructor
@Builder
public class TreeSelect {
public static final String COMPANY = " company ";
public static final String SUB_COMPANY = " subCompany ";
public static final String DEPARTMENT = " department ";
public static final String COMPANY = " 0 ";
public static final String SUB_COMPANY = " 1 ";
public static final String DEPARTMENT = " 2 ";
private String key ;
private String id ;
private String title ;
private String type ;
private String icon ;
private String canceled ;
private List < TreeSelect > children ;
private String cancelSql ;
public List < TreeSelect > getChildren ( ) {
if ( null ! = children ) {
return children ;
@ -38,27 +41,27 @@ public class TreeSelect {
children = new ArrayList < > ( ) ;
RecordSet rs = new RecordSet ( ) ;
if ( COMPANY . equals ( type ) ) {
String sql = "select id ,subcompanyname from hrmsubcompany where (canceled is null or canceled != 1) and (supsubcomid is null or supsubcomid = 0) and companyid = ? order by showorder desc";
String sql = "select id ,subcompanyname ,canceled from hrmsubcompany where " + getCancelSqlStr ( ) + " and (supsubcomid is null or supsubcomid = 0) and companyid = ? order by showorder desc";
rs . executeQuery ( sql , key ) ;
while ( rs . next ( ) ) {
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( "id" ) ) . title ( rs . getString ( "subcompanyname" ) ) . type( SUB_COMPANY ) . build ( ) ) ;
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( "id" ) ) . title ( rs . getString ( "subcompanyname" ) ) . canceled( rs . getString ( "canceled" ) ) . type( SUB_COMPANY ) . cancelSql ( cancelSql ) . build ( ) ) ;
}
} else if ( SUB_COMPANY . equals ( type ) ) {
String sql = "select id ,subcompanyname from hrmsubcompany where (canceled is null or canceled != 1) and supsubcomid = ? order by showorder desc";
String sql = "select id ,subcompanyname ,canceled from hrmsubcompany where " + getCancelSqlStr ( ) + " and supsubcomid = ? order by showorder desc";
rs . executeQuery ( sql , key ) ;
while ( rs . next ( ) ) {
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( "id" ) ) . title ( rs . getString ( "subcompanyname" ) ) . type( SUB_COMPANY ) . build ( ) ) ;
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( "id" ) ) . title ( rs . getString ( "subcompanyname" ) ) . canceled( rs . getString ( "canceled" ) ) . type( SUB_COMPANY ) . cancelSql ( cancelSql ) . build ( ) ) ;
}
sql = "select id,departmentname from hrmdepartment where (canceled is null or canceled != 1) and (supdepid is null or supdepid =0) and subcompanyid1 = ? order by showorder desc";
sql = "select id,departmentname ,canceled from hrmdepartment where " + getCancelSqlStr ( ) + " and (supdepid is null or supdepid =0) and subcompanyid1 = ? order by showorder desc";
rs . executeQuery ( sql , key ) ;
while ( rs . next ( ) ) {
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( "id" ) ) . title ( rs . getString ( "departmentname" ) ) . type( DEPARTMENT ) . build ( ) ) ;
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( "id" ) ) . title ( rs . getString ( "departmentname" ) ) . canceled( rs . getString ( "canceled" ) ) . type( DEPARTMENT ) . cancelSql ( cancelSql ) . build ( ) ) ;
}
} else if ( DEPARTMENT . equals ( type ) ) {
String sql = "select id,departmentname from hrmdepartment where (canceled is null or canceled != 1) and supdepid = ? order by showorder desc";
String sql = "select id,departmentname ,canceled from hrmdepartment where " + getCancelSqlStr ( ) + " and supdepid = ? order by showorder desc";
rs . executeQuery ( sql , key ) ;
while ( rs . next ( ) ) {
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( "id" ) ) . title ( rs . getString ( "departmentname" ) ) . type( DEPARTMENT ) . build ( ) ) ;
children . add ( TreeSelect . builder ( ) . key ( rs . getString ( "id" ) ) . title ( rs . getString ( "departmentname" ) ) . canceled( rs . getString ( "canceled" ) ) . type( DEPARTMENT ) . cancelSql ( cancelSql ) . build ( ) ) ;
}
}
return CollectionUtils . isEmpty ( children ) ? null : children ;
@ -81,4 +84,23 @@ public class TreeSelect {
public String getId ( ) {
return key ;
}
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) " ;
}
}
}