安科讯定时任务统计在职数

安科讯聚才林项目
Chengliang 9 months ago
parent 774316c8ae
commit 9996672826

@ -0,0 +1,30 @@
package com.engine.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2024/8/6 9:31 AM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PersonStatisticsPo {
private Integer dataId;
/**
* 1 2
*/
private Integer type;
private Integer onJob;
}

@ -0,0 +1,120 @@
package weaver.interfaces.akx.cronjob;
import cn.hutool.core.thread.ThreadUtil;
import com.engine.entity.PersonStatisticsPo;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.interfaces.schedule.BaseCronJob;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
/**
* @Author liang.cheng
* @Date 2024/8/6 9:27 AM
* @Description:
* @Version 1.0
*/
public class PersonStatisticsCron extends BaseCronJob {
@Override
public void execute() {
RecordSet rs = new RecordSet();
//1.需要更新的数据List
List<PersonStatisticsPo> list = new ArrayList<>();
//2.分部数据
rs.executeQuery("select id from hrmsubcompany");
while (rs.next()) {
list.add(PersonStatisticsPo.builder().dataId(Util.getIntValue(rs.getString("id"))).type(1).build());
}
//3.部门数据
rs.executeQuery("select id from hrmdepartment");
while (rs.next()) {
list.add(PersonStatisticsPo.builder().dataId(Util.getIntValue(rs.getString("id"))).type(2).build());
}
// 核心线程数
int corePoolSize = 5;
// 最大线程数
int maxPoolSize = 10;
// 设置每个子列表的大小
int batchSize = 100;
List<List<PersonStatisticsPo>> splittedLists = splitList(list, batchSize);
// 创建线程池
ExecutorService executorService = ThreadUtil.newExecutor(corePoolSize, maxPoolSize);
// 遍历每个子列表,并提交给线程池执行
for (List<PersonStatisticsPo> subList : splittedLists) {
executorService.submit(() -> {
// 在此处编写处理子列表的逻辑
for (PersonStatisticsPo personStatisticsPo : subList) {
// 处理逻辑
buildCount(personStatisticsPo);
}
});
}
// 关闭线程池
executorService.shutdown();
// 等待线程池关闭
while (!executorService.isTerminated()) {
// 空循环等待线程池终止
}
for (PersonStatisticsPo item : list) {
if (item.getType() == 1) {
rs.executeUpdate("update hrmsubcompanydefined set rstj = ? where subcomid = ?",item.getOnJob(),item.getDataId());
}else {
rs.executeUpdate("update hrmdepartmentdefined set rstj = ? where deptid = ?",item.getOnJob(),item.getDataId());
}
}
}
private <T> List<List<T>> splitList(List<T> list, int batchSize) {
List<List<T>> splittedLists = new ArrayList<>();
for (int i = 0; i < list.size(); i += batchSize) {
int endIndex = Math.min(i + batchSize, list.size());
List<T> subList = list.subList(i, endIndex);
splittedLists.add(subList);
}
return splittedLists;
}
private PersonStatisticsPo buildCount(PersonStatisticsPo ps) {
RecordSet rs = new RecordSet();
DepartmentComInfo dept = new DepartmentComInfo();
SubCompanyComInfo subCompany = new SubCompanyComInfo();
ArrayList<Integer> list = new ArrayList<>();
list.add(ps.getDataId());
StringBuilder onJob = new StringBuilder();
if (ps.getType() == 1) {
subCompany.getSubCompanyLists(String.valueOf(ps.getDataId()), list);
String value = StringUtils.join(list,",");
onJob.append("select count(1) from hrmresource where status < 4 and subcompanyid1 in (").append(value).append(")");
}else {
dept.getAllChildDeptByDepId(list,String.valueOf(ps.getDataId()));
String value = StringUtils.join(list,",");
onJob.append("select count(1) as count from hrmresource where status < 4 and departmentid in (").append(value).append(")");
}
rs.executeQuery(onJob.toString());
rs.next();
ps.setOnJob(Util.getIntValue(rs.getString("count"),0));
return ps;
}
}
Loading…
Cancel
Save