From 25494efadf6ba8df646e923d8f320cf08151dae5 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Sat, 20 Jun 2026 15:18:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(blueprint):=20master-detail=20recipe=20?= =?UTF-8?q?=E6=8E=A5=E5=85=A5=20registry/composer=20+=20YAML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PageRecipeRegistry.defaults+compile switch 加 master-detail-v1。 RecipePageComposer.Spec 携带 childTable/listColumn/childAttributes (7-arg 兼容构造保留),toBlueprint 装配 PageBlueprintChild。 新增 page-recipes/master-detail-v1.yaml(镜像 maintenance/tree, gates 含 typed-page-schema/amis-schema)。 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../ai/page-recipes/master-detail-v1.yaml | 62 +++++++++++++++++++ .../schema/blueprint/PageRecipeRegistry.java | 18 +++++- .../schema/blueprint/RecipePageComposer.java | 39 +++++++++++- .../blueprint/PageRecipeRegistryTest.java | 47 ++++++++++++++ .../blueprint/RecipePageComposerTest.java | 24 +++++++ 5 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 platform-ai/src/main/resources/ai/page-recipes/master-detail-v1.yaml create mode 100644 platform-metadata/src/test/java/com/eip4/platform/metadata/schema/blueprint/PageRecipeRegistryTest.java diff --git a/platform-ai/src/main/resources/ai/page-recipes/master-detail-v1.yaml b/platform-ai/src/main/resources/ai/page-recipes/master-detail-v1.yaml new file mode 100644 index 0000000..1486005 --- /dev/null +++ b/platform-ai/src/main/resources/ai/page-recipes/master-detail-v1.yaml @@ -0,0 +1,62 @@ +schemaVersion: 1 +recipe: master-detail-v1 +title: EIP4 master-detail page +purpose: 主子表实体维护页,覆盖主表列表、含内联子表的新增/编辑、删除;子表为 amis input-table。 +compiler: com.eip4.platform.metadata.schema.blueprint.PageBlueprintCompiler +requirements: + childTable: 子表表名(普通实体 tabletype=1,含指向主表的引用列) + listColumn: 主表 LIST 属性列名(amis input-table 的 name,如 DETAILS) + childFields: 子表可编辑列(非空) +amis: + rootType: page + body: + type: crud + syncLocation: false + apiPattern: /api/flow/{tableName}_SEARCH + headerToolbar: + - addButton: + label: 新增 + level: primary + icon: fa fa-plus + actionType: dialog + formApiPattern: post:/api/flow/{tableName}_ADD + child: + type: input-table + namePattern: "{listColumn}" + addable: true + removable: true + needConfirm: false + staticOn: ${__readonly} + - editButton: + label: 编辑 + level: primary + actionType: dialog + disabledOn: ${!selectedItems || selectedItems.length === 0} + initApiPattern: post:/api/flow/{tableName}_LOAD + formApiPattern: post:/api/flow/{tableName}_UPDATE + child: + type: input-table + namePattern: "{listColumn}" + - deleteButton: + label: 删除 + level: danger + actionType: ajax + confirmText: 确认要删除此记录吗? + apiPattern: /api/flow/{tableName}_DELETE + - pagination + footerToolbar: + - statistics + - pagination +fieldMappings: + string: input-text + integer: input-number + number: input-number + date: input-date + datetime: input-datetime + boolean: switch +gates: + - page-recipe + - typed-page-schema + - amis-schema + - local-smoke + - playwright-render diff --git a/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/PageRecipeRegistry.java b/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/PageRecipeRegistry.java index deca6b4..264ef6a 100644 --- a/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/PageRecipeRegistry.java +++ b/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/PageRecipeRegistry.java @@ -24,7 +24,7 @@ public final class PageRecipeRegistry { } public static PageRecipeRegistry defaults() { - return new PageRecipeRegistry(List.of(maintenanceCrud(), treeCrud())); + return new PageRecipeRegistry(List.of(maintenanceCrud(), treeCrud(), masterDetail())); } public Optional find(String recipe) { @@ -50,6 +50,7 @@ public final class PageRecipeRegistry { return switch (blueprint.recipe()) { case PageBlueprint.RECIPE_MAINTENANCE_CRUD -> new PageBlueprintCompiler(objectMapper).compile(blueprint); case PageBlueprint.RECIPE_TREE_CRUD -> new PageBlueprintCompiler(objectMapper).compile(blueprint); + case PageBlueprint.RECIPE_MASTER_DETAIL -> new PageBlueprintCompiler(objectMapper).compile(blueprint); default -> throw new IllegalArgumentException("Unsupported page recipe: " + blueprint.recipe()); }; } @@ -83,4 +84,19 @@ public final class PageRecipeRegistry { "boolean", "switch"), List.of("page-recipe", "typed-page-schema", "amis-schema", "local-smoke", "playwright-render")); } + + private static PageRecipeDefinition masterDetail() { + return new PageRecipeDefinition( + PageBlueprint.RECIPE_MASTER_DETAIL, + PageBlueprint.VERSION, + "EIP4 master-detail page", + Map.of( + "string", "input-text", + "integer", "input-number", + "number", "input-number", + "date", "input-date", + "datetime", "input-datetime", + "boolean", "switch"), + List.of("page-recipe", "typed-page-schema", "amis-schema", "local-smoke", "playwright-render")); + } } diff --git a/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/RecipePageComposer.java b/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/RecipePageComposer.java index 4782540..2814e5c 100644 --- a/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/RecipePageComposer.java +++ b/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/RecipePageComposer.java @@ -44,12 +44,29 @@ public final class RecipePageComposer { } String displayField = firstNonBlank(spec.displayField(), deriveDisplayField(spec.attributes())); int pageSize = spec.pageSize() < 1 ? 20 : spec.pageSize(); + PageBlueprintChild child = toChild(spec); // templateId 由端点层服务端生成;compose 阶段用占位(compiler.validate 只要求非空)。 return new PageBlueprint( PageBlueprint.VERSION, spec.recipe(), "compose-placeholder", spec.title(), spec.tableName(), spec.entityName(), spec.tableName() + "_ID", displayField, fields, - true, true, true, pageSize); + true, true, true, pageSize, child); + } + + /** master-detail recipe 才装配子表(childTable/listColumn 非空);否则 null(单表/树)。 */ + private static PageBlueprintChild toChild(Spec spec) { + if (spec.childTable() == null || spec.childTable().isBlank() + || spec.listColumn() == null || spec.listColumn().isBlank()) { + return null; + } + List childFields = new ArrayList<>(); + for (AttrSpec a : spec.childAttributes()) { + childFields.add(new PageBlueprintField( + a.column(), a.display(), a.type(), + a.required(), false, true, + a.referenceTable(), a.displayColumn())); + } + return new PageBlueprintChild(spec.childTable().trim(), spec.listColumn().trim(), null, childFields); } private static String deriveDisplayField(List attrs) { @@ -68,7 +85,12 @@ public final class RecipePageComposer { return fallback; } - /** 装配输入:等价于 GET /api/meta/entity/{table}/attributes 的读取结果 + recipe/title/displayField/pageSize。 */ + /** + * 装配输入:等价于 GET /api/meta/entity/{table}/attributes 的读取结果 + recipe/title/displayField/pageSize。 + * + *

