feat(design): POST /api/design/publish 确保默认流落库(幂等)(建物3-Task11)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-20 10:07:13 +08:00
parent 9765872382
commit 74478f030e
5 changed files with 152 additions and 1 deletions

View File

@@ -0,0 +1,8 @@
package com.eip4.platform.metadata.publish;
import org.springframework.stereotype.Service;
/** 平台内自包含部署包生成器(Task 13 实现)。 */
@Service
public class DeploymentPackageBuilder {
}

View File

@@ -0,0 +1,14 @@
package com.eip4.platform.metadata.publish;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
/** 平台内菜单注册唯一入口(Task 12 实现)。 */
@Service
public class MenuRegistrar {
private final JdbcTemplate jdbcTemplate;
public MenuRegistrar(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
}

View File

@@ -0,0 +1,53 @@
package com.eip4.platform.metadata.publish;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.springframework.stereotype.Service;
import com.dsasp.server.common.util.UserSession;
import com.eip4.platform.metadata.flow.FlowServiceWithSynthesis;
/**
* 发布编排(建物 3):发布按钮一次性完成 ①确保默认流落库 ②注册菜单 ③生成 production 部署包。
*
* <p>红线:本类只 live-apply 到当前连接库(菜单/流),生产部署包恒人审、不在此执行生产 SQL。
*/
@Service
public class PublishOrchestrator {
private final FlowServiceWithSynthesis flowService;
private final MenuRegistrar menuRegistrar; // Task 12 注入
private final DeploymentPackageBuilder deploymentPackageBuilder; // Task 13 注入
private final DefaultFlowPreviewService flowPreviewService; // flowNames 回填(复用 Task 10 预览服务)
public PublishOrchestrator(FlowServiceWithSynthesis flowService,
MenuRegistrar menuRegistrar,
DeploymentPackageBuilder deploymentPackageBuilder,
DefaultFlowPreviewService flowPreviewService) {
this.flowService = flowService;
this.menuRegistrar = menuRegistrar;
this.deploymentPackageBuilder = deploymentPackageBuilder;
this.flowPreviewService = flowPreviewService;
}
/**
* 确保实体的 5(+2) 条默认服务流落库(幂等)。
*
* @return true 表示本次新建了默认流;false 表示实体已有流(幂等无操作)。
*/
public boolean ensureFlows(String entityId) {
Properties ctx = UserSession.getAdmin();
return flowService.addDefaultFlowService(entityId, ctx);
}
/** 返回实体当前持久化的流名列表(发布后读 SYS_SERVICEFLOW,经 Task 10 预览服务)。 */
public List<String> flowNames(String entityId) {
List<String> out = new ArrayList<>();
for (DefaultFlowPreviewService.FlowItem f : flowPreviewService.preview(entityId).flows()) {
out.add(f.flowName());
}
return out;
}
}

View File

@@ -57,16 +57,19 @@ public class DesignFeatureController {
private final JdbcTemplate jdbcTemplate; // 仅 requireAdmin 用 private final JdbcTemplate jdbcTemplate; // 仅 requireAdmin 用
private final boolean skipAdminCheck; // 仅单测置 true private final boolean skipAdminCheck; // 仅单测置 true
private final com.eip4.platform.metadata.publish.DefaultFlowPreviewService flowPreviewService; // Task 10 private final com.eip4.platform.metadata.publish.DefaultFlowPreviewService flowPreviewService; // Task 10
private final com.eip4.platform.metadata.publish.PublishOrchestrator publishOrchestrator; // Task 11-13
/** 生产构造(Spring 注入)。 */ /** 生产构造(Spring 注入)。 */
public DesignFeatureController(JdbcTemplate jdbcTemplate, public DesignFeatureController(JdbcTemplate jdbcTemplate,
PageSchemaWriter pageSchemaWriter, PageSchemaWriter pageSchemaWriter,
EntityAttributeReader attributeReader, EntityAttributeReader attributeReader,
com.eip4.platform.metadata.publish.DefaultFlowPreviewService flowPreviewService) { com.eip4.platform.metadata.publish.DefaultFlowPreviewService flowPreviewService,
com.eip4.platform.metadata.publish.PublishOrchestrator publishOrchestrator) {
this.jdbcTemplate = jdbcTemplate; this.jdbcTemplate = jdbcTemplate;
this.pageSchemaWriter = pageSchemaWriter; this.pageSchemaWriter = pageSchemaWriter;
this.attributeReader = attributeReader; this.attributeReader = attributeReader;
this.flowPreviewService = flowPreviewService; this.flowPreviewService = flowPreviewService;
this.publishOrchestrator = publishOrchestrator;
this.composer = new RecipePageComposer(MAPPER); this.composer = new RecipePageComposer(MAPPER);
this.strictValidator = TypedPageSchemaValidator.defaults(); this.strictValidator = TypedPageSchemaValidator.defaults();
this.skipAdminCheck = false; this.skipAdminCheck = false;
@@ -80,6 +83,7 @@ public class DesignFeatureController {
this.pageSchemaWriter = pageSchemaWriter; this.pageSchemaWriter = pageSchemaWriter;
this.attributeReader = attributeReader; this.attributeReader = attributeReader;
this.flowPreviewService = null; this.flowPreviewService = null;
this.publishOrchestrator = null;
this.composer = new RecipePageComposer(MAPPER); this.composer = new RecipePageComposer(MAPPER);
this.strictValidator = TypedPageSchemaValidator.defaults(); this.strictValidator = TypedPageSchemaValidator.defaults();
this.skipAdminCheck = skipAdminCheck; this.skipAdminCheck = skipAdminCheck;
@@ -191,6 +195,40 @@ public class DesignFeatureController {
return resp; return resp;
} }
@Operation(summary = "发布:确保默认流落库 + 注册菜单 + 产 production 人审部署包(仅管理员)",
description = "对当前连接库 live-apply(流/菜单),生产部署包恒人审,不在此执行生产 SQL")
@PostMapping("/publish")
public Map<String, Object> publish(@RequestBody Map<String, Object> body) {
requireAdmin();
String entityId = requireDesignString(body, "entityId");
String tableName = requireDesignString(body, "tableName");
String templateId = requireDesignString(body, "templateId");
String menuName = requireDesignString(body, "menuName");
String operator = currentUserId();
boolean flowsCreated = publishOrchestrator.ensureFlows(entityId);
Map<String, Object> data = new LinkedHashMap<>();
data.put("entityId", entityId);
data.put("tableName", tableName);
data.put("templateId", templateId);
data.put("flowsCreated", flowsCreated);
data.put("flows", publishOrchestrator.flowNames(entityId));
// menuId / deploymentPackage 由 Task 12 / 13 补齐
Map<String, Object> resp = new LinkedHashMap<>();
resp.put("status", 0);
resp.put("data", data);
return resp;
}
private static String requireDesignString(Map<String, Object> body, String key) {
Object v = body == null ? null : body.get(key);
if (v == null || v.toString().isBlank()) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "缺少必填参数: " + key);
}
return v.toString().trim();
}
// ===== admin 门禁(逐字对齐 PageSchemaController.requireAdmin / currentUserId)===== // ===== admin 门禁(逐字对齐 PageSchemaController.requireAdmin / currentUserId)=====
private void requireAdmin() { private void requireAdmin() {

View File

@@ -0,0 +1,38 @@
package com.eip4.platform.metadata.publish;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import com.eip4.platform.metadata.flow.FlowServiceWithSynthesis;
class PublishFlowEnsureTest {
@Test
void ensureFlowsDelegatesToAddDefaultFlowServiceAndReportsCreated() {
FlowServiceWithSynthesis flowService = mock(FlowServiceWithSynthesis.class);
when(flowService.addDefaultFlowService(eq("ENT-9"), any(Properties.class))).thenReturn(true);
PublishOrchestrator orch = new PublishOrchestrator(flowService, null, null, null);
boolean created = orch.ensureFlows("ENT-9");
assertThat(created).isTrue();
verify(flowService).addDefaultFlowService(eq("ENT-9"), any(Properties.class));
}
@Test
void ensureFlowsReturnsFalseWhenFlowsAlreadyPresent() {
FlowServiceWithSynthesis flowService = mock(FlowServiceWithSynthesis.class);
when(flowService.addDefaultFlowService(eq("ENT-9"), any(Properties.class))).thenReturn(false);
PublishOrchestrator orch = new PublishOrchestrator(flowService, null, null, null);
assertThat(orch.ensureFlows("ENT-9")).isFalse();
}
}