diff --git a/.gitignore b/.gitignore index 9154f4c..5683e7b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,15 @@ -# ---> Java -# Compiled class file -*.class +/weaver-hrm-recruit.iml +/out/ +/.idea/ -# Log file -*.log +HELP.md +target/ -# BlueJ files -*.ctxt +### IntelliJ IDEA ### +.idea -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* +/src/test +/src/rebel.xml +/src/META-INF +/log diff --git a/src/com/engine/recruit/exception/CustomizeRunTimeException.java b/src/com/engine/recruit/exception/CustomizeRunTimeException.java new file mode 100644 index 0000000..c4a7d1a --- /dev/null +++ b/src/com/engine/recruit/exception/CustomizeRunTimeException.java @@ -0,0 +1,22 @@ +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); + } +} diff --git a/src/com/engine/recruit/util/ExceptionUtil.java b/src/com/engine/recruit/util/ExceptionUtil.java new file mode 100644 index 0000000..6a87a0f --- /dev/null +++ b/src/com/engine/recruit/util/ExceptionUtil.java @@ -0,0 +1,20 @@ +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 ""; + } +} diff --git a/src/com/engine/recruit/util/ResponseResult.java b/src/com/engine/recruit/util/ResponseResult.java new file mode 100644 index 0000000..a8d177d --- /dev/null +++ b/src/com/engine/recruit/util/ResponseResult.java @@ -0,0 +1,184 @@ +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 { + + 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 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 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 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 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 apidatas = new HashMap<>(); + apidatas.put("status", true); + return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect); + } + + + /** + * 成功返回 + */ + private String Ok(R r) { + Map 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 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 apidatas = new HashMap<>(); + apidatas.put("status", false); + apidatas.put("errormsg", message); + apidatas.put("error", e.getMessage()); + return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect); + } + +} diff --git a/src/weaver/interfaces/recruit/action/RecruitFlowToModeAction.java b/src/weaver/interfaces/recruit/action/RecruitFlowToModeAction.java new file mode 100644 index 0000000..3878e84 --- /dev/null +++ b/src/weaver/interfaces/recruit/action/RecruitFlowToModeAction.java @@ -0,0 +1,151 @@ +package weaver.interfaces.recruit.action; + +import org.apache.commons.collections.CollectionUtils; +import weaver.conn.RecordSetTrans; +import weaver.general.BaseBean; +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; + +/** + * 招聘需求流程明细表数据转建模台账 + * + * @author:dxfeng + * @createTime: 2023/09/01 + * @version: 1.0 + */ +public class RecruitFlowToModeAction implements Action { + /** + * 流程主表表名(uf_zpxqjh) + */ + private static final String MAIN_TABLE_NAME = "uf_zpxqjh"; + /** + * 流程明细表表名(uf_zpxqjh_dt1) + */ + private static final String DETAIL_TABLE_NAME = "uf_zpxqjh_dt1"; + /** + * 建模台账表表名(uf_zpxq) + */ + private static final String MODE_TABLE_NAME = "uf_zpxq"; + + @Override + public String execute(RequestInfo requestInfo) { + String billTableName = requestInfo.getRequestManager().getBillTableName(); + MainTableInfo mainTableInfo = requestInfo.getMainTableInfo(); + + DetailTableInfo detailTableInfo = requestInfo.getDetailTableInfo(); + DetailTable detailTable = detailTableInfo.getDetailTable(0); + String detailTableName = detailTable.getTableDBName(); + if (!MAIN_TABLE_NAME.equals(billTableName) || !DETAIL_TABLE_NAME.equals(detailTableName)) { + requestInfo.getRequestManager().setMessagecontent("接口动作【RecruitFlowToModeAction】未适配当前流程,请检查流程配置"); + return FAILURE_AND_CONTINUE; + } + Map mainMap = new HashMap<>(16); + // 需求审批流程ID + mainMap.put("xqsplc", requestInfo.getRequestid()); + Property[] propertyArray = mainTableInfo.getProperty(); + for (Property property : propertyArray) { + mainMap.put(property.getName(), property.getValue()); + } + + List> insertList = new ArrayList<>(); + Row[] rows = detailTable.getRow(); + for (Row row : rows) { + Map detailMap = new HashMap<>(16); + detailMap.putAll(mainMap); + Cell[] cells = row.getCell(); + for (Cell cell : cells) { + detailMap.put(cell.getName(), cell.getValue()); + } + insertList.add(detailMap); + } + + // 数据插入处理 + if (CollectionUtils.isNotEmpty(insertList)) { + // 插入建模表 + 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 ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + try { + List> paramList = new ArrayList<>(); + // 构建插入参数集合 + buildParamList(insertList, paramList); + + rst.executeBatchSql(sql, paramList); + rst.commit(); + } catch (Exception e) { + rst.rollback(); + new BaseBean().writeLog(e.getMessage()); + requestInfo.getRequestManager().setMessagecontent("接口动作【RecruitFlowToModeAction】执行异常"); + return FAILURE_AND_CONTINUE; + } + } + + return SUCCESS; + } + + + /** + * 构建插入参数集合 + * + * @param insertList 待插入数据集合 + * @param paramList SQL插入参数集合 + */ + private void buildParamList(List> insertList, List> paramList) { + for (Map map : insertList) { + List param = new ArrayList<>(); + // 需求审批流程 + param.add(map.get("xqsplc")); + // 需求状态 + param.add(map.get("xqzt")); + // 申请人 + param.add(map.get("sqr")); + // 申请时间 + param.add(map.get("sqsj")); + // 申请部门 + param.add(map.get("sqbm")); + // 年度 + param.add(map.get("nd")); + // 审批方式 + param.add(map.get("spfs")); + // 需求类型 + param.add(map.get("xqlx")); + // 备注 + param.add(map.get("bz")); + // 需求名称 + param.add(map.get("xqmc")); + // 招聘原因 + param.add(map.get("zpyy")); + // 招聘需求负责人 + param.add(map.get("zpxqfzr")); + // 所属分部 + param.add(map.get("szfb")); + // 所属部门 + param.add(map.get("szbm")); + // 岗位 + param.add(map.get("gw")); + // 岗位职责 + param.add(map.get("gwzz")); + // 任职要求 + param.add(map.get("rzyq")); + // 职位性质 + param.add(map.get("zwxz")); + // 工作地点 + param.add(map.get("gzdd")); + // 工作年限 + param.add(map.get("gznx")); + // 最低学历要求 + param.add(map.get("zdxlyq")); + // 招聘人数 + param.add(map.get("zprs")); + // 期望到岗时间 + param.add(map.get("qwdgsj")); + paramList.add(param); + } + } +}