master-detail recipe 额外携带子表:{@code childTable}(子表表名)/{@code listColumn}(主表 LIST 属性 + * 列名,即 amis input-table 的 name)/{@code childAttributes}(子表可编辑列)。单表/树 recipe 三者置空。 + */ public record Spec( String tableName, String entityName, @@ -76,9 +98,20 @@ public final class RecipePageComposer { String title, String displayField, int pageSize, - List attributes) { + List attributes, + String childTable, + String listColumn, + List childAttributes) { public Spec { attributes = attributes == null ? List.of() : List.copyOf(attributes); + childAttributes = childAttributes == null ? List.of() : List.copyOf(childAttributes); + } + + /** 7-arg 兼容构造:单表/树 recipe 无子表。保持既有调用方/测试零改。 */ + public Spec(String tableName, String entityName, String recipe, String title, + String displayField, int pageSize, List attributes) { + this(tableName, entityName, recipe, title, displayField, pageSize, attributes, + null, null, List.of()); } } diff --git a/platform-metadata/src/test/java/com/eip4/platform/metadata/schema/blueprint/PageRecipeRegistryTest.java b/platform-metadata/src/test/java/com/eip4/platform/metadata/schema/blueprint/PageRecipeRegistryTest.java new file mode 100644 index 0000000..d4de87f --- /dev/null +++ b/platform-metadata/src/test/java/com/eip4/platform/metadata/schema/blueprint/PageRecipeRegistryTest.java @@ -0,0 +1,47 @@ +package com.eip4.platform.metadata.schema.blueprint; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +class PageRecipeRegistryTest { + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + @Test + @DisplayName("defaults() 注册 master-detail-v1,含 typed-page-schema/amis-schema 闸") + void defaultsRegistersMasterDetail() { + PageRecipeRegistry registry = PageRecipeRegistry.defaults(); + assertTrue(registry.supports(PageBlueprint.RECIPE_MASTER_DETAIL)); + PageRecipeDefinition def = registry.find(PageBlueprint.RECIPE_MASTER_DETAIL).orElseThrow(); + assertTrue(def.gates().contains("typed-page-schema")); + assertTrue(def.gates().contains("amis-schema")); + } + + @Test + @DisplayName("compile master-detail-v1 经 registry → 含 input-table 子表的 amis 页") + void compilesMasterDetailViaRegistry() { + PageBlueprint blueprint = new PageBlueprint( + PageBlueprint.VERSION, + PageBlueprint.RECIPE_MASTER_DETAIL, + "tpl", "采购", "EIP4AI_PURCHASE", "采购", "EIP4AI_PURCHASE_ID", "TITLE", + List.of(new PageBlueprintField("TITLE", "标题", "string", true, true, true)), + true, true, true, 20, + new PageBlueprintChild("EIP4AI_PURCHASE_ITEM", "DETAILS", "ITEMNAME", + List.of(new PageBlueprintField("ITEMNAME", "物料", "string", true, false, true)))); + + ObjectNode page = PageRecipeRegistry.defaults().compile(blueprint, MAPPER); + assertEquals("page", page.path("type").asText()); + // 编辑表单含 input-table 子表。 + String json = page.toString(); + assertTrue(json.contains("\"input-table\"")); + assertTrue(json.contains("\"DETAILS\"")); + } +} diff --git a/platform-metadata/src/test/java/com/eip4/platform/metadata/schema/blueprint/RecipePageComposerTest.java b/platform-metadata/src/test/java/com/eip4/platform/metadata/schema/blueprint/RecipePageComposerTest.java index dea08b3..e9dfdf1 100644 --- a/platform-metadata/src/test/java/com/eip4/platform/metadata/schema/blueprint/RecipePageComposerTest.java +++ b/platform-metadata/src/test/java/com/eip4/platform/metadata/schema/blueprint/RecipePageComposerTest.java @@ -78,6 +78,30 @@ class RecipePageComposerTest { assertEquals("page", page.path("type").asText()); } + @Test + @DisplayName("5. compose master-detail → 编辑表单含 name= 的 input-table 子表(列经 controlType)") + void composesMasterDetailWithChild() { + RecipePageComposer.Spec spec = new RecipePageComposer.Spec( + "EIP4AI_PURCHASE", "采购", PageBlueprint.RECIPE_MASTER_DETAIL, + "采购申请", "TITLE", 20, + List.of( + new RecipePageComposer.AttrSpec("TITLE", "标题", "string", true, null, null), + new RecipePageComposer.AttrSpec("AMOUNT", "金额", "number", false, null, null)), + "EIP4AI_PURCHASE_ITEM", "DETAILS", + List.of( + new RecipePageComposer.AttrSpec("ITEMNAME", "物料", "string", true, null, null), + new RecipePageComposer.AttrSpec("QTY", "数量", "integer", false, null, null))); + + ObjectNode page = composer.compose(spec); + String json = page.toString(); + assertTrue(json.contains("\"input-table\""), json); + assertTrue(json.contains("\"DETAILS\""), json); + // 编辑表单 initApi 走 _LOAD。 + assertEquals("/api/flow/EIP4AI_PURCHASE_LOAD", + page.path("body").path("headerToolbar").get(1) + .path("dialog").path("body").path("initApi").path("url").asText()); + } + @Test @DisplayName("4. 端到端: compose 含 reference 列的页 → list 列 name 显名 _DISPLAY__") void composeRendersReferenceDisplayEndToEnd() {