|
| 1 | +package com.codingapi.springboot.flow.service.impl; |
| 2 | + |
| 3 | +import com.codingapi.springboot.flow.bind.BindDataSnapshot; |
| 4 | +import com.codingapi.springboot.flow.domain.FlowNode; |
| 5 | +import com.codingapi.springboot.flow.domain.FlowWork; |
| 6 | +import com.codingapi.springboot.flow.event.FlowApprovalEvent; |
| 7 | +import com.codingapi.springboot.flow.record.FlowRecord; |
| 8 | +import com.codingapi.springboot.flow.repository.FlowBindDataRepository; |
| 9 | +import com.codingapi.springboot.flow.repository.FlowRecordRepository; |
| 10 | +import com.codingapi.springboot.flow.service.FlowRecordVerifyService; |
| 11 | +import com.codingapi.springboot.flow.service.FlowServiceRepositoryHolder; |
| 12 | +import com.codingapi.springboot.flow.user.IFlowOperator; |
| 13 | +import com.codingapi.springboot.framework.event.EventPusher; |
| 14 | +import org.springframework.transaction.annotation.Transactional; |
| 15 | + |
| 16 | +import java.util.List; |
| 17 | + |
| 18 | +@Transactional |
| 19 | +public class FlowStopService { |
| 20 | + |
| 21 | + |
| 22 | + private final IFlowOperator currentOperator; |
| 23 | + private final FlowRecordVerifyService flowRecordVerifyService; |
| 24 | + private final FlowRecordRepository flowRecordRepository; |
| 25 | + private final FlowBindDataRepository flowBindDataRepository ; |
| 26 | + |
| 27 | + private FlowRecord flowRecord; |
| 28 | + private FlowWork flowWork; |
| 29 | + private FlowNode flowNode; |
| 30 | + private BindDataSnapshot snapshot; |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + public FlowStopService(long recordId, |
| 35 | + IFlowOperator currentOperator, |
| 36 | + FlowServiceRepositoryHolder flowServiceRepositoryHolder) { |
| 37 | + this.currentOperator = currentOperator; |
| 38 | + this.flowRecordRepository = flowServiceRepositoryHolder.getFlowRecordRepository(); |
| 39 | + this.flowBindDataRepository = flowServiceRepositoryHolder.getFlowBindDataRepository(); |
| 40 | + this.flowRecordVerifyService = new FlowRecordVerifyService( |
| 41 | + flowServiceRepositoryHolder.getFlowWorkRepository(), |
| 42 | + flowServiceRepositoryHolder.getFlowRecordRepository(), |
| 43 | + flowServiceRepositoryHolder.getFlowProcessRepository(), |
| 44 | + recordId, |
| 45 | + currentOperator); |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | + // 加载流程 |
| 50 | + private void loadFlow() { |
| 51 | + // 验证流程的提交状态 |
| 52 | + flowRecordVerifyService.verifyFlowRecordSubmitState(); |
| 53 | + // 验证当前操作者 |
| 54 | + flowRecordVerifyService.verifyFlowRecordCurrentOperator(); |
| 55 | + |
| 56 | + // 加载流程设计 |
| 57 | + flowRecordVerifyService.loadFlowWork(); |
| 58 | + // 加载流程节点 |
| 59 | + flowRecordVerifyService.loadFlowNode(); |
| 60 | + // 验证没有子流程 |
| 61 | + flowRecordVerifyService.verifyChildrenRecordsIsEmpty(); |
| 62 | + |
| 63 | + this.flowRecord = flowRecordVerifyService.getFlowRecord(); |
| 64 | + this.flowNode = flowRecordVerifyService.getFlowNode(); |
| 65 | + this.flowWork = flowRecordVerifyService.getFlowWork(); |
| 66 | + this.snapshot = flowBindDataRepository.getBindDataSnapshotById(flowRecord.getSnapshotId()); |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + /** |
| 72 | + * 提交流程 |
| 73 | + **/ |
| 74 | + public void stop() { |
| 75 | + // 加载流程信息 |
| 76 | + this.loadFlow(); |
| 77 | + |
| 78 | + // 停止流程 |
| 79 | + flowRecord.stop(); |
| 80 | + flowRecordRepository.update(flowRecord); |
| 81 | + |
| 82 | + List<FlowRecord> todoRecords = flowRecordRepository.findFlowRecordByProcessId(flowRecord.getProcessId()); |
| 83 | + for (FlowRecord record : todoRecords) { |
| 84 | + if (record.isTodo()) { |
| 85 | + record.stop(); |
| 86 | + flowRecordRepository.update(record); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + flowRecordRepository.finishFlowRecordByProcessId(flowRecord.getProcessId()); |
| 91 | + |
| 92 | + EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_STOP, |
| 93 | + flowRecord, |
| 94 | + flowRecord.getCurrentOperator(), |
| 95 | + flowWork, |
| 96 | + snapshot.toBindData() |
| 97 | + ), true); |
| 98 | + |
| 99 | + } |
| 100 | + |
| 101 | + |
| 102 | +} |
0 commit comments