diff --git a/src/main/java/aiyh/utils/action/CusBaseAction.java b/src/main/java/aiyh/utils/action/CusBaseAction.java index 9b114a6..47ff1f2 100644 --- a/src/main/java/aiyh/utils/action/CusBaseAction.java +++ b/src/main/java/aiyh/utils/action/CusBaseAction.java @@ -19,6 +19,7 @@ import java.util.*; * * @author EBU7-dev-1 aiyh */ +@Deprecated public abstract class CusBaseAction implements Action { @@ -36,13 +37,13 @@ public abstract class CusBaseAction implements Action { *

初始化流程默认的处理方法

*/ private void initHandleMethod() { -// 提交 + // 提交 actionHandleMethod.put(ActionRunType.SUBMIT, this::doSubmit); -// 退回 + // 退回 actionHandleMethod.put(ActionRunType.REJECT, this::doReject); -// 撤回 + // 撤回 actionHandleMethod.put(ActionRunType.WITHDRAW, this::doWithdraw); -// 强制收回 + // 强制收回 actionHandleMethod.put(ActionRunType.DRAW_BACK, this::doDrawBack); } @@ -55,7 +56,7 @@ public abstract class CusBaseAction implements Action { String requestId = requestInfo.getRequestid(); User user = requestInfo.getRequestManager().getUser(); int workflowId = requestManager.getWorkflowid(); -// 操作类型 submit - 提交 reject - 退回 等 + // 操作类型 submit - 提交 reject - 退回 等 String src = requestManager.getSrc(); if ("".equals(billTable)) { WorkflowComInfo workflowComInfo = new WorkflowComInfo(); @@ -68,13 +69,13 @@ public abstract class CusBaseAction implements Action { if (StringUtils.isEmpty(src)) { src = "submit"; } -// 初始化默认的流程处理方法 + // 初始化默认的流程处理方法 initHandleMethod(); -// 提供自定义注册处理方法 + // 提供自定义注册处理方法 registerHandler(actionHandleMethod); -// 获取流程对应的处理方法 + // 获取流程对应的处理方法 CusBaseActionHandleFunction cusBaseActionHandleFunction = actionHandleMethod.get(src); -// 默认没有直接成功不做拦截 + // 默认没有直接成功不做拦截 if (null == cusBaseActionHandleFunction) { return Action.SUCCESS; } @@ -124,8 +125,7 @@ public abstract class CusBaseAction implements Action { /** *

action 提交流程业务处理方法

*

具体业务逻辑实现 - * 全局存在log成员变量,用于日志的输出 - * Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 + * 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 *

* * @param requestId 流程请求ID @@ -142,8 +142,7 @@ public abstract class CusBaseAction implements Action { /** *

action 退回流程业务处理方法

*

具体业务逻辑实现 - * 全局存在log成员变量,用于日志的输出 - * Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 + * 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 *

* * @param requestId 流程请求ID @@ -159,8 +158,7 @@ public abstract class CusBaseAction implements Action { /** *

action 撤回、撤回流程流程业务处理方法

*

具体业务逻辑实现 - * 全局存在log成员变量,用于日志的输出 - * Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 + * 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 *

* * @param requestId 流程请求ID @@ -177,8 +175,7 @@ public abstract class CusBaseAction implements Action { /** *

action 强制收回流程业务处理方法

*

具体业务逻辑实现 - * 全局存在log成员变量,用于日志的输出 - * Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 + * 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 *

* * @param requestId 流程请求ID @@ -199,7 +196,7 @@ public abstract class CusBaseAction implements Action { */ @Deprecated protected Map getMainTableValue() { -// 获取主表数据 + // 获取主表数据 Property[] propertyArr = globalRequestInfo.getMainTableInfo().getProperty(); return getStringMap(propertyArr); } @@ -210,7 +207,7 @@ public abstract class CusBaseAction implements Action { * @return 流程主表数据 */ protected Map getMainTableValue(RequestInfo requestInfo) { -// 获取主表数据 + // 获取主表数据 Property[] propertyArr = requestInfo.getMainTableInfo().getProperty(); return getStringMap(propertyArr); } diff --git a/src/main/java/aiyh/utils/action/CusBaseActionHandleFunction.java b/src/main/java/aiyh/utils/action/CusBaseActionHandleFunction.java index 1a8b86a..ac80efc 100644 --- a/src/main/java/aiyh/utils/action/CusBaseActionHandleFunction.java +++ b/src/main/java/aiyh/utils/action/CusBaseActionHandleFunction.java @@ -10,6 +10,7 @@ import weaver.workflow.request.RequestManager; *

create: 2022-07-23 18:05

*/ +@Deprecated @FunctionalInterface public interface CusBaseActionHandleFunction { /** diff --git a/src/main/java/aiyh/utils/action/SafeCusBaseAction.java b/src/main/java/aiyh/utils/action/SafeCusBaseAction.java new file mode 100644 index 0000000..c638269 --- /dev/null +++ b/src/main/java/aiyh/utils/action/SafeCusBaseAction.java @@ -0,0 +1,288 @@ +package aiyh.utils.action; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import weaver.hrm.User; +import weaver.interfaces.workflow.action.Action; +import weaver.soa.workflow.request.*; +import weaver.workflow.request.RequestManager; +import weaver.workflow.workflow.WorkflowBillComInfo; +import weaver.workflow.workflow.WorkflowComInfo; + +import java.util.*; + +/** + *

基础的action,实现一些基础的参数

+ * + * @author EBU7-dev-1 aiyh + */ +public abstract class SafeCusBaseAction implements Action { + + + /** + * 全局日志对象 + */ + protected final Logger log = Util.getLogger(); + private final Map actionHandleMethod = new HashMap<>(); + + /** + *

初始化流程默认的处理方法

+ */ + private void initHandleMethod() { + // 提交 + actionHandleMethod.put(ActionRunType.SUBMIT, this::doSubmit); + // 退回 + actionHandleMethod.put(ActionRunType.REJECT, this::doReject); + // 撤回 + actionHandleMethod.put(ActionRunType.WITHDRAW, this::doWithdraw); + // 强制收回 + actionHandleMethod.put(ActionRunType.DRAW_BACK, this::doDrawBack); + } + + + @Override + public final String execute(RequestInfo requestInfo) { + RequestManager requestManager = requestInfo.getRequestManager(); + String billTable = requestManager.getBillTableName(); + String requestId = requestInfo.getRequestid(); + User user = requestInfo.getRequestManager().getUser(); + int workflowId = requestManager.getWorkflowid(); + // 操作类型 submit - 提交 reject - 退回 等 + String src = requestManager.getSrc(); + if ("".equals(billTable)) { + WorkflowComInfo workflowComInfo = new WorkflowComInfo(); + String formId = workflowComInfo.getFormId(String.valueOf(workflowId)); + WorkflowBillComInfo workflowBillComInfo = new WorkflowBillComInfo(); + billTable = workflowBillComInfo.getTablename(formId); + } + try { + Util.verifyRequiredField(this); + if (StringUtils.isEmpty(src)) { + src = "submit"; + } + // 初始化默认的流程处理方法 + initHandleMethod(); + // 提供自定义注册处理方法 + registerHandler(actionHandleMethod); + // 获取流程对应的处理方法 + SafeCusBaseActionHandleFunction cusBaseActionHandleFunction = actionHandleMethod.get(src); + // 默认没有直接成功不做拦截 + if (null == cusBaseActionHandleFunction) { + return Action.SUCCESS; + } + cusBaseActionHandleFunction.handle(requestId, billTable, workflowId, user, requestInfo); + } catch (CustomerException e) { + if (e.getCode() != null && e.getCode() == 500) { + Util.actionFail(requestManager, e.getMessage()); + return Action.FAILURE_AND_CONTINUE; + } + if (this.exceptionCallback(e, requestManager)) { + return Action.FAILURE_AND_CONTINUE; + } + } catch (Exception e) { + if (this.exceptionCallback(e, requestManager)) { + return Action.FAILURE_AND_CONTINUE; + } + } + return Action.SUCCESS; + } + + + /** + *

程序执行异常回调

+ * + * @param e 异常信息 + * @param requestManager requestManager对象 + * @return 是否阻止action往下提交,true- 阻止, false-放行 + */ + public boolean exceptionCallback(Exception e, RequestManager requestManager) { + e.printStackTrace(); + log.error(Util.logStr("getDataId action fail, exception message is [{}], error stack trace msg is: \n{}", + e.getMessage(), Util.getErrString(e))); + Util.actionFail(requestManager, e.getMessage()); + return true; + } + + + /** + *

流程其他流转类型处理方法注册

+ * + * @param actionHandleMethod 处理方法对应map + */ + public void registerHandler(Map actionHandleMethod) { + } + + + /** + *

action 提交流程业务处理方法

+ *

具体业务逻辑实现 + * 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 + *

+ * + * @param requestId 流程请求ID + * @param billTable 流程对应主表名称 + * @param workflowId 流程对应流程ID + * @param user 当前节点操作者用户 + * @param requestInfo 请求管理对象 + */ + + public abstract void doSubmit(String requestId, String billTable, int workflowId, + User user, RequestInfo requestInfo); + + + /** + *

action 退回流程业务处理方法

+ *

具体业务逻辑实现 + * 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 + *

+ * + * @param requestId 流程请求ID + * @param billTable 流程对应主表名称 + * @param workflowId 流程对应流程ID + * @param user 当前节点操作者用户 + * @param requestInfo 请求管理对象 + */ + public void doReject(String requestId, String billTable, int workflowId, + User user, RequestInfo requestInfo) { + } + + /** + *

action 撤回、撤回流程流程业务处理方法

+ *

具体业务逻辑实现 + * 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 + *

+ * + * @param requestId 流程请求ID + * @param billTable 流程对应主表名称 + * @param workflowId 流程对应流程ID + * @param user 当前节点操作者用户 + * @param requestInfo 请求管理对象 + */ + public void doWithdraw(String requestId, String billTable, int workflowId, + User user, RequestInfo requestInfo) { + } + + + /** + *

action 强制收回流程业务处理方法

+ *

具体业务逻辑实现 + * 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 + *

+ * + * @param requestId 流程请求ID + * @param billTable 流程对应主表名称 + * @param workflowId 流程对应流程ID + * @param user 当前节点操作者用户 + * @param requestInfo 请求管理对象 + */ + public void doDrawBack(String requestId, String billTable, int workflowId, + User user, RequestInfo requestInfo) { + } + + /** + *

获取流程主表数据

+ * + * @return 流程主表数据 + */ + protected Map getMainTableValue(RequestInfo requestInfo) { + // 获取主表数据 + Property[] propertyArr = requestInfo.getMainTableInfo().getProperty(); + return getStringMap(propertyArr); + } + + @NotNull + private Map getStringMap(Property[] propertyArr) { + if (null == propertyArr) { + return Collections.emptyMap(); + } + Map mainTable = new HashMap<>((int) Math.ceil(propertyArr.length * 1.4)); + for (Property property : propertyArr) { + String fieldName = property.getName(); + String value = property.getValue(); + mainTable.put(fieldName, value); + } + return mainTable; + } + + + /** + *

获取所有明细数据

+ * + * @return 以明细表需要为键,以明细表数据为值的键值对明细数据信息 + */ + protected Map>> getDetailTableValue(RequestInfo requestInfo) { + DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable(); + return getListMap(detailTableArr); + } + + + @NotNull + private Map>> getListMap(DetailTable[] detailTableArr) { + Map>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 1.4)); + for (DetailTable detailTable : detailTableArr) { + List> detailData = getDetailValue(detailTable); + detailDataList.put(detailTable.getId(), detailData); + } + return detailDataList; + } + + + /** + *

获取指定明细表的表数据

+ * + * @param detailNo 明细表编号 + * @return 明细数据 + */ + protected List> getDetailTableValueByDetailNo(int detailNo, RequestInfo requestInfo) { + DetailTable detailTable = requestInfo.getDetailTableInfo().getDetailTable(detailNo); + return getDetailValue(detailTable); + } + + /** + *

根据明细表信息获取明细表数据

+ * + * @param detailTable 明细表对象 + * @return 明细表数据 + */ + @NotNull + private List> getDetailValue(DetailTable detailTable) { + Row[] rowArr = detailTable.getRow(); + List> detailData = new ArrayList<>(rowArr.length); + for (Row row : rowArr) { + Cell[] cellArr = row.getCell(); + Map rowData = new HashMap<>((int) Math.ceil(cellArr.length * (1 + 0.4))); + rowData.put("id", row.getId()); + for (Cell cell : cellArr) { + String fieldName = cell.getName(); + String value = cell.getValue(); + rowData.put(fieldName, value); + } + detailData.add(rowData); + } + return detailData; + } + + + public static final class ActionRunType { + /** + * 退回 + */ + public static final String REJECT = "reject"; + /** + * 撤回 + */ + public static final String WITHDRAW = "withdraw"; + /** + * 强制收回 + */ + public static final String DRAW_BACK = "drawBack"; + /** + * 提交 + */ + public static final String SUBMIT = "submit"; + } + +} diff --git a/src/main/java/aiyh/utils/action/SafeCusBaseActionHandleFunction.java b/src/main/java/aiyh/utils/action/SafeCusBaseActionHandleFunction.java new file mode 100644 index 0000000..4785ab1 --- /dev/null +++ b/src/main/java/aiyh/utils/action/SafeCusBaseActionHandleFunction.java @@ -0,0 +1,26 @@ +package aiyh.utils.action; + +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; + +/** + *

流程类型处理方法

+ * + * @author EBU7-dev-1 aiyh + *

create: 2022-07-23 18:05

+ */ + +@FunctionalInterface +public interface SafeCusBaseActionHandleFunction { + /** + *

流程处理方法action

+ * + * @param requestId 流程请求ID + * @param billTable 流程对应主表名称 + * @param workflowId 流程对应流程ID + * @param user 当前节点操作者用户 + * @param requestInfo 请求管理对象 + */ + void handle(String requestId, String billTable, int workflowId, + User user, RequestInfo requestInfo); +}