feat(ai-recipe): align maintenance-crud-v1 to converter house-style

AI 生成的单表维护页与转换器基线产出存在「陌生感」:缺查询区、走自创
/api/entity REST 而非保真层服务流、动作放 per-row 操作列。本次对齐:

- crud.api → /api/flow/<TABLE>_SEARCH(amis 自动追 page/perPage,无 adaptor)
  + selectable/checkOnItemClick/primaryField
- 补 filter 查询区(string 列 → input-text 文本搜索)
- 新增/编辑/删除挂 headerToolbar 操作 selectedItems(带 id + disabledOn 守卫,
  删掉 per-row 操作列);增改 inline 表单绑 _ADD/_UPDATE + reload,编辑用
  dialog data:{"&":"${selectedItems[0]}"} 预填 + hidden 主键;删除
  data={ids:"${selectedItems|pick:<PK>|join:','}"}(照搬基线,键为 ids)
- 连带:AiFeatureDraftGenerator.expectedPageApi + AiAgentService 的
  render-plan 门禁改 recipe-aware(原硬编码 /api/entity + /list? 会让整条
  pipeline 409)

证据:2727 转换页聚合 0 用 per-row operation 列 / 1976 headerToolbar /
1211 filter / 1277 _SEARCH。DefaultFlowHelper 流名吻合,AI pipeline 仅生成
list 页无独立表单页 → recipe 保持 inline 自包含。

验证:platform-metadata 397 + platform-ai 61 测试绿;8093 live 经 AI pipeline
重生成页 + 浏览器实证查询区/工具栏/选中守卫/flow 取数/编辑预填全绿,0 console error。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-19 19:07:39 +08:00
parent d3b88467e0
commit 1ff0d334d0
5 changed files with 187 additions and 74 deletions

View File

