|
@@ -1,40 +1,32 @@
|
|
|
package com.fjhx.utils;
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fjhx.constants.FlowConstant;
|
|
|
import com.fjhx.constants.FlowExplainConstant;
|
|
|
-import com.fjhx.constants.StatusConstant;
|
|
|
-import com.fjhx.entity.example.ExampleDetails;
|
|
|
-import com.fjhx.entity.example.ExampleInfo;
|
|
|
import com.fjhx.entity.process.ProcessNodeButton;
|
|
|
-import com.fjhx.entity.process.ProcessTenant;
|
|
|
import com.fjhx.enums.ButtonNameEnum;
|
|
|
import com.fjhx.feign.IFlowClient;
|
|
|
-import com.fjhx.params.ExampleInfoEx;
|
|
|
-import com.fjhx.params.FlowInfoVo;
|
|
|
-import com.fjhx.params.GetNodeButtonVo;
|
|
|
+import com.fjhx.params.ExampleResult;
|
|
|
+import com.fjhx.params.JumpVo;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
|
|
|
public class FlowConstructor {
|
|
|
|
|
|
private static final IFlowClient flowClient = SpringUtil.getBean(IFlowClient.class);
|
|
|
|
|
|
- private ExampleAbstract exampleAbstract;
|
|
|
-
|
|
|
- private FlowConstructor() {
|
|
|
-
|
|
|
- }
|
|
|
+ private final ExampleAbstract exampleAbstract;
|
|
|
|
|
|
/**
|
|
|
* 初始化
|
|
|
*/
|
|
|
public static FlowConstructor init(ExampleAbstract exampleAbstract) {
|
|
|
- FlowConstructor flowConstructor = new FlowConstructor();
|
|
|
- flowConstructor.exampleAbstract = exampleAbstract;
|
|
|
- return flowConstructor;
|
|
|
+ return new FlowConstructor(exampleAbstract);
|
|
|
+ }
|
|
|
+
|
|
|
+ private FlowConstructor(ExampleAbstract exampleAbstract) {
|
|
|
+ this.exampleAbstract = exampleAbstract;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -43,86 +35,34 @@ public class FlowConstructor {
|
|
|
* @param flowLinkNo 流程关联编号
|
|
|
* @return 流程实例对象
|
|
|
*/
|
|
|
- public ExampleInfo create(Long flowLinkNo, String remarks) {
|
|
|
+ public ExampleResult create(Long flowLinkNo, String remarks, Object cacheData) {
|
|
|
|
|
|
// 获取流程编码
|
|
|
- String code = exampleAbstract.getCode();
|
|
|
- Assert.notEmpty(code, FlowExplainConstant.CODE_EMPTY);
|
|
|
-
|
|
|
- // 获取租户流程
|
|
|
- R<FlowInfoVo> r = flowClient.getProcessTenant(flowLinkNo, code);
|
|
|
- Assert.eqTrue(r.isSuccess(), r.getMsg());
|
|
|
- FlowInfoVo flowInfoVo = r.getData();
|
|
|
-
|
|
|
- // 创建流程实例
|
|
|
- ExampleInfoEx exampleInfo = new ExampleInfoEx();
|
|
|
- exampleInfo.setProcessInfoId(flowInfoVo.getId());
|
|
|
- exampleInfo.setFlowLinkNo(flowLinkNo);
|
|
|
- if (ObjectUtil.isNotEmpty(exampleAbstract.cacheData)) {
|
|
|
- exampleInfo.setCacheData(JSONObject.toJSONString(exampleAbstract.cacheData));
|
|
|
- }
|
|
|
+ String code = getCode();
|
|
|
|
|
|
- ExampleDetails startExampleDetails = new ExampleDetails();
|
|
|
- startExampleDetails.setRemarks(remarks);
|
|
|
-
|
|
|
- // 如果租户流程为空,直接完成流程
|
|
|
- ProcessTenant processTenant = flowInfoVo.processTenantEntity();
|
|
|
- if (ObjectUtil.isEmpty(processTenant)) {
|
|
|
- exampleInfo.setProcessNodeId(FlowConstant.OVER_PROCESS_FLAG);
|
|
|
- exampleInfo.setComplete(StatusConstant.YES);
|
|
|
- exampleInfo.setProcessNodeCode(FlowConstant.END_CODE);
|
|
|
-
|
|
|
- startExampleDetails.setNameType(ButtonNameEnum.START.getType());
|
|
|
- // 执行流程结束方法
|
|
|
- exampleAbstract.end();
|
|
|
- }
|
|
|
- // 租户流程不为空,走租户流程
|
|
|
- else {
|
|
|
- Long processTenantId = processTenant.getId();
|
|
|
+ // 缓存对象转字符串
|
|
|
+ String cacheDataStr = getCacheDataStr(cacheData);
|
|
|
|
|
|
- // 赋值租户流程id
|
|
|
- exampleInfo.setProcessTenantId(processTenantId);
|
|
|
+ // 查询跳转节点
|
|
|
+ String nodeCode = exampleAbstract.circulation(FlowConstant.START_CODE);
|
|
|
|
|
|
- // 调用方法查看是否有指定跳转节点,没有则正常流转
|
|
|
- String circulation = exampleAbstract.circulation(FlowConstant.START_CODE);
|
|
|
+ // 执行流程
|
|
|
+ R<ExampleResult> exampleResultR = flowClient.create(flowLinkNo, code, nodeCode, remarks, cacheDataStr);
|
|
|
+ ExampleResult result = Assert.result(exampleResultR);
|
|
|
|
|
|
- GetNodeButtonVo getNodeButtonVo = new GetNodeButtonVo();
|
|
|
- getNodeButtonVo.setProcessTenantId(processTenantId);
|
|
|
- getNodeButtonVo.setNodeCode(ObjectUtil.isEmpty(circulation) ? FlowConstant.START_CODE : circulation);
|
|
|
+ exampleAbstract.setCacheData(cacheData);
|
|
|
|
|
|
- R<ProcessNodeButton> nodeButtonResult = flowClient.getNodeButton(getNodeButtonVo);
|
|
|
- Assert.eqTrue(nodeButtonResult.isSuccess(), nodeButtonResult.getMsg());
|
|
|
-
|
|
|
- ProcessNodeButton processNodeButton = nodeButtonResult.getData();
|
|
|
- startExampleDetails.setProcessNodeId(processNodeButton.getProcessNodeId());
|
|
|
- startExampleDetails.setProcessNodeButtonId(processNodeButton.getId());
|
|
|
- startExampleDetails.setNameType(processNodeButton.getNameType());
|
|
|
-
|
|
|
- // 流转节点
|
|
|
- Long jumpNodeId = processNodeButton.getJumpNodeId();
|
|
|
-
|
|
|
- // 流程结束
|
|
|
- if (jumpNodeId.equals(FlowConstant.OVER_PROCESS_FLAG)) {
|
|
|
- exampleInfo.setComplete(StatusConstant.YES);
|
|
|
- exampleInfo.setProcessNodeCode(FlowConstant.END_CODE);
|
|
|
+ // 如果流程结束,执行结束方法
|
|
|
+ if (ButtonNameEnum.END.getType().equals(result.getHandleType())) {
|
|
|
+ try {
|
|
|
exampleAbstract.end();
|
|
|
+ } catch (Exception e) {
|
|
|
+ rollBack(result);
|
|
|
+ throw e;
|
|
|
}
|
|
|
- // 正常流转到下一节点
|
|
|
- else {
|
|
|
- exampleInfo.setComplete(StatusConstant.NO);
|
|
|
- }
|
|
|
-
|
|
|
- // 赋值跳转节点id
|
|
|
- exampleInfo.setProcessNodeId(jumpNodeId);
|
|
|
- exampleInfo.setProcessNodeCode(processNodeButton.getProcessNodeCode());
|
|
|
}
|
|
|
- exampleInfo.setExampleDetails(startExampleDetails);
|
|
|
-
|
|
|
- // 保存流程实例
|
|
|
- R<ExampleInfo> exampleInfoSaveResult = flowClient.exampleInfoSave(exampleInfo);
|
|
|
- Assert.eqTrue(exampleInfoSaveResult.isSuccess(), exampleInfoSaveResult.getMsg());
|
|
|
|
|
|
- return exampleInfoSaveResult.getData();
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -131,69 +71,96 @@ public class FlowConstructor {
|
|
|
* @param flowLinkNo 流程关联编号
|
|
|
* @param buttonId 按钮id
|
|
|
* @param remarks 审批意见
|
|
|
+ * @param cacheData 缓存对象
|
|
|
*/
|
|
|
- public void jump(Long flowLinkNo, Long buttonId, String remarks) {
|
|
|
-
|
|
|
- R<ExampleInfo> exampleInfoResult = flowClient.getExampleInfo(flowLinkNo);
|
|
|
- Assert.eqTrue(exampleInfoResult.isSuccess(), exampleInfoResult.getMsg());
|
|
|
-
|
|
|
- ExampleInfo exampleInfo = exampleInfoResult.getData();
|
|
|
-
|
|
|
- // 获取流程缓存
|
|
|
- exampleAbstract.cacheData = exampleInfo.getCacheData();
|
|
|
-
|
|
|
- // 赋值新缓存
|
|
|
- if (ObjectUtil.isNotEmpty(exampleAbstract.cacheData)) {
|
|
|
- exampleInfo.setCacheData(JSONObject.toJSONString(exampleAbstract.cacheData));
|
|
|
+ public ExampleResult jump(Long flowLinkNo, Long buttonId, String remarks, Object cacheData) {
|
|
|
+
|
|
|
+ // 缓存对象转字符串
|
|
|
+ String cacheDataStr = getCacheDataStr(cacheData);
|
|
|
+
|
|
|
+ // 获取按钮
|
|
|
+ ProcessNodeButton processNodeButton = Assert.result(flowClient.getNodeButtonById(buttonId));
|
|
|
+
|
|
|
+ // 查询跳转节点
|
|
|
+ String processNodeCode = processNodeButton.getProcessNodeCode();
|
|
|
+ String nodeCode = exampleAbstract.circulation(processNodeCode);
|
|
|
+
|
|
|
+ JumpVo jumpVo = new JumpVo();
|
|
|
+ jumpVo.setFlowLinkNo(flowLinkNo);
|
|
|
+ jumpVo.setButtonId(buttonId);
|
|
|
+ jumpVo.setRemarks(remarks);
|
|
|
+ jumpVo.setCacheDataStr(cacheDataStr);
|
|
|
+ if (ObjectUtil.isNotEmpty(nodeCode)) {
|
|
|
+ jumpVo.setSpecifyJump(true);
|
|
|
+ jumpVo.setJumpNodeCode(nodeCode);
|
|
|
+ } else {
|
|
|
+ jumpVo.setSpecifyJump(false);
|
|
|
+ jumpVo.setJumpNodeId(processNodeButton.getJumpNodeId());
|
|
|
+ jumpVo.setJumpNodeCode(processNodeButton.getJumpNodeCode());
|
|
|
+ jumpVo.setNameType(processNodeButton.getNameType());
|
|
|
}
|
|
|
|
|
|
- // 调用方法查看是否有指定跳转节点,没有则正常流转
|
|
|
- GetNodeButtonVo getNodeButtonVo = new GetNodeButtonVo();
|
|
|
- getNodeButtonVo.setProcessTenantId(exampleInfo.getProcessTenantId());
|
|
|
- getNodeButtonVo.setNodeCode(exampleAbstract.circulation(exampleInfo.getProcessNodeCode()));
|
|
|
- getNodeButtonVo.setButtonId(buttonId);
|
|
|
-
|
|
|
- R<ProcessNodeButton> nodeButtonResult = flowClient.getNodeButton(getNodeButtonVo);
|
|
|
- Assert.eqTrue(nodeButtonResult.isSuccess(), nodeButtonResult.getMsg());
|
|
|
+ R<ExampleResult> exampleResultR = flowClient.jump(jumpVo);
|
|
|
+ ExampleResult result = Assert.result(exampleResultR);
|
|
|
|
|
|
- ProcessNodeButton processNodeButton = nodeButtonResult.getData();
|
|
|
+ exampleAbstract.setCacheData(cacheData);
|
|
|
|
|
|
- // 赋值跳转节点id
|
|
|
- exampleInfo.setProcessNodeId(processNodeButton.getJumpNodeId());
|
|
|
- exampleInfo.setProcessNodeCode(processNodeButton.getProcessNodeCode());
|
|
|
-
|
|
|
- // 流程正常结束
|
|
|
- if (processNodeButton.getJumpNodeId().equals(FlowConstant.OVER_PROCESS_FLAG)) {
|
|
|
- exampleInfo.setComplete(StatusConstant.YES);
|
|
|
- exampleInfo.setProcessNodeCode(FlowConstant.END_CODE);
|
|
|
- exampleAbstract.end();
|
|
|
- }
|
|
|
- // 驳回结束
|
|
|
- else if (ButtonNameEnum.REJECT.getType().equals(processNodeButton.getNameType())) {
|
|
|
- exampleInfo.setComplete(StatusConstant.YES);
|
|
|
- exampleInfo.setProcessNodeCode(FlowConstant.END_CODE);
|
|
|
- exampleAbstract.reject(processNodeButton.getProcessNodeCode());
|
|
|
+ // 如果流程结束,执行结束方法
|
|
|
+ if (ButtonNameEnum.END.getType().equals(result.getHandleType())) {
|
|
|
+ try {
|
|
|
+ exampleAbstract.end();
|
|
|
+ } catch (Exception e) {
|
|
|
+ rollBack(result);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
}
|
|
|
- // 正常流转到下一节点
|
|
|
- else {
|
|
|
- exampleInfo.setComplete(StatusConstant.NO);
|
|
|
+
|
|
|
+ // 如果流程结束,执行结束方法
|
|
|
+ if (ButtonNameEnum.REJECT.getType().equals(result.getHandleType())) {
|
|
|
+ try {
|
|
|
+ exampleAbstract.reject(result.getOldExampleInfo().getProcessNodeCode());
|
|
|
+ } catch (Exception e) {
|
|
|
+ rollBack(result);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 流程明细
|
|
|
- ExampleDetails startExampleDetails = new ExampleDetails();
|
|
|
- startExampleDetails.setRemarks(remarks);
|
|
|
- startExampleDetails.setProcessNodeId(processNodeButton.getProcessNodeId());
|
|
|
- startExampleDetails.setProcessNodeButtonId(processNodeButton.getId());
|
|
|
- startExampleDetails.setNameType(processNodeButton.getNameType());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- // 创建vo
|
|
|
- ExampleInfoEx exampleInfoEx = BeanUtil.toBean(exampleInfo, ExampleInfoEx.class);
|
|
|
- exampleInfoEx.setExampleDetails(startExampleDetails);
|
|
|
+ /**
|
|
|
+ * 业务异常回滚流程
|
|
|
+ *
|
|
|
+ * @param result 流程返回值
|
|
|
+ */
|
|
|
+ public void rollBack(ExampleResult result) {
|
|
|
+ flowClient.rollBack(result);
|
|
|
+ }
|
|
|
|
|
|
- // 保存流程实例
|
|
|
- R<ExampleInfo> exampleInfoSaveResult = flowClient.exampleInfoSave(exampleInfoEx);
|
|
|
- Assert.eqTrue(exampleInfoSaveResult.isSuccess(), exampleInfoSaveResult.getMsg());
|
|
|
+ /**
|
|
|
+ * 缓存对象转字符串
|
|
|
+ *
|
|
|
+ * @param cacheData 缓存对象
|
|
|
+ * @return 缓存字符串
|
|
|
+ */
|
|
|
+ private String getCacheDataStr(Object cacheData) {
|
|
|
+ String cacheDataStr = "";
|
|
|
+ if (ObjectUtil.isNotEmpty(cacheData)) {
|
|
|
+ cacheDataStr = JSONObject.toJSONString(cacheData);
|
|
|
+ }
|
|
|
+ return cacheDataStr;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取流程编码
|
|
|
+ *
|
|
|
+ * @return 流程编码
|
|
|
+ */
|
|
|
+ private String getCode() {
|
|
|
+ String code = exampleAbstract.getCode();
|
|
|
+ Assert.notEmpty(code, FlowExplainConstant.CODE_EMPTY);
|
|
|
+ return code;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|