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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.codingapi.flow.event;

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

/**
* 运行中流程实例强制同步事件
*
* <p>流程实例的运行时快照引用由 {@code oldWorkRuntimeId} 换绑为 {@code newWorkRuntimeId} 后触发,
* 业务方可据此刷新本地缓存或提示流程参与人。每个被同步的实例产生一条事件。</p>
*/
@Getter
@AllArgsConstructor
public class FlowRecordForceSyncEvent implements IFlowEvent {

/**
* 被同步的流程记录(实例内任一记录,用于定位流程实例与节点)
*/
private final FlowRecord flowRecord;

/**
* 同步前的运行时快照id
*/
private final long oldWorkRuntimeId;

/**
* 同步后的运行时快照id
*/
private final long newWorkRuntimeId;

private final boolean mock;

/**
* 事件分区键:按被同步实例的流程id串行投递
*/
@Override
public String eventKey() {
return flowRecord == null ? null : flowRecord.getProcessId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public static FlowNotFoundException record(long recordId) {
String.format("Flow record not found: %d", recordId));
}

/**
* Flow instance not found
*
* @param processId flow instance process id
* @return exception
*/
public static FlowNotFoundException process(String processId) {
return new FlowNotFoundException("notFound.process.id",
String.format("Flow instance not found: %s", processId));
}

/**
* Node not found
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,40 @@ public static FlowStateException recordNotSupportReissue() {
"Flow record is not finished normally, reissue not allowed");
}

/**
* Force sync rejected because the latest workflow structure does not match the runtime snapshot
*
* @param processId flow instance process id
* @param detail structure differences
* @return exception
*/
public static FlowStateException forceSyncStructureInconsistent(String processId, String detail) {
return new FlowStateException("state.forceSync.structureInconsistent",
String.format("Flow instance %s cannot force sync, workflow structure changed: %s", processId, detail));
}

/**
* Force sync only supports running flow instances
*
* @param processId flow instance process id
* @return exception
*/
public static FlowStateException forceSyncInstanceNotRunning(String processId) {
return new FlowStateException("state.forceSync.notRunning",
String.format("Flow instance %s is not running, force sync not allowed", processId));
}

/**
* Records of one flow instance reference different runtime snapshots
*
* @param processId flow instance process id
* @return exception
*/
public static FlowStateException forceSyncRuntimeInconsistent(String processId) {
return new FlowStateException("state.forceSync.runtimeInconsistent",
String.format("Flow instance %s references different runtime snapshots, force sync not allowed", processId));
}

/**
* Workflow script not found when executing a node or action
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import com.codingapi.flow.mock.MockRepositoryHolder;
import com.codingapi.flow.mock.repository.FlowRecordRepositoryMockImpl;
import com.codingapi.flow.mock.repository.FlowTodoRecordRepositoryMockImpl;
import com.codingapi.flow.node.nodes.StartNode;
import com.codingapi.flow.pojo.response.FlowRecordContent;
import com.codingapi.flow.query.FlowRecordQueryService;
import com.codingapi.flow.record.FlowRecord;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -78,4 +81,19 @@ public Page<FlowRecordContent> findDoneRecordPage(long userId, PageRequest reque
return toPage(recordList, request);
}

@Override
public Page<FlowRecordContent> findRunningInstancePage(String workCode, String title, PageRequest request) {
FlowRecordRepositoryMockImpl flowRecordRepositoryMock = (FlowRecordRepositoryMockImpl) mockRepositoryHolder.getFlowRecordRepository();
List<FlowRecordContent> recordList = flowRecordRepositoryMock.findAll().stream()
.filter(record -> workCode.equals(record.getWorkCode()))
.filter(record -> record.getFlowState() == FlowRecord.SATE_FLOW_RUNNING)
.filter(record -> record.getFromId() == 0 && StartNode.NODE_TYPE.equals(record.getNodeType()))
.filter(record -> !record.isHidden())
.filter(record -> !StringUtils.hasText(title)
|| (record.getTitle() != null && record.getTitle().contains(title)))
.map(FlowRecordContent::convert)
.toList();
return toPage(recordList, request);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.codingapi.flow.pojo.request;

import com.codingapi.flow.exception.FlowValidationException;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* 运行中流程实例强制同步最新流程设计请求(独立接口,不属于常规审批动作)。
*
* <p>强制同步只换绑运行时快照引用:选中实例的记录改指向最新设计对应的快照,
* 未选中的实例保持原快照不变。同步前会校验选中实例的结构与最新设计一致。</p>
*/
@Data
@NoArgsConstructor
public class FlowForceSyncRequest {

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

/**
* 选中同步的流程实例唯一标识列表(未选中的实例不会被修改)
*/
private List<String> processIds;

/**
* 操作者
*/
private long operatorId;

public FlowForceSyncRequest(String workCode, List<String> processIds, long operatorId) {
this.workCode = workCode;
this.processIds = processIds;
this.operatorId = operatorId;
}

public void verify() {
if (!StringUtils.hasText(workCode)) {
throw FlowValidationException.required("workCode");
}
if (processIds == null || processIds.isEmpty()) {
throw FlowValidationException.required("processIds");
}
if (processIds.stream().anyMatch(processId -> !StringUtils.hasText(processId))) {
throw FlowValidationException.required("processIds");
}
if (operatorId <= 0) {
throw FlowValidationException.required("operatorId");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.codingapi.flow.pojo.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* 运行中流程实例强制同步结果
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FlowForceSyncResult {

/**
* 本次同步使用的运行时快照id(同一设计版本下多个实例共享同一份快照)
*/
private long workflowRuntimeId;

/**
* 该快照对应的设计版本(流程设计的更新时间)
*/
private long workVersion;

/**
* 已换绑到新快照的流程实例
*/
private List<String> syncedProcessIds;

/**
* 已是最新快照而跳过的流程实例
*/
private List<String> skippedProcessIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@ public interface FlowRecordQueryService {
Page<FlowRecordContent> findNotifyRecordPage(long userId, PageRequest request);

Page<FlowRecordContent> findDoneRecordPage(long userId, PageRequest request);

/**
* 查询指定流程编码下运行中的流程实例(以开始节点记录代表一个实例)
*
* <p>用于「运行中实例强制同步最新流程设计」时选择同步范围(issue #281)。</p>
*
* @param workCode 流程编码
* @param title 流程标题(模糊匹配,可为空)
* @param request 分页
* @return 运行中的流程实例分页
*/
Page<FlowRecordContent> findRunningInstancePage(String workCode, String title, PageRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ public void saveFlowRecord(FlowRecord flowRecord) {
}


/**
* 从待办合并组中摘除指定流程记录(issue #281)。
*
* <p>运行实例换绑运行时快照前,需要先解除其记录与旧快照合并待办的关联,
* 换绑后重新保存记录即可按新的合并键重建待办组。</p>
*
* @param flowRecords 待摘除的流程记录(须仍指向旧快照的合并键)
*/
public void detachTodoMergeRecords(List<FlowRecord> flowRecords) {
FlowTodoMigrateService flowTodoMigrateService = new FlowTodoMigrateService(flowRecords);
flowTodoMigrateService.registerRepositories(this.flowTodoRecordRepository, this.flowTodoMergeRepository, this.flowRecordRepository);
flowTodoMigrateService.detach();
}

/**
* 获取流程的合并记录
* @param mergeKey 流程合并key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.codingapi.flow.pojo.request.*;
import com.codingapi.flow.pojo.response.ActionResponse;
import com.codingapi.flow.pojo.response.FlowContent;
import com.codingapi.flow.pojo.response.FlowForceSyncResult;
import com.codingapi.flow.pojo.response.ProcessNode;
import com.codingapi.flow.service.impl.*;
import com.codingapi.flow.session.IRepositoryHolder;
Expand Down Expand Up @@ -146,4 +147,21 @@ public long reissue(FlowReissueRequest request) {
FlowReissueService flowReissueService = new FlowReissueService(request, this.repositoryHolder);
return flowReissueService.reissue();
}

/**
* 运行中流程实例强制同步最新流程设计(独立接口,不属于常规审批动作)。
* <p>
* 仅对请求中选中的运行实例生效,把其流程记录的运行时快照引用换绑为最新设计对应的快照;
* 未选中的实例保持原快照。同步前会校验结构一致性(不允许新增/删除节点、改变节点类型/层级/顺序,
* 旧按钮动作必须保留),表单字段不做校验。
*
* @param request 强制同步请求
* @return 同步结果
*/
public FlowForceSyncResult forceSync(FlowForceSyncRequest request) {
FlowOperatorLocalThreadCache.getInstance().clear();
FlowRuntimeScriptLocalCache.getInstance().clear();
FlowForceSyncService flowForceSyncService = new FlowForceSyncService(request, this.repositoryHolder);
return flowForceSyncService.sync();
}
}
Loading
Loading