@@ -28,6 +28,16 @@ public final class PageBlueprintCompiler {
throw new IllegalArgumentException("Unsupported page recipe: " + blueprint.recipe());
}
/**
* 单表维护页,对齐转换器 house-style:
* <ul>
* <li>列表数据走保真层服务流 {@code /api/flow/<TABLE>_SEARCH}(含显名/枚举/引用列约定),
* 而非自创 {@code /api/entity} REST;amis crud 自动追加 page/perPage。</li>
* <li>顶部带查询区 {@code filter}(按 string 列生成文本搜索)。</li>
* <li>新增/编辑/删除按钮挂 {@code headerToolbar} 并操作 {@code selectedItems}(基线习惯,
* 不生成 per-row「操作」列);写入走 {@code _ADD/_UPDATE/_DELETE} 服务流。</li>
* </ul>
*/
private ObjectNode maintenanceCrud(PageBlueprint blueprint) {
ObjectNode page = objectMapper.createObjectNode();
page.put("type", "page");
@@ -37,25 +47,21 @@ public final class PageBlueprintCompiler {
crud.put("type", "crud");
crud.put("name", crudName);
crud.put("syncLocation", false);
ObjectNode api = crud.putObject("api");
api.put("method", "get");
api.put("url", "/api/entity/" + blueprint.tableName() + "/list?page=${page}&perPage=${perPage}");
api.put("adaptor", "return payload;");
crud.put("api", "/api/flow/" + blueprint.tableName() + "_SEARCH");
crud.put("selectable", true);
crud.put("checkOnItemClick", true);
crud.put("primaryField", blueprint.primaryKey());
crud.set("filter", searchFilter(blueprint));
ArrayNode headerToolbar = crud.putArray("headerToolbar");
if (blueprint.allowCreate()) {
ObjectNode addButton = headerToolbar.addObject();
addButton.put("type", "button");
addButton.put("label", "新增");
addButton.put("level", "primary");
addButton.put("icon", "fa fa-plus");
addButton.put("actionType", "dialog");
ObjectNode addDialog = addButton.putObject("dialog");
addDialog.put("title", "新增" + blueprint.entityName());
ObjectNode addForm = addDialog.putObject("body");
addForm.put("type", "form");
addForm.put("api", "post:/api/entity/" + blueprint.tableName() + "/save");
addForm.set("body", formControls(blueprint, false));
headerToolbar.add(maintenanceAddButton(blueprint, crudName));
}
if (blueprint.allowEdit()) {
headerToolbar.add(maintenanceEditButton(blueprint, crudName));
}
if (blueprint.allowDelete()) {
headerToolbar.add(maintenanceDeleteButton(blueprint, crudName));
}
headerToolbar.add("pagination");
@@ -63,7 +69,7 @@ public final class PageBlueprintCompiler {
footerToolbar.add("statistics");
footerToolbar.add("pagination");
crud.put("perPage", blueprint.pageSize());
crud.set("columns", columns(blueprint, crudName));
crud.set("columns", maintenanceColumns(blueprint));
return page;
}
@@ -107,7 +113,7 @@ public final class PageBlueprintCompiler {
return page;
}
private ArrayNode columns(PageBlueprint blueprint, String crudName) {
private ArrayNode maintenanceColumns(PageBlueprint blueprint) {
ArrayNode columns = objectMapper.createArrayNode();
for (PageBlueprintField field : blueprint.fields()) {
if (!field.listVisible()) {
@@ -117,23 +123,105 @@ public final class PageBlueprintCompiler {
column.put("name", field.name());
column.put("label", field.label());
}
if (!blueprint.allowEdit() && !blueprint.allowDelete()) {
return columns;
}
ObjectNode op = columns.addObject();
op.put("type", "operation");
op.put("label", "操作");
op.put("width", 180);
ArrayNode buttons = op.putArray("buttons");
if (blueprint.allowEdit()) {
addEditAction(blueprint, buttons);
}
if (blueprint.allowDelete()) {
addDeleteAction(blueprint, buttons, crudName);
}
return columns;
}
/** 顶部查询区:按 string 列生成文本搜索;若无 string 列则回退按 displayField 搜索。 */
private ObjectNode searchFilter(PageBlueprint blueprint) {
ObjectNode filter = objectMapper.createObjectNode();
filter.put("title", "查询");
ArrayNode body = filter.putArray("body");
for (PageBlueprintField field : blueprint.fields()) {
if (field.listVisible() && "string".equals(field.type())) {
body.add(textSearch(field.name(), field.label()));
}
}
if (body.isEmpty()) {
String name = blueprint.displayField();
body.add(textSearch(name, displayLabel(blueprint, name)));
}
return filter;
}
private ObjectNode textSearch(String name, String label) {
ObjectNode control = objectMapper.createObjectNode();
control.put("type", "input-text");
control.put("name", name);
control.put("label", label);
control.put("clearable", true);
return control;
}
private static String displayLabel(PageBlueprint blueprint, String name) {
for (PageBlueprintField field : blueprint.fields()) {
if (field.name().equals(name)) {
return field.label();
}
}
return name;
}
private ObjectNode maintenanceAddButton(PageBlueprint blueprint, String crudName) {
ObjectNode addButton = objectMapper.createObjectNode();
addButton.put("type", "button");
addButton.put("id", "新增");
addButton.put("label", "新增");
addButton.put("level", "primary");
addButton.put("icon", "fa fa-plus");
addButton.put("actionType", "dialog");
ObjectNode addDialog = addButton.putObject("dialog");
addDialog.put("title", "新增" + blueprint.entityName());
addDialog.put("size", "lg");
ObjectNode addForm = addDialog.putObject("body");
addForm.put("type", "form");
addForm.put("api", "post:/api/flow/" + blueprint.tableName() + "_ADD");
addForm.put("reload", crudName);
addForm.set("body", formControls(blueprint, false));
return addButton;
}
private ObjectNode maintenanceEditButton(PageBlueprint blueprint, String crudName) {
ObjectNode edit = objectMapper.createObjectNode();
edit.put("type", "button");
edit.put("id", "编辑");
edit.put("label", "编辑");
edit.put("level", "primary");
edit.put("actionType", "dialog");
edit.put("disabledOn", "${!selectedItems || selectedItems.length === 0}");
ObjectNode dialog = edit.putObject("dialog");
dialog.put("title", "编辑" + blueprint.entityName());
dialog.put("size", "lg");
// 选中行铺进对话框作用域,内层表单据此预填(自包含,无需 _LOAD 服务往返)。
dialog.putObject("data").put("&", "${selectedItems[0]}");
ObjectNode editForm = dialog.putObject("body");
editForm.put("type", "form");
editForm.put("api", "post:/api/flow/" + blueprint.tableName() + "_UPDATE");
editForm.put("reload", crudName);
ArrayNode editControls = formControls(blueprint, false);
editControls.add(hidden(blueprint.primaryKey(), "${" + blueprint.primaryKey() + "}"));
editForm.set("body", editControls);
return edit;
}
private ObjectNode maintenanceDeleteButton(PageBlueprint blueprint, String crudName) {
ObjectNode del = objectMapper.createObjectNode();
del.put("type", "button");
del.put("id", "删除");
del.put("label", "删除");
del.put("level", "danger");
del.put("actionType", "ajax");
del.put("disabledOn", "${!selectedItems || selectedItems.length === 0}");
del.put("confirmText", "确认要删除此记录吗?");
ObjectNode delApi = del.putObject("api");
delApi.put("method", "post");
delApi.put("url", "/api/flow/" + blueprint.tableName() + "_DELETE");
// 与转换器 house-style 一致:选中行主键逗号拼成 ids 串(单/多选通吃,运行时 _DELETE fanout 逐 id)。
delApi.putObject("data").put("ids",
"${selectedItems|pick:" + blueprint.primaryKey() + "|join:','}");
del.put("reload", crudName);
return del;
}
private ArrayNode treeColumns(PageBlueprint blueprint, String crudName) {
ArrayNode columns = objectMapper.createArrayNode();
for (PageBlueprintField field : blueprint.fields()) {
@@ -197,26 +285,6 @@ public final class PageBlueprintCompiler {
editForm.set("body", editControls);
}
private void addEditAction(PageBlueprint blueprint, ArrayNode buttons) {
ObjectNode edit = buttons.addObject();
edit.put("type", "button");
edit.put("label", "编辑");
edit.put("level", "link");
edit.put("actionType", "dialog");
ObjectNode editDialog = edit.putObject("dialog");
editDialog.put("title", "编辑${" + blueprint.displayField() + "}");
ObjectNode editForm = editDialog.putObject("body");
editForm.put("type", "form");
editForm.put("api", "post:/api/entity/" + blueprint.tableName() + "/save");
ArrayNode editControls = formControls(blueprint, true);
ObjectNode hiddenPk = objectMapper.createObjectNode();
hiddenPk.put("type", "hidden");
hiddenPk.put("name", blueprint.primaryKey());
hiddenPk.put("value", "${" + blueprint.primaryKey() + "}");
editControls.add(hiddenPk);
editForm.set("body", editControls);
}
private void addDeleteAction(PageBlueprint blueprint, ArrayNode buttons, String crudName) {
ObjectNode del = buttons.addObject();
del.put("type", "button");

View File

@@ -1,7 +1,9 @@
package com.eip4.platform.metadata.schema.blueprint;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
@@ -9,6 +11,7 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
class PageBlueprintCompilerTest {
@@ -16,7 +19,7 @@ class PageBlueprintCompilerTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
@Test
@DisplayName("maintenance-crud-v1 编译为 EIP4 标准 amis CRUD 页")
@DisplayName("maintenance-crud-v1 编译为对齐转换器 house-style 的 amis CRUD 页")
void compilesMaintenanceCrudRecipe() {
PageBlueprint blueprint = new PageBlueprint(
PageBlueprint.VERSION,
@@ -42,17 +45,53 @@ class PageBlueprintCompilerTest {
ObjectNode crud = (ObjectNode) schema.path("body");
assertEquals("crud", crud.path("type").asText());
assertEquals("eip4aiContractTypeCrud", crud.path("name").asText());
assertEquals("/api/entity/EIP4AI_CONTRACT_TYPE/list?page=${page}&perPage=${perPage}",
crud.path("api").path("url").asText());
assertEquals("新增", crud.path("headerToolbar").get(0).path("label").asText());
assertEquals("post:/api/entity/EIP4AI_CONTRACT_TYPE/save",
crud.path("headerToolbar").get(0).path("dialog").path("body").path("api").asText());
assertEquals("switch", crud.path("headerToolbar").get(0).path("dialog").path("body")
.path("body").get(1).path("type").asText());
assertEquals("hidden", crud.path("columns").get(2).path("buttons").get(0).path("dialog")
.path("body").path("body").get(2).path("type").asText());
assertEquals("text-danger", crud.path("columns").get(2).path("buttons").get(1)
.path("className").asText());
// ① 列表数据走保真层服务流 _SEARCH(基线口径),非自创 /api/entity REST。
assertEquals("/api/flow/EIP4AI_CONTRACT_TYPE_SEARCH", crud.path("api").asText());
assertTrue(crud.path("selectable").asBoolean());
assertTrue(crud.path("checkOnItemClick").asBoolean());
assertEquals("EIP4AI_CONTRACT_TYPE_ID", crud.path("primaryField").asText());
// ② 顶部查询区(filter):按 string 列生成文本搜索;boolean 列不入查询区。
assertEquals("查询", crud.path("filter").path("title").asText());
assertEquals("input-text", crud.path("filter").path("body").get(0).path("type").asText());
assertEquals("NAME", crud.path("filter").path("body").get(0).path("name").asText());
assertEquals(1, crud.path("filter").path("body").size());
// ③ 动作按钮挂 headerToolbar 操作 selectedItems(基线 house-style,无 per-row 操作列)。
ArrayNode header = (ArrayNode) crud.path("headerToolbar");
assertEquals("新增", header.get(0).path("label").asText());
assertEquals("dialog", header.get(0).path("actionType").asText());
assertEquals("post:/api/flow/EIP4AI_CONTRACT_TYPE_ADD",
header.get(0).path("dialog").path("body").path("api").asText());
assertEquals("switch", header.get(0).path("dialog").path("body").path("body").get(1).path("type").asText());
assertEquals("编辑", header.get(1).path("label").asText());
assertTrue(header.get(1).path("disabledOn").asText().contains("selectedItems"));
assertEquals("${selectedItems[0]}", header.get(1).path("dialog").path("data").path("&").asText());
assertEquals("post:/api/flow/EIP4AI_CONTRACT_TYPE_UPDATE",
header.get(1).path("dialog").path("body").path("api").asText());
assertEquals("hidden", header.get(1).path("dialog").path("body").path("body").get(2).path("type").asText());
assertEquals("删除", header.get(2).path("label").asText());
assertEquals("ajax", header.get(2).path("actionType").asText());
assertEquals("danger", header.get(2).path("level").asText());
assertEquals("/api/flow/EIP4AI_CONTRACT_TYPE_DELETE", header.get(2).path("api").path("url").asText());
assertEquals("${selectedItems|pick:EIP4AI_CONTRACT_TYPE_ID|join:','}",
header.get(2).path("api").path("data").path("ids").asText());
assertFalse(header.get(2).path("confirmText").asText().isBlank());
assertEquals("pagination", header.get(3).asText());
assertEquals("statistics", crud.path("footerToolbar").get(0).asText());
assertEquals("pagination", crud.path("footerToolbar").get(1).asText());
// ④ 列表列 = listVisible 业务列,无 per-row「操作」列。
ArrayNode columns = (ArrayNode) crud.path("columns");
assertEquals(2, columns.size());
assertEquals("NAME", columns.get(0).path("name").asText());
for (int i = 0; i < columns.size(); i++) {
assertFalse("operation".equals(columns.get(i).path("type").asText()));
}
}
@Test