Browse Source

流程添加 加签 退回指定节点

yzc 1 year ago
parent
commit
328ddc2209

+ 6 - 0
hx-flow/src/main/java/com/fjhx/flow/entity/flow/dto/FlowResult.java

@@ -1,5 +1,6 @@
 package com.fjhx.flow.entity.flow.dto;
 
+import com.fjhx.flow.entity.flow.po.FlowDefinitionNode;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import lombok.Getter;
 import lombok.Setter;
@@ -33,4 +34,9 @@ public class FlowResult {
      */
     private Long userId;
 
+    /**
+     * 已审批节点列表
+     */
+    private List<FlowDefinitionNode> flowDefinitionNodeList;
+
 }

+ 5 - 0
hx-flow/src/main/java/com/fjhx/flow/entity/flow/dto/JumpDto.java

@@ -54,4 +54,9 @@ public class JumpDto {
      */
     private List<ObsFile> fileList;
 
+    /**
+     * 下一处理节点id
+     */
+    private Long handleNodeId;
+
 }

+ 3 - 0
hx-flow/src/main/java/com/fjhx/flow/enums/HandleTypeEnum.java

@@ -16,6 +16,9 @@ public enum HandleTypeEnum {
     RETURN_TO_PREVIOUS(3, "返回上一步"),
     RETURN_TO_SUBMITTER(4, "退回到发起人"),
     CANCELLATION(5, "作废"),
+    ADD_APPROVAL(6,"加签"),
+    TRANSFER(7,"移交"),
+    RETURN_TO_NODE(8,"退回")
     ;
 
     private final Integer key;

+ 2 - 1
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowDefinitionServiceImpl.java

@@ -62,7 +62,8 @@ public class FlowDefinitionServiceImpl extends ServiceImpl<FlowDefinitionMapper,
                 .keyword(dto, new SqlField("fi", FlowInfo::getFlowKey), new SqlField("fi", FlowInfo::getFlowName))
                 .eq("fd", FlowDefinition::getCurrentVersion, StatusConstant.YES)
                 .eq("fd", FlowDefinition::getTenantId, dto.getTenantId())
-                .in("fd", FlowDefinition::getFlowInfoId, flowInfoIdList);
+                .in("fd", FlowDefinition::getFlowInfoId, flowInfoIdList)
+                .orderByAsc("fi", FlowInfo::getCreateTime);
         return baseMapper.getPage(dto.getPage(), wrapper);
     }
 

+ 25 - 8
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowExampleServiceImpl.java

@@ -29,10 +29,7 @@ import com.ruoyi.system.utils.UserUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.function.BiConsumer;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -269,7 +266,27 @@ public class FlowExampleServiceImpl extends ServiceImpl<FlowExampleMapper, FlowE
         }
 
         String nodeButtonSet = flowDefinitionNode.getNodeButtonSet();
