Skip to content

Commit 4a07ebd

Browse files
authored
Merge pull request #275 from codingapi/feature/issue-272-reissue
feat: 已完成流程支持二次发起 (framework + infra + api)
2 parents b42a66e + d31e032 commit 4a07ebd

28 files changed

Lines changed: 1257 additions & 9 deletions

File tree

‎docs/Integration/auto-configuration.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
| `NodeViewJavaScriptCacheContextRegister` | **`NodeViewJavaScriptRepository`** | 构造器内执行 `NodeViewJavaScriptCacheContext.getInstance().setNodeViewJavaScriptRepository(repo)`(15 分钟缓存上下文) |
1919
| `GatewayContextRegister` | **`FlowOperatorGateway`** | 把操作人网关灌入 `GatewayContext` 单例(`InitializingBean`) |
2020
| `FlowScriptContextRegister` | `ApplicationContext` + **`FlowOperatorGateway`** + `FlowRecordRepository` | 给 `FlowScriptContext` 单例设置 `IBeanFactory`(转发 Spring 容器,脚本 `$bind` 依赖) |
21-
| `RepositoryHolderContextRegister` | `WorkflowService` + `FlowRecordService` + 5 个仓储 + `GatewayContextRegister` | 把 7 个依赖灌入 `RepositoryHolderContext` 单例(`InitializingBean`) |
21+
| `RepositoryHolderContextRegister` | `WorkflowService` + `FlowRecordService` + 6 个仓储 + `GatewayContextRegister` | 把 8 个依赖灌入 `RepositoryHolderContext` 单例(`InitializingBean`) |
2222
| `FlowRecordService` | `FlowTodoRecordRepository` + `FlowTodoMergeRepository` + `FlowRecordRepository` | 记录服务 Bean |
2323
| `WorkflowService` | `WorkflowVersionRepository` + `WorkflowRepository` + `WorkflowRuntimeRepository` | 流程设计服务 Bean |
2424
| `FlowService` | `RepositoryHolderContextRegister`(仅保证顺序) | `new FlowService(RepositoryHolderContext.getInstance())`,业务入口 |
@@ -42,7 +42,7 @@ public void afterPropertiesSet() {
4242
workflowService, flowRecordService,
4343
parallelBranchRepository, delayTaskRepository,
4444
urgeIntervalRepository, flowOperatorAssignmentRepository,
45-
subProcessRepository);
45+
subProcessRepository, flowReissueRepository);
4646
}
4747

4848
// FlowScriptContextRegister

