24282 2 yıl önce
ebeveyn
işleme
69bcc57cbe

+ 10 - 0
hx-flow/src/main/java/com/fjhx/flow/controller/flow/FlowExampleController.java

@@ -3,6 +3,7 @@ package com.fjhx.flow.controller.flow;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.flow.entity.flow.dto.FlowExampleSelectDto;
+import com.fjhx.flow.entity.flow.dto.FlowNodeDto;
 import com.fjhx.flow.entity.flow.po.FlowInfo;
 import com.fjhx.flow.entity.flow.vo.ApprovalRecordVo;
 import com.fjhx.flow.entity.flow.vo.FlowExampleVo;
@@ -10,6 +11,7 @@ import com.fjhx.flow.service.flow.FlowExampleService;
 import com.ruoyi.common.constant.BaseSourceConstant;
 import com.ruoyi.common.core.domain.BaseSelectDto;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -82,4 +84,12 @@ public class FlowExampleController {
         return flowExampleService.getPage(dto);
     }
 
+    /**
+     * 发起流程记录
+     */
+    @PostMapping("/getFlowNode")
+    public List<ApprovalRecordVo.Record> getFlowNode(@Validated @RequestBody FlowNodeDto dto) {
+        return flowExampleService.getFlowNode(dto);
+    }
+
 }

+ 18 - 0
hx-flow/src/main/java/com/fjhx/flow/entity/flow/dto/FlowNodeDto.java

@@ -0,0 +1,18 @@
+package com.fjhx.flow.entity.flow.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotBlank;
+
+@Getter
+@Setter
+public class FlowNodeDto {
+
+    /**
+     * 流程key
+     */
+    @NotBlank(message = "流程key不能为空")
+    private String flowKey;
+
+}

+ 6 - 1
hx-flow/src/main/java/com/fjhx/flow/service/flow/FlowExampleService.java

@@ -2,11 +2,11 @@ package com.fjhx.flow.service.flow;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.flow.entity.flow.dto.FlowExampleSelectDto;
+import com.fjhx.flow.entity.flow.dto.FlowNodeDto;
 import com.fjhx.flow.entity.flow.po.FlowExample;
 import com.fjhx.flow.entity.flow.po.FlowInfo;
 import com.fjhx.flow.entity.flow.vo.ApprovalRecordVo;
 import com.fjhx.flow.entity.flow.vo.FlowExampleVo;
-import com.ruoyi.common.core.domain.BaseSelectDto;
 import com.ruoyi.common.core.service.BaseService;
 
 import java.util.List;
@@ -52,4 +52,9 @@ public interface FlowExampleService extends BaseService<FlowExample> {
      */
     Page<FlowExampleVo> getPage(FlowExampleSelectDto dto);
 
+    /**
+     * 发起流程记录
+     */
+    List<ApprovalRecordVo.Record> getFlowNode(FlowNodeDto dto);
+
 }

+ 44 - 11
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowExampleServiceImpl.java

@@ -3,6 +3,7 @@ package com.fjhx.flow.service.flow.impl;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.flow.entity.flow.dto.FlowExampleSelectDto;
+import com.fjhx.flow.entity.flow.dto.FlowNodeDto;
 import com.fjhx.flow.entity.flow.po.*;
 import com.fjhx.flow.entity.flow.vo.ApprovalRecordVo;
 import com.fjhx.flow.entity.flow.vo.FlowExampleVo;
@@ -11,6 +12,7 @@ import com.fjhx.flow.enums.HandleTypeEnum;
 import com.fjhx.flow.enums.NodeTypeEnum;
 import com.fjhx.flow.mapper.flow.FlowExampleMapper;
 import com.fjhx.flow.service.flow.*;
+import com.ruoyi.common.constant.StatusConstant;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.core.text.Convert;
 import com.ruoyi.common.exception.ServiceException;
@@ -124,8 +126,12 @@ public class FlowExampleServiceImpl extends ServiceImpl<FlowExampleMapper, FlowE
         // 赋值节点信息以及处理人名称
         setNodeInfoAndHandleUserName(recordList, flowDefinitionNodeList);
 
