@ -1,23 +1,25 @@
package com.engine.organization.service.impl ;
package com.engine.organization.service.impl ;
import cn.hutool.core.thread.ThreadUtil ;
import com.engine.common.util.ServiceUtil ;
import com.engine.common.util.ServiceUtil ;
import com.engine.core.impl.Service ;
import com.engine.core.impl.Service ;
import com.engine.organization.entity.chart.ChartPO ;
import com.engine.organization.entity.chart.* ;
import com.engine.organization.entity.chart.CompanyTreePO ;
import com.engine.organization.entity.chart.params.RecursionParam ;
import com.engine.organization.entity.chart.StatisticsVO ;
import com.engine.organization.entity.chart.params.StatisticsParam ;
import com.engine.organization.entity.chart.TreeSelect ;
import com.engine.organization.enums.ModuleTypeEnum ;
import com.engine.organization.enums.ModuleTypeEnum ;
import com.engine.organization.mapper.hrmresource.SystemDataMapper ;
import com.engine.organization.mapper.hrmresource.SystemDataMapper ;
import com.engine.organization.service.ChartService ;
import com.engine.organization.service.ChartService ;
import com.engine.organization.service.OrgChartService ;
import com.engine.organization.service.OrgChartService ;
import com.engine.organization.util.HasRightUtil ;
import com.engine.organization.util.HasRightUtil ;
import com.engine.organization.util.OrganizationAssert ;
import com.engine.organization.util.OrganizationAssert ;
import com.engine.organization.util.OrganizationCommonUtil ;
import com.engine.organization.util.OrganizationDateUtil ;
import com.engine.organization.util.OrganizationDateUtil ;
import com.engine.organization.util.db.DBType ;
import com.engine.organization.util.db.DBType ;
import com.engine.organization.util.db.MapperProxyFactory ;
import com.engine.organization.util.db.MapperProxyFactory ;
import lombok.SneakyThrows ;
import lombok.SneakyThrows ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.opensaml.saml2.metadata.Organization ;
import weaver.conn.RecordSet ;
import weaver.conn.RecordSet ;
import weaver.conn.RecordSetTrans ;
import weaver.conn.RecordSetTrans ;
import weaver.general.Util ;
import weaver.general.Util ;
@ -27,7 +29,11 @@ import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.resource.ResourceComInfo ;
import weaver.hrm.resource.ResourceComInfo ;
import java.time.LocalDate ;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.util.* ;
import java.util.* ;
import java.util.concurrent.ExecutorService ;
import java.util.concurrent.Executors ;
import java.util.concurrent.ThreadPoolExecutor ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
/ * *
/ * *
@ -559,6 +565,196 @@ public class ChartServiceImpl extends Service implements ChartService {
return result ;
return result ;
}
}
@Override
public Map < String , Object > recordStatistics ( StatisticsParam statisticsParam ) {
Map < String , Object > result = new HashMap < > ( 2 ) ;
long startTime = System . currentTimeMillis ( ) ;
//需要更新的数据List
List < StatisticsPO > list = filterIds ( statisticsParam . getCompanyId ( ) ) ;
RecordSetTrans rst = new RecordSetTrans ( ) ;
// 核心线程数
int corePoolSize = 5 ;
// 最大线程数
int maxPoolSize = 10 ;
// 设置每个子列表的大小
int batchSize = 100 ;
List < List < StatisticsPO > > splittedLists = OrganizationCommonUtil . splitList ( list , batchSize ) ;
// 创建线程池
ExecutorService executorService = ThreadUtil . newExecutor ( corePoolSize , maxPoolSize ) ;
// 遍历每个子列表,并提交给线程池执行
for ( List < StatisticsPO > subList : splittedLists ) {
executorService . submit ( ( ) - > {
// 在此处编写处理子列表的逻辑
for ( StatisticsPO statisticsPO : subList ) {
// 处理逻辑
StatisticsPO po = buildCount ( statisticsPO ) ;
statisticsPO . setOnJobNum ( po . getOnJobNum ( ) ) ;
statisticsPO . setStaffNum ( po . getStaffNum ( ) ) ;
statisticsPO . setUpdateTime ( OrganizationDateUtil . getFormatLocalDateTime ( LocalDateTime . now ( ) ) ) ;
}
} ) ;
}
// 关闭线程池
executorService . shutdown ( ) ;
// 等待线程池关闭
while ( ! executorService . isTerminated ( ) ) {
// 空循环等待线程池终止
}
try {
rst . setAutoCommit ( false ) ;
for ( StatisticsPO item : list ) {
rst . executeUpdate ( "update jcl_org_onjob set on_job_num = ?,staff_num = ? where data_id = ? and type = ?" , item . getOnJobNum ( ) ,
item . getStaffNum ( ) , item . getDataId ( ) , item . getType ( ) ) ;
}
rst . commit ( ) ;
} catch ( Exception e ) {
rst . rollback ( ) ;
}
long endTime = System . currentTimeMillis ( ) ;
long executionTime = endTime - startTime ;
result . put ( "time" , executionTime ) ;
return result ;
}
/ * *
* 生 成 人 数
* @param stp
* @return
* /
private StatisticsPO buildCount ( StatisticsPO stp ) {
RecordSet rs = new RecordSet ( ) ;
DepartmentComInfo dept = new DepartmentComInfo ( ) ;
SubCompanyComInfo subCompany = new SubCompanyComInfo ( ) ;
ArrayList < Integer > list = new ArrayList < > ( ) ;
list . add ( stp . getDataId ( ) ) ;
StringBuilder jobSql = new StringBuilder ( ) ;
StringBuilder staffSql = new StringBuilder ( ) ;
if ( ModuleTypeEnum . subcompanyfielddefined . getValue ( ) . equals ( stp . getType ( ) ) ) {
subCompany . getSubCompanyLists ( String . valueOf ( stp . getDataId ( ) ) , list ) ;
String value = StringUtils . join ( list , "," ) ;
jobSql . append ( "select count(1) as count from hrmresource where status < 4 and subcompanyid1 in (" ) . append ( value ) . append ( ")" ) ;
staffSql . append ( "select a.staff_num from jcl_org_staff a inner join jcl_org_staffplan b\n" +
" on a.plan_id = b.id\n" +
" and a.ec_company = ? and a.ec_department is null\n" +
" and b.plan_year = ?" ) ;
} else {
dept . getAllChildDeptByDepId ( list , String . valueOf ( stp . getDataId ( ) ) ) ;
String value = StringUtils . join ( list , "," ) ;
jobSql . append ( "select count(1) as count from hrmresource where status < 4 and departmentid in (" ) . append ( value ) . append ( ")" ) ;
staffSql . append ( "select a.staff_num from jcl_org_staff a inner join jcl_org_staffplan b\n" +
" on a.plan_id = b.id\n" +
" and a.ec_department = ? and a.job_id is null\n" +
" and b.plan_year = ?" ) ;
}
rs . executeQuery ( jobSql . toString ( ) ) ;
rs . next ( ) ;
stp . setOnJobNum ( Util . getIntValue ( rs . getString ( "count" ) ) ) ;
rs . executeQuery ( staffSql . toString ( ) , stp . getDataId ( ) , OrganizationDateUtil . getFormatYear ( new Date ( ) ) ) ;
if ( rs . next ( ) ) {
stp . setStaffNum ( Util . getIntValue ( rs . getString ( "staff_num" ) ) ) ;
}
return stp ;
}
/ * *
* 基 础 数 据 过 滤
* @param companyId
* @return
* /
private List < StatisticsPO > filterIds ( Integer companyId ) {
RecordSet rs = new RecordSet ( ) ;
RecordSet iRs = new RecordSet ( ) ;
List < Integer > hisCompanyList = new ArrayList < > ( ) ;
List < Integer > hisDepartmentList = new ArrayList < > ( ) ;
rs . executeQuery ( "select data_id from jcl_org_onjob where type = 1" ) ;
while ( rs . next ( ) ) {
hisCompanyList . add ( Util . getIntValue ( rs . getString ( "data_id" ) ) ) ;
}
rs . executeQuery ( "select data_id from jcl_org_onjob where type = 2" ) ;
while ( rs . next ( ) ) {
hisDepartmentList . add ( Util . getIntValue ( rs . getString ( "data_id" ) ) ) ;
}
List < StatisticsPO > companyList = new ArrayList < > ( ) ;
List < StatisticsPO > departmentList = new ArrayList < > ( ) ;
StringBuilder sql = new StringBuilder ( ) ;
StringBuilder sql1 = new StringBuilder ( ) ;
sql . append ( "select id,supsubcomid from hrmsubcompany where 1=1" ) ;
sql1 . append ( "select id,supdepid from hrmdepartment where 1=1" ) ;
if ( companyId ! = null ) {
sql . append ( " and id = " ) . append ( companyId ) ;
sql1 . append ( " and subcompanyid1 = " ) . append ( companyId ) ;
}
rs . executeQuery ( sql . toString ( ) ) ;
while ( rs . next ( ) ) {
StatisticsPO statisticsPO = StatisticsPO . builder ( )
. dataId ( Util . getIntValue ( rs . getString ( "id" ) ) )
. superId ( Util . getIntValue ( rs . getString ( "supsubcomid" ) ) )
. type ( 1 )
. onJobNum ( 0 )
. staffNum ( 0 )
. creator ( user . getUID ( ) )
. createTime ( OrganizationDateUtil . getFormatLocalDateTime ( LocalDateTime . now ( ) ) )
. updateTime ( OrganizationDateUtil . getFormatLocalDateTime ( LocalDateTime . now ( ) ) )
. build ( ) ;
companyList . add ( statisticsPO ) ;
}
rs . executeQuery ( sql1 . toString ( ) ) ;
while ( rs . next ( ) ) {
StatisticsPO statisticsPO = StatisticsPO . builder ( )
. dataId ( Util . getIntValue ( rs . getString ( "id" ) ) )
. superId ( Util . getIntValue ( rs . getString ( "supdepid" ) ) )
. type ( 2 )
. onJobNum ( 0 )
. staffNum ( 0 )
. creator ( user . getUID ( ) )
. createTime ( OrganizationDateUtil . getFormatLocalDateTime ( LocalDateTime . now ( ) ) )
. updateTime ( OrganizationDateUtil . getFormatLocalDateTime ( LocalDateTime . now ( ) ) )
. build ( ) ;
departmentList . add ( statisticsPO ) ;
}
List < StatisticsPO > addCompanyList = companyList . stream ( )
. filter ( entity - > ! hisCompanyList . contains ( entity . getDataId ( ) ) )
. collect ( Collectors . toList ( ) ) ;
List < StatisticsPO > addDeptList = departmentList . stream ( )
. filter ( entity - > ! hisDepartmentList . contains ( entity . getDataId ( ) ) )
. collect ( Collectors . toList ( ) ) ;
addCompanyList . addAll ( addDeptList ) ;
if ( CollectionUtils . isNotEmpty ( addCompanyList ) ) {
addCompanyList . forEach ( item - > iRs . executeUpdate ( "insert into jcl_org_onjob(data_id,super_id,type,on_job_num,staff_num,creator,create_time,update_time)" +
" values(?,?,?,?,?,?,?,?)" , item . getDataId ( ) , item . getSuperId ( ) , item . getType ( ) ,
item . getOnJobNum ( ) , item . getStaffNum ( ) , item . getCreator ( ) , item . getCreateTime ( ) , item . getUpdateTime ( ) ) ) ;
}
companyList . addAll ( departmentList ) ;
return companyList ;
}
/ * *
/ * *
* 添 加 树 结 构 所 有 上 级 节 点
* 添 加 树 结 构 所 有 上 级 节 点
*
*