|
|
package com.engine.shgw.action;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.engine.shgw.Util.ActionUtils;
|
|
|
import com.engine.shgw.Util.CommUtils;
|
|
|
import com.time.util.DateUtil;
|
|
|
import weaver.conn.RecordSet;
|
|
|
import weaver.general.BaseBean;
|
|
|
import weaver.general.Util;
|
|
|
import weaver.interfaces.workflow.action.Action;
|
|
|
import weaver.soa.workflow.request.RequestInfo;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 离职流程更新编制数
|
|
|
* <p>
|
|
|
* 离职流程
|
|
|
* 部门维度 离职部门 在编数-1 所有上级部门在编数-1
|
|
|
* 分部维度 离职分部 在编数-1 所有上级分部在编数-1
|
|
|
*
|
|
|
* @author wangj
|
|
|
* @version 1.00版本
|
|
|
* @Date 2024/5/14
|
|
|
*/
|
|
|
|
|
|
public class ResignationUpdateOrgStaffAction implements Action {
|
|
|
//部门 数据库字段名
|
|
|
private String bmKey;
|
|
|
|
|
|
@Override
|
|
|
public String execute(RequestInfo requestInfo) {
|
|
|
BaseBean bb = new BaseBean();
|
|
|
try {
|
|
|
String tableName = requestInfo.getRequestManager().getBillTableName();
|
|
|
String requestid = requestInfo.getRequestid();
|
|
|
String createdate = getWfRequestDate(requestid);
|
|
|
//获取主表数据
|
|
|
Map mainInfo = ActionUtils.getMainInfo(requestInfo);
|
|
|
bb.writeLog("-ResignationUpdateOrgStaffAction-主表数据是:" + JSONObject.toJSONString(mainInfo));
|
|
|
|
|
|
//部门 数据库字段名
|
|
|
bmKey = Util.null2String(bmKey);
|
|
|
// //公司 数据库字段名
|
|
|
// gsKey = Util.null2String(gsKey);
|
|
|
|
|
|
if("".equals(bmKey)){
|
|
|
requestInfo.getRequestManager().setMessagecontent("必传字段为空,请联系管理员!");
|
|
|
return Action.FAILURE_AND_CONTINUE;
|
|
|
}
|
|
|
|
|
|
//分部
|
|
|
// String fb = Util.null2String(mainInfo.get(gsKey));
|
|
|
//部门
|
|
|
String bm = Util.null2String(mainInfo.get(bmKey));
|
|
|
|
|
|
//分部维度
|
|
|
// if (!"".equals(fb)) {
|
|
|
// updateOrgStaffBySubCom(fb);
|
|
|
// }
|
|
|
|
|
|
//部门维度
|
|
|
if (!"".equals(bm)) {
|
|
|
updateOrgStaffByDept(bm,createdate);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
requestInfo.getRequestManager().setMessagecontent("接口异常:" + e.getMessage());
|
|
|
return Action.FAILURE_AND_CONTINUE;
|
|
|
}
|
|
|
return Action.SUCCESS;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取所有分部id以及父级id
|
|
|
*
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
private String getAllSupComIds(String id) {
|
|
|
String allsubcomids = id;
|
|
|
RecordSet rs = new RecordSet();
|
|
|
String sql = "select supsubcomid from hrmsubcompany where (canceled = 0 or canceled is null) and id = '" + id + "'";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()) {
|
|
|
String supsubcomid = Util.null2String(rs.getString("supsubcomid"));
|
|
|
if ("".equals(supsubcomid) || "0".equals(supsubcomid)) {
|
|
|
continue;
|
|
|
}
|
|
|
allsubcomids = allsubcomids + "," + supsubcomid;
|
|
|
supsubcomid = getAllSupComIds(supsubcomid);
|
|
|
allsubcomids = allsubcomids + "," + supsubcomid;
|
|
|
}
|
|
|
allsubcomids = CommUtils.distinctStringWithDot(allsubcomids);
|
|
|
return allsubcomids;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取所有部门id以及父级id
|
|
|
*
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
private String getAllSupDeptIds(String id) {
|
|
|
String allsubdeptids = id;
|
|
|
RecordSet rs = new RecordSet();
|
|
|
String sql = "select supdepid from hrmdepartment where (canceled = 0 or canceled is null) and id = '" + id + "'";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()) {
|
|
|
String supdepid = Util.null2String(rs.getString("supdepid"));
|
|
|
if ("".equals(supdepid) || "0".equals(supdepid)) {
|
|
|
continue;
|
|
|
}
|
|
|
allsubdeptids = allsubdeptids + "," + supdepid;
|
|
|
supdepid = getAllSupDeptIds(supdepid);
|
|
|
allsubdeptids = allsubdeptids + "," + supdepid;
|
|
|
}
|
|
|
allsubdeptids = CommUtils.distinctStringWithDot(allsubdeptids);
|
|
|
return allsubdeptids;
|
|
|
}
|
|
|
|
|
|
private void updateOrgStaffBySubCom(String subcomid) {
|
|
|
RecordSet rs = new RecordSet();
|
|
|
String sql = "select a.id,a.ec_company,a.ec_department,a.job_id,a.staff_num,a.permanent_num,a.lack_status from jcl_org_staff a left join jcl_org_staffplan b on a.plan_id = b.id where a.delete_type = 0 and b.control_dimension = 1 and b.forbidden_tag = 0 and a.ec_company = '" + subcomid + "'";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()) {
|
|
|
String id = Util.null2String(rs.getString("id"));
|
|
|
int staff_num = Util.getIntValue(rs.getString("staff_num"));
|
|
|
int permanent_num = Util.getIntValue(rs.getString("permanent_num"));
|
|
|
updateOrgStaff(id, staff_num, permanent_num);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void updateOrgStaffByDept(String deptid,String createdate) {
|
|
|
RecordSet rs = new RecordSet();
|
|
|
String sql = "select a.id,a.ec_company,a.ec_department,a.job_id,a.staff_num,a.permanent_num,a.lack_status from jcl_org_staff a left join jcl_org_staffplan b on a.plan_id = b.id where a.delete_type = 0 and b.control_dimension = 2 and b.forbidden_tag = 0 and a.ec_department = '" + deptid + "' and b.time_end >= '"+createdate+"' and b.time_start <= '"+createdate+"'";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()) {
|
|
|
String id = Util.null2String(rs.getString("id"));
|
|
|
int staff_num = Util.getIntValue(rs.getString("staff_num"));
|
|
|
int permanent_num = Util.getIntValue(rs.getString("permanent_num"));
|
|
|
updateOrgStaff(id, staff_num, permanent_num);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新在编人数、编制状态
|
|
|
*
|
|
|
* @param id
|
|
|
* @param staff_num
|
|
|
* @param permanent_num
|
|
|
*/
|
|
|
private void updateOrgStaff(String id, int staff_num, int permanent_num) {
|
|
|
RecordSet rs = new RecordSet();
|
|
|
permanent_num = permanent_num - 1;
|
|
|
|
|
|
//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 String getWfRequestDate(String requestid){
|
|
|
String date = "";
|
|
|
if("".equals(requestid)){
|
|
|
date = DateUtil.getCurrentTime("yyyy-MM-dd");
|
|
|
return date;
|
|
|
}
|
|
|
RecordSet rs = new RecordSet();
|
|
|
String sql = "select createdate from workflow_requestbase where requestid = '"+requestid+"'";
|
|
|
rs.execute(sql);
|
|
|
while (rs.next()){
|
|
|
date = Util.null2String(rs.getString("createdate"));
|
|
|
}
|
|
|
return date;
|
|
|
}
|
|
|
}
|