[ysch-flow] S2.7 apply 可选回带期望定义版本(版本竞态人类可读报错,⭐)

preview 回带 defVersion,apply 支持可选 expectedDefVersion:两者不一致时直接业务码拒绝并说
「流程已更新,请刷新后重新选择审批人(期望 x,当前已发布 y)」,而不是让选好的 nodeId/候选
在新版本里对不上、报成「指派节点不存在」(《方案》§8.3 补强 2 / §18 决策 8)。
检查点放在 renderAssignJson 之前,引擎与指派校验都不被触发,不污染幂等键。
opt-in 设计:不传该字段的存量调用方(svc-hall / notice / work-leave)行为逐字不变——
已由「withoutExpectedVersion_behavesExactlyAsBefore」钉住。
OapiModels 两处为纯新增字段;新增 5 例单测(不传/传对/传旧/preview 回带/无指派节点),
mvn -o test -Dtest=!*IT 176 例全绿(原 171 + 新 5)。
This commit is contained in:
chenxing
2026-10-18 01:16:48 +08:00
parent 82ffe2f030
commit f4121b2c1e
3 changed files with 173 additions and 0 deletions
@@ -42,6 +42,12 @@ public final class OapiModels {
private Map<String, Object> formData;
/** 发起时指派(可选,2026-10-13):[{nodeId, userIds}],校验失败业务码拒绝发起 */
private List<AssignItem> assigns;
/**
* 期望的定义版本(可选,2026-10-17 S2.7 版本竞态):调用方拿 apply/preview 时回带的
* {@code defVersion} 原样传回。不匹配即业务码拒绝,报「流程已更新,请刷新后重新选择审批人」,
* 不再让选人结果落到改版后的线上而报「指派节点不存在」。不传=现状行为逐字不变(存量零影响)。
*/
private Integer expectedDefVersion;
}
/** 发起时指派项(apply 可选字段) */
@@ -55,6 +61,11 @@ public final class OapiModels {
@Data
public static class ApplyPreviewVo {
private String flowGuid;
/**
* 本次预览依据的已发布定义版本(2026-10-17 S2.7):调用方在 apply 时以
* {@code expectedDefVersion} 原样回带,改版即人类可读拒绝而非「指派节点不存在」。
*/
private Integer defVersion;
private List<PreviewNodeVo> nodes;
}
@@ -120,6 +120,14 @@ public class OapiFlowService {
schId, body.getFlowGuid(), FlwEnums.DefStatus.PUBLISHED.getCode())
.orElseThrow(() -> new BizException(ErrorCode.PARAM_ERROR,
"流程不存在或未发布:" + body.getFlowGuid()));
// S2.7 版本竞态(可选、opt-in):调用方回带预览时的定义版本,改版即人类可读拒绝,
// 免得选好的 nodeId/候选人在新版本里对不上而报「指派节点不存在」。不传=现状逐字不变。
if (body.getExpectedDefVersion() != null
&& !body.getExpectedDefVersion().equals(def.getVersion())) {
throw new BizException(ErrorCode.PARAM_ERROR,
"流程已更新,请刷新后重新选择审批人(期望定义版本 " + body.getExpectedDefVersion()
+ ",当前已发布版本 " + def.getVersion() + ")");
}
String assignJson = renderAssignJson(schId, def, body.getAssigns(), body.getSubmitterId());
String cleanAppKey = appKey == null || appKey.trim().isEmpty() ? null : appKey.trim();
FlowInstanceService.ApplyCommand cmd = new FlowInstanceService.ApplyCommand(
@@ -253,6 +261,7 @@ public class OapiFlowService {
FlowDefModel model = FlowDefModel.parse(objectMapper, def.getContentJson());
OapiModels.ApplyPreviewVo vo = new OapiModels.ApplyPreviewVo();
vo.setFlowGuid(def.getFlowGuid());
vo.setDefVersion(def.getVersion());
List<OapiModels.PreviewNodeVo> nodes = new ArrayList<>();
for (FlowDefModel.Node node : model.nodes) {
if (!FlowDefModel.TYPE_APPROVAL.equals(node.type) || node.assignPolicy == null) {