Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/Integration/auto-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
| `NodeViewJavaScriptCacheContextRegister` | **`NodeViewJavaScriptRepository`** | 构造器内执行 `NodeViewJavaScriptCacheContext.getInstance().setNodeViewJavaScriptRepository(repo)`(15 分钟缓存上下文) |
| `GatewayContextRegister` | **`FlowOperatorGateway`** | 把操作人网关灌入 `GatewayContext` 单例(`InitializingBean`) |
| `FlowScriptContextRegister` | `ApplicationContext` + **`FlowOperatorGateway`** + `FlowRecordRepository` | 给 `FlowScriptContext` 单例设置 `IBeanFactory`(转发 Spring 容器,脚本 `$bind` 依赖) |
| `RepositoryHolderContextRegister` | `WorkflowService` + `FlowRecordService` + 5 个仓储 + `GatewayContextRegister` | 把 7 个依赖灌入 `RepositoryHolderContext` 单例(`InitializingBean`) |
| `RepositoryHolderContextRegister` | `WorkflowService` + `FlowRecordService` + 6 个仓储 + `GatewayContextRegister` | 把 8 个依赖灌入 `RepositoryHolderContext` 单例(`InitializingBean`) |
| `FlowRecordService` | `FlowTodoRecordRepository` + `FlowTodoMergeRepository` + `FlowRecordRepository` | 记录服务 Bean |
| `WorkflowService` | `WorkflowVersionRepository` + `WorkflowRepository` + `WorkflowRuntimeRepository` | 流程设计服务 Bean |
| `FlowService` | `RepositoryHolderContextRegister`(仅保证顺序) | `new FlowService(RepositoryHolderContext.getInstance())`,业务入口 |
Expand All @@ -42,7 +42,7 @@ public void afterPropertiesSet() {
workflowService, flowRecordService,
parallelBranchRepository, delayTaskRepository,
urgeIntervalRepository, flowOperatorAssignmentRepository,
subProcessRepository);
subProcessRepository, flowReissueRepository);
}

