需求:批量创建人员信息
思路步骤: 先新增一个流程,将人员信息放到明细表中,然后用户填充好数据后,通过Action节点后进行调用接口在系统中创建人员账号信息。
核心代码如下:?
package com.kaka.workflow;
import com.kaka.workflow.utils.PinyinUtills;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.interfaces.workflow.action.BaseAction;
import weaver.soa.workflow.request.RequestInfo;
import weaver.general.BaseBean;
import weaver.workflow.request.RequestManager;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.HashMap;
import static com.kaka.workflow.utils.MD5Utils.stringToUpperMD5;
public class AddPersonInfo extends BaseAction {
private static Log log = LogFactory.getLog(AddPersonInfo.class);
@Override
public String execute(RequestInfo requestInfo) {
String requestid = requestInfo.getRequestid();//获取流程请求id
log.info("进来了创建人员信息,流程请求id=========" + requestid);
RecordSet rs=null;
HashMap map = new HashMap();
String workcode ="";
try {
rs = new RecordSet();
String sql="select f.sqr,f.szgs,dt1.* from formtable_main_247 f inner join formtable_main_247_dt1 dt1 on f.id=dt1.mainid where f.requestid="+requestid;
log.info("sql>>>>>>="+sql);
rs.executeQuery(sql);
while(rs.next()){ //遍历取值
log.info("创建人=>"+rs.getString("sqr"));
map.put("sqr",rs.getString("sqr"));//创建人
map.put("gh",rs.getString("gh"));//登录名
map.put("xm",rs.getString("xm"));//姓名
map.put("mm", stringToUpperMD5(rs.getString("mm")));//密码
map.put("pinyin",PinyinUtills.pinYinOf(rs.getString("xm")));//姓名拼音
map.put("csrq",dateValue(rs.getString("csrq")));//出生日期
workcode = checkWorkcode(rs.getString("gh"), requestInfo);
map.put("gh", rs.getString("gh"));//工号
map.put("xb",rs.getString("xb"));//性别
map.put("dh",rs.getString("dh"));//电话
map.put("yx",rs.getString("yx"));//邮箱
map.put("rzrq",dateValue(rs.getString("rzrq")));//入职日期
map.put("probationenddate",UpdateThreeMonths(rs.getString("rzrq")));//试用期结束时间
map.put("htjsrq",getAfterthreeYear(rs.getString("rzrq")));//合同结束日期
map.put("gw",rs.getString("gw"));//岗位
map.put("bm",rs.getString("bm"));//部门
map.put("fb",rs.getString("szgs"));//分部
map.put("zjsj",rs.getString("zjsj"));//直接上级
log.info("工号="+workcode);
if(!"".equals(workcode)||!workcode.isEmpty()){
requestInfo.getRequestManager().setMessageid(weaver.workflow.request.WorkflowRequestMessage.WF_REQUEST_ERROR_CODE_07);
requestInfo.getRequestManager().setMessagecontent("工号 "+workcode+" 已经存在,请另重置");
return FAILURE_AND_CONTINUE;
}else{
InsertPersonInfo(map); //执行sql插入数据
}
}
}catch (Exception e){
log.info(e.getMessage());
}
return SUCCESS;
}
/***
* @MethodName: dateValue
* @Description: 格式化日期
* @Param: [date]
* @return: java.lang.String
* @Author: kaka
* @Date: 2023/9/24 13:37
*/
public static String dateValue(String date) throws Exception{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
Date parse = format.parse(date);
return format2.format(parse);
}
/***
* @MethodName: getAfterthreeYear
* @Description: 3年后的今天
* @Param: [date]
* @return: java.lang.String
* @Author: kaka
* @Date: 2023/9/6 23:00
*/
public static String getAfterthreeYear(String rzrq) {
LocalDate today = LocalDate.now();
// System.out.println("今天日期是:" + today);
int twoYears = 3;
LocalDate threeYear = today.plus(twoYears, ChronoUnit.YEARS);
return String.valueOf(threeYear);
// System.out.println("两年后的日期是:" + threeYear);
}
/***
* @MethodName: UpdateThreeMons
* @Description: 3个月后的今天
* @Param: []
* @return: void
* @Author: kaka
* @Date: 2023/9/12 16:39
*/
public static String UpdateThreeMonths(String rzrq) {
LocalDate today = LocalDate.parse(rzrq);
int i = 3;
LocalDate threeMonth = today.plus(i, ChronoUnit.MONTHS);
return String.valueOf(threeMonth);
}
//执行sql新增人员数据
public void InsertPersonInfo(HashMap map){
RecordSetTrans rst = new RecordSetTrans();
rst.setAutoCommit(false); //开启事务
log.info("进来了>>>>InsertPersonInfo");
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
try{
String upsql="insert into hrmresource(id,loginid,password,workcode,dsporder,lastname,pinyinlastname,ECOLOGY_PINYIN_SEARCH,sex,birthday,created,modified,status,joblevel,systemlanguage,maritalstatus,\n" +
"mobile,email,companystartdate,startdate,enddate,jobtitle,seclevel,departmentid,subcompanyid1,\n" +
"managerid,createrid,createdate,lastmodid,lastmoddate,lastlogindate,probationenddate)\n" +
"values((SELECT max(id)+1 from hrmresource),'"+map.get("gh")+"','"+map.get("mm")+"','"+map.get("gh")+"',(SELECT max(id)+1 from hrmresource),'"+map.get("xm")+"','"+map.get("pinyin")+"','"+map.get("pinyin")+"','"+map.get("xb")+"','"+map.get("csrq")+"','"+format+"','"+format+"','0','0','7','0',\n" +
"'"+map.get("dh")+"','"+map.get("yx")+"','"+map.get("rzrq")+"','"+map.get("rzrq")+"','"+map.get("htjsrq")+"','"+map.get("gw")+"','0','"+map.get("bm")+"','"+map.get("fb")+"',\n" +
"'"+map.get("zjsj")+"','"+map.get("sqr")+"','"+map.get("rzrq")+"','"+map.get("sqr")+"','"+map.get("rzrq")+"','"+map.get("rzrq")+"','"+map.get("probationenddate")+"');";
log.info("upsql=>"+upsql);
boolean b = rst.executeUpdate(upsql);
if(b){
log.info("新增成功>>>>>>>>>>>");
}
rst.commit();//提交事务
}catch (Exception e){
log.info(e.getMessage());
rst.rollback();//回滚事务
}
}
//校验重复工号
public String checkWorkcode(String xrgh,RequestInfo requestInfo){
RequestManager manager = requestInfo.getRequestManager();
//传入工号比对HRMresource表中的工号
BaseBean baseBean = new BaseBean();
String workcode="";
try{
RecordSet rs = new RecordSet();
String sql=" select workcode from hrmresource where loginid='"+xrgh+"' or workcode='"+xrgh+"'";
baseBean.writeLog("校验工号>>>>>"+sql);
rs.executeQuery(sql);
while(rs.next()){
workcode= rs.getString("workcode");
}
}catch (Exception e){
log.info(e.getMessage());
}
return workcode;
}
}
关键信息提取
运行结果:? 在我的人事中搜索新增人员的名字就可以查到细信息