You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weaver-hrm-organization/src/com/engine/shgw/action/EmploymentUpdateOrgStaffGdA...

135 lines
4.8 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.engine.shgw.action;
import com.alibaba.fastjson.JSONObject;
import com.engine.shgw.Util.ActionUtils;
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;
/**
* 入职流程
归档节点action
* 流程结束后 冻结数转为在编人数 部门 冻结数-1 在编数+1
*
* @author wangj
* @version 1.00版本
* @Date 2024/5/14
*/
public class EmploymentUpdateOrgStaffGdAction implements Action {
//部门 数据库字段名
private String bmKey;
@Override
public String execute(RequestInfo requestInfo) {
BaseBean bb = new BaseBean();
try {
//获取主表数据
Map mainInfo = ActionUtils.getMainInfo(requestInfo);
String requestid = requestInfo.getRequestid();
String createdate = getWfRequestDate(requestid);
bb.writeLog("-EmploymentUpdateOrgStaffGdAction-主表数据是:" + 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;
}
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);
}
}
/**
* 更新冻结数-1 在编数+1
*
* @param id
*/
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 freeze_num = freeze_num-1,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;
}
}