招聘需求流程明细表数据转建模台账Action

This commit is contained in:
dxfeng 2023-09-14 13:45:39 +08:00
parent 8696c025af
commit 77c1912aa8
4 changed files with 62 additions and 238 deletions

View File

@ -1,22 +0,0 @@
package com.engine.recruit.exception;
/**
* @Author weaver_cl
* @Description:
* @Date 2023/2/21
* @Version V1.0
**/
public class CustomizeRunTimeException extends RuntimeException{
public CustomizeRunTimeException(String message) {
super(message);
}
public CustomizeRunTimeException(Throwable cause) {
super(cause);
}
public CustomizeRunTimeException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -1,20 +0,0 @@
package com.engine.recruit.util;
/**
* @Author weaver_cl
* @Description:
* @Date 2023/2/21
* @Version V1.0
**/
public class ExceptionUtil {
public static String getRealMessage(Throwable e) {
while (e != null) {
Throwable cause = e.getCause();
if (cause == null) {
return e.getMessage();
}
e = cause;
}
return "";
}
}

View File

@ -1,184 +0,0 @@
package com.engine.recruit.util;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.core.exception.ECException;
import com.engine.recruit.exception.CustomizeRunTimeException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import weaver.general.BaseBean;
import weaver.hrm.User;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
@Slf4j
public class ResponseResult<T, R> {
private static final long serialVersionUID = 1L;
private final User user;
private final BaseBean baseBean = new BaseBean();
private final Boolean isLog = "true".equals(baseBean.getPropValue("hrmSalary", "log"));
public ResponseResult(User user) {
this.user = user;
}
/**
* 统一返回方法(自定义返回格式)
*/
public String customRun(Function<T, R> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
return getJsonString(f.apply(t));
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!");
}
}
/**
* 统一返回方法
*/
public String run(Function<T, R> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
return Ok(f.apply(t));
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!");
}
}
/**
* 统一返回方法有参无返回
*/
public String run(Consumer<T> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
f.accept(t);
return Ok();
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
return Error(ExceptionUtil.getRealMessage(e));
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!", e);
}
}
/**
* 统一返回方法无参有返回
*/
public String run(Supplier<R> f) {
try {
if (isLog) {
log.info("run api");
}
return Ok(f.get());
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!", e);
}
}
private static String getJsonString(Object apidatas) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.writeValueAsString(apidatas);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return "";
}
/**
* 成功返回
*/
private String Ok() {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("status", true);
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
/**
* 成功返回
*/
private String Ok(R r) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("status", true);
apidatas.put("data", r);
String success = getJsonString(apidatas);
if (isLog) {
log.info("run salary api success return {}", success);
}
return success;
}
/**
* 失败返回
*/
private static String Error(String message) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("status", false);
apidatas.put("errormsg", message);
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
/**
* 系统异常失败返回
*/
private static String Error(String message, Exception e) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("status", false);
apidatas.put("errormsg", message);
apidatas.put("error", e.getMessage());
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
}

View File

