|
@@ -113,39 +113,50 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
// 流程实例明细列表
|
|
|
List<FlowExampleDetail> flowExampleDetailList = new ArrayList<>();
|
|
|
|
|
|
+ // 执行开始流程方法
|
|
|
+ Long businessId = flowDelegate.start(flowId, dto.getData());
|
|
|
+ FlowThreadLocalUtil.setBusinessId(businessId);
|
|
|
+
|
|
|
+ FlowExampleDetail startExampleDetail = new FlowExampleDetail();
|
|
|
+ startExampleDetail.setFlowExampleId(flowId);
|
|
|
+ startExampleDetail.setFlowDefinitionNodeId(startNode.getId());
|
|
|
+ startExampleDetail.setFlowDefinitionNodeType(startNode.getNodeType());
|
|
|
+ startExampleDetail.setHandleType(HandleTypeEnum.NEXT.getKey());
|
|
|
+ startExampleDetail.setHandleRemark(dto.getRemark());
|
|
|
+ flowExampleDetailList.add(startExampleDetail);
|
|
|
+
|
|
|
+ // 如果下个节点是结束节点
|
|
|
+ if (NodeTypeEnum.END.equals(NodeTypeEnum.getEnum(nextUserNode.getNodeType()))) {
|
|
|
+
|
|
|
+ // 添加明细
|
|
|
+ invokeEndMethod(nextUserNode, flowDelegateCls, flowDelegate);
|
|
|
+
|
|
|
+ // 结束流程
|
|
|
+ FlowExampleDetail endExampleDetail = new FlowExampleDetail();
|
|
|
+ endExampleDetail.setFlowExampleId(flowId);
|
|
|
+ endExampleDetail.setFlowDefinitionNodeId(nextUserNode.getId());
|
|
|
+ endExampleDetail.setFlowDefinitionNodeType(nextUserNode.getNodeType());
|
|
|
+ endExampleDetail.setHandleType(HandleTypeEnum.OVER.getKey());
|
|
|
+ flowExampleDetailList.add(endExampleDetail);
|
|
|
+
|
|
|
+ // 流程已通过
|
|
|
+ flowExample.setStatus(FlowStatusEnum.HAVE_PASSED.getKey());
|
|
|
+ } else {
|
|
|
+ // 流程进行中
|
|
|
+ flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ flowExample.setTitle(StrUtil.format(flowDefinition.getTitleTemplate(), templateMap, true));
|
|
|
+ flowExample.setFlowKey(dto.getFlowKey());
|
|
|
+ flowExample.setDefinitionId(flowDefinition.getId());
|
|
|
+ flowExample.setDefinitionNodeId(nextUserNode.getId());
|
|
|
+ flowExample.setBusinessId(businessId);
|
|
|
+ flowExample.setStartData(dto.getData().toJSONString());
|
|
|
+
|
|
|
// 开启一个事务
|
|
|
TransactionStatus transaction = platformTransactionManager.getTransaction(transactionDefinition);
|
|
|
|
|
|
try {
|
|
|
-
|
|
|
- // 执行开始流程方法
|
|
|
- Long businessId = flowDelegate.start(flowId, dto.getData());
|
|
|
- FlowThreadLocalUtil.setBusinessId(businessId);
|
|
|
-
|
|
|
- FlowExampleDetail startExampleDetail = new FlowExampleDetail();
|
|
|
- startExampleDetail.setFlowExampleId(flowId);
|
|
|
- startExampleDetail.setFlowDefinitionNodeId(startNode.getId());
|
|
|
- startExampleDetail.setFlowDefinitionNodeType(startNode.getNodeType());
|
|
|
- startExampleDetail.setHandleType(HandleTypeEnum.NEXT.getKey());
|
|
|
- flowExampleDetailList.add(startExampleDetail);
|
|
|
-
|
|
|
- // 如果下个节点是结束节点
|
|
|
- if (NodeTypeEnum.END.equals(NodeTypeEnum.getEnum(nextUserNode.getNodeType()))) {
|
|
|
- // 添加明细
|
|
|
- flowExampleDetailList.add(executeEndFun(flowId, nextUserNode, flowDelegateCls, flowDelegate));
|
|
|
- // 流程已通过
|
|
|
- flowExample.setStatus(FlowStatusEnum.HAVE_PASSED.getKey());
|
|
|
- } else {
|
|
|
- // 流程进行中
|
|
|
- flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
|
- }
|
|
|
-
|
|
|
- flowExample.setTitle(StrUtil.format(flowDefinition.getTitleTemplate(), templateMap, true));
|
|
|
- flowExample.setFlowKey(dto.getFlowKey());
|
|
|
- flowExample.setDefinitionId(flowDefinition.getId());
|
|
|
- flowExample.setDefinitionNodeId(nextUserNode.getId());
|
|
|
- flowExample.setBusinessId(businessId);
|
|
|
- flowExample.setStartData(dto.getData().toJSONString());
|
|
|
flowExampleService.save(flowExample);
|
|
|
flowExampleDetailService.saveBatch(flowExampleDetailList);
|
|
|
|
|
@@ -154,8 +165,8 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
} catch (Exception e) {
|
|
|
// 回滚事务
|
|
|
platformTransactionManager.rollback(transaction);
|
|
|
- log.error("业务错误", e);
|
|
|
- throw new ServiceException("业务代码错误");
|
|
|
+ log.error("保存流程异常", e);
|
|
|
+ throw new ServiceException("保存流程异常");
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -163,11 +174,16 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
@Override
|
|
|
public void jump(JumpDto dto) {
|
|
|
Long flowId = dto.getFlowId();
|
|
|
+
|
|
|
FlowExample flowExample = flowExampleService.getById(flowId);
|
|
|
if (flowExample == null) {
|
|
|
throw new ServiceException("没有找到流程");
|
|
|
}
|
|
|
|
|
|
+ if (!flowExample.getVersion().equals(dto.getVersion())) {
|
|
|
+ throw new ServiceException("流程已被处理");
|
|
|
+ }
|
|
|
+
|
|
|
Integer status = flowExample.getStatus();
|
|
|
if (status > 1) {
|
|
|
throw new ServiceException("流程已结束");
|
|
@@ -192,19 +208,9 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
throw new ServiceException("没有找到当前审批节点");
|
|
|
}
|
|
|
|
|
|
- // 查找跳转节点
|
|
|
+ // 查找跳转类型
|
|
|
HandleTypeEnum handleTypeEnum = HandleTypeEnum.getEnum(dto.getHandleType());
|
|
|
|
|
|
- // 发起流程参数
|
|
|
- JSONObject startDataJson = JSONObject.parseObject(flowExample.getStartData());
|
|
|
- Map<String, Object> templateMap = flowDelegate.initTemplateMap(dto.getData(), startDataJson);
|
|
|
- FlowThreadLocalUtil.setTemplateData(templateMap);
|
|
|
- FlowThreadLocalUtil.setStartData(dto.getData());
|
|
|
- FlowThreadLocalUtil.setCurrentData(dto.getData());
|
|
|
- FlowThreadLocalUtil.setFlowId(flowId);
|
|
|
- FlowThreadLocalUtil.setBusinessId(flowExample.getBusinessId());
|
|
|
- FlowThreadLocalUtil.setHandleTypeEnum(handleTypeEnum);
|
|
|
-
|
|
|
// 流程实例明细列表
|
|
|
List<FlowExampleDetail> flowExampleDetailList = new ArrayList<>();
|
|
|
|
|
@@ -220,6 +226,18 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
|
|
|
FlowDefinitionNode jumpUserNode = null;
|
|
|
|
|
|
+ // 发起流程参数
|
|
|
+ JSONObject startDataJson = JSONObject.parseObject(flowExample.getStartData());
|
|
|
+ Map<String, Object> templateMap = flowDelegate.initTemplateMap(dto.getData(), startDataJson);
|
|
|
+ FlowThreadLocalUtil.setTemplateData(templateMap);
|
|
|
+ FlowThreadLocalUtil.setStartData(dto.getData());
|
|
|
+ FlowThreadLocalUtil.setCurrentData(dto.getData());
|
|
|
+ FlowThreadLocalUtil.setFlowId(flowId);
|
|
|
+ FlowThreadLocalUtil.setBusinessId(flowExample.getBusinessId());
|
|
|
+ FlowThreadLocalUtil.setHandleTypeEnum(handleTypeEnum);
|
|
|
+
|
|
|
+ FlowStatusEnum flowStatusEnum;
|
|
|
+
|
|
|
switch (handleTypeEnum) {
|
|
|
case NEXT:
|
|
|
// 父级节点map
|
|
@@ -232,7 +250,8 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
// 如果下个节点是结束节点
|
|
|
if (NodeTypeEnum.END.equals(NodeTypeEnum.getEnum(jumpUserNode.getNodeType()))) {
|
|
|
// 流程已通过
|
|
|
- flowExample.setStatus(FlowStatusEnum.HAVE_PASSED.getKey());
|
|
|
+ flowStatusEnum = FlowStatusEnum.HAVE_PASSED;
|
|
|
+
|
|
|
// 结束流程
|
|
|
FlowExampleDetail endExampleDetail = new FlowExampleDetail();
|
|
|
endExampleDetail.setFlowExampleId(flowId);
|
|
@@ -242,9 +261,10 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
flowExampleDetailList.add(endExampleDetail);
|
|
|
} else {
|
|
|
// 流程进行中
|
|
|
- flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
|
+ flowStatusEnum = FlowStatusEnum.IN_PROGRESS;
|
|
|
}
|
|
|
break;
|
|
|
+
|
|
|
case PREVIOUS:
|
|
|
// 节点id对象map
|
|
|
Map<Long, FlowDefinitionNode> nodeMap = flowDefinitionNodeList.stream()
|
|
@@ -256,15 +276,37 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
// 如果流程回退到开始节点
|
|
|
if (NodeTypeEnum.START.equals(NodeTypeEnum.getEnum(jumpUserNode.getNodeType()))) {
|
|
|
// 流程进行中
|
|
|
- flowExample.setStatus(FlowStatusEnum.UNINITIATED.getKey());
|
|
|
+ flowStatusEnum = FlowStatusEnum.UNINITIATED;
|
|
|
} else {
|
|
|
// 流程进行中
|
|
|
- flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
|
+ flowStatusEnum = FlowStatusEnum.IN_PROGRESS;
|
|
|
}
|
|
|
break;
|
|
|
+
|
|
|
case OVER:
|
|
|
- flowExample.setStatus(FlowStatusEnum.REJECTED.getKey());
|
|
|
+ flowStatusEnum = FlowStatusEnum.REJECTED;
|
|
|
break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ throw new ServiceException("未知节点处理类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ flowExample.setStatus(flowStatusEnum.getKey());
|
|
|
+
|
|
|
+ // 执行当前节点方法
|
|
|
+ String handlingMethod = currentNode.getHandlingMethod();
|
|
|
+ if (StrUtil.isNotBlank(handlingMethod)) {
|
|
|
+ invokeMethod(flowDelegateCls, flowDelegate, handlingMethod);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行结束方法
|
|
|
+ if (jumpUserNode != null && NodeTypeEnum.END.equals(NodeTypeEnum.getEnum(jumpUserNode.getNodeType()))) {
|
|
|
+ invokeEndMethod(jumpUserNode, flowDelegateCls, flowDelegate);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 驳回通用方法
|
|
|
+ if (handleTypeEnum.equals(HandleTypeEnum.OVER)) {
|
|
|
+ flowDelegate.rejected();
|
|
|
}
|
|
|
|
|
|
// 开启一个事务
|
|
@@ -273,23 +315,13 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
try {
|
|
|
flowExampleService.updateById(flowExample);
|
|
|
flowExampleDetailService.saveBatch(flowExampleDetailList);
|
|
|
-
|
|
|
- if (jumpUserNode != null) {
|
|
|
- String handlingMethod = jumpUserNode.getHandlingMethod();
|
|
|
- if (StrUtil.isNotBlank(handlingMethod)) {
|
|
|
- invokeMethod(flowDelegateCls, flowDelegate, handlingMethod);
|
|
|
- }
|
|
|
- } else {
|
|
|
- flowDelegate.rejected();
|
|
|
- }
|
|
|
-
|
|
|
// 提交事务
|
|
|
platformTransactionManager.commit(transaction);
|
|
|
} catch (Exception e) {
|
|
|
// 提交事务
|
|
|
platformTransactionManager.rollback(transaction);
|
|
|
- log.error("业务错误", e);
|
|
|
- throw new ServiceException("业务代码错误");
|
|
|
+ log.error("保存流程异常", e);
|
|
|
+ throw new ServiceException("保存流程异常");
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -297,14 +329,11 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
/**
|
|
|
* 执行结束方法
|
|
|
*
|
|
|
- * @param flowId 流程id
|
|
|
* @param nextUserNode 下个用户节点
|
|
|
* @param flowDelegateCls 流程代理class
|
|
|
* @param flowDelegate 流程代理对象
|
|
|
- * @return 节点明细
|
|
|
*/
|
|
|
- private FlowExampleDetail executeEndFun(Long flowId, FlowDefinitionNode nextUserNode,
|
|
|
- Class<? extends FlowDelegate> flowDelegateCls, FlowDelegate flowDelegate) {
|
|
|
+ private void invokeEndMethod(FlowDefinitionNode nextUserNode, Class<? extends FlowDelegate> flowDelegateCls, FlowDelegate flowDelegate) {
|
|
|
|
|
|
// 走非默认方法
|
|
|
String handlingMethod = nextUserNode.getHandlingMethod();
|
|
@@ -316,13 +345,6 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
flowDelegate.end();
|
|
|
}
|
|
|
|
|
|
- // 结束流程
|
|
|
- FlowExampleDetail endExampleDetail = new FlowExampleDetail();
|
|
|
- endExampleDetail.setFlowExampleId(flowId);
|
|
|
- endExampleDetail.setFlowDefinitionNodeId(nextUserNode.getId());
|
|
|
- endExampleDetail.setFlowDefinitionNodeType(nextUserNode.getNodeType());
|
|
|
- endExampleDetail.setHandleType(HandleTypeEnum.OVER.getKey());
|
|
|
- return endExampleDetail;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -389,7 +411,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
}
|
|
|
// 如果不为分支
|
|
|
else {
|
|
|
- if (nextNodeList.size() != 1) {
|
|
|
+ if (nextNodeList == null || nextNodeList.size() != 1) {
|
|
|
throw new ServiceException("流程定义错误");
|
|
|
}
|
|
|
// 查找下一个节点方法
|