feat(blueprint): master-detail recipe 接入 registry/composer + YAML
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
@@ -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<PageRecipeDefinition> 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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<PageBlueprintField> 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<AttrSpec> 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。
|
||||
*
|
||||
* <p>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<AttrSpec> attributes) {
|
||||
List<AttrSpec> attributes,
|
||||
String childTable,
|
||||
String listColumn,
|
||||
List<AttrSpec> 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<AttrSpec> attributes) {
|
||||
this(tableName, entityName, recipe, title, displayField, pageSize, attributes,
|
||||
null, null, List.of());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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\""));
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,30 @@ class RecipePageComposerTest {
|
||||
assertEquals("page", page.path("type").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("5. compose master-detail → 编辑表单含 name=<listColumn> 的 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 显名 <COL>_DISPLAY__")
|
||||
void composeRendersReferenceDisplayEndToEnd() {
|
||||
|
||||
Reference in New Issue
Block a user