-        for (String buttonTypeStr : nodeButtonSet.split(",")) {
+
+        //按特定顺序排序按钮(通过,退回(指定节点),审批驳回,加签,移交)
+        List<String> nodeButtonList = new ArrayList<>();
+        List<String> nodeButtonTempList = Arrays.stream(nodeButtonSet.split(",")).collect(Collectors.toList());
+        List<HandleTypeEnum> sortList = Arrays.asList(
+                HandleTypeEnum.SKIP_TO_NEXT,
+                HandleTypeEnum.RETURN_TO_NODE,
+                HandleTypeEnum.REJECT,
+                HandleTypeEnum.ADD_APPROVAL,
+                HandleTypeEnum.TRANSFER
+        );
+        for (HandleTypeEnum handleTypeEnum : sortList) {
+            String type = handleTypeEnum.getKey().toString();
+            if (nodeButtonTempList.contains(type)) {
+                nodeButtonList.add(type);
+                nodeButtonTempList.remove(type);
+            }
+        }
+        nodeButtonList.addAll(nodeButtonTempList);
+
+        for (String buttonTypeStr : nodeButtonList) {
 
             if (StrUtil.isBlank(buttonTypeStr)) {
                 continue;
@@ -284,12 +301,12 @@ public class FlowExampleServiceImpl extends ServiceImpl<FlowExampleMapper, FlowE
             }
         }
 
-        // 如果查看人是流程创建人,且流程未开始,添加作废按钮
+        // 如果查看人是流程创建人,且流程未开始,添加驳回按钮
         if (Objects.equals(flowExample.getCreateUser(), SecurityUtils.getUserId())
                 && Objects.equals(flowExample.getStatus(), FlowStatusEnum.READY_START.getKey())) {
             ApprovalRecordVo.ButtonInfo buttonInfo = new ApprovalRecordVo.ButtonInfo();
-            buttonInfo.setType(HandleTypeEnum.CANCELLATION.getKey());
-            buttonInfo.setName(HandleTypeEnum.CANCELLATION.getValue());
+            buttonInfo.setType(HandleTypeEnum.REJECT.getKey());
+            buttonInfo.setName(HandleTypeEnum.REJECT.getValue());
             buttonInfoList.add(buttonInfo);
         }
 

+ 95 - 0
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowProcessServiceImpl.java

@@ -5,8 +5,10 @@ import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fjhx.file.utils.ObsFileUtil;
 import com.fjhx.flow.core.FlowBean;
 import com.fjhx.flow.core.FlowDelegate;
@@ -39,6 +41,7 @@ import org.springframework.stereotype.Service;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.sql.Wrapper;
 import java.util.*;
 import java.util.function.Function;
 import java.util.regex.Matcher;
@@ -249,6 +252,20 @@ public class FlowProcessServiceImpl implements FlowProcessService {
             case CANCELLATION:
                 flowResult = cancellation(context);
                 break;
+            //加签
+            case ADD_APPROVAL:
+                //修改状态为审批通过
+                dto.setHandleType(HandleTypeEnum.SKIP_TO_NEXT.getKey());
+                flowResult = transfer(context, dto);
+                break;
+            //移交
+            case TRANSFER:
+                flowResult = transfer(context, dto);
+                break;
+            // 退回到指定节点
+            case RETURN_TO_NODE:
+                flowResult = returnToNode(context, dto);
+                break;
 
             default:
                 throw new ServiceException("未知流程跳转类型");
@@ -401,6 +418,81 @@ public class FlowProcessServiceImpl implements FlowProcessService {
         throw new ServiceException("流程定义错误:未找到结束节点");
     }
 
+    private FlowResult transfer(FlowJumpContext context, JumpDto dto) {
+        Long handleUserId = dto.getHandleUserId();
+        if (ObjectUtil.isEmpty(handleUserId)){
+            List<SysUser> userList = sysUserService.list(Wrappers.<SysUser>query().eq("company_id", SecurityUtils.getCompanyId()));
+
+            FlowResult flowResult = new FlowResult();
+            flowResult.setSuccess(false);
+            flowResult.setUserList(userList);
+            return flowResult;
+        }
+
+        //生成下一节点信息(复制当前节点)
+        FlowResult flowResult = getHandleUser(context.getCurrentNode(), context.getJumpHandleUserId());
+        // 流程进行中
+        context.setFlowStatus(FlowStatusEnum.IN_PROGRESS);
+        // 赋值流程节点审批人为加签用户
+        context.setJumpHandleUserId(handleUserId);
+        context.setJumpNode(context.getCurrentNode());
+        return flowResult;
+    }
+
+    /**
+     * 跳转到指定节点
+     */
+    private FlowResult returnToNode(FlowJumpContext context, JumpDto dto) {
+        if (ObjectUtil.isEmpty(dto.getHandleNodeId())) {
+
+            FlowExample flowExample = context.getFlowExample();
+
+            // 获取已完成节点
+            List<Long> flowNodeIds = flowExampleDetailService.listObject(FlowExampleDetail::getFlowDefinitionNodeId,
+                    q -> q.eq(FlowExampleDetail::getFlowExampleId, dto.getFlowId()));
+
+            // 获取流程全部节点
+            List<FlowDefinitionNode> flowDefinitionNodeList = flowDefinitionNodeService.list(
+                    q -> q.eq(FlowDefinitionNode::getFlowDefinitionId, flowExample.getDefinitionId())
+                            .in(FlowDefinitionNode::getId, flowNodeIds)
+            );
+
+            FlowResult flowResult = new FlowResult();
+            flowResult.setSuccess(false);
+            flowResult.setFlowDefinitionNodeList(flowDefinitionNodeList);
+
+            return flowResult;
+        }
+
+        Long handleNodeId = dto.getHandleNodeId();
+        List<FlowDefinitionNode> flowDefinitionNodeList = context.getFlowDefinitionNodeList();
+        // 节点map
+        Map<Long, FlowDefinitionNode> nodeMap = flowDefinitionNodeList.stream()
+                .collect(Collectors.toMap(FlowDefinitionNode::getId, Function.identity()));
+
+        // 查找指定节点信息
+        FlowDefinitionNode jumpNode = nodeMap.get(handleNodeId);
+
+        context.setJumpNode(jumpNode);
+
+        // 如果流程回退到开始节点
+        if (NodeTypeEnum.START.getKey().equals(jumpNode.getNodeType())) {
+            // 流程未发起
+            context.setFlowStatus(FlowStatusEnum.READY_START);
+            // 流程节点处理人为流程发起人
+            context.setJumpHandleUserId(context.getFlowExample().getCreateUser());
+            return new FlowResult(true);
+        }
+
+        FlowResult flowResult = getHandleUser(jumpNode, context.getJumpHandleUserId());
+        // 流程进行中
+        context.setFlowStatus(FlowStatusEnum.IN_PROGRESS);
+        // 赋值流程节点审批人
+        context.setJumpHandleUserId(flowResult.getUserId());
+
+        return flowResult;
+    }
+
     /**
      * 执行节点方法
      */
@@ -787,6 +879,8 @@ public class FlowProcessServiceImpl implements FlowProcessService {
 
         switch (handleTypeEnum) {
             // 跳转下一节点
+            case ADD_APPROVAL:
+            case TRANSFER:
             case SKIP_TO_NEXT:
                 // 如果流程结束
                 if (FlowStatusEnum.PASS.equals(flowStatusEnum)) {
@@ -812,6 +906,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                 break;
 
             // 退回上一节点
+            case RETURN_TO_NODE:
             case RETURN_TO_PREVIOUS:
 
                 // 查找上次审批节点