ecology-develop/src/weaver/interfaces/hzzx/cronjob/RecordUserCountJob.java

142 lines
4.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package weaver.interfaces.hzzx.cronjob;
import com.engine.hzzx.conn.DataUtil;
import com.engine.hzzx.entity.RecruitingPlan;
import com.engine.hzzx.exception.CustomizeRunTimeException;
import org.apache.commons.collections.CollectionUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.interfaces.schedule.BaseCronJob;
import java.util.*;
/**
* @author:dxfeng
* @createTime: 2025/03/20
* @version: 1.0
*/
public class RecordUserCountJob extends BaseCronJob {
private static final String MAIN_TABLE = "uf_nmgbmzgrs";
private static final String OPERATE_ID = "1";
RecordSet rs = new RecordSet();
@Override
public void execute() {
try {
String sql = "select id from hrmdepartment where ISNULL(SUPDEPID,0)=0 and ISNULL(CANCELED,0)=0 ";
rs.executeQuery(sql);
List<RecruitingPlan> recruitingPlanList = new ArrayList<>();
while (rs.next()) {
fillDepartmentInfo(rs.getInt("id"), recruitingPlanList);
}
// 遍历recruitingPlanList插入明细表数据
for (RecruitingPlan plan : recruitingPlanList) {
insertMainData(plan, DateUtil.getCurrentDate());
}
} catch (Exception e) {
throw new CustomizeRunTimeException(e.getMessage());
}
}
/**
* 遍历部门,查询部门下在岗人数
*
* @param departmentId
* @param recruitingPlanList
* @return
*/
private int fillDepartmentInfo(Integer departmentId, List<RecruitingPlan> recruitingPlanList) {
if (departmentId == null || departmentId < 0) {
return 0;
}
// 查询当前部门下的在岗人数
int userCount = countUsersByDeptId(departmentId);
List<Integer> childDepartmentIdList = getChildDepartmentId(departmentId);
if (CollectionUtils.isNotEmpty(childDepartmentIdList)) {
for (Integer childDepartmentId : childDepartmentIdList) {
userCount += fillDepartmentInfo(childDepartmentId, recruitingPlanList);
}
}
recruitingPlanList.add(new RecruitingPlan(departmentId, userCount));
return userCount;
}
/**
* 插入主表数据
*
* @param plan
* @return
*/
private String insertMainData(RecruitingPlan plan,String year) {
rs.executeQuery("select id from " + MAIN_TABLE + " where nd = ? and bm = ? ",year , plan.getDepartmentId());
if(rs.next()){
Map<String, String> updateData = new HashMap<>();
DataUtil.buildModeUpdateFields(updateData, OPERATE_ID);
updateData.put("id", rs.getString("id"));
updateData.put("nmzgrs",plan.getOnJobNumber() + "");
}
// 插入基本数据
Map<String, String> insertData = new HashMap<>();
DataUtil.buildModeInsertFields(insertData, OPERATE_ID);
String uuid = UUID.randomUUID().toString();
insertData.put("modeuuid", uuid);
int formModeId = DataUtil.getModeIdByTableName(MAIN_TABLE);
insertData.put("formmodeid", String.valueOf(formModeId));
insertData.put("nd", year);
insertData.put("bm", plan.getDepartmentId() + "");
insertData.put("nmzgrs", plan.getOnJobNumber() + "");
DataUtil.insertData(insertData, MAIN_TABLE);
int id = DataUtil.refreshRight(uuid, MAIN_TABLE, formModeId, OPERATE_ID);
if (id > 0) {
return String.valueOf(id);
}
return "";
}
/**
* 查询子部门
*
* @param departmentId
* @return
*/
private List<Integer> getChildDepartmentId(Integer departmentId) {
List<Integer> departmentIdList = new ArrayList<>();
RecordSet rs = new RecordSet();
rs.executeQuery("select id from HrmDepartment where supdepid = ?", departmentId);
while (rs.next()) {
departmentIdList.add(rs.getInt("id"));
}
return departmentIdList;
}
/**
* 查询部门下在岗人数
*
* @param departmentId
* @return
*/
private int countUsersByDeptId(Integer departmentId) {
RecordSet rs = new RecordSet();
rs.executeQuery("select count(id) from hrmresource where departmentid = ?", departmentId);
if (rs.next()) {
return rs.getInt(1);
}
return 0;
}
private int countPlanedNum(Integer departmentId) {
RecordSet rs = new RecordSet();
rs.executeQuery("select count(id) from uf_zpxqhztzaz where zpbm = ? and sqrq like '%" + DateUtil.getYear() + "%' ", departmentId);
return 0;
}
}