// FlowScriptContextRegister
Expand Down
5 changes: 3 additions & 2 deletions docs/Integration/repository-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public interface UrgeIntervalRepository {
| `UrgeIntervalEntity` | `t_flow_urge_interval` |
| `FlowOperatorAssignmentEntity` | `t_flow_operator_assignment` |
| `SubProcessRecordEntity` | `t_flow_sub_process_record` |
| `FlowReissueRecordEntity` | `t_flow_record_reissue`(已完成流程二次发起关系) |

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

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

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

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

Expand All @@ -245,7 +246,7 @@ RepositoryHolderContext.getInstance().register(
workflowService, flowRecordService,
parallelBranchRepository, delayTaskRepository,
urgeIntervalRepository, flowOperatorAssignmentRepository,
subProcessRepository);
subProcessRepository, flowReissueRepository);
// 2. 注册操作人网关
GatewayContext.getInstance().setFlowOperatorGateway(userGateway);
```
13 changes: 13 additions & 0 deletions flow-engine-example/src/main/resources/sql/dm-sequences.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-- t_flow_todo_record -> t_flow_todo_record_seq
-- t_flow_todo_marge -> t_flow_todo_marge_seq
-- t_flow_sub_process_record-> t_flow_sub_process_record_seq
-- t_flow_record_reissue -> t_flow_record_reissue_seq
--
-- 序列名 / 步长 与实体 @SequenceGenerator(sequenceName=..., allocationSize=50) 严格一致,
-- 请勿修改,否则 hibernate 会在 insert 时报“无法解析的成员访问表达式[...NEXTVAL]”或出现主键重复。
Expand Down Expand Up @@ -70,5 +71,17 @@ BEGIN
END;
EXECUTE IMMEDIATE 'CREATE SEQUENCE t_flow_sub_process_record_seq INCREMENT BY 50 START WITH ' || v_start;
END IF;

-- ---------- 5. t_flow_record_reissue_seq ----------
SELECT COUNT(*) INTO v_cnt FROM all_sequences
WHERE sequence_name = 'T_FLOW_RECORD_REISSUE_SEQ' AND sequence_owner = USER;
IF v_cnt = 0 THEN
BEGIN
SELECT NVL(MAX(id), 0) + 1 INTO v_start FROM t_flow_record_reissue;
EXCEPTION WHEN OTHERS THEN
v_start := 1;
END;
EXECUTE IMMEDIATE 'CREATE SEQUENCE t_flow_record_reissue_seq INCREMENT BY 50 START WITH ' || v_start;
END IF;
END;
/
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.codingapi.flow.record.FlowRecord;
import com.codingapi.flow.repository.DelayTaskRepository;
import com.codingapi.flow.repository.FlowOperatorAssignmentRepository;
import com.codingapi.flow.repository.FlowReissueRepository;
import com.codingapi.flow.repository.ParallelBranchRepository;
import com.codingapi.flow.repository.SubProcessRepository;
import com.codingapi.flow.repository.UrgeIntervalRepository;
Expand Down Expand Up @@ -47,6 +48,8 @@ private RepositoryHolderContext() {
private FlowOperatorAssignmentRepository flowOperatorAssignmentRepository;
@Getter
private SubProcessRepository subProcessRepository;
@Getter
private FlowReissueRepository flowReissueRepository;

/**
* 是否已经注册成功
Expand All @@ -58,7 +61,8 @@ public boolean isRegistered() {
&& flowRecordService != null
&& urgeIntervalRepository != null
&& flowOperatorAssignmentRepository != null
&& subProcessRepository != null;
&& subProcessRepository != null
&& flowReissueRepository != null;
}


Expand All @@ -74,14 +78,16 @@ public void register(WorkflowService workflowService,
DelayTaskRepository delayTaskRepository,
UrgeIntervalRepository urgeIntervalRepository,
FlowOperatorAssignmentRepository flowOperatorAssignmentRepository,
SubProcessRepository subProcessRepository) {
SubProcessRepository subProcessRepository,
FlowReissueRepository flowReissueRepository) {
this.workflowService = workflowService;
this.flowRecordService = flowRecordService;
this.parallelBranchRepository = parallelBranchRepository;
this.delayTaskRepository = delayTaskRepository;
this.urgeIntervalRepository = urgeIntervalRepository;
this.flowOperatorAssignmentRepository = flowOperatorAssignmentRepository;
this.subProcessRepository = subProcessRepository;
this.flowReissueRepository = flowReissueRepository;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.codingapi.flow.domain;

import lombok.Getter;
import lombok.Setter;

/**
* 已完成流程的二次发起关系记录。
*
* <p>用于记录「哪条已完成的流程记录被二次发起过、新流程是哪一条」,据此可分析出实际被废止的流程。
* 二次发起不会改写源流程记录:新流程是重新创建的独立流程实例(新的流程id),
* 源流程记录、待办与历史记录全部保持原样可查。</p>
*/
@Getter
public class FlowReissueRecord {

/**
* 主键
*/
@Setter
private long id;

/**
* 被二次发起的源流程记录id
*/
private final long sourceRecordId;

/**
* 被二次发起的源流程id
*/
private final String sourceProcessId;

/**
* 二次发起产生的新流程记录id
*/
private final long newRecordId;

/**
* 二次发起产生的新流程id
*/
private final String newProcessId;

/**
* 流程编码
*/
private final String workCode;

/**
* 源流程所处的运行时版本id
*/
private final long workRuntimeId;

/**
* 执行二次发起的操作人(流程管理员)
*/
private final long operatorId;

/**
* 执行二次发起的操作人名称
*/
private final String operatorName;

/**
* 操作时间(毫秒时间戳)
*/
private final long createTime;

/**
* 二次发起说明
*/
private final String advice;

public FlowReissueRecord(long id,
long sourceRecordId,
String sourceProcessId,
long newRecordId,
String newProcessId,
String workCode,
long workRuntimeId,
long operatorId,
String operatorName,
long createTime,
String advice) {
this.id = id;
this.sourceRecordId = sourceRecordId;
this.sourceProcessId = sourceProcessId;
this.newRecordId = newRecordId;
this.newProcessId = newProcessId;
this.workCode = workCode;
this.workRuntimeId = workRuntimeId;
this.operatorId = operatorId;
this.operatorName = operatorName;
this.createTime = createTime;
this.advice = advice;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.codingapi.flow.event;

import com.codingapi.flow.operator.IFlowOperator;
import com.codingapi.flow.record.FlowRecord;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* 流程二次发起事件
* <p>
* 仅当流程管理员对已正常完成的流程记录执行二次发起时触发:源流程记录保持不变,
* 新流程以源流程的表单数据重新创建并停在开始节点。业务方可据此调整已落库的业务数据状态。
*/
@Getter
@AllArgsConstructor
public class FlowRecordReissueEvent implements IFlowEvent {

/**
* 被二次发起的源流程记录(已完成)
*/
private final FlowRecord sourceRecord;

/**
* 二次发起产生的新流程记录(开始节点待办)
*/
private final FlowRecord newRecord;

/**
* 执行二次发起的操作人(流程管理员)
*/
private final IFlowOperator operator;

private final boolean mock;
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ public static FlowStateException subProcessResetScriptMismatch(int expected, int
+ "but the original group has %d instances", actual, expected));
}

/**
* Record not support reissue (only a normally finished record can be reissued)
*
* @return exception
*/
public static FlowStateException recordNotSupportReissue() {
return new FlowStateException("state.record.notSupportReissue",
"Flow record is not finished normally, reissue not allowed");
}

/**
* Workflow script not found when executing a node or action
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class MockRepositoryHolder implements IRepositoryHolder {
private final WorkflowService workflowService;
private final FlowOperatorGateway flowOperatorGateway;
private final SubProcessRepository subProcessRepository;
private final FlowReissueRepository flowReissueRepository;
private final Map<String, List<Long>> operatorAssignmentCache = new HashMap<>();

public MockRepositoryHolder(FlowOperatorGateway flowOperatorGateway,
Expand All @@ -50,6 +51,7 @@ public MockRepositoryHolder(FlowOperatorGateway flowOperatorGateway,
this.parallelBranchRepository = new ParallelBranchRepositoryMockImpl();
this.urgeIntervalRepository = new UrgeIntervalRepositoryMockImpl();
this.subProcessRepository = new SubProcessRepositoryMockImpl();
this.flowReissueRepository = new FlowReissueRepositoryMockImpl();
this.workflowRepository = workflowRepository;
this.workflowRuntimeRepository = new WorkflowRuntimeRepositoryMockImpl();
this.workflowVersionRepository = new WorkflowVersionRepositoryMockImpl();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.codingapi.flow.mock.repository;

import com.codingapi.flow.domain.FlowReissueRecord;
import com.codingapi.flow.repository.FlowReissueRepository;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class FlowReissueRepositoryMockImpl implements FlowReissueRepository {

private final Map<Long, FlowReissueRecord> cache = new LinkedHashMap<>();
private long nextId = 1;

@Override
public synchronized void save(FlowReissueRecord record) {
if (record.getId() == 0) {
// 使用单调递增 id,避免与已存在的记录主键冲突
record.setId(nextId++);
}
cache.put(record.getId(), record);
}

@Override
public synchronized List<FlowReissueRecord> findBySourceRecordId(long sourceRecordId) {
return cache.values().stream()
.filter(record -> record.getSourceRecordId() == sourceRecordId)
.toList();
}

@Override
public synchronized List<FlowReissueRecord> findBySourceProcessId(String sourceProcessId) {
return cache.values().stream()
.filter(record -> record.getSourceProcessId().equals(sourceProcessId))
.toList();
}

@Override
public synchronized List<FlowReissueRecord> findByNewProcessId(String newProcessId) {
return cache.values().stream()
.filter(record -> record.getNewProcessId().equals(newProcessId))
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.codingapi.flow.pojo.request;

import com.codingapi.flow.exception.FlowValidationException;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
* 已完成流程的二次发起请求(独立接口,不属于常规审批动作)。
*
* <p>二次发起以「已正常完成的流程记录」为目标:复制源流程的表单数据创建一条全新的流程,
* 新流程停在开始节点成为发起人的待办,由发起人调整数据后重新提交执行。
* 源流程记录不做任何改写(不作废、不迁移数据)。</p>
*/
@Data
@NoArgsConstructor
public class FlowReissueRequest {

/**
* 被二次发起的源流程记录id(必须是已正常完成的流程记录)
*/
private long sourceRecordId;

/**
* 操作者(必须是流程管理员)
*/
private long operatorId;

/**
* 二次发起时使用的表单数据;为空时按源流程记录的表单数据复制
*/
private Map<String, Object> formData;

/**
* 二次发起说明
*/
private String advice;

public FlowReissueRequest(long sourceRecordId, long operatorId) {
this.sourceRecordId = sourceRecordId;
this.operatorId = operatorId;
}

public void verify() {
if (sourceRecordId <= 0) {
throw FlowValidationException.required("sourceRecordId");
}
if (operatorId <= 0) {
throw FlowValidationException.required("operatorId");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ public class FlowContent {
*/
private boolean resetSubProcess;

/**
* 支持二次发起(独立能力标识,非审批动作)。
* <p>仅当当前记录已正常完成且操作人为流程管理员时为 true;前端可据此在已办详情中
* 展示「重新发起」入口,调用 {@code /api/cmd/record/reissue} 接口。</p>
*/
private boolean reissue;

/**
* 设置操作动作按钮
*
Expand Down
Loading
Loading