From 4170596ba1ddb4c276edc5339bbbfc4b5b2fa1f1 Mon Sep 17 00:00:00 2001
From: "youHong.ai" <774495953@qq.com>
Date: Tue, 13 Dec 2022 17:38:15 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9action=E6=A8=A1=E6=9D=BF?=
=?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=BD=9C=E5=9C=A8?=
=?UTF-8?q?=E7=9A=84=E7=BA=BF=E7=A8=8B=E4=B8=8D=E5=AE=89=E5=85=A8=E9=97=AE?=
=?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/aiyh/utils/action/CusBaseAction.java | 35 +--
.../action/CusBaseActionHandleFunction.java | 1 +
.../aiyh/utils/action/SafeCusBaseAction.java | 288 ++++++++++++++++++
.../SafeCusBaseActionHandleFunction.java | 26 ++
4 files changed, 331 insertions(+), 19 deletions(-)
create mode 100644 src/main/java/aiyh/utils/action/SafeCusBaseAction.java
create mode 100644 src/main/java/aiyh/utils/action/SafeCusBaseActionHandleFunction.java
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