|
|
package com.engine.shgw.job;
|
|
|
|
|
|
import com.engine.shgw.Util.CommUtils;
|
|
|
import com.time.util.DateUtil;
|
|
|
import weaver.conn.RecordSet;
|
|
|
import weaver.general.Util;
|
|
|
import weaver.interfaces.schedule.BaseCronJob;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 更新部门编制-在编数信息
|
|
|
*
|
|
|
* @author wangj
|
|
|
* @version 1.00版本
|
|
|
* @Date 2024/5/13
|
|
|
*/
|
|
|
|
|
|
public class UpdateOrgStaffingJob extends BaseCronJob {
|
|
|
@Override
|
|
|
public void execute() {
|
|
|
RecordSet rs = new RecordSet();
|
|
|
List<Map<String,String>> planlist = new ArrayList<>(100);
|
|
|
String date = DateUtil.getCurrentTime("yyyy-MM-dd");
|
|
|
//获取启用状态的编制方案
|
|
|
String sql = "select id,ec_company,control_dimension from jcl_org_staffplan where forbidden_tag = 0 and time_end >= '"+date+"' and time_start <= '"+date+"'";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()){
|
|
|
String id = Util.null2String(rs.getString("id"));
|
|
|
//适用分部 测试看没限制
|
|
|
String subcompany = Util.null2String(rs.getString("ec_company"));
|
|
|
//控制维度 1 分部/2 部门/3 岗位
|
|
|
String dimension = Util.null2String(rs.getString("control_dimension"));
|
|
|
|
|
|
Map<String,String> map = new HashMap<>(10);
|
|
|
map.put("id",id);
|
|
|
map.put("subcompany",subcompany);
|
|
|
map.put("dimension",dimension);
|
|
|
planlist.add(map);
|
|
|
}
|
|
|
|
|
|
for (Map map : planlist){
|
|
|
String planid = Util.null2String(map.get("id"));
|
|
|
//控制维度 1 分部/2 部门/3 岗位
|
|
|
String dimension = Util.null2String(map.get("dimension"));
|
|
|
sql = "select id,ec_company,ec_department,job_id,staff_num,permanent_num,lack_status from jcl_org_staff where plan_id = "+planid+" and delete_type = 0";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()){
|
|
|
//编制信息id
|
|
|
String id = Util.null2String(rs.getString("id"));
|
|
|
//分部id
|
|
|
String subcompanyid = Util.null2String(rs.getString("ec_company"));
|
|
|
//部门id
|
|
|
String deptid = Util.null2String(rs.getString("ec_department"));
|
|
|
//岗位id
|
|
|
String job_id = Util.null2String(rs.getString("job_id"));
|
|
|
//编制数
|
|
|
int staff_num = Util.getIntValue(rs.getString("staff_num"),0);
|
|
|
|
|
|
|
|
|
|
|
|
//lack_status 缺编状态 1缺编,2满编,3超编
|
|
|
|
|
|
if("1".equals(dimension)){
|
|
|
//分部维度
|
|
|
updateOrgPermanentNumBySubCom(id,subcompanyid,staff_num);
|
|
|
}else if("2".equals(dimension)){
|
|
|
//部门维度
|
|
|
updateOrgPermanentNumByDept(id,deptid,staff_num);
|
|
|
}else if("3".equals(dimension)){
|
|
|
//岗位维度
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Description: 更新编制信息的 在编数 编制状态
|
|
|
* @Author: wangj
|
|
|
*/
|
|
|
private void updateOrgPermanentNumByDept(String id,String deptid,int staff_num){
|
|
|
RecordSet rs = new RecordSet();
|
|
|
//统计该部门以及所有下级部门的人员-用工性质
|
|
|
int permanent_num = 0;
|
|
|
|
|
|
permanent_num = getOrgPermanentNumByDept(deptid);
|
|
|
|
|
|
//lack_status 缺编状态 1缺编,2满编,3超编
|
|
|
int lack_status = 1;
|
|
|
if(permanent_num < staff_num){
|
|
|
lack_status = 1;
|
|
|
}else if(permanent_num == staff_num){
|
|
|
lack_status = 2;
|
|
|
}else if(permanent_num > staff_num){
|
|
|
lack_status = 3;
|
|
|
}
|
|
|
String sql = "update jcl_org_staff set permanent_num = ?,lack_status = ? where id = ?";
|
|
|
rs.executeUpdate(sql,permanent_num,lack_status,id);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取部门以及所有下级部门人员数量
|
|
|
* @param deptid
|
|
|
* @return
|
|
|
*/
|
|
|
private int getOrgPermanentNumByDept(String deptid){
|
|
|
int num = 0;
|
|
|
RecordSet rs = new RecordSet();
|
|
|
//获取部门以及所有下级部门id
|
|
|
String deptids = getAllSubDeptIds(deptid);
|
|
|
String sql = "select count(1) as sl from hrmresource where status < 4 and accounttype != 1 and departmentid in ("+deptids+")";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()){
|
|
|
num = Util.getIntValue(rs.getString("sl"));
|
|
|
}
|
|
|
return num;
|
|
|
}
|
|
|
|
|
|
private String getAllSubDeptIds(String deptid){
|
|
|
String deptids = deptid;
|
|
|
RecordSet rs = new RecordSet();
|
|
|
String sql = "select id from hrmdepartment where (canceled = 0 or canceled is null) and supdepid = '"+deptid+"'";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()){
|
|
|
String id = Util.null2String(rs.getString("id"));
|
|
|
if("".equals(id)) continue;
|
|
|
|
|
|
String subdeptids = getAllSubDeptIds(id);
|
|
|
deptids = deptids + "," +subdeptids;
|
|
|
}
|
|
|
deptids = CommUtils.distinctStringWithDot(deptids);
|
|
|
return deptids;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 分部维度 更新在编人数 缺编状态
|
|
|
* @param id
|
|
|
* @param subcomid
|
|
|
* @param staff_num
|
|
|
*/
|
|
|
private void updateOrgPermanentNumBySubCom(String id,String subcomid,int staff_num){
|
|
|
RecordSet rs = new RecordSet();
|
|
|
//统计该分部以及所有下级分部的人员
|
|
|
int permanent_num = 0;
|
|
|
|
|
|
permanent_num = getOrgPermanentNumBySubCom(subcomid);
|
|
|
|
|
|
//lack_status 缺编状态 1缺编,2满编,3超编
|
|
|
int lack_status = 1;
|
|
|
if(permanent_num < staff_num){
|
|
|
lack_status = 1;
|
|
|
}else if(permanent_num == staff_num){
|
|
|
lack_status = 2;
|
|
|
}else if(permanent_num > staff_num){
|
|
|
lack_status = 3;
|
|
|
}
|
|
|
String sql = "update jcl_org_staff set permanent_num = ?,lack_status = ? where id = ?";
|
|
|
rs.executeUpdate(sql,permanent_num,lack_status,id);
|
|
|
}
|
|
|
|
|
|
private int getOrgPermanentNumBySubCom(String subcomid){
|
|
|
int num = 0;
|
|
|
RecordSet rs = new RecordSet();
|
|
|
//获取分部以及所有下级分部id
|
|
|
String subcomids = getAllSubComIds(subcomid);
|
|
|
String sql = "select count(1) as sl from hrmresource where status < 4 and accounttype != 1 and subcompanyid1 in ("+subcomids+")";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()){
|
|
|
num = Util.getIntValue(rs.getString("sl"));
|
|
|
}
|
|
|
return num;
|
|
|
}
|
|
|
|
|
|
private String getAllSubComIds(String subcomid){
|
|
|
String subcomids = subcomid;
|
|
|
RecordSet rs = new RecordSet();
|
|
|
String sql = "select id from hrmsubcompany where (canceled = 0 or canceled is null) and supsubcomid = '"+subcomid+"'";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()){
|
|
|
String id = Util.null2String(rs.getString("id"));
|
|
|
if("".equals(id)) continue;
|
|
|
|
|
|
String subids = getAllSubComIds(id);
|
|
|
subcomids = subcomids + "," +subids;
|
|
|
}
|
|
|
subcomids = CommUtils.distinctStringWithDot(subcomids);
|
|
|
return subcomids;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|