|
@@ -23,7 +23,6 @@ import com.fjhx.flow.service.flow.*;
|
|
|
import com.googlecode.aviator.AviatorEvaluator;
|
|
|
import com.googlecode.aviator.Expression;
|
|
|
import com.ruoyi.common.constant.StatusConstant;
|
|
|
-import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
@@ -37,6 +36,7 @@ import java.lang.reflect.Method;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -277,18 +277,25 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
case RETURN_TO_PREVIOUS:
|
|
|
|
|
|
// 查找上一个节点
|
|
|
- FlowExampleDetail lastOneFlowExampleDetail = getLastOneUserNode(flowId);
|
|
|
-
|
|
|
- // 赋值流程所在id
|
|
|
- flowExample.setDefinitionNodeId(lastOneFlowExampleDetail.getFlowDefinitionNodeId());
|
|
|
- flowExample.setHandleUserId(lastOneFlowExampleDetail.getCreateUser());
|
|
|
- FlowThreadLocalUtil.setNextHandleUserId(lastOneFlowExampleDetail.getCreateUser());
|
|
|
+ FlowDefinitionNode lastOneUserNode = getLastOneUserNode(currentNode, flowDefinitionNodeList);
|
|
|
|
|
|
// 如果流程回退到开始节点
|
|
|
- if (NodeTypeEnum.START.getKey().equals(lastOneFlowExampleDetail.getFlowDefinitionNodeType())) {
|
|
|
+ if (NodeTypeEnum.START.getKey().equals(lastOneUserNode.getNodeType())) {
|
|
|
// 流程未发起
|
|
|
flowExample.setStatus(FlowStatusEnum.READY_START.getKey());
|
|
|
} else {
|
|
|
+ FlowResult handleUser = getHandleUser(lastOneUserNode, dto.getHandleUserId());
|
|
|
+
|
|
|
+ // 如果上一节点处理用户只有1人,赋值用户id
|
|
|
+ if (handleUser.getSuccess()) {
|
|
|
+ flowExample.setHandleUserId(handleUser.getUserId());
|
|
|
+ FlowThreadLocalUtil.setNextHandleUserId(handleUser.getUserId());
|
|
|
+ }
|
|
|
+ // 如果下一节点处理用户有多人,则返回用户列表让用户选择下一节点处理人id
|
|
|
+ else {
|
|
|
+ return handleUser;
|
|
|
+ }
|
|
|
+
|
|
|
// 流程进行中
|
|
|
flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
|
}
|
|
@@ -415,18 +422,24 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
|
/**
|
|
|
* 查找上一个节点
|
|
|
*
|
|
|
- * @param flowExampleId 流程实例id
|
|
|
+ * @param currentNode 当前节点
|
|
|
+ * @param flowDefinitionNodeList 流程节点列表
|
|
|
* @return 用户节点
|
|
|
*/
|
|
|
- private FlowExampleDetail getLastOneUserNode(Long flowExampleId) {
|
|
|
- FlowExampleDetail flowExampleDetail = flowExampleDetailService.getOne(q -> q
|
|
|
- .eq(FlowExampleDetail::getFlowExampleId, flowExampleId)
|
|
|
- .orderByDesc(BaseIdPo::getId)
|
|
|
- .last("limit 1,1"));
|
|
|
- if (flowExampleDetail == null) {
|
|
|
- throw new ServiceException("没有找到回退节点");
|
|
|
+ private FlowDefinitionNode getLastOneUserNode(FlowDefinitionNode currentNode, List<FlowDefinitionNode> flowDefinitionNodeList) {
|
|
|
+ // 节点map
|
|
|
+ Map<Long, FlowDefinitionNode> nodeMap = flowDefinitionNodeList.stream()
|
|
|
+ .collect(Collectors.toMap(FlowDefinitionNode::getId, Function.identity()));
|
|
|
+
|
|
|
+ // 查找上个节点
|
|
|
+ FlowDefinitionNode lastNode = nodeMap.get(currentNode.getParentId());
|
|
|
+
|
|
|
+ // 如果为分支
|
|
|
+ if (NodeTypeEnum.BRANCH.equals(NodeTypeEnum.getEnum(lastNode.getNodeType()))) {
|
|
|
+ return getLastOneUserNode(lastNode, flowDefinitionNodeList);
|
|
|
}
|
|
|
- return flowExampleDetail;
|
|
|
+
|
|
|
+ return lastNode;
|
|
|
}
|
|
|
|
|
|
/**
|