package com.engine.organization.service.impl ;
import com.engine.common.util.ServiceUtil ;
import com.engine.core.impl.Service ;
import com.engine.organization.entity.chart.ChartPO ;
import com.engine.organization.entity.chart.history.DepartmentHistory ;
import com.engine.organization.entity.chart.history.SubcompanyHistory ;
import com.engine.organization.mapper.hrmresource.SystemDataMapper ;
import com.engine.organization.mapper.jclorgmap.JclOrgMapper ;
import com.engine.organization.service.ChartService ;
import com.engine.organization.service.OrgChartService ;
import com.engine.organization.util.HasRightUtil ;
import com.engine.organization.util.OrganizationAssert ;
import com.engine.organization.util.OrganizationDateUtil ;
import com.engine.organization.util.db.MapperProxyFactory ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang3.StringUtils ;
import weaver.conn.RecordSet ;
import weaver.conn.RecordSetTrans ;
import weaver.general.StringUtil ;
import weaver.general.Util ;
import weaver.hrm.User ;
import weaver.hrm.resource.ResourceComInfo ;
import java.time.LocalDate ;
import java.util.* ;
/ * *
* @author : dxfeng
* @createTime : 2023 / 06 / 29
* @version : 1.0
* /
public class ChartServiceImpl extends Service implements ChartService {
private static final String COMPANY_RIGHT = "OrgChart:All" ;
public String COMPANY_TABLE = "" ;
public String SUB_COMPANY_TABLE = "" ;
public String SUB_COMPANY_DEFINED_TABLE = "" ;
public String DEPARTMENT_TABLE = "" ;
public String DEPARTMENT_DEFINED_TABLE = "" ;
public String SUB_COMPANY_ID = "''" ;
public String DEPARTMENT_ID = "''" ;
/ * *
* 显 示 虚 拟 组 织
* /
boolean showVirtual = false ;
/ * *
* 是 否 已 创 建 虚 拟 组 织 字 段
* /
boolean hasVirtualFields ;
private JclOrgMapper getJclOrgMapMapper ( ) {
return MapperProxyFactory . getProxy ( JclOrgMapper . class , true ) ;
}
private OrgChartService getOrgChartService ( User user ) {
return ServiceUtil . getService ( OrgChartServiceImpl . class , user ) ;
}
/ * *
* 是 否 实 际 组 织 维 度
* /
boolean isRealDimension ;
/ * *
* 是 否 即 时 数 据
* /
boolean isRealTime ;
@Override
public Map < String , Object > getCompanyData ( Map < String , Object > params ) {
Map < String , Object > result = new HashMap < > ( ) ;
boolean hasRight = HasRightUtil . hasRight ( user , COMPANY_RIGHT , true ) ;
result . put ( "hasRight" , hasRight ) ;
if ( ! hasRight ) {
return result ;
}
// 根结点
String root = Util . null2String ( params . get ( "root" ) ) ;
root = StringUtils . isBlank ( root ) ? "0" : root ;
// 维度
String dimension = Util . null2String ( params . get ( "fclass" ) ) ;
dimension = StringUtils . isBlank ( dimension ) ? "0" : dimension ;
// 是否展示虚拟组织
String isVirtual = Util . null2String ( params . get ( "fisvitual" ) ) ;
showVirtual = "1" . equals ( isVirtual ) ;
String depth = Util . null2String ( params . get ( "level" ) ) ;
//版本id
String id = Util . null2String ( params . get ( "id" ) ) ;
// 初始化表名
initTableNameByClass ( dimension , id ) ;
RecordSet rs = new RecordSet ( ) ;
List < ChartPO > dataList = new ArrayList < > ( ) ;
String sql = "" ;
ChartPO topChartPO = null ;
//查询当前实际数据
if ( isRealTime ) {
sql = getRealTimeTopSql ( root , dimension ) ;
} else {
sql = getLastTimeTopSql ( root , dimension , id ) ;
}
rs . executeQuery ( sql ) ;
// 封装顶部节点
if ( rs . next ( ) ) {
topChartPO = new ChartPO ( ) ;
topChartPO . setFtype ( rs . getString ( "type" ) ) ;
topChartPO . setFobjid ( rs . getString ( "id" ) ) ;
topChartPO . setFname ( rs . getString ( "name" ) ) ;
topChartPO . setParentId ( null ) ;
topChartPO . setExpand ( "1" ) ;
topChartPO . setFisvitual ( rs . getString ( "isvitual" ) ) ;
topChartPO . setHasChildren ( getHasChildren ( topChartPO . getFtype ( ) , topChartPO . getFobjid ( ) ) . toString ( ) ) ;
dataList . add ( topChartPO ) ;
}
// 向下查询数据
if ( null ! = topChartPO ) {
findChildData ( topChartPO , dataList , Integer . parseInt ( depth ) , id ) ;
}
result . put ( "api_status" , true ) ;
result . put ( "data" , dataList ) ;
return result ;
}
@Override
public Map < String , Object > asyncCompanyData ( Map < String , Object > params ) {
// 维度
String dimension = Util . null2String ( params . get ( "fclass" ) ) ;
dimension = StringUtils . isBlank ( dimension ) ? "0" : dimension ;
// 是否展示虚拟组织
String isVirtual = Util . null2String ( params . get ( "fisvitual" ) ) ;
showVirtual = "1" . equals ( isVirtual ) ;
//版本id
String versionId = Util . null2String ( params . get ( "id" ) ) ;
// 初始化表名
initTableNameByClass ( dimension , versionId ) ;
String ids = ( String ) params . get ( "ids" ) ;
List < ChartPO > dataList = new ArrayList < > ( ) ;
if ( StringUtils . isNotBlank ( ids ) ) {
RecordSet rs = new RecordSet ( ) ;
String [ ] split = ids . split ( "," ) ;
for ( String s : split ) {
//TODO 查询当前实际数据
if ( s . contains ( "_" ) ) {
String fObjId = s . split ( "_" ) [ 1 ] ;
if ( s . startsWith ( "s" ) ) {
if ( isRealTime ) {
rs . executeQuery ( getRealTimeChildSql ( "" , "1" , fObjId ) ) ;
} else {
rs . executeQuery ( getLastTimeChildSql ( "" , "1" , fObjId , versionId ) ) ;
}
} else if ( s . startsWith ( "d" ) ) {
if ( isRealTime ) {
rs . executeQuery ( getRealTimeChildSql ( "" , "2" , fObjId ) ) ;
} else {
rs . executeQuery ( getLastTimeChildSql ( "" , "2" , fObjId , versionId ) ) ;
}
}
while ( rs . next ( ) ) {
ChartPO chartPO = new ChartPO ( ) ;
chartPO . setFtype ( rs . getString ( "type" ) ) ;
chartPO . setFobjid ( rs . getString ( "id" ) ) ;
chartPO . setFname ( rs . getString ( "name" ) ) ;
chartPO . setParentId ( s ) ;
chartPO . setExpand ( "0" ) ;
chartPO . setFisvitual ( rs . getString ( "isvitual" ) ) ;
chartPO . setHasChildren ( getHasChildren ( chartPO . getFtype ( ) , chartPO . getFobjid ( ) ) . toString ( ) ) ;
dataList . add ( chartPO ) ;
}
}
}
}
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( "api_status" , true ) ;
result . put ( "data" , dataList ) ;
return result ;
}
@Override
public Map < String , Object > getDepartmentDetail ( Map < String , Object > params ) {
String rootId = Util . null2String ( params . get ( "rootId" ) ) ;
// 维度
String dimension = Util . null2String ( params . get ( "fclass" ) ) ;
dimension = StringUtils . isBlank ( dimension ) ? "0" : dimension ;
// 是否显示岗位
String showJobStr = Util . null2String ( params . get ( "showJob" ) ) ;
boolean showJob = "1" . equals ( showJobStr ) ;
//版本id
String versionId = Util . null2String ( params . get ( "id" ) ) ;
OrganizationAssert . isFalse ( StringUtils . isBlank ( rootId ) | | ! rootId . startsWith ( "d_" ) , "数据有误,未查询到对应数据" ) ;
String departmentId = rootId . split ( "_" ) [ 1 ] ;
String detauleType = Util . null2String ( params . get ( "detauleType" ) ) ;
if ( ! "chart" . equals ( detauleType ) ) {
// 展示列表模块
return ServiceUtil . getService ( HrmResourceServiceImpl . class , user ) . chartResourceList ( Integer . parseInt ( departmentId ) , versionId , dimension ) ;
}
// 初始化表名
initTableNameByClass ( dimension , versionId ) ;
List < ChartPO > dataList = new ArrayList < > ( ) ;
List < ChartPO > jobTitleList = new ArrayList < > ( ) ;
int departmentOnJob = 0 ;
int resourceNum ;
RecordSet rs = new RecordSet ( ) ;
// TODO 查询当前实际的数据
String sql ;
if ( isRealTime ) {
// 查询部门本身
if ( hasVirtualFields ) {
sql = "select a.id,a.departmentname as name,b.bmfzr,b.bmlx as isvitual from " + DEPARTMENT_TABLE + " a left join hrmdepartmentdefined b on a.id = b.deptid where a.id = '" + departmentId + "'" ;
} else {
sql = "select a.id,a.departmentname as name,b.bmfzr from " + DEPARTMENT_TABLE + " a left join hrmdepartmentdefined b on a.id = b.deptid where a.id = '" + departmentId + "'" ;
}
} else {
if ( hasVirtualFields ) {
sql = "select " + DEPARTMENT_ID + " as id,a.departmentname as name,fleader as bmfzr,isvirtual as isvitual from " + DEPARTMENT_TABLE + " a where a.id = '" + departmentId + "' and versionid = " + versionId ;
} else {
sql = "select " + DEPARTMENT_ID + " as id,a.departmentname as name from " + DEPARTMENT_TABLE + " a where a.id = '" + departmentId + "' and versionid = " + versionId ;
}
}
rs . executeQuery ( sql ) ;
ChartPO departmentChartPO = new ChartPO ( ) ;
if ( rs . next ( ) ) {
String fLeader = Util . null2String ( rs . getString ( "bmfzr" ) ) ;
departmentChartPO . setFtype ( "2" ) ;
departmentChartPO . setFobjid ( departmentId ) ;
departmentChartPO . setId ( rootId ) ;
departmentChartPO . setFname ( rs . getString ( "name" ) ) ;
// 岗位处理后的ID
departmentChartPO . setExpand ( "1" ) ;
departmentChartPO . setFisvitual ( rs . getString ( "isvitual" ) ) ;
// 部门负责人
departmentChartPO . setFleader ( getDepartmentLeader ( fLeader ) ) ;
dataList . add ( departmentChartPO ) ;
}
if ( showJob ) {
// 查询部门下的岗位
if ( isRealTime ) {
sql = "select a.id,a.jobtitlename as name from hrmjobtitles a inner join jcl_org_job b on a.id = b.ec_jobtitle where b.ec_department = '" + departmentId + "'" ;
} else {
sql = "select jobid as id ,jobname as name from jcl_chart_job where departmentid = '" + departmentId + "' and versionid = " + versionId ;
}
rs . executeQuery ( sql ) ;
while ( rs . next ( ) ) {
ChartPO chartPO = new ChartPO ( ) ;
chartPO . setFtype ( "3" ) ;
chartPO . setFobjid ( rs . getString ( "id" ) ) ;
chartPO . setId ( departmentId + "_" + chartPO . getFobjid ( ) ) ;
chartPO . setFname ( rs . getString ( "name" ) ) ;
// 岗位处理后的ID
chartPO . setParentId ( rootId ) ;
chartPO . setExpand ( "1" ) ;
chartPO . setHasChildren ( "1" ) ;
jobTitleList . add ( chartPO ) ;
}
// 遍历岗位、查询对应岗位下的人员
if ( isRealTime ) {
if ( isRealDimension ) {
sql = "select a.id,a.lastname as name ,a.belongto ,a.companyworkyear from hrmresource a where a.status < 4 and a.departmentid = ? and a.jobtitle = ?" ;
} else {
sql = "select a.id,a.lastname as name ,a.belongto ,a.companyworkyear from hrmresource a inner join hrmresourcevirtual b on a.id = b.resourceid where a.status < 4 and b.departmentid = ? and a.jobtitle = ?" ;
}
} else {
sql = "select a.resourceid as id,a.lastname as name ,a.belongto ,a.companyworkyear from jcl_chart_resource a where a.status < 4 and a.departmentid = ? and a.jobtitleid = ? and versionid = " + versionId ;
}
for ( ChartPO jobTitlePO : jobTitleList ) {
resourceNum = 0 ;
rs . executeQuery ( sql , departmentId , jobTitlePO . getFobjid ( ) ) ;
String parentId = departmentId + "_" + jobTitlePO . getFobjid ( ) ;
while ( rs . next ( ) ) {
ChartPO chartPO = getResourceChartPO ( rs . getString ( "id" ) , rs . getString ( "name" ) , parentId , rs . getString ( "belongto" ) , rs . getString ( "companyworkyear" ) ) ;
resourceNum + + ;
dataList . add ( chartPO ) ;
}
jobTitlePO . setFonjob ( resourceNum ) ;
departmentOnJob + = resourceNum ;
dataList . add ( jobTitlePO ) ;
}
departmentChartPO . setHasChildren ( CollectionUtils . isNotEmpty ( jobTitleList ) ? "1" : "0" ) ;
} else {
// 直接查询岗位下的人员
if ( isRealTime ) {
if ( isRealDimension ) {
sql = "select a.id,a.lastname as name ,a.belongto ,a.companyworkyear from hrmresource a where a.status < 4 and a.departmentid = ? " ;
} else {
sql = "select a.id,a.lastname as name ,a.belongto ,a.companyworkyear from hrmresource a inner join hrmresourcevirtual b on a.id = b.resourceid where a.status < 4 and b.departmentid = ? " ;
}
} else {
sql = "select a.resourceid as id,a.lastname as name ,a.belongto ,a.companyworkyear from jcl_chart_resource a where a.status < 4 and a.departmentid = ? and versionid = " + versionId ;
}
rs . executeQuery ( sql , departmentId ) ;
while ( rs . next ( ) ) {
ChartPO chartPO = getResourceChartPO ( rs . getString ( "id" ) , rs . getString ( "name" ) , rootId , rs . getString ( "belongto" ) , rs . getString ( "companyworkyear" ) ) ;
dataList . add ( chartPO ) ;
departmentOnJob + + ;
}
}
departmentChartPO . setFonjob ( departmentOnJob ) ;
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( "api_status" , true ) ;
result . put ( "data" , dataList ) ;
return result ;
}
@Override
public String selectVersionDate ( String id ) {
RecordSet rs = new RecordSet ( ) ;
rs . executeQuery ( "select recorddate from jcl_org_chartversion where id = ?" , id ) ;
rs . next ( ) ;
return rs . getString ( "recorddate" ) ;
}
/ * *
* 构 建 人 员 图 谱 元 素
*
* @param id 人 员 ID
* @param name 人 员 名 称
* @param parentId 父 级 ID
* @param belongTo 是 否 次 账 号
* @param companyWorkYear 司 龄
* @return
* /
private ChartPO getResourceChartPO ( String id , String name , String parentId , String belongTo , String companyWorkYear ) {
ChartPO chartPO = new ChartPO ( ) ;
chartPO . setFtype ( "4" ) ;
chartPO . setFobjid ( id ) ;
chartPO . setId ( chartPO . getFobjid ( ) ) ;
chartPO . setFname ( name ) ;
// 岗位处理后的ID
chartPO . setParentId ( parentId ) ;
chartPO . setExpand ( "0" ) ;
chartPO . setHasChildren ( "0" ) ;
chartPO . setBelongto ( Util . null2String ( belongTo ) ) ;
chartPO . setCompanyWorkYear ( companyWorkYear ) ;
try {
chartPO . setFleaderimg ( new ResourceComInfo ( ) . getMessagerUrls ( chartPO . getId ( ) ) ) ;
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
return chartPO ;
}
/ * *
* 获 取 历 史 顶 部 元 素 sql
*
* @param root
* @param dimension 维 度 ID
* @param versionId
* @return
* /
private String getLastTimeTopSql ( String root , String dimension , String versionId ) {
if ( "0" . equals ( root ) ) {
//查询集团维度历史版本
if ( isRealDimension ) {
//组织维度
return "select id,companyname as name,'0' as type from " + COMPANY_TABLE ;
} else {
//查询其他维度集团版本信息
return "select id,companyname as name,'0' as type from " + COMPANY_TABLE + " where " +
" versionid = " + versionId + " and companyvirtualid = " + dimension ;
}
} else {
if ( hasVirtualFields ) {
if ( showVirtual ) {
return "select " + SUB_COMPANY_ID + " as id,subcompanyname as name,'1' as type,isvirtual as isvitual from " + SUB_COMPANY_TABLE + " where versionid = " + versionId + " and subcompanyid = " + root ;
} else {
return "select " + SUB_COMPANY_ID + " as id,subcompanyname as name,'1' as type,isvirtual as isvitual from " + SUB_COMPANY_TABLE + " where versionid = " + versionId + " and subcompanyid = " + root + " and (isvirtual is null or isvirtual != '1')" ;
}
} else {
return "select " + SUB_COMPANY_ID + " as id,subcompanyname as name,'1' as type from " + SUB_COMPANY_TABLE + " where versionid = " + versionId + " and subcompanyid = " + root ;
}
}
}
@Override
public Map < String , Object > versionRecord ( Map < String , Object > params , User user ) {
RecordSetTrans recordSetTrans = new RecordSetTrans ( ) ;
recordSetTrans . setAutoCommit ( false ) ; //关闭自动提交
RecordSet rs = new RecordSet ( ) ;
// 维度
String dimension = Util . null2String ( params . get ( "fclass" ) ) ;
dimension = StringUtils . isBlank ( dimension ) ? "0" : dimension ;
//描述
String description = Util . null2String ( params . get ( "description" ) ) ;
//当前日期
String currentDate = OrganizationDateUtil . getFormatLocalDateTime ( new Date ( ) ) ;
//当前用户
String currentUser = String . valueOf ( user . getUID ( ) ) ;
//版本记录表数据存储
getOrgChartService ( user ) . insertChartVersion ( Integer . valueOf ( dimension ) , description ) ;
String versionId = "" ;
String createDate = OrganizationDateUtil . getFormatLocalDate ( LocalDate . now ( ) ) ;
rs . executeQuery ( "select id from JCL_ORG_CHARTVERSION where fclass = ? and createtime = ?" , dimension , createDate ) ;
if ( rs . next ( ) ) {
versionId = Util . null2String ( rs . getString ( "id" ) ) ;
}
if ( "0" . equals ( dimension ) ) {
//实体维度
trueDimension ( versionId , currentUser , currentDate ) ;
} else {
virtualDimension ( versionId , currentUser , currentDate , dimension ) ;
}
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( "api_status" , true ) ;
return result ;
}
private void trueDimension ( String versionId , String currentUser , String currentDate ) {
RecordSet rs = new RecordSet ( ) ;
rs . execute ( "delete from jcl_chart_subcompany where versionid = " + versionId ) ;
rs . execute ( "delete from jcl_chart_department where versionid = " + versionId ) ;
rs . execute ( "delete from jcl_chart_job where versionid = " + versionId ) ;
rs . execute ( "delete from jcl_chart_resource where versionid = " + versionId ) ;
String subCompanyQuerySql ; //分部查询数据sql
String deptQuerySql ; //部门查询数据sql
//判断是否有虚拟组织字段
boolean virtualFlag = isHasVirtualFields ( ) ;
if ( virtualFlag ) {
subCompanyQuerySql = "select a.id as subcompanyid,\n" +
" a.subcompanyname,\n" +
" a.subcompanydesc,\n" +
" a.companyid as company,\n" +
" b.supsubcomid as supsubcompanyid,\n" +
" b.subcompanyname as supsubcompany,\n" +
" a.canceled,\n" +
" a.subcompanycode,\n" +
" a.limitusers,\n" +
" a.tlevel,\n" +
" c.fblx as isvirtual\n" +
" from hrmsubcompany a\n" +
" left join hrmsubcompany b on a.supsubcomid = b.id\n" +
" left join hrmsubcompanydefined c on a.id = c.subcomid " ;
deptQuerySql = "select a.id as departmentid, a.departmentmark, a.departmentname, a.subcompanyid1 as subcompanyid, " +
"b.SUBCOMPANYNAME as subcompany,a.supdepid as supdepartmentid,c.departmentname as supdepartment," +
"a.canceled,a.departmentcode,a.coadjutant,a.tlevel,d.bmlx as isvirtual,a.bmfzr as fleader " +
"from hrmdepartment a left join hrmsubcompany b on a.subcompanyid1 = b.id " +
"left join hrmdepartment c on a.supdepid = c.id " +
"left join hrmdepartmentdefined d on a.id=d.deptid" ;
} else {
subCompanyQuerySql = "select a.id as subcompanyid,\n" +
" a.subcompanyname,\n" +
" a.subcompanydesc,\n" +
" a.companyid as company,\n" +
" b.supsubcomid as supsubcompanyid,\n" +
" b.subcompanyname as supsubcompany,\n" +
" a.canceled,\n" +
" a.subcompanycode,\n" +
" a.limitusers,\n" +
" a.tlevel,\n" +
" from hrmsubcompany a\n" +
" left join hrmsubcompany b on a.supsubcomid = b.id" ;
deptQuerySql = "select a.id as departmentid,\n" +
" a.departmentmark,\n" +
" a.departmentname,\n" +
" a.subcompanyid1 as subcompanyid,\n" +
" b.SUBCOMPANYNAME as subcompany,\n" +
" a.supdepid as supdepartmentid,\n" +
" c.departmentname as supdepartment,\n" +
" a.canceled,\n" +
" a.departmentcode,\n" +
" a.coadjutant,\n" +
" a.tlevel,\n" +
" a.bmfzr as fleader\n" +
" from hrmdepartment a\n" +
" left join hrmsubcompany b on a.subcompanyid1 = b.id\n" +
" left join hrmdepartment c on a.supdepid = c.id" ;
}
List < Object > insertList = new ArrayList < > ( ) ;
List < List < Object > > insertParamList = new ArrayList < > ( ) ;
//当前分部版本存储
rs . executeQuery ( subCompanyQuerySql ) ;
while ( rs . next ( ) ) {
insertList = new ArrayList < > ( ) ;
insertList . add ( currentUser ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "subcompanyid" ) ) ? null : rs . getInt ( "subcompanyid" ) ) ;
insertList . add ( rs . getString ( "subcompanyname" ) ) ;
insertList . add ( rs . getString ( "subcompanydesc" ) ) ;
insertList . add ( rs . getString ( "company" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "supsubcompanyid" ) ) ? null : rs . getInt ( "supsubcompanyid" ) ) ;
insertList . add ( rs . getString ( "supsubcompany" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "canceled" ) ) ? null : rs . getInt ( "canceled" ) ) ;
insertList . add ( rs . getString ( "subcompanycode" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "limitusers" ) ) ? null : rs . getInt ( "limitusers" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "tlevel" ) ) ? null : rs . getInt ( "tlevel" ) ) ;
insertList . add ( currentDate ) ;
insertList . add ( virtualFlag ? Util . getIntValue ( rs . getString ( "isvirtual" ) , 0 ) : 1 ) ;
insertList . add ( StringUtils . isBlank ( versionId ) ? null : Util . getIntValue ( versionId ) ) ;
insertParamList . add ( insertList ) ;
}
String insertSubSql = "insert into jcl_chart_subcompany(creater, subcompanyid, subcompanyname, subcompanydesc, company,\n" +
" supsubcompanyid, supsubcompany, canceled, subcompanycode, limitusers,\n" +
" tlevel, versiondate, isvirtual,versionId) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)" ;
insertData ( insertSubSql , insertParamList ) ;
//当前部门版本存储
rs . executeQuery ( deptQuerySql ) ;
insertParamList = new ArrayList < > ( ) ;
while ( rs . next ( ) ) {
insertList = new ArrayList < > ( ) ;
insertList . add ( currentUser ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "departmentid" ) ) ? null : rs . getInt ( "departmentid" ) ) ;
insertList . add ( rs . getString ( "departmentmark" ) ) ;
insertList . add ( rs . getString ( "departmentname" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "subcompanyid" ) ) ? null : rs . getInt ( "subcompanyid" ) ) ;
insertList . add ( rs . getString ( "subcompany" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "supdepartmentid" ) ) ? null : rs . getInt ( "supdepartmentid" ) ) ;
insertList . add ( rs . getString ( "supdepartment" ) ) ;
insertList . add ( rs . getInt ( "canceled" ) ) ;
insertList . add ( rs . getString ( "departmentcode" ) ) ;
insertList . add ( rs . getString ( "coadjutant" ) ) ;
// insertList.add(rs.getInt("tlevel"));
insertList . add ( rs . getString ( "fleader" ) ) ;
insertList . add ( currentDate ) ;
insertList . add ( virtualFlag ? Util . getIntValue ( rs . getString ( "isvirtual" ) , 0 ) : 1 ) ;
insertList . add ( StringUtils . isBlank ( versionId ) ? null : Util . getIntValue ( versionId ) ) ;
insertParamList . add ( insertList ) ;
}
String insertDeptSql = "insert into jcl_chart_department(creater, departmentid, departmentmark, departmentname, subcompanyid,\n" +
" subcompany, supdepartmentid, supdepartment, canceled, departmentcode,\n" +
" coadjutant, fleader,versiondate, isvirtual,versionid) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" ;
insertData ( insertDeptSql , insertParamList ) ;
//当前岗位版本存储
rs . executeQuery ( "select a.id as jobid,a.job_name as jobname,a.ec_department as departmentid," +
"c.departmentname as department,a.ec_company as subcompanyid,d.subcompanyname as subcompany," +
"b.jobresponsibility,a.forbidden_tag as canceled,a.job_no as jobcode,a.description " +
"from jcl_org_job a left join hrmjobtitles b on a.ec_jobtitle = b.id " +
"left join hrmdepartment c on a.ec_department=c.id " +
"left join hrmsubcompany d on a.ec_company=d.id" ) ;
insertParamList = new ArrayList < > ( ) ;
while ( rs . next ( ) ) {
insertList = new ArrayList < > ( ) ;
insertList . add ( rs . getString ( "jobid" ) ) ;
insertList . add ( currentUser ) ;
insertList . add ( rs . getString ( "jobname" ) ) ;
insertList . add ( rs . getString ( "departmentid" ) ) ;
insertList . add ( rs . getString ( "department" ) ) ;
insertList . add ( rs . getString ( "subcompanyid" ) ) ;
insertList . add ( rs . getString ( "subcompany" ) ) ;
insertList . add ( rs . getString ( "jobresponsibility" ) ) ;
insertList . add ( rs . getString ( "canceled" ) ) ;
insertList . add ( rs . getString ( "jobcode" ) ) ;
insertList . add ( rs . getString ( "description" ) ) ;
insertList . add ( currentDate ) ;
insertList . add ( StringUtils . isBlank ( versionId ) ? null : Util . getIntValue ( versionId ) ) ;
insertParamList . add ( insertList ) ;
}
String insertJobSql = "insert into jcl_chart_job(jobid,creater,jobname,departmentid,department,subcompanyid," +
"subcompany,jobresponsibility,canceled,jobcode,description,versiondate,versionid)values(?,?,?,?,?,?,?,?,?,?,?,?,?)" ;
insertData ( insertJobSql , insertParamList ) ;
//当前人员版本存储
rs . executeQuery ( "select a.id as resourceid,workyear,usekind,managerstr,status,sex,accounttype,belongto," +
"loginid,maritalstatus,a.telephone,mobile,mobilecall,email,b.locationname,resourcetype,startdate," +
"enddate,c.id as jobtitleid,d.JOBTITLENAME as jobtitle,joblevel,seclevel,departmentid,e.departmentname as department," +
"a.subcompanyid1 as subcompanyid,f.subcompanyname as subcompany,a.costcenterid as costcenter," +
"a.managerid as manager,a.assistantid as assistant,workcode,classification,policy," +
"degree,a.lastname,a.companyworkyear from hrmresource a " +
"left join hrmlocations b on a.locationid = b.id " +
"left join jcl_org_job c on a.jobtitle = c.id " +
"left join hrmjobtitles d on c.ec_jobtitle = d.id " +
"left join hrmdepartment e on a.departmentid = e.id " +
"left join hrmsubcompany f on a.subcompanyid1=f.id" ) ;
insertParamList = new ArrayList < > ( ) ;
while ( rs . next ( ) ) {
insertList = new ArrayList < > ( ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "resourceid" ) ) ? null : rs . getInt ( "resourceid" ) ) ;
insertList . add ( currentUser ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "workyear" ) ) ? null : rs . getInt ( "workyear" ) ) ;
insertList . add ( rs . getString ( "usekind" ) ) ;
insertList . add ( rs . getString ( "managerstr" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "status" ) ) ? null : rs . getInt ( "status" ) ) ;
insertList . add ( rs . getString ( "sex" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "accounttype" ) ) ? null : rs . getInt ( "accounttype" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "belongto" ) ) ? null : rs . getInt ( "belongto" ) ) ;
insertList . add ( rs . getString ( "loginid" ) ) ;
insertList . add ( rs . getString ( "maritalstatus" ) ) ;
insertList . add ( rs . getString ( "telephone" ) ) ;
insertList . add ( rs . getString ( "mobile" ) ) ;
insertList . add ( rs . getString ( "mobilecall" ) ) ;
insertList . add ( rs . getString ( "email" ) ) ;
insertList . add ( rs . getString ( "locationname" ) ) ;
insertList . add ( rs . getString ( "resourcetype" ) ) ;
insertList . add ( rs . getString ( "startdate" ) ) ;
insertList . add ( rs . getString ( "enddate" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "jobtitleid" ) ) ? null : rs . getInt ( "jobtitleid" ) ) ;
insertList . add ( rs . getString ( "jobtitle" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "joblevel" ) ) ? null : rs . getInt ( "joblevel" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "seclevel" ) ) ? null : rs . getInt ( "seclevel" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "departmentid" ) ) ? null : rs . getInt ( "departmentid" ) ) ;
insertList . add ( rs . getString ( "department" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "subcompanyid" ) ) ? null : rs . getInt ( "subcompanyid" ) ) ;
insertList . add ( rs . getString ( "subcompany" ) ) ;
insertList . add ( rs . getString ( "costcenter" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "manager" ) ) ? null : rs . getInt ( "manager" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "assistant" ) ) ? null : rs . getInt ( "assistant" ) ) ;
insertList . add ( rs . getString ( "workcode" ) ) ;
insertList . add ( rs . getString ( "classification" ) ) ;
insertList . add ( currentDate ) ;
insertList . add ( rs . getString ( "policy" ) ) ;
insertList . add ( rs . getString ( "degree" ) ) ;
insertList . add ( StringUtils . isBlank ( versionId ) ? null : Util . getIntValue ( versionId ) ) ;
insertList . add ( rs . getString ( "lastname" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "companyworkyear" ) ) ? null : rs . getString ( "companyworkyear" ) ) ;
insertParamList . add ( insertList ) ;
}
String insertResourceSql = "insert into jcl_chart_resource(resourceid, creater, workyear, usekind, managerstr," +
"status, sex, accounttype,belongto, loginid, maritalstatus, telephone, mobile, mobilecall, email," +
"locationname, resourcetype, startdate, enddate, jobtitleid, jobtitle, joblevel,seclevel, departmentid," +
"department, subcompanyid, subcompany, costcenter,manager, assistant, workcode, classification, " +
"versiondate, policy, degree,versionid,lastname,companyworkyear) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" ;
insertData ( insertResourceSql , insertParamList ) ;
}
private void virtualDimension ( String versionId , String currentUser , String currentDate , String fclass ) {
RecordSet rs = new RecordSet ( ) ;
List < Object > insertList ;
List < List < Object > > insertParamList = new ArrayList < > ( ) ;
rs . execute ( "delete from jcl_chart_companyvirtual where versionid = " + versionId ) ;
rs . execute ( "delete from jcl_chart_subcompanyvirtual where versionid = " + versionId ) ;
rs . execute ( "delete from jcl_chart_departmentvirtual where versionid = " + versionId ) ;
rs . execute ( "delete from jcl_chart_resource where versionid = " + versionId ) ;
//虚拟总部存储
rs . executeQuery ( "select id as companyvirtualid,companyname,companycode,companydesc,showorder,canceled," +
"virtualtype,virtualtypedesc from hrmcompanyvirtual where id=?" , fclass ) ;
while ( rs . next ( ) ) {
insertList = new ArrayList < > ( ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "companyvirtualid" ) ) ? null : rs . getInt ( "companyvirtualid" ) ) ;
insertList . add ( currentUser ) ;
insertList . add ( rs . getString ( "companyname" ) ) ;
insertList . add ( rs . getString ( "companycode" ) ) ;
insertList . add ( rs . getString ( "companydesc" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "showorder" ) ) ? null : rs . getInt ( "showorder" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "canceled" ) ) ? null : rs . getInt ( "canceled" ) ) ;
insertList . add ( rs . getString ( "virtualtype" ) ) ;
insertList . add ( rs . getString ( "virtualtypedesc" ) ) ;
insertList . add ( currentDate ) ;
insertList . add ( StringUtils . isBlank ( versionId ) ? null : Util . getIntValue ( versionId ) ) ;
insertParamList . add ( insertList ) ;
}
String insertVirtualComSql = "insert into jcl_chart_companyvirtual(companyvirtualid,creater,companyname,companycode,companydesc,showorder,\n" +
"canceled,virtualtype,virtualtypedesc,versiondate,versionid) values(?,?,?,?,?,?,?,?,?,?,?)" ;
insertData ( insertVirtualComSql , insertParamList ) ;
//虚拟分部版本存储
rs . executeQuery ( "select a.id as subcompanyvirtualid,a.subcompanyname,a.subcompanycode,a.subcompanydesc," +
"b.subcompanyname as supsubcompany,a.supsubcomid,c.companyname as company,a.companyid,a.canceled," +
"a.virtualtypeid as virtualtype,a.tlevel,a.showorder from hrmsubcompanyvirtual a " +
"left join hrmsubcompanyvirtual b on a.supsubcomid = b.id\n" +
"left join hrmcompanyvirtual c on a.companyid = c.id where a.companyid=?" , fclass ) ;
insertParamList = new ArrayList < > ( ) ;
while ( rs . next ( ) ) {
insertList = new ArrayList < > ( ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "subcompanyvirtualid" ) ) ? null : rs . getInt ( "subcompanyvirtualid" ) ) ;
insertList . add ( currentUser ) ;
insertList . add ( rs . getString ( "subcompanyname" ) ) ;
insertList . add ( rs . getString ( "subcompanycode" ) ) ;
insertList . add ( rs . getString ( "subcompanydesc" ) ) ;
insertList . add ( rs . getString ( "supsubcompany" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "supsubcomid" ) ) ? null : rs . getInt ( "supsubcomid" ) ) ;
insertList . add ( rs . getString ( "company" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "companyid" ) ) ? null : rs . getInt ( "companyid" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "canceled" ) ) ? null : rs . getInt ( "canceled" ) ) ;
insertList . add ( rs . getString ( "virtualtype" ) ) ;
insertList . add ( rs . getString ( "tlevel" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "showorder" ) ) ? null : rs . getInt ( "showorder" ) ) ;
insertList . add ( currentDate ) ;
insertList . add ( StringUtils . isBlank ( versionId ) ? null : Util . getIntValue ( versionId ) ) ;
insertParamList . add ( insertList ) ;
}
String insertVirtualSubComSql = "insert into jcl_chart_subcompanyvirtual(subcompanyvirtualid, creater, " +
"subcompanyname, subcompanycode,subcompanydesc, supsubcompany, supsubcomid, company, companyid," +
"canceled, virtualtype, tlevel, showorder, versiondate,versionid) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" ;
insertData ( insertVirtualSubComSql , insertParamList ) ;
//虚拟部门版本存储
rs . executeQuery ( "select a.id as departmentvirtualid,a.departmentname,a.departmentcode,a.departmentmark," +
"b.DEPARTMENTNAME as supdeptment,b.SUPDEPID as supdepid,a.allsupdepid,c.SUBCOMPANYNAME as subcompany," +
"a.SUBCOMPANYID1 as subcompanyid,a.canceled,a.virtualtype,a.tlevel,a.showorder from hrmdepartmentvirtual a " +
"left join hrmdepartmentvirtual b on a.SUPDEPID = b.id " +
"left join hrmsubcompanyvirtual c on a.SUBCOMPANYID1 = c.id where a.companyid = " , fclass ) ;
insertParamList = new ArrayList < > ( ) ;
while ( rs . next ( ) ) {
insertList = new ArrayList < > ( ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "departmentvirtualid" ) ) ? null : rs . getInt ( "departmentvirtualid" ) ) ;
insertList . add ( currentUser ) ;
insertList . add ( rs . getString ( "departmentname" ) ) ;
insertList . add ( rs . getString ( "departmentcode" ) ) ;
insertList . add ( rs . getString ( "departmentmark" ) ) ;
insertList . add ( rs . getString ( "supdeptment" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "supdepid" ) ) ? null : rs . getInt ( "supdepid" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "allsupdepid" ) ) ? null : rs . getInt ( "allsupdepid" ) ) ;
insertList . add ( rs . getString ( "subcompany" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "subcompanyid" ) ) ? null : rs . getInt ( "subcompanyid" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "canceled" ) ) ? null : rs . getInt ( "canceled" ) ) ;
insertList . add ( rs . getString ( "virtualtype" ) ) ;
insertList . add ( rs . getString ( "tlevel" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "showorder" ) ) ? null : rs . getInt ( "showorder" ) ) ;
insertList . add ( currentDate ) ;
insertList . add ( StringUtils . isBlank ( versionId ) ? null : Util . getIntValue ( versionId ) ) ;
insertParamList . add ( insertList ) ;
}
String insertVirtualDeptSql = "insert into jcl_chart_departmentvirtual(departmentvirtualid, creater, " +
"departmentname, departmentcode,departmentmark, supdeptment, supdepid, allsupdepid, subcompany, " +
"subcompanyid, canceled, virtualtype, tlevel, showorder, versiondate,versionid) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" ;
insertData ( insertVirtualDeptSql , insertParamList ) ;
//虚拟人员版本存储
rs . executeQuery ( "select resourceid,a.managerid,b.SUBCOMPANYID1 as subcompanyid,b.departmentid,a.managerstr," +
"virtualtype from hrmresourcevirtual a left join hrmresource b on a.RESOURCEID=b.ID where a.virtualtype=?" , fclass ) ;
insertParamList = new ArrayList < > ( ) ;
while ( rs . next ( ) ) {
insertList = new ArrayList < > ( ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "resourceid" ) ) ? null : rs . getInt ( "resourceid" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "managerid" ) ) ? null : rs . getInt ( "managerid" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "subcompanyid" ) ) ? null : rs . getInt ( "subcompanyid" ) ) ;
insertList . add ( StringUtils . isBlank ( rs . getString ( "departmentid" ) ) ? null : rs . getInt ( "departmentid" ) ) ;
insertList . add ( rs . getString ( "managerstr" ) ) ;
insertList . add ( rs . getString ( "virtualtype" ) ) ;
insertList . add ( currentDate ) ;
insertList . add ( StringUtils . isBlank ( versionId ) ? null : Util . getIntValue ( versionId ) ) ;
insertParamList . add ( insertList ) ;
}
String insertVirtualHrmSql = "insert into jcl_chart_resource(resourceid,MANAGER,subcompanyid," +
"departmentid,managerstr,virtualtype,versiondate,versionid) values (?,?,?,?,?,?,?,?)" ;
insertData ( insertVirtualHrmSql , insertParamList ) ;
}
private void insertData ( String insertSql , List < List < Object > > insertParamList ) {
RecordSetTrans recordSetTrans = new RecordSetTrans ( ) ;
recordSetTrans . setAutoCommit ( false ) ; //关闭自动提交
try {
recordSetTrans . executeBatchSql ( insertSql , insertParamList ) ;
recordSetTrans . commit ( ) ;
} catch ( Exception e ) {
recordSetTrans . rollback ( ) ;
e . printStackTrace ( ) ;
}
}
private boolean isHasVirtualFields ( ) {
RecordSet rs = new RecordSet ( ) ;
boolean flag = false ;
rs . executeQuery ( "select count(1) as num from hrm_formfield where (GROUPID =6 and FIELDNAME = 'fblx') or (GROUPID =7 and FIELDNAME = 'bmlx')" ) ;
if ( rs . next ( ) ) {
String num = rs . getString ( "num" ) ;
flag = "2" . equals ( num ) ;
}
return flag ;
}
/ * *
* 查 询 实 时 数 据 , 顶 级 元 素 SQL
*
* @param root 顶 级 元 素 ID
* @param dimension 维 度 ID
* @return 查 询 SQL
* /
private String getRealTimeTopSql ( String root , String dimension ) {
if ( "0" . equals ( root ) ) {
// 查询集团数据
if ( isRealDimension ) {
// 查询实际集团表
return "select id,companyname as name,'0' as type from " + COMPANY_TABLE ;
} else {
// 查询其他维度集团信息
return "select id,companyname as name,'0' as type from " + COMPANY_TABLE + " where id = '" + dimension + "'" ;
}
} else {
if ( hasVirtualFields ) {
if ( showVirtual ) {
return "select a.id,a.subcompanyname as name,'1' as type ,b.fblx as isvitual from " + SUB_COMPANY_TABLE + " a left join " + SUB_COMPANY_DEFINED_TABLE + " b on a.id = b.subcomid where a.id = '" + root + "'" ;
} else {
return "select a.id,a.subcompanyname as name,'1' as type ,b.fblx as isvitual from " + SUB_COMPANY_TABLE + " a left join " + SUB_COMPANY_DEFINED_TABLE + " b on a.id = b.subcomid where a.id = '" + root + "' and (b.fblx is null or b.fblx!='1')" ;
}
} else {
return "select id,subcompanyname as name,'1' as type from " + SUB_COMPANY_TABLE + " where id = '" + root + "'" ;
}
}
}
/ * *
* 查 询 实 时 数 据 , 子 元 素 SQL
*
* @param sql 查 询 SQL
* @param fType 上 级 元 素 类 型
* @param fObjId 上 级 元 素 ID
* @return 查 询 SQL
* /
private String getRealTimeChildSql ( String sql , String fType , String fObjId ) {
if ( StringUtils . isNotBlank ( fType ) ) {
switch ( fType ) {
case "0" :
if ( hasVirtualFields ) {
if ( showVirtual ) {
sql = "select a.id,a.subcompanyname as name,'1' as type ,b.fblx as isvitual from " + SUB_COMPANY_TABLE + " a left join " + SUB_COMPANY_DEFINED_TABLE + " b on a.id = b.subcomid where (a.canceled is null or a.canceled != '1') and (a.supsubcomid is null or a.supsubcomid = '0') and a.companyid = '" + fObjId + "'" ;
} else {
sql = "select a.id,a.subcompanyname as name,'1' as type ,b.fblx as isvitual from " + SUB_COMPANY_TABLE + " a left join " + SUB_COMPANY_DEFINED_TABLE + " b on a.id = b.subcomid where (a.canceled is null or a.canceled != '1') and (a.supsubcomid is null or a.supsubcomid = '0') and (b.fblx is null or b.fblx != '1') and a.companyid = '" + fObjId + "'" ;
}
} else {
sql = "select a.id,a.subcompanyname as name,'1' as type from " + SUB_COMPANY_TABLE + " a where (a.canceled is null or a.canceled != '1') and (a.supsubcomid is null or a.supsubcomid = '0') and a.companyid = '" + fObjId + "'" ;
}
break ;
case "1" :
if ( hasVirtualFields ) {
if ( showVirtual ) {
sql = "select a.id,a.subcompanyname as name,'1' as type ,b.fblx as isvitual from " + SUB_COMPANY_TABLE + " a left join " + SUB_COMPANY_DEFINED_TABLE + " b on a.id = b.subcomid where (a.canceled is null or a.canceled != '1') and a.supsubcomid = '" + fObjId + "'" +
" union select a.id,a.departmentname as name,'2' as type ,b.bmlx as isvitual from " + DEPARTMENT_TABLE + " a left join " + DEPARTMENT_DEFINED_TABLE + " b on a.id = b.deptid where (a.canceled is null or a.canceled != '1') and (a.supdepid is null or a.supdepid = '0') and subcompanyid1 = '" + fObjId + "'" ;
} else {
sql = "select a.id,a.subcompanyname as name,'1' as type ,b.fblx as isvitual from " + SUB_COMPANY_TABLE + " a left join " + SUB_COMPANY_DEFINED_TABLE + " b on a.id = b.subcomid where (a.canceled is null or a.canceled != '1') and (b.fblx is null or b.fblx != '1') and a.supsubcomid = '" + fObjId + "'" +
" union select a.id,a.departmentname as name,'2' as type ,b.bmlx as isvitual from " + DEPARTMENT_TABLE + " a left join " + DEPARTMENT_DEFINED_TABLE + " b on a.id = b.deptid where (a.canceled is null or a.canceled != '1') and (a.supdepid is null or a.supdepid = '0') and (b.bmlx is null or b.bmlx != '1') and subcompanyid1 = '" + fObjId + "'" ;
}
} else {
sql = "select a.id,a.subcompanyname as name,'1' as type from " + SUB_COMPANY_TABLE + " a where (canceled is null or canceled != '1') and supsubcomid = '" + fObjId + "'" +
" union select a.id,a.departmentname as name,'2' as type from " + DEPARTMENT_TABLE + " a where (canceled is null or canceled != '1') and (supdepid is null or supdepid = '0') and subcompanyid1 = '" + fObjId + "'" ;
}
break ;
case "2" :
if ( hasVirtualFields ) {
if ( showVirtual ) {
sql = "select a.id,a.departmentname as name,'2' as type ,b.bmlx as isvitual from " + DEPARTMENT_TABLE + " a left join " + DEPARTMENT_DEFINED_TABLE + " b on a.id = b.deptid where (a.canceled is null or a.canceled != '1') and supdepid = '" + fObjId + "'" ;
} else {
sql = "select a.id,a.departmentname as name,'2' as type ,b.bmlx as isvitual from " + DEPARTMENT_TABLE + " a left join hrmdepartmentdefined b on a.id = b.deptid where (canceled is null or canceled != '1') and (b.bmlx is null or b.bmlx != '1') and a.supdepid = '" + fObjId + "'" ;
}
} else {
sql = "select a.id,a.departmentname as name,'2' as type from " + DEPARTMENT_TABLE + " a where (canceled is null or canceled != '1') and supdepid = '" + fObjId + "'" ;
}
break ;
default :
break ;
}
}
return sql ;
}
/ * *
* 查 询 历 史 数 据 , 子 元 素 SQL
*
* @param sql 查 询 SQL
* @param fType 上 级 元 素 类 型
* @param fObjId 上 级 元 素 ID
* @return 查 询 SQL
* /
private String getLastTimeChildSql ( String sql , String fType , String fObjId , String versionId ) {
if ( StringUtils . isNotBlank ( fType ) ) {
switch ( fType ) {
case "0" :
if ( hasVirtualFields ) {
if ( showVirtual ) {
sql = "select " + SUB_COMPANY_ID + " as id,a.subcompanyname as name,'1' as type ,isvirtual as isvitual from " + SUB_COMPANY_TABLE + " a where (a.canceled is null or a.canceled != '1') and (a.supsubcompanyid is null or a.supsubcompanyid = '0') and versionid = " + versionId ;
} else {
sql = "select " + SUB_COMPANY_ID + " as id,a.subcompanyname as name,'1' as type ,isvirtual as isvitual from " + SUB_COMPANY_TABLE + " a where (a.canceled is null or a.canceled != '1') and (a.supsubcompanyid is null or a.supsubcompanyid = '0') and (isvirtual is null or isvirtual != '1') and versionid = " + versionId ;
}
} else {
sql = "select " + SUB_COMPANY_ID + " as id,a.subcompanyname as name,'1' as type from " + SUB_COMPANY_TABLE + " a where (a.canceled is null or a.canceled != '1') and (a.supsubcompanyid is null or a.supsubcompanyid = '0') and versionid = " + versionId ;
}
if ( ! isRealDimension ) {
sql + = " and companyid = " + fObjId ;
}
break ;
case "1" :
if ( hasVirtualFields ) {
if ( showVirtual ) {
sql = "select " + SUB_COMPANY_ID + " as id,a.subcompanyname as name,'1' as type ,isvirtual as isvitual from " + SUB_COMPANY_TABLE + " a where (a.canceled is null or a.canceled != '1') and a.supsubcompanyid = '" + fObjId + "' and versionid = " + versionId +
" union select " + DEPARTMENT_ID + " as id,a.departmentname as name,'2' as type ,isvirtual as isvitual from " + DEPARTMENT_TABLE + " a where (a.canceled is null or a.canceled != '1') and (a.supdepartmentid is null or a.supdepartmentid = '0') and subcompanyid = '" + fObjId + "' and versionid = " + versionId ;
} else {
sql = "select " + SUB_COMPANY_ID + " as id,a.subcompanyname as name,'1' as type ,isvirtual as isvitual from " + SUB_COMPANY_TABLE + " a where (a.canceled is null or a.canceled != '1') and (isvirtual is null or isvirtual != '1') and a.supsubcompanyid = '" + fObjId + "' and versionid = " + versionId +
" union select " + DEPARTMENT_ID + " as id,a.departmentname as name,'2' as type ,isvirtual as isvitual from " + DEPARTMENT_TABLE + " a where (a.canceled is null or a.canceled != '1') and (a.supdepartmentid is null or a.supdepartmentid = '0') and (isvirtual is null or isvirtual != '1') and subcompanyid = '" + fObjId + "' and versionid = " + versionId ;
}
} else {
sql = "select " + SUB_COMPANY_ID + " as id,a.subcompanyname as name,'1' as type from " + SUB_COMPANY_TABLE + " a where (canceled is null or canceled != '1') and supsubcompanyid = '" + fObjId + "' and versionid = " + versionId +
" union select " + DEPARTMENT_ID + " as id,a.departmentname as name,'2' as type from " + DEPARTMENT_TABLE + " a where (canceled is null or canceled != '1') and (supdepartmentid is null or supdepartmentid = '0') and subcompanyid = '" + fObjId + "' and versionid = " + versionId ;
}
break ;
case "2" :
if ( hasVirtualFields ) {
if ( showVirtual ) {
sql = "select " + DEPARTMENT_ID + " as id,a.departmentname as name,'2' as type ,isvirtual as isvitual from " + DEPARTMENT_TABLE + " a where (a.canceled is null or a.canceled != '1') and supdepartmentid = '" + fObjId + "' and versionid = " + versionId ;
} else {
sql = "select " + DEPARTMENT_ID + " as id,a.departmentname as name,'2' as type ,isvirtual as isvitual from " + DEPARTMENT_TABLE + " a where (canceled is null or canceled != '1') and (isvirtual is null or isvirtual != '1') and a.supdepartmentid = '" + fObjId + "' and versionid = " + versionId ;
}
} else {
sql = "select " + DEPARTMENT_ID + " as id,a.departmentname as name,'2' as type from " + DEPARTMENT_TABLE + " a where (canceled is null or canceled != '1') and supdepartmentid = '" + fObjId + "' and versionid = " + versionId ;
}
break ;
default :
break ;
}
}
return sql ;
}
/ * *
* 查 询 实 时 数 据 , 子 节 点 元 素
*
* @param topChartPO 父 级 元 素
* @param dataList 所 有 元 素 集 合
* @param selectDepth 所 选 部 门 层 级
* /
private void findChildData ( ChartPO topChartPO , List < ChartPO > dataList , Integer selectDepth , String versionId ) {
String fType = topChartPO . getFtype ( ) ;
String fObjId = topChartPO . getFobjid ( ) ;
String sql = "" ;
if ( isRealTime ) {
sql = getRealTimeChildSql ( sql , fType , fObjId ) ;
} else {
sql = getLastTimeChildSql ( sql , fType , fObjId , versionId ) ;
}
if ( StringUtils . isNotBlank ( sql ) ) {
List < ChartPO > currentList = new ArrayList < > ( ) ;
RecordSet recordSet = new RecordSet ( ) ;
recordSet . executeQuery ( sql ) ;
while ( recordSet . next ( ) ) {
ChartPO chartPO = new ChartPO ( ) ;
chartPO . setFtype ( recordSet . getString ( "type" ) ) ;
chartPO . setFobjid ( recordSet . getString ( "id" ) ) ;
chartPO . setFname ( recordSet . getString ( "name" ) ) ;
chartPO . setParentId ( topChartPO . getId ( ) ) ;
chartPO . setFisvitual ( recordSet . getString ( "isvitual" ) ) ;
chartPO . setHasChildren ( getHasChildren ( chartPO . getFtype ( ) , chartPO . getFobjid ( ) ) . toString ( ) ) ;
chartPO . setDepartmentDepth ( getDepartmentDepth ( chartPO , topChartPO ) ) ;
// 小于、等于所选层级元素展开
chartPO . setExpand ( inDepth ( selectDepth , chartPO . getDepartmentDepth ( ) ) ? "1" : "0" ) ;
currentList . add ( chartPO ) ;
}
for ( ChartPO chartPO : currentList ) {
if ( inDepth ( selectDepth , chartPO . getDepartmentDepth ( ) ) ) {
findChildData ( chartPO , dataList , selectDepth , versionId ) ;
}
}
dataList . addAll ( currentList ) ;
}
}
/ * *
* 根 据 维 度 初 始 化 表 名
*
* @param dimension 所 选 维 度
* /
public void initTableNameByClass ( String dimension , String id ) {
isRealDimension = StringUtils . isBlank ( dimension ) | | "0" . equals ( dimension ) ;
isRealTime = StringUtils . isBlank ( id ) | | "0" . equals ( id ) ;
if ( isRealTime ) {
if ( isRealDimension ) {
COMPANY_TABLE = "hrmcompany" ;
SUB_COMPANY_TABLE = "hrmsubcompany" ;
SUB_COMPANY_DEFINED_TABLE = "hrmsubcompanydefined" ;
DEPARTMENT_TABLE = "hrmdepartment" ;
DEPARTMENT_DEFINED_TABLE = "hrmdepartmentdefined" ;
RecordSet rs = new RecordSet ( ) ;
rs . executeQuery ( "select count(1) as num from hrm_formfield where (GROUPID =6 and FIELDNAME = 'fblx') or (GROUPID =7 and FIELDNAME = 'bmlx')" ) ;
if ( rs . next ( ) ) {
String num = rs . getString ( "num" ) ;
hasVirtualFields = "2" . equals ( num ) ;
} else {
hasVirtualFields = false ;
}
} else {
COMPANY_TABLE = "hrmcompanyvirtual" ;
SUB_COMPANY_TABLE = "hrmsubcompanyvirtual" ;
DEPARTMENT_TABLE = "hrmdepartmentvirtual" ;
// 其他维度,无虚拟组织
hasVirtualFields = false ;
}
} else {
if ( isRealDimension ) {
COMPANY_TABLE = "hrmcompany" ;
SUB_COMPANY_TABLE = "jcl_chart_subcompany" ;
DEPARTMENT_TABLE = "jcl_chart_department" ;
SUB_COMPANY_ID = "subcompanyid" ;
DEPARTMENT_ID = "departmentid" ;
hasVirtualFields = true ;
} else {
COMPANY_TABLE = "jcl_chart_companyvirtual" ;
SUB_COMPANY_TABLE = "jcl_chart_subcompanyvirtual" ;
DEPARTMENT_TABLE = "jcl_chart_departmentvirtual" ;
SUB_COMPANY_ID = "subcompanyvirtualid" ;
DEPARTMENT_ID = "departmentvirtualid" ;
// 其他维度,无虚拟组织
hasVirtualFields = false ;
}
}
}
/ * *
* 判 断 是 否 有 子 元 素
*
* @param fType 元 素 类 型
* @param fObjId 元 素 ID
* @return boolean 包 含 子 元 素 : true , 不 包 含 子 元 素 : false
* /
private Boolean getHasChildren ( String fType , String fObjId ) {
//String sql = "";
//if (StringUtils.isNotBlank(fType)) {
// switch (fType) {
// case "0":
// sql = "select id from " + SUB_COMPANY_TABLE + " where (supsubcomid is null or supsubcomid = '0') and companyid = '" + fObjId + "'";
// break;
// case "1":
// if (hasVirtualFields && !showVirtual) {
// sql = "select a.id from " + SUB_COMPANY_TABLE + " a left join " + SUB_COMPANY_DEFINED_TABLE + " b on a.id = b.subcomid where (a.canceled is null or a.canceled != '1') and (b.fblx is null or b.fblx != '1') and a.supsubcomid = '" + fObjId + "' union select a.id from " + DEPARTMENT_TABLE + " a left join " + DEPARTMENT_DEFINED_TABLE + " b on a.id = b.deptid where (a.canceled is null or a.canceled != '1') and (a.supdepid is null or a.supdepid = '0') and (b.bmlx is null or b.bmlx != '1') and subcompanyid1 = '" + fObjId + "'";
// } else {
// sql = "select id from " + SUB_COMPANY_TABLE + " where (canceled is null or canceled != '1') and supsubcomid = '" + fObjId + "' union select id from " + DEPARTMENT_TABLE + " where (canceled is null or canceled != '1') and (supdepid is null or supdepid = '0') and subcompanyid1 = '" + fObjId + "'";
// }
// break;
// case "2":
// if (hasVirtualFields && !showVirtual) {
// sql = "select a.id from " + DEPARTMENT_TABLE + " a left join hrmdepartmentdefined b on a.id = b.deptid where (canceled is null or canceled != '1') and (b.bmlx is null or b.bmlx != '1') and a.supdepid = '" + fObjId + "'";
// } else {
// sql = "select id from " + DEPARTMENT_TABLE + " where (canceled is null or canceled != '1') and supdepid = '" + fObjId + "'";
// }
// break;
// default:
// break;
// }
//}
//if (StringUtils.isNotBlank(sql)) {
// RecordSet rs = new RecordSet();
// rs.executeQuery(sql);
// return rs.next();
//}
return false ;
}
/ * *
* 获 取 部 门 负 责 人
*
* @param ids 部 门 负 责 人 ID
* @return 人 员 名 称
* /
private String getDepartmentLeader ( String ids ) {
if ( ! isRealTime ) {
return ids ;
}
if ( StringUtils . isBlank ( ids ) ) {
return "" ;
}
List < String > leaderList = new ArrayList < > ( ) ;
String [ ] split = ids . split ( "," ) ;
for ( String s : split ) {
String lastName = MapperProxyFactory . getProxy ( SystemDataMapper . class ) . getScHrmResourceNameById ( s ) ;
if ( StringUtils . isNotBlank ( lastName ) ) {
leaderList . add ( lastName ) ;
}
}
return StringUtils . join ( leaderList , "," ) ;
}
/ * *
* 当 前 元 素 是 否 在 展 开 层 级 内
*
* @param selectDepth 所 选 部 门 层 级
* @param currentDepth 当 前 部 门 层 级
* /
private boolean inDepth ( Integer selectDepth , Integer currentDepth ) {
if ( selectDepth = = 1 ) {
return true ;
}
return currentDepth < selectDepth + 1 ;
}
/ * *
* 获 取 当 前 部 门 层 级
*
* @param chartPO 当 前 元 素
* @param parentChart 上 级 元 素
* /
private Integer getDepartmentDepth ( ChartPO chartPO , ChartPO parentChart ) {
if ( "2" . equals ( chartPO . getFtype ( ) ) ) {
if ( "1" . equals ( parentChart . getFtype ( ) ) ) {
return 2 ;
}
return parentChart . getDepartmentDepth ( ) + 1 ;
}
return 0 ;
}
}