|
| 1 | +package com.codingapi.springboot.flow.service.impl; |
| 2 | + |
| 3 | +import com.codingapi.springboot.flow.bind.BindDataSnapshot; |
| 4 | +import com.codingapi.springboot.flow.bind.IBindData; |
| 5 | +import com.codingapi.springboot.flow.domain.FlowNode; |
| 6 | +import com.codingapi.springboot.flow.domain.FlowWork; |
| 7 | +import com.codingapi.springboot.flow.domain.Opinion; |
| 8 | +import com.codingapi.springboot.flow.pojo.FlowStepResult; |
| 9 | +import com.codingapi.springboot.flow.record.FlowRecord; |
| 10 | +import com.codingapi.springboot.flow.repository.FlowOperatorRepository; |
| 11 | +import com.codingapi.springboot.flow.repository.FlowRecordRepository; |
| 12 | +import com.codingapi.springboot.flow.service.FlowNodeService; |
| 13 | +import com.codingapi.springboot.flow.service.FlowServiceRepositoryHolder; |
| 14 | +import com.codingapi.springboot.flow.user.IFlowOperator; |
| 15 | + |
| 16 | +import java.util.ArrayList; |
| 17 | +import java.util.List; |
| 18 | + |
| 19 | +public class FlowStepService { |
| 20 | + private final FlowWork flowWork; |
| 21 | + |
| 22 | + private final IFlowOperator currentOperator; |
| 23 | + private final IBindData bindData; |
| 24 | + private final FlowServiceRepositoryHolder flowServiceRepositoryHolder; |
| 25 | + |
| 26 | + private FlowNodeService flowNodeService; |
| 27 | + private FlowNode flowNode; |
| 28 | + |
| 29 | + public FlowStepService(String workCode, IFlowOperator currentOperator, IBindData bindData, FlowServiceRepositoryHolder flowServiceRepositoryHolder) { |
| 30 | + this.currentOperator = currentOperator; |
| 31 | + this.bindData = bindData; |
| 32 | + this.flowServiceRepositoryHolder = flowServiceRepositoryHolder; |
| 33 | + this.flowWork = flowServiceRepositoryHolder.getFlowWorkRepository().getFlowWorkByCode(workCode); |
| 34 | + } |
| 35 | + |
| 36 | + |
| 37 | + public FlowStepResult getFlowStep() { |
| 38 | + FlowStepResult flowStepResult = new FlowStepResult(); |
| 39 | + // 获取开始节点 |
| 40 | + FlowNode start = flowWork.getStartNode(); |
| 41 | + if (start == null) { |
| 42 | + throw new IllegalArgumentException("start node not found"); |
| 43 | + } |
| 44 | + |
| 45 | + this.flowNode = start; |
| 46 | + // 设置开始流程的上一个流程id |
| 47 | + long preId = 0; |
| 48 | + |
| 49 | + // 创建流程id |
| 50 | + String processId = "flow_" + System.currentTimeMillis(); |
| 51 | + |
| 52 | + List<FlowRecord> historyRecords = new ArrayList<>(); |
| 53 | + |
| 54 | + FlowOperatorRepository flowOperatorRepository = flowServiceRepositoryHolder.getFlowOperatorRepository(); |
| 55 | + FlowRecordRepository flowRecordRepository = flowServiceRepositoryHolder.getFlowRecordRepository(); |
| 56 | + |
| 57 | + BindDataSnapshot snapshot = new BindDataSnapshot(bindData); |
| 58 | + flowNodeService = new FlowNodeService(flowOperatorRepository, |
| 59 | + flowRecordRepository, |
| 60 | + snapshot, |
| 61 | + Opinion.pass("同意"), |
| 62 | + currentOperator, |
| 63 | + currentOperator, |
| 64 | + historyRecords, |
| 65 | + flowWork, |
| 66 | + null, |
| 67 | + processId, |
| 68 | + preId); |
| 69 | + |
| 70 | + flowNodeService.setNextNode(start); |
| 71 | + |
| 72 | + this.flowNode = start; |
| 73 | + flowStepResult.addFlowNode(this.flowNode); |
| 74 | + |
| 75 | + do { |
| 76 | + flowNodeService.loadNextPassNode(this.flowNode); |
| 77 | + this.flowNode = flowNodeService.getNextNode(); |
| 78 | + flowStepResult.addFlowNode(this.flowNode); |
| 79 | + } while (!flowNode.isOverNode()); |
| 80 | + |
| 81 | + return flowStepResult; |
| 82 | + } |
| 83 | +} |
0 commit comments