-        // 添加未开始记录
-        addNotStarted(recordList, flowExample, flowDefinitionNodeList);
+        Integer status = flowExample.getStatus();
+
+        if (!FlowStatusEnum.PASS.getKey().equals(status) && !FlowStatusEnum.REJECT.getKey().equals(status)) {
+            // 添加未开始记录
+            addNotStarted(recordList, flowDefinitionNodeList, flowExample.getDefinitionNodeId());
+        }
 
         // 获取button列表
         List<ApprovalRecordVo.ButtonInfo> buttonInfoList = getButtonInfoList(flowExample, flowDefinitionNodeList);
@@ -153,6 +159,38 @@ public class FlowExampleServiceImpl extends ServiceImpl<FlowExampleMapper, FlowE
         return doSelectExample(dto, wrapper);
     }
 
+    @Override
+    public List<ApprovalRecordVo.Record> getFlowNode(FlowNodeDto dto) {
+
+        List<ApprovalRecordVo.Record> recordList = new ArrayList<>();
+
+        // 查找可用流程
+        FlowDefinition flowDefinition = flowDefinitionService.getOne(q -> q
+                .eq(FlowDefinition::getFlowKey, dto.getFlowKey())
+                .eq(FlowDefinition::getCurrentVersion, StatusConstant.YES));
+
+        // 获取流程全部节点
+        List<FlowDefinitionNode> flowDefinitionNodeList = flowDefinitionNodeService.list(
+                q -> q.eq(FlowDefinitionNode::getFlowDefinitionId, flowDefinition.getId()));
+
+        // 查找开始节点
+        FlowDefinitionNode startNode = flowDefinitionNodeList.stream()
+                .filter(item -> item.getNodeType().equals(NodeTypeEnum.START.getKey()))
+                .findFirst().orElse(null);
+
+        if (startNode == null) {
+            throw new ServiceException("未找到开始节点");
+        }
+
+        // 查找节点
+        addNotStarted(recordList, flowDefinitionNodeList, 0L);
+
+        // 赋值开始节点创作人
+        recordList.get(0).setProcessedUser(SecurityUtils.getLoginUser().getUser().getNickName());
+
+        return recordList;
+    }
+
     private List<ApprovalRecordVo.ButtonInfo> getButtonInfoList(FlowExample flowExample,
                                                                 List<FlowDefinitionNode> flowDefinitionNodeList) {
 
@@ -189,20 +227,15 @@ public class FlowExampleServiceImpl extends ServiceImpl<FlowExampleMapper, FlowE
     /**
      * 添加未开始记录
      */
-    private void addNotStarted(List<ApprovalRecordVo.Record> recordList, FlowExample flowExample,
-                               List<FlowDefinitionNode> flowDefinitionNodeList) {
-
-        Integer status = flowExample.getStatus();
-
-        if (FlowStatusEnum.PASS.getKey().equals(status) || FlowStatusEnum.REJECT.getKey().equals(status)) {
-            return;
-        }
+    private void addNotStarted(List<ApprovalRecordVo.Record> recordList,
+                               List<FlowDefinitionNode> flowDefinitionNodeList,
+                               Long definitionNodeId) {
 
         // 父节点id map
         Map<Long, FlowDefinitionNode> flowDefinitionNodeMap = flowDefinitionNodeList.stream()
                 .collect(Collectors.toMap(FlowDefinitionNode::getParentId, Function.identity()));
 
-        FlowDefinitionNode nextNode = flowDefinitionNodeMap.get(flowExample.getDefinitionNodeId());
+        FlowDefinitionNode nextNode = flowDefinitionNodeMap.get(definitionNodeId);
 
         while (nextNode != null) {
 

+ 3 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResponseAdvice.java

@@ -38,6 +38,9 @@ public class ResponseAdvice implements ResponseBodyAdvice<Object> {
             if (Objects.equals(status, 404) && Objects.equals(error, "Not Found")) {
                 return R.fail(404, "Not Found");
             }
+            if (Objects.equals(status, 500) && Objects.equals(error, "Internal Server Error")) {
+                return R.fail(500, "Internal Server Error");
+            }
         }
 
         // 提供一定的灵活度,如果body已经被包装了,就不进行包装