@ -2,15 +2,16 @@ package weaver.interfaces.recruit.action;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* 招聘需求流程明细表数据转建模台账
@ -22,9 +23,9 @@ import java.util.Map;
public class RecruitFlowToModeAction implements Action {
/**
* 建模台账表表名(uf_zpxq)
* 建模台账表表名(uf_jcl_zp_zpxq)
*/
private static final String MODE_TABLE_NAME = "uf_zpxq";
private static final String MODE_TABLE_NAME = "uf_jcl_zp_zpxq";
@Override
public String execute(RequestInfo requestInfo) {
@ -36,11 +37,28 @@ public class RecruitFlowToModeAction implements Action {
Map<String, Object> mainMap = new HashMap<>(16);
// 需求审批流程ID
mainMap.put("xqsplc", requestInfo.getRequestid());
int formModeId = -1;
RecordSet rs = new RecordSet();
rs.executeQuery("select id from modeinfo where formid =( select id from workflow_bill where tablename = ? )", MODE_TABLE_NAME);
if (rs.next()) {
formModeId = rs.getInt("id");
}
Property[] propertyArray = mainTableInfo.getProperty();
for (Property property : propertyArray) {
mainMap.put(property.getName(), property.getValue());
}
mainMap.put("formmodeid", formModeId);
mainMap.put("modedatacreater", requestInfo.getRequestManager().getCreater());
String dateTime = DateUtil.getFullDate();
String[] split = dateTime.split(" ");
mainMap.put("modedatacreatedate", split[0]);
mainMap.put("modedatacreatetime", split[1]);
mainMap.put("modedatamodifier", requestInfo.getRequestManager().getCreater());
mainMap.put("modedatamodifydatetime", dateTime);
mainMap.put("modedatacreatertype", "0");
List<Map<String, Object>> insertList = new ArrayList<>();
Row[] rows = detailTable.getRow();
for (Row row : rows) {
@ -58,14 +76,18 @@ public class RecruitFlowToModeAction implements Action {
// 插入建模表
RecordSetTrans rst = new RecordSetTrans();
rst.setAutoCommit(false);
String sql = " insert into " + MODE_TABLE_NAME + "(xqsplc,xqzt,sqr,sqsj,sqbm,nd,spfs,xqlx,bz,xqmc,zpyy,zpxqfzr,szfb,szbm,gw,gwzz,rzyq,zwxz,gzdd,gznx,zdxlyq,zprs,qwdgsj)" +
" values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
String sql = " insert into " + MODE_TABLE_NAME + "(modeuuid,modedatacreatertype,formmodeid,modedatacreater,modedatacreatedate,modedatacreatetime,modedatamodifier,modedatamodifydatetime,xqsplc,xqzt,sqr,sqsj,sqbm,nd,spfs,xqlx,bz,xqmc,zpyy,zpxqfzr,szfb,szbm,gw,gwzz,rzyq,zwxz,gzdd,gznx,zdxlyq,zprs,qwdgsj)" +
" values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try {
List<List<Object>> paramList = new ArrayList<>();
// 构建插入参数集合
buildParamList(insertList, paramList);
rst.executeBatchSql(sql, paramList);
for (List<Object> objects : paramList) {
String uuid = UUID.randomUUID().toString();
objects.add(0, uuid);
rst.executeUpdate(sql, objects);
refreshRight(rst, uuid, formModeId);
}
rst.commit();
} catch (Exception e) {
rst.rollback();
@ -88,6 +110,14 @@ public class RecruitFlowToModeAction implements Action {
private void buildParamList(List<Map<String, Object>> insertList, List<List<Object>> paramList) {
for (Map<String, Object> map : insertList) {
List<Object> param = new ArrayList<>();
// 填充建模表相关字段
param.add(map.get("modedatacreatertype"));
param.add(map.get("formmodeid"));
param.add(map.get("modedatacreater"));
param.add(map.get("modedatacreatedate"));
param.add(map.get("modedatacreatetime"));
param.add(map.get("modedatamodifier"));
param.add(map.get("modedatamodifydatetime"));
// 需求审批流程
param.add(map.get("xqsplc"));
// 需求状态
@ -141,10 +171,30 @@ public class RecruitFlowToModeAction implements Action {
/**
* 将空字符串转化为NULL
*
* @param str
* @return
* @param str 字符串
* @return Object
*/
private Object parseBlankToNull(String str) {
return StringUtils.isBlank(str) ? null : str;
}
/**
* 权限重构
*
* @param rst RecordSetTrans
* @param uuid UUID
* @param formModeId 建模ID
* @throws Exception Exception
*/
private void refreshRight(RecordSetTrans rst, String uuid, int formModeId) throws Exception {
rst.executeQuery("select id from " + MODE_TABLE_NAME + " where modeuuid='" + uuid + "'");
if (rst.next()) {
//建模数据的id
int bid = Util.getIntValue(rst.getString("id"));
ModeRightInfo modeRightInfo = new ModeRightInfo();
modeRightInfo.setNewRight(true);
//新建的时候添加共享
modeRightInfo.editModeDataShare(1, formModeId, bid);
}
}
}