‎docs/Integration/repository-integration.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public interface UrgeIntervalRepository {
194194
| `UrgeIntervalEntity` | `t_flow_urge_interval` |
195195
| `FlowOperatorAssignmentEntity` | `t_flow_operator_assignment` |
196196
| `SubProcessRecordEntity` | `t_flow_sub_process_record` |
197+
| `FlowReissueRecordEntity` | `t_flow_record_reissue`(已完成流程二次发起关系) |
197198

198199
Spring Data 仓储接口位于 `jpa/` 包,全部继承外部 `FastRepository`(来自 `springboot-starter-data-fast`)。
199200

@@ -233,7 +234,7 @@ public class GroovyScriptRepositoryImpl implements GroovyScriptRepository, Initi
233234
## 6. 替换存储
234235

235236
- **引入 `flow-engine-starter-infra`**:开箱即用(推荐)。
236-
- **不引入 infra**:自行实现 11 个仓储接口 + `NodeViewJavaScriptRepository` 为 Spring Bean 即可。starter 的 `RepositoryHolderContextRegister` 会自动注入。framework 测试包(`src/test/java/com/codingapi/flow/repository/`)提供了一套内存实现可作参考。
237+
- **不引入 infra**:自行实现 12 个仓储接口 + `NodeViewJavaScriptRepository` 为 Spring Bean 即可。starter 的 `RepositoryHolderContextRegister` 会自动注入。framework 测试包(`src/test/java/com/codingapi/flow/repository/`)提供了一套内存实现可作参考。
237238

238239
## 7. 离线/最小装配(脱离 Spring)
239240

@@ -245,7 +246,7 @@ RepositoryHolderContext.getInstance().register(
245246
workflowService, flowRecordService,
246247
parallelBranchRepository, delayTaskRepository,
247248
urgeIntervalRepository, flowOperatorAssignmentRepository,
248-
subProcessRepository);
249+
subProcessRepository, flowReissueRepository);
249250
// 2. 注册操作人网关
250251
GatewayContext.getInstance().setFlowOperatorGateway(userGateway);
251252
```

‎flow-engine-example/src/main/resources/sql/dm-sequences.sql‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
-- t_flow_todo_record -> t_flow_todo_record_seq
77
-- t_flow_todo_marge -> t_flow_todo_marge_seq
88
-- t_flow_sub_process_record-> t_flow_sub_process_record_seq
9+
-- t_flow_record_reissue -> t_flow_record_reissue_seq
910
--
1011
-- 序列名 / 步长 与实体 @SequenceGenerator(sequenceName=..., allocationSize=50) 严格一致,
1112
-- 请勿修改,否则 hibernate 会在 insert 时报“无法解析的成员访问表达式[...NEXTVAL]”或出现主键重复。
@@ -70,5 +71,17 @@ BEGIN
7071
END;
7172
EXECUTE IMMEDIATE 'CREATE SEQUENCE t_flow_sub_process_record_seq INCREMENT BY 50 START WITH ' || v_start;
7273
END IF;
74+
75+
-- ---------- 5. t_flow_record_reissue_seq ----------
76+
SELECT COUNT(*) INTO v_cnt FROM all_sequences
77+
WHERE sequence_name = 'T_FLOW_RECORD_REISSUE_SEQ' AND sequence_owner = USER;
78+
IF v_cnt = 0 THEN
79+
BEGIN
80+
SELECT NVL(MAX(id), 0) + 1 INTO v_start FROM t_flow_record_reissue;
81+
EXCEPTION WHEN OTHERS THEN
82+
v_start := 1;
83+
END;
84+
EXECUTE IMMEDIATE 'CREATE SEQUENCE t_flow_record_reissue_seq INCREMENT BY 50 START WITH ' || v_start;
85+
END IF;
7386
END;
7487
/

‎flow-engine-framework/src/main/java/com/codingapi/flow/context/RepositoryHolderContext.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.codingapi.flow.record.FlowRecord;
99
import com.codingapi.flow.repository.DelayTaskRepository;
1010
import com.codingapi.flow.repository.FlowOperatorAssignmentRepository;
11+
import com.codingapi.flow.repository.FlowReissueRepository;
1112
import com.codingapi.flow.repository.ParallelBranchRepository;
1213
import com.codingapi.flow.repository.SubProcessRepository;
1314
import com.codingapi.flow.repository.UrgeIntervalRepository;
@@ -47,6 +48,8 @@ private RepositoryHolderContext() {
4748
private FlowOperatorAssignmentRepository flowOperatorAssignmentRepository;
4849
@Getter
4950
private SubProcessRepository subProcessRepository;
51+
@Getter
52+
private FlowReissueRepository flowReissueRepository;
5053

5154
/**
5255
* 是否已经注册成功
@@ -58,7 +61,8 @@ public boolean isRegistered() {
5861
&& flowRecordService != null
5962
&& urgeIntervalRepository != null
6063
&& flowOperatorAssignmentRepository != null
61-
&& subProcessRepository != null;
64+
&& subProcessRepository != null
65+
&& flowReissueRepository != null;
6266
}
6367

6468

@@ -74,14 +78,16 @@ public void register(WorkflowService workflowService,
7478
DelayTaskRepository delayTaskRepository,
7579
UrgeIntervalRepository urgeIntervalRepository,
7680
FlowOperatorAssignmentRepository flowOperatorAssignmentRepository,
77-
SubProcessRepository subProcessRepository) {
81+
SubProcessRepository subProcessRepository,
82+
FlowReissueRepository flowReissueRepository) {
7883
this.workflowService = workflowService;
7984
this.flowRecordService = flowRecordService;
8085
this.parallelBranchRepository = parallelBranchRepository;
8186
this.delayTaskRepository = delayTaskRepository;
8287
this.urgeIntervalRepository = urgeIntervalRepository;
8388
this.flowOperatorAssignmentRepository = flowOperatorAssignmentRepository;
8489
this.subProcessRepository = subProcessRepository;
90+
this.flowReissueRepository = flowReissueRepository;
8591
}
8692

8793

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.codingapi.flow.domain;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
/**
7+
* 已完成流程的二次发起关系记录。
8+
*
9+
* <p>用于记录「哪条已完成的流程记录被二次发起过、新流程是哪一条」,据此可分析出实际被废止的流程。
10+
* 二次发起不会改写源流程记录:新流程是重新创建的独立流程实例(新的流程id),
11+
* 源流程记录、待办与历史记录全部保持原样可查。</p>
12+
*/
13+
@Getter
14+
public class FlowReissueRecord {
15+
16+
/**
17+
* 主键
18+
*/
19+
@Setter
20+
private long id;
21+
22+
/**
23+
* 被二次发起的源流程记录id
24+
*/
25+
private final long sourceRecordId;
26+
27+
/**
28+
* 被二次发起的源流程id
29+
*/
30+
private final String sourceProcessId;
31+
32+
/**
33+
* 二次发起产生的新流程记录id
34+
*/
35+
private final long newRecordId;
36+
37+
/**
38+
* 二次发起产生的新流程id
39+
*/
40+
private final String newProcessId;
41+
42+
/**
43+
* 流程编码
44+
*/
45+
private final String workCode;
46+
47+
/**
48+
* 源流程所处的运行时版本id
49+
*/
50+
private final long workRuntimeId;
51+
52+
/**
53+
* 执行二次发起的操作人(流程管理员)
54+
*/
55+
private final long operatorId;
56+
57+
/**
58+
* 执行二次发起的操作人名称
59+
*/
60+
private final String operatorName;
61+
62+
/**
63+
* 操作时间(毫秒时间戳)
64+
*/
65+
private final long createTime;
66+
67+
/**
68+
* 二次发起说明
69+
*/
70+
private final String advice;
71+
72+
public FlowReissueRecord(long id,
73+
long sourceRecordId,
74+
String sourceProcessId,
75+
long newRecordId,
76+
String newProcessId,
77+
String workCode,
78+
long workRuntimeId,
79+
long operatorId,
80+
String operatorName,
81+
long createTime,
82+
String advice) {
83+
this.id = id;
84+
this.sourceRecordId = sourceRecordId;
85+
this.sourceProcessId = sourceProcessId;
86+
this.newRecordId = newRecordId;
87+
this.newProcessId = newProcessId;
88+
this.workCode = workCode;
89+
this.workRuntimeId = workRuntimeId;
90+
this.operatorId = operatorId;
91+
this.operatorName = operatorName;
92+
this.createTime = createTime;
93+
this.advice = advice;
94+
}
95+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.codingapi.flow.event;
2+
3+
import com.codingapi.flow.operator.IFlowOperator;
4+
import com.codingapi.flow.record.FlowRecord;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Getter;
7+
8+
/**
9+
* 流程二次发起事件
10+
* <p>
11+
* 仅当流程管理员对已正常完成的流程记录执行二次发起时触发:源流程记录保持不变,
12+
* 新流程以源流程的表单数据重新创建并停在开始节点。业务方可据此调整已落库的业务数据状态。
13+
*/
14+
@Getter
15+
@AllArgsConstructor
16+
public class FlowRecordReissueEvent implements IFlowEvent {
17+
18+
/**
19+
* 被二次发起的源流程记录(已完成)
20+
*/
21+
private final FlowRecord sourceRecord;
22+
23+
/**
24+
* 二次发起产生的新流程记录(开始节点待办)
25+
*/
26+
private final FlowRecord newRecord;
27+
28+
/**
29+
* 执行二次发起的操作人(流程管理员)
30+
*/
31+
private final IFlowOperator operator;
32+
33+
private final boolean mock;
34+
}

‎flow-engine-framework/src/main/java/com/codingapi/flow/exception/FlowStateException.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ public static FlowStateException subProcessResetScriptMismatch(int expected, int
209209
+ "but the original group has %d instances", actual, expected));
210210
}
211211

212+
/**
213+
* Record not support reissue (only a normally finished record can be reissued)
214+
*
215+
* @return exception
216+
*/
217+
public static FlowStateException recordNotSupportReissue() {
218+
return new FlowStateException("state.record.notSupportReissue",
219+
"Flow record is not finished normally, reissue not allowed");
220+
}
221+
212222
/**
213223
* Workflow script not found when executing a node or action
214224
*

‎flow-engine-framework/src/main/java/com/codingapi/flow/mock/MockRepositoryHolder.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class MockRepositoryHolder implements IRepositoryHolder {
3838
private final WorkflowService workflowService;
3939
private final FlowOperatorGateway flowOperatorGateway;
4040
private final SubProcessRepository subProcessRepository;
41+
private final FlowReissueRepository flowReissueRepository;
4142
private final Map<String, List<Long>> operatorAssignmentCache = new HashMap<>();
4243

4344
public MockRepositoryHolder(FlowOperatorGateway flowOperatorGateway,
@@ -50,6 +51,7 @@ public MockRepositoryHolder(FlowOperatorGateway flowOperatorGateway,
5051
this.parallelBranchRepository = new ParallelBranchRepositoryMockImpl();
5152
this.urgeIntervalRepository = new UrgeIntervalRepositoryMockImpl();
5253
this.subProcessRepository = new SubProcessRepositoryMockImpl();
54+
this.flowReissueRepository = new FlowReissueRepositoryMockImpl();
5355
this.workflowRepository = workflowRepository;
5456
this.workflowRuntimeRepository = new WorkflowRuntimeRepositoryMockImpl();
5557
this.workflowVersionRepository = new WorkflowVersionRepositoryMockImpl();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.codingapi.flow.mock.repository;
2+
3+
import com.codingapi.flow.domain.FlowReissueRecord;
4+
import com.codingapi.flow.repository.FlowReissueRepository;
5+
6+
import java.util.LinkedHashMap;
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
public class FlowReissueRepositoryMockImpl implements FlowReissueRepository {
11+
12+
private final Map<Long, FlowReissueRecord> cache = new LinkedHashMap<>();
13+
private long nextId = 1;
14+
15+
@Override
16+
public synchronized void save(FlowReissueRecord record) {
17+
if (record.getId() == 0) {
18+
// 使用单调递增 id,避免与已存在的记录主键冲突
19+
record.setId(nextId++);
20+
}
21+
cache.put(record.getId(), record);
22+
}
23+
24+
@Override
25+
public synchronized List<FlowReissueRecord> findBySourceRecordId(long sourceRecordId) {
26+
return cache.values().stream()
27+
.filter(record -> record.getSourceRecordId() == sourceRecordId)
28+
.toList();
29+
}
30+
31+
@Override
32+
public synchronized List<FlowReissueRecord> findBySourceProcessId(String sourceProcessId) {
33+
return cache.values().stream()
34+
.filter(record -> record.getSourceProcessId().equals(sourceProcessId))
35+
.toList();
36+
}
37+
38+
@Override
39+
public synchronized List<FlowReissueRecord> findByNewProcessId(String newProcessId) {
40+
return cache.values().stream()
41+
.filter(record -> record.getNewProcessId().equals(newProcessId))
42+
.toList();
43+
}
44+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.codingapi.flow.pojo.request;
2+
3+
import com.codingapi.flow.exception.FlowValidationException;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.util.Map;
8+
9+
/**
10+
* 已完成流程的二次发起请求(独立接口,不属于常规审批动作)。
11+
*
12+
* <p>二次发起以「已正常完成的流程记录」为目标:复制源流程的表单数据创建一条全新的流程,
13+
* 新流程停在开始节点成为发起人的待办,由发起人调整数据后重新提交执行。
14+
* 源流程记录不做任何改写(不作废、不迁移数据)。</p>
15+
*/
16+
@Data
17+
@NoArgsConstructor
18+
public class FlowReissueRequest {
19+
20+
/**
21+
* 被二次发起的源流程记录id(必须是已正常完成的流程记录)
22+
*/
23+
private long sourceRecordId;
24+
25+
/**
26+
* 操作者(必须是流程管理员)
27+
*/
28+
private long operatorId;
29+
30+
/**
31+
* 二次发起时使用的表单数据;为空时按源流程记录的表单数据复制
32+
*/
33+
private Map<String, Object> formData;
34+
35+
/**
36+
* 二次发起说明
37+
*/
38+
private String advice;
39+
40+
public FlowReissueRequest(long sourceRecordId, long operatorId) {
41+
this.sourceRecordId = sourceRecordId;
42+
this.operatorId = operatorId;
43+
}
44+
45+
public void verify() {
46+
if (sourceRecordId <= 0) {
47+
throw FlowValidationException.required("sourceRecordId");
48+
}
49+
if (operatorId <= 0) {
50+
throw FlowValidationException.required("operatorId");
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)