@ -4,6 +4,7 @@ import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.date.DateUtil ;
import com.engine.core.impl.Service ;
import com.engine.core.impl.Service ;
import com.engine.organization.service.OrgChartService ;
import com.engine.organization.service.OrgChartService ;
import com.engine.organization.util.db.DBType ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.StringUtils ;
import weaver.conn.RecordSet ;
import weaver.conn.RecordSet ;
import weaver.hrm.User ;
import weaver.hrm.User ;
@ -31,7 +32,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
defaultItem . put ( "id" , "0" ) ;
defaultItem . put ( "id" , "0" ) ;
defaultItem . put ( "companyname" , "行政维度" ) ;
defaultItem . put ( "companyname" , "行政维度" ) ;
fclasslist . add ( defaultItem ) ;
fclasslist . add ( defaultItem ) ;
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
Map < String , Object > item = new HashMap < > ( ) ;
Map < String , Object > item = new HashMap < > ( ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "companyname" , rs . getString ( "companyname" ) ) ;
item . put ( "companyname" , rs . getString ( "companyname" ) ) ;
@ -42,7 +43,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
List < Map < String , Object > > companylist = new ArrayList < > ( ) ;
List < Map < String , Object > > companylist = new ArrayList < > ( ) ;
Map < String , Object > defaultCompanyItem = new HashMap < > ( ) ;
Map < String , Object > defaultCompanyItem = new HashMap < > ( ) ;
companylist . add ( defaultCompanyItem ) ;
companylist . add ( defaultCompanyItem ) ;
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
Map < String , Object > item = new HashMap < > ( ) ;
Map < String , Object > item = new HashMap < > ( ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "fnumber" , rs . getString ( "fnumber" ) ) ;
item . put ( "fnumber" , rs . getString ( "fnumber" ) ) ;
@ -57,26 +58,29 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
private String companyDateWhereSql ( Map < String , Object > request2Map ) {
private String companyDateWhereSql ( Map < String , Object > request2Map ) {
String date = ( String ) request2Map . get ( "date" ) ; // 数据日期
String date = ( String ) request2Map . get ( "date" ) ; // 数据日期
if ( StringUtils . isBlank ( date ) ) {
if ( StringUtils . isBlank ( date ) ) {
date = DateUtil . format ( DateUtil . offset ( new Date ( ) , DateField . DAY_OF_MONTH , 1 ) , "yyyy-MM-dd" ) ;
date = DateUtil . format ( DateUtil . offset ( new Date ( ) , DateField . DAY_OF_MONTH , 1 ) , "yyyy-MM-dd" ) ;
}
}
String fclass = ( String ) request2Map . get ( "fclass" ) ; // 维度
String fclass = ( String ) request2Map . get ( "fclass" ) ; // 维度
String fisvitual = ( String ) request2Map . get ( "fisvitual" ) ; // 是否显示虚拟组织
String fisvitual = ( String ) request2Map . get ( "fisvitual" ) ; // 是否显示虚拟组织
if ( StringUtils . isBlank ( fisvitual ) ) {
if ( StringUtils . isBlank ( fisvitual ) ) {
fisvitual = "0" ;
fisvitual = "0" ;
}
}
String whereSql = " where 1 = 1 " ;
String whereSql = " where 1 = 1 " ;
whereSql + = " and ((fdatebegin <= '" + date + "' and fdateend >= '" + date + "') or (fdatebegin <= '" + date + "' and fdateend is null )) " ;
if ( DBType . isOracle ( ) ) {
whereSql + = " and fclass = " + fclass + " " ;
whereSql + = " and ((fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and fdateend >= to_date('" + date + "','yyyy-MM-DD')) or (fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and fdateend is null )) " ;
} else {
whereSql + = " and ((fdatebegin <= '" + date + "' and fdateend >= '" + date + "') or (fdatebegin <= '" + date + "' and fdateend is null )) " ;
}
whereSql + = " and fclass = " + fclass + " " ;
if ( "0" . equals ( fisvitual ) ) {
if ( "0" . equals ( fisvitual ) ) {
whereSql + = " and fisvitual = 0 " ;
whereSql + = " and fisvitual = 0 " ;
} else {
} else {
whereSql + = " and fisvitual in (0, 1) " ;
whereSql + = " and fisvitual in (0, 1) " ;
}
}
@ -89,16 +93,16 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
String root = ( String ) request2Map . get ( "root" ) ; // 根节点
String root = ( String ) request2Map . get ( "root" ) ; // 根节点
String level = ( String ) request2Map . get ( "level" ) ; // 显示层级
String level = ( String ) request2Map . get ( "level" ) ; // 显示层级
if ( StringUtils . isBlank ( level ) ) {
if ( StringUtils . isBlank ( level ) ) {
level = "3" ;
level = "3" ;
}
}
String whereSql = companyDateWhereSql ( request2Map ) ;
String whereSql = companyDateWhereSql ( request2Map ) ;
String whereItemSql = " " ;
String whereItemSql = " " ;
if ( "0" . equals ( root ) ) { // 集团的情况
if ( "0" . equals ( root ) ) { // 集团的情况
whereItemSql + = " and ftype = 0 " ;
whereItemSql + = " and ftype = 0 " ;
} else {
} else {
whereItemSql + = " and id = '" + root + "' " ;
whereItemSql + = " and id = '" + root + "' " ;
}
}
// 获取根节点
// 获取根节点
@ -106,7 +110,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
rs . executeQuery ( "select id, fname, ftype, fparentid, fnumber from jcl_org_map " + whereSql + whereItemSql ) ;
rs . executeQuery ( "select id, fname, ftype, fparentid, fnumber from jcl_org_map " + whereSql + whereItemSql ) ;
List < Map < String , Object > > list = new ArrayList < > ( ) ;
List < Map < String , Object > > list = new ArrayList < > ( ) ;
String id = null ;
String id = null ;
if ( rs . next ( ) ) {
if ( rs . next ( ) ) {
Map < String , Object > item = new HashMap < > ( ) ;
Map < String , Object > item = new HashMap < > ( ) ;
id = rs . getString ( "id" ) ;
id = rs . getString ( "id" ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
@ -120,7 +124,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
}
int currentLevel = 1 ;
int currentLevel = 1 ;
if ( currentLevel + 1 < = Integer . parseInt ( level ) ) {
if ( currentLevel + 1 < = Integer . parseInt ( level ) ) {
findCompanyItemByParantId ( id , currentLevel + 1 , level , rs , list , whereSql , true ) ;
findCompanyItemByParantId ( id , currentLevel + 1 , level , rs , list , whereSql , true ) ;
}
}
@ -133,7 +137,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
private void findCompanyItemByParantId ( String id , int currentLevel , String level , RecordSet rs , List < Map < String , Object > > list , String whereSql , boolean expand ) {
private void findCompanyItemByParantId ( String id , int currentLevel , String level , RecordSet rs , List < Map < String , Object > > list , String whereSql , boolean expand ) {
rs . executeQuery ( "select id, fname, ftype, fparentid, fnumber from jcl_org_map " + whereSql + " and fparentid = " + id ) ;
rs . executeQuery ( "select id, fname, ftype, fparentid, fnumber from jcl_org_map " + whereSql + " and fparentid = " + id ) ;
List < Map < String , Object > > currentList = new ArrayList < > ( ) ;
List < Map < String , Object > > currentList = new ArrayList < > ( ) ;
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
Map < String , Object > item = new HashMap < > ( ) ;
Map < String , Object > item = new HashMap < > ( ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "fname" , rs . getString ( "fname" ) ) ;
item . put ( "fname" , rs . getString ( "fname" ) ) ;
@ -148,9 +152,9 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
list . addAll ( currentList ) ;
list . addAll ( currentList ) ;
for ( Map < String , Object > stringObjectMap : currentList ) {
for ( Map < String , Object > stringObjectMap : currentList ) {
if ( currentLevel + 1 < = Integer . parseInt ( level ) ) {
if ( currentLevel + 1 < = Integer . parseInt ( level ) ) {
findCompanyItemByParantId ( ( String ) stringObjectMap . get ( "id" ) , currentLevel + 1 , level , rs , list , whereSql , true ) ;
findCompanyItemByParantId ( ( String ) stringObjectMap . get ( "id" ) , currentLevel + 1 , level , rs , list , whereSql , true ) ;
} else if ( currentLevel = = Integer . parseInt ( level ) ) {
} else if ( currentLevel = = Integer . parseInt ( level ) ) {
findCompanyItemByParantId ( ( String ) stringObjectMap . get ( "id" ) , currentLevel + 1 , level , rs , list , whereSql , false ) ;
findCompanyItemByParantId ( ( String ) stringObjectMap . get ( "id" ) , currentLevel + 1 , level , rs , list , whereSql , false ) ;
}
}
}
}
@ -159,25 +163,29 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
private String userWhereSql ( Map < String , Object > request2Map ) {
private String userWhereSql ( Map < String , Object > request2Map ) {
String date = ( String ) request2Map . get ( "date" ) ; // 数据日期
String date = ( String ) request2Map . get ( "date" ) ; // 数据日期
if ( StringUtils . isBlank ( date ) ) {
if ( StringUtils . isBlank ( date ) ) {
date = DateUtil . format ( DateUtil . offset ( new Date ( ) , DateField . DAY_OF_MONTH , 1 ) , "yyyy-MM-dd" ) ;
date = DateUtil . format ( DateUtil . offset ( new Date ( ) , DateField . DAY_OF_MONTH , 1 ) , "yyyy-MM-dd" ) ;
}
}
String fclass = ( String ) request2Map . get ( "fclass" ) ; // 维度
String fclass = ( String ) request2Map . get ( "fclass" ) ; // 维度
String fisvitual = ( String ) request2Map . get ( "fisvitual" ) ; // 是否显示虚拟组织
String fisvitual = ( String ) request2Map . get ( "fisvitual" ) ; // 是否显示虚拟组织
if ( StringUtils . isBlank ( fisvitual ) ) {
if ( StringUtils . isBlank ( fisvitual ) ) {
fisvitual = "0" ;
fisvitual = "0" ;
}
}
String whereSql = " where 1 = 1 " ;
String whereSql = " where 1 = 1 " ;
whereSql + = " and ((t.fdatebegin <= '" + date + "' and t.fdateend >= '" + date + "') or (t.fdatebegin <= '" + date + "' and t.fdateend is null )) " ;
if ( DBType . isOracle ( ) ) {
whereSql + = " and t.fclass = " + fclass + " " ;
whereSql + = " and ((t.fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and t.fdateend >= to_date('" + date + "','yyyy-MM-DD')) or (t.fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and t.fdateend is null )) " ;
} else {
whereSql + = " and ((t.fdatebegin <= '" + date + "' and t.fdateend >= '" + date + "') or (t.fdatebegin <= '" + date + "' and t.fdateend is null )) " ;
}
whereSql + = " and t.fclass = " + fclass + " " ;
if ( "0" . equals ( fisvitual ) ) {
if ( "0" . equals ( fisvitual ) ) {
whereSql + = " and t.fisvitual = 0 " ;
whereSql + = " and t.fisvitual = 0 " ;
} else {
} else {
whereSql + = " and t.fisvitual in (0, 1) " ;
whereSql + = " and t.fisvitual in (0, 1) " ;
}
}
return whereSql ;
return whereSql ;
@ -187,17 +195,17 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
public Map < String , Object > getUserData ( Map < String , Object > request2Map , User user ) {
public Map < String , Object > getUserData ( Map < String , Object > request2Map , User user ) {
String root = ( String ) request2Map . get ( "root" ) ; // 根节点
String root = ( String ) request2Map . get ( "root" ) ; // 根节点
String level = ( String ) request2Map . get ( "level" ) ; // 显示层级
String level = ( String ) request2Map . get ( "level" ) ; // 显示层级
if ( StringUtils . isBlank ( level ) ) {
if ( StringUtils . isBlank ( level ) ) {
level = "3" ;
level = "3" ;
}
}
String whereSql = userWhereSql ( request2Map ) ;
String whereSql = userWhereSql ( request2Map ) ;
String whereItemSql = " " ;
String whereItemSql = " " ;
if ( "0" . equals ( root ) ) { // 集团的情况
if ( "0" . equals ( root ) ) { // 集团的情况
whereItemSql + = " and t.ftype = 0 " ;
whereItemSql + = " and t.ftype = 0 " ;
} else {
} else {
whereItemSql + = " and t.id = '" + root + "' " ;
whereItemSql + = " and t.id = '" + root + "' " ;
}
}
// 获取根节点
// 获取根节点
@ -205,7 +213,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
rs . executeQuery ( "select t.id, t.fname, t.ftype, t.fparentid, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fleader from jcl_org_map t " + whereSql + whereItemSql ) ;
rs . executeQuery ( "select t.id, t.fname, t.ftype, t.fparentid, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fleader from jcl_org_map t " + whereSql + whereItemSql ) ;
List < Map < String , Object > > list = new ArrayList < > ( ) ;
List < Map < String , Object > > list = new ArrayList < > ( ) ;
String id = null ;
String id = null ;
if ( rs . next ( ) ) {
if ( rs . next ( ) ) {
Map < String , Object > item = new HashMap < > ( ) ;
Map < String , Object > item = new HashMap < > ( ) ;
id = rs . getString ( "id" ) ;
id = rs . getString ( "id" ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
@ -225,7 +233,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
}
int currentLevel = 1 ;
int currentLevel = 1 ;
if ( currentLevel + 1 < = Integer . parseInt ( level ) ) {
if ( currentLevel + 1 < = Integer . parseInt ( level ) ) {
findUserItemByParantId ( id , currentLevel + 1 , level , rs , list , whereSql , true ) ;
findUserItemByParantId ( id , currentLevel + 1 , level , rs , list , whereSql , true ) ;
}
}
@ -240,12 +248,12 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
String ids = ( String ) request2Map . get ( "ids" ) ;
String ids = ( String ) request2Map . get ( "ids" ) ;
String whereSql = userWhereSql ( request2Map ) ;
String whereSql = userWhereSql ( request2Map ) ;
whereSql + = " and fparentid in (" + ids + ") " ;
whereSql + = " and fparentid in (" + ids + ") " ;
RecordSet rs = new RecordSet ( ) ;
RecordSet rs = new RecordSet ( ) ;
rs . executeQuery ( "select t.id, t.fname, t.ftype, t.fparentid, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fleader from jcl_org_map t " + whereSql ) ;
rs . executeQuery ( "select t.id, t.fname, t.ftype, t.fparentid, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fleader from jcl_org_map t " + whereSql ) ;
List < Map < String , Object > > currentList = new ArrayList < > ( ) ;
List < Map < String , Object > > currentList = new ArrayList < > ( ) ;
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
Map < String , Object > item = new HashMap < > ( ) ;
Map < String , Object > item = new HashMap < > ( ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "fname" , rs . getString ( "fname" ) ) ;
item . put ( "fname" , rs . getString ( "fname" ) ) ;
@ -291,12 +299,12 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
String ids = ( String ) request2Map . get ( "ids" ) ;
String ids = ( String ) request2Map . get ( "ids" ) ;
String whereSql = companyDateWhereSql ( request2Map ) ;
String whereSql = companyDateWhereSql ( request2Map ) ;
whereSql + = " and fparentid in (" + ids + ") " ;
whereSql + = " and fparentid in (" + ids + ") " ;
RecordSet rs = new RecordSet ( ) ;
RecordSet rs = new RecordSet ( ) ;
rs . executeQuery ( "select id, fname, ftype, fparentid, fnumber from jcl_org_map " + whereSql ) ;
rs . executeQuery ( "select id, fname, ftype, fparentid, fnumber from jcl_org_map " + whereSql ) ;
List < Map < String , Object > > currentList = new ArrayList < > ( ) ;
List < Map < String , Object > > currentList = new ArrayList < > ( ) ;
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
Map < String , Object > item = new HashMap < > ( ) ;
Map < String , Object > item = new HashMap < > ( ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "fname" , rs . getString ( "fname" ) ) ;
item . put ( "fname" , rs . getString ( "fname" ) ) ;
@ -316,7 +324,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
private void findUserItemByParantId ( String id , int currentLevel , String level , RecordSet rs , List < Map < String , Object > > list , String whereSql , boolean expand ) {
private void findUserItemByParantId ( String id , int currentLevel , String level , RecordSet rs , List < Map < String , Object > > list , String whereSql , boolean expand ) {
rs . executeQuery ( "select t.id, t.fname, t.ftype, t.fparentid, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber from jcl_org_map t " + whereSql + " and t.fparentid = " + id ) ;
rs . executeQuery ( "select t.id, t.fname, t.ftype, t.fparentid, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber from jcl_org_map t " + whereSql + " and t.fparentid = " + id ) ;
List < Map < String , Object > > currentList = new ArrayList < > ( ) ;
List < Map < String , Object > > currentList = new ArrayList < > ( ) ;
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
Map < String , Object > item = new HashMap < > ( ) ;
Map < String , Object > item = new HashMap < > ( ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "id" , rs . getString ( "id" ) ) ;
item . put ( "fname" , rs . getString ( "fname" ) ) ;
item . put ( "fname" , rs . getString ( "fname" ) ) ;
@ -334,9 +342,9 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
}
for ( Map < String , Object > stringObjectMap : currentList ) {
for ( Map < String , Object > stringObjectMap : currentList ) {
if ( "4" . equals ( stringObjectMap . get ( "ftype" ) ) ) { // 员工信息
if ( "4" . equals ( stringObjectMap . get ( "ftype" ) ) ) { // 员工信息
rs . executeQuery ( "select id, mobile, homeaddress from hrmresource where id = ? " , stringObjectMap . get ( "fnumber" ) ) ;
rs . executeQuery ( "select id, mobile, homeaddress from hrmresource where id = ? " , stringObjectMap . get ( "fnumber" ) ) ;
if ( rs . next ( ) ) {
if ( rs . next ( ) ) {
stringObjectMap . put ( "mobile" , rs . getString ( "mobile" ) ) ;
stringObjectMap . put ( "mobile" , rs . getString ( "mobile" ) ) ;
stringObjectMap . put ( "address" , rs . getString ( "homeaddress" ) ) ;
stringObjectMap . put ( "address" , rs . getString ( "homeaddress" ) ) ;
}
}
@ -344,14 +352,14 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
"left join hrmdepartment d\n" +
"left join hrmdepartment d\n" +
"on hrm.departmentid = d.id\n" +
"on hrm.departmentid = d.id\n" +
"where hrm.id = ? " , stringObjectMap . get ( "fnumber" ) ) ;
"where hrm.id = ? " , stringObjectMap . get ( "fnumber" ) ) ;
if ( rs . next ( ) ) {
if ( rs . next ( ) ) {
stringObjectMap . put ( "department" , rs . getString ( "departmentname" ) ) ;
stringObjectMap . put ( "department" , rs . getString ( "departmentname" ) ) ;
}
}
}
}
if ( currentLevel + 1 < = Integer . parseInt ( level ) ) {
if ( currentLevel + 1 < = Integer . parseInt ( level ) ) {
findUserItemByParantId ( ( String ) stringObjectMap . get ( "id" ) , currentLevel + 1 , level , rs , list , whereSql , true ) ;
findUserItemByParantId ( ( String ) stringObjectMap . get ( "id" ) , currentLevel + 1 , level , rs , list , whereSql , true ) ;
} else if ( currentLevel = = Integer . parseInt ( level ) ) { // 多查一层
} else if ( currentLevel = = Integer . parseInt ( level ) ) { // 多查一层
findUserItemByParantId ( ( String ) stringObjectMap . get ( "id" ) , currentLevel + 1 , level , rs , list , whereSql , false ) ;
findUserItemByParantId ( ( String ) stringObjectMap . get ( "id" ) , currentLevel + 1 , level , rs , list , whereSql , false ) ;
}
}
}
}
@ -360,12 +368,12 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
private boolean hasChildren ( String id , boolean isCompany ) {
private boolean hasChildren ( String id , boolean isCompany ) {
String whereSql = " where fparentid = " + id + " " ;
String whereSql = " where fparentid = " + id + " " ;
if ( isCompany ) {
if ( isCompany ) {
whereSql + = " and ftype in (0, 1, 2) " ;
whereSql + = " and ftype in (0, 1, 2) " ;
}
}
grs . executeQuery ( "select count(1) as count from jcl_org_map " + whereSql ) ;
grs . executeQuery ( "select count(1) as count from jcl_org_map " + whereSql ) ;
String count = "0" ;
String count = "0" ;
if ( grs . next ( ) ) {
if ( grs . next ( ) ) {
count = grs . getString ( "count" ) ;
count = grs . getString ( "count" ) ;
}
}
return ! "0" . equals ( count ) ;
return ! "0" . equals ( count ) ;