feat(design): publish 生成 production 人审部署包(DECISION-2,manifest+rollback)(建物3-Task13)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
package com.eip4.platform.metadata.publish;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Production 人审部署包(建物 3 · DECISION-2)。
|
||||||
|
*
|
||||||
|
* <p>与 platform-ai 的 {@code AiDeploymentPackage} 同形精简版:
|
||||||
|
* 不含 taskId/changeSetId/runEvidence(人走五环无 AiTask 上下文),其余字段一致。
|
||||||
|
* 恒 requiresHumanApproval=true —— 生产上线走既有人审流程,本包不执行任何生产 SQL。
|
||||||
|
*/
|
||||||
|
public record DeploymentPackage(
|
||||||
|
String status,
|
||||||
|
boolean requiresHumanApproval,
|
||||||
|
long generatedAt,
|
||||||
|
Map<String, Object> manifest,
|
||||||
|
List<String> sqlStatements,
|
||||||
|
List<String> rollbackSqlStatements,
|
||||||
|
List<String> warnings) {
|
||||||
|
}
|
||||||
@@ -1,8 +1,111 @@
|
|||||||
package com.eip4.platform.metadata.publish;
|
package com.eip4.platform.metadata.publish;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/** 平台内自包含部署包生成器(Task 13 实现)。 */
|
/**
|
||||||
|
* 平台内自包含 production 部署包生成器(建物 3 · DECISION-2)。
|
||||||
|
*
|
||||||
|
* <p>不依赖 platform-ai(依赖图:platform-ai → platform-metadata,反向不可)。
|
||||||
|
* 从发布编排上下文合成 change-set,产出与 AiDeploymentPackage 同形的 {@link DeploymentPackage}。
|
||||||
|
* 产物为 production 人审草稿:manifest + 顺序 SQL(page_schema / serviceflow / menu)+ 对称 rollback。
|
||||||
|
* 实体 DDL 因不在此处掌握列定义,以占位 + warning 提示人工补全,恒 requiresHumanApproval=true。
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class DeploymentPackageBuilder {
|
public class DeploymentPackageBuilder {
|
||||||
|
|
||||||
|
/** 发布编排上下文 → 部署包输入。 */
|
||||||
|
public record Input(
|
||||||
|
String entityId,
|
||||||
|
String tableName,
|
||||||
|
String templateId,
|
||||||
|
String menuName,
|
||||||
|
String menuId,
|
||||||
|
List<String> flows) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeploymentPackage build(Input in) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
|
Map<String, Object> manifest = new LinkedHashMap<>();
|
||||||
|
manifest.put("entityId", in.entityId());
|
||||||
|
manifest.put("templateId", in.templateId());
|
||||||
|
manifest.put("tableName", in.tableName());
|
||||||
|
manifest.put("menuId", in.menuId());
|
||||||
|
manifest.put("menuName", in.menuName());
|
||||||
|
manifest.put("flowCount", in.flows() == null ? 0 : in.flows().size());
|
||||||
|
manifest.put("flows", in.flows() == null ? List.of() : List.copyOf(in.flows()));
|
||||||
|
manifest.put("generatedAt", now);
|
||||||
|
manifest.put("source", "design-publish");
|
||||||
|
|
||||||
|
List<String> sql = new ArrayList<>();
|
||||||
|
sql.add("-- [1] 实体 DDL:本平台内 net-new 实体由元数据引擎建表,"
|
||||||
|
+ "生产环境请人工从源库导出 CREATE TABLE " + in.tableName() + " 及索引后置入此处。");
|
||||||
|
sql.add("-- [2] 标准层页面 schema(唯一真相 PageSchemaWriter.upsertStandard 的等价 SQL):");
|
||||||
|
sql.add("-- 生产请用导出的 schema JSON 替换 :schemaJson 占位");
|
||||||
|
// 列名严格对齐唯一写口 PageSchemaWriter.upsertStandard:
|
||||||
|
// (template_id, name, schema_json, schema_etag, version, update_time) + ON CONFLICT(template_id)。
|
||||||
|
// sys_page_schema 无 layer/updateby/updatetime 列,勿用(评审 §B.9-6 已核)。
|
||||||
|
sql.add("INSERT INTO sys_page_schema(template_id, name, schema_json, schema_etag, version, update_time)"
|
||||||
|
+ " VALUES(" + sqlString(in.templateId()) + ", " + sqlString(in.menuName())
|
||||||
|
+ ", :schemaJson, :schemaEtag, 1, " + now + ")"
|
||||||
|
+ " ON CONFLICT (template_id) DO UPDATE SET schema_json=EXCLUDED.schema_json,"
|
||||||
|
+ " schema_etag=EXCLUDED.schema_etag, version=sys_page_schema.version+1,"
|
||||||
|
+ " update_time=EXCLUDED.update_time;");
|
||||||
|
sql.add("-- [3] 默认服务流:生产请用导出的 contentxml 替换 :contentxml 占位");
|
||||||
|
if (in.flows() != null) {
|
||||||
|
for (String flow : in.flows()) {
|
||||||
|
sql.add("INSERT INTO sys_serviceflow(sys_serviceflow_id, displayname, contentxml, entityid)"
|
||||||
|
+ " VALUES(" + sqlString(flow) + ", " + sqlString(flow) + ", :contentxml, "
|
||||||
|
+ sqlString(in.entityId()) + ")"
|
||||||
|
+ " ON CONFLICT (sys_serviceflow_id) DO NOTHING;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sql.add("-- [4] 功能菜单:生产请替换 ${parentMenuId}/${menuRoot} 为目标环境的菜单父节点");
|
||||||
|
sql.add("INSERT INTO sys_menu(sys_menu_id, name, parentid, view_templateid, typename, menuroot, seq,"
|
||||||
|
+ " isactive, version, createtime, createby, updatetime, updateby)"
|
||||||
|
+ " VALUES(" + sqlString(in.menuId()) + ", " + sqlString(in.menuName())
|
||||||
|
+ ", ${parentMenuId}, " + sqlString(in.templateId()) + ", '功能菜单', ${menuRoot}, 0,"
|
||||||
|
+ " 1, 0, " + now + ", 'DESIGN_PUBLISH', " + now + ", 'DESIGN_PUBLISH')"
|
||||||
|
+ " ON CONFLICT (sys_menu_id) DO NOTHING;");
|
||||||
|
|
||||||
|
List<String> rollback = new ArrayList<>();
|
||||||
|
rollback.add("UPDATE sys_menu SET isactive=0, updatetime=" + now
|
||||||
|
+ ", updateby='DESIGN_PUBLISH_ROLLBACK', version=version+1"
|
||||||
|
+ " WHERE TRIM(view_templateid)=" + sqlString(in.templateId()) + ";");
|
||||||
|
rollback.add("DELETE FROM sys_page_schema WHERE template_id=" + sqlString(in.templateId()) + ";");
|
||||||
|
if (in.flows() != null && !in.flows().isEmpty()) {
|
||||||
|
List<String> quoted = new ArrayList<>();
|
||||||
|
for (String flow : in.flows()) {
|
||||||
|
quoted.add(sqlString(flow));
|
||||||
|
}
|
||||||
|
rollback.add("DELETE FROM sys_serviceflow WHERE sys_serviceflow_id IN ("
|
||||||
|
+ String.join(", ", quoted) + ");");
|
||||||
|
}
|
||||||
|
rollback.add("-- 实体 DELETE:人工确认后 DELETE /api/meta/entity/" + in.tableName()
|
||||||
|
+ "(含物理表 DROP),并清理 SYS_ENTITY/SYS_ENTITYATTRIBUTE 元数据。");
|
||||||
|
|
||||||
|
List<String> warnings = new ArrayList<>();
|
||||||
|
warnings.add("实体 DDL 与 schema_json/contentxml 为占位,生产部署前须由人工从本地库导出真实定义置入。");
|
||||||
|
warnings.add("sys_menu 的 ${parentMenuId}/${menuRoot} 须替换为生产环境目标菜单父节点。");
|
||||||
|
warnings.add("本部署包恒人审:生产上线走既有人工审核流程,平台不自动在生产执行任何 SQL。");
|
||||||
|
|
||||||
|
return new DeploymentPackage(
|
||||||
|
"READY_FOR_HUMAN_REVIEW",
|
||||||
|
true,
|
||||||
|
now,
|
||||||
|
manifest,
|
||||||
|
List.copyOf(sql),
|
||||||
|
List.copyOf(rollback),
|
||||||
|
List.copyOf(warnings));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String sqlString(String value) {
|
||||||
|
String text = value == null ? "" : value;
|
||||||
|
return "'" + text.replace("'", "''") + "'";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,17 @@ public class PublishOrchestrator {
|
|||||||
return menuRegistrar.register(templateId, menuName, parentMenuId, operator);
|
return menuRegistrar.register(templateId, menuName, parentMenuId, operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** generateDeploymentPackage != false 时生成 production 人审部署包;否则返回 null。 */
|
||||||
|
public DeploymentPackage buildDeploymentPackage(String entityId, String tableName, String templateId,
|
||||||
|
String menuName, String menuId,
|
||||||
|
List<String> flows, boolean generate) {
|
||||||
|
if (!generate) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return deploymentPackageBuilder.build(new DeploymentPackageBuilder.Input(
|
||||||
|
entityId, tableName, templateId, menuName, menuId, flows));
|
||||||
|
}
|
||||||
|
|
||||||
/** 返回实体当前持久化的流名列表(发布后读 SYS_SERVICEFLOW,经 Task 10 预览服务)。 */
|
/** 返回实体当前持久化的流名列表(发布后读 SYS_SERVICEFLOW,经 Task 10 预览服务)。 */
|
||||||
public List<String> flowNames(String entityId) {
|
public List<String> flowNames(String entityId) {
|
||||||
List<String> out = new ArrayList<>();
|
List<String> out = new ArrayList<>();
|
||||||
|
|||||||
@@ -218,7 +218,23 @@ public class DesignFeatureController {
|
|||||||
String parentMenuId = body.get("parentMenuId") == null ? null : body.get("parentMenuId").toString().trim();
|
String parentMenuId = body.get("parentMenuId") == null ? null : body.get("parentMenuId").toString().trim();
|
||||||
String menuId = publishOrchestrator.registerMenu(templateId, menuName, parentMenuId, operator);
|
String menuId = publishOrchestrator.registerMenu(templateId, menuName, parentMenuId, operator);
|
||||||
data.put("menuId", menuId);
|
data.put("menuId", menuId);
|
||||||
// deploymentPackage 由 Task 13 补齐
|
|
||||||
|
boolean generatePkg = !(Boolean.FALSE.equals(body.get("generateDeploymentPackage")));
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> flowsForPkg = (List<String>) data.get("flows");
|
||||||
|
com.eip4.platform.metadata.publish.DeploymentPackage pkg = publishOrchestrator.buildDeploymentPackage(
|
||||||
|
entityId, tableName, templateId, menuName, menuId, flowsForPkg, generatePkg);
|
||||||
|
if (pkg != null) {
|
||||||
|
Map<String, Object> pkgMap = new LinkedHashMap<>();
|
||||||
|
pkgMap.put("status", pkg.status());
|
||||||
|
pkgMap.put("requiresHumanApproval", pkg.requiresHumanApproval());
|
||||||
|
pkgMap.put("generatedAt", pkg.generatedAt());
|
||||||
|
pkgMap.put("manifest", pkg.manifest());
|
||||||
|
pkgMap.put("sqlStatements", pkg.sqlStatements());
|
||||||
|
pkgMap.put("rollbackSqlStatements", pkg.rollbackSqlStatements());
|
||||||
|
pkgMap.put("warnings", pkg.warnings());
|
||||||
|
data.put("deploymentPackage", pkgMap);
|
||||||
|
}
|
||||||
Map<String, Object> resp = new LinkedHashMap<>();
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
resp.put("status", 0);
|
resp.put("status", 0);
|
||||||
resp.put("data", data);
|
resp.put("data", data);
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.eip4.platform.metadata.publish;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class DeploymentPackageBuilderTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void buildProducesManifestRollbackAndRequiresHumanApproval() {
|
||||||
|
DeploymentPackageBuilder builder = new DeploymentPackageBuilder();
|
||||||
|
DeploymentPackageBuilder.Input input = new DeploymentPackageBuilder.Input(
|
||||||
|
"ENT-1", "DEMO_TBL", "TPL-1", "演示功能", "MENU-1",
|
||||||
|
List.of("DEMO_TBL_ADD", "DEMO_TBL_UPDATE", "DEMO_TBL_SEARCH",
|
||||||
|
"DEMO_TBL_DELETE", "DEMO_TBL_LOAD"));
|
||||||
|
|
||||||
|
DeploymentPackage pkg = builder.build(input);
|
||||||
|
|
||||||
|
assertThat(pkg.requiresHumanApproval()).isTrue();
|
||||||
|
assertThat(pkg.status()).isEqualTo("READY_FOR_HUMAN_REVIEW");
|
||||||
|
assertThat(pkg.manifest()).containsKeys("entityId", "templateId", "tableName", "menuId", "flowCount");
|
||||||
|
assertThat(pkg.manifest().get("flowCount")).isEqualTo(5);
|
||||||
|
// SQL 草稿覆盖四类工件
|
||||||
|
assertThat(pkg.sqlStatements()).anyMatch(s -> s.contains("sys_page_schema"));
|
||||||
|
assertThat(pkg.sqlStatements()).anyMatch(s -> s.contains("sys_serviceflow"));
|
||||||
|
assertThat(pkg.sqlStatements()).anyMatch(s -> s.contains("sys_menu"));
|
||||||
|
// §B.9-6: 真实列对齐——sys_page_schema 无 layer 列,SQL 不得出现 'layer'
|
||||||
|
assertThat(pkg.sqlStatements()).noneMatch(s -> s.contains("layer"));
|
||||||
|
// rollback 对称且含 DELETE
|
||||||
|
assertThat(pkg.rollbackSqlStatements()).anyMatch(s -> s.contains("DELETE FROM sys_page_schema"));
|
||||||
|
assertThat(pkg.rollbackSqlStatements()).anyMatch(s -> s.contains("DELETE FROM sys_serviceflow"));
|
||||||
|
assertThat(pkg.rollbackSqlStatements()).anyMatch(s -> s.contains("sys_menu"));
|
||||||
|
// 生产 DDL 由人工补全 → warning
|
||||||
|
assertThat(pkg.warnings()).isNotEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user