fix(recipe): 表单/列表/查询/子表排除标准审计列,生成页真正可用
recipe 编译器此前把标准审计列(主键/VERSION/CREATETIME/UPDATETIME/CREATEBY/UPDATEBY/ ISACTIVE)也渲成可编辑必填表单字段、列表列、查询条件、子表 EditGrid 单元格——致新建出的 页 11 列过宽、表单杂乱不可用(此前 e2e 都走 API 未经表单 UI 故未暴露,影响所有主子表功能)。 PageBlueprintCompiler 在 maintenanceColumns/treeColumns/searchFilter/formControlsExcluding/ masterDetailFormControls/childInputTable 统一排除系统列(SYSTEM_COLUMNS + 主键)。编辑表单仍保留 hidden 主键(_UPDATE 定位)。子表按子表 PK 排除。 +2 单测(维护页 forms/list/查询排除+编辑表单 hidden 主键;主子表主表单/子表排除), 全量测试绿,live 验证维护页+主子表页 schema 系统列全清(仅留编辑表单 hidden 主键)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,12 +15,25 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
*/
|
||||
public final class PageBlueprintCompiler {
|
||||
|
||||
/** 标准审计/系统列:系统自管,不进表单/列表/子表可编辑单元格(杂乱且非用户可编辑)。 */
|
||||
private static final java.util.Set<String> SYSTEM_COLUMNS = java.util.Set.of(
|
||||
"VERSION", "CREATETIME", "UPDATETIME", "CREATEBY", "UPDATEBY", "ISACTIVE");
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public PageBlueprintCompiler(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
/** 是否标准审计/系统列(含主键):用于把这些列排除出表单/列表/子表渲染。 */
|
||||
private static boolean isSystemColumn(String column, String primaryKey) {
|
||||
if (column == null) {
|
||||
return false;
|
||||
}
|
||||
return SYSTEM_COLUMNS.contains(column.toUpperCase(Locale.ROOT))
|
||||
|| column.equalsIgnoreCase(primaryKey);
|
||||
}
|
||||
|
||||
public ObjectNode compile(PageBlueprint blueprint) {
|
||||
validate(blueprint);
|
||||
if (PageBlueprint.RECIPE_MAINTENANCE_CRUD.equals(blueprint.recipe())) {
|
||||
@@ -144,7 +157,12 @@ public final class PageBlueprintCompiler {
|
||||
table.put("needConfirm", false);
|
||||
table.put("staticOn", "${__readonly}");
|
||||
ArrayNode columns = table.putArray("columns");
|
||||
String childPk = child.childTable() + "_ID";
|
||||
for (PageBlueprintField field : child.fields()) {
|
||||
// 排除子表标准审计列(子表PK/VERSION/CREATETIME/...):不渲成可编辑单元格,避免子表过宽杂乱。
|
||||
if (isSystemColumn(field.name(), childPk)) {
|
||||
continue;
|
||||
}
|
||||
ObjectNode col = columns.addObject();
|
||||
col.put("name", field.name());
|
||||
col.put("label", field.label());
|
||||
@@ -197,7 +215,7 @@ public final class PageBlueprintCompiler {
|
||||
PageBlueprintChild child = blueprint.child();
|
||||
ArrayNode controls = objectMapper.createArrayNode();
|
||||
for (PageBlueprintField field : blueprint.fields()) {
|
||||
if (!field.formVisible()) {
|
||||
if (!field.formVisible() || isSystemColumn(field.name(), blueprint.primaryKey())) {
|
||||
continue;
|
||||
}
|
||||
PageBlueprintChild.RollupColumn rollup = child == null ? null : child.rollupFor(field.name());
|
||||
@@ -361,7 +379,7 @@ public final class PageBlueprintCompiler {
|
||||
private ArrayNode maintenanceColumns(PageBlueprint blueprint) {
|
||||
ArrayNode columns = objectMapper.createArrayNode();
|
||||
for (PageBlueprintField field : blueprint.fields()) {
|
||||
if (!field.listVisible()) {
|
||||
if (!field.listVisible() || isSystemColumn(field.name(), blueprint.primaryKey())) {
|
||||
continue;
|
||||
}
|
||||
ObjectNode column = columns.addObject();
|
||||
@@ -423,7 +441,8 @@ public final class PageBlueprintCompiler {
|
||||
filter.put("title", "查询");
|
||||
ArrayNode body = filter.putArray("body");
|
||||
for (PageBlueprintField field : blueprint.fields()) {
|
||||
if (field.listVisible() && "string".equals(field.type())) {
|
||||
if (field.listVisible() && "string".equals(field.type())
|
||||
&& !isSystemColumn(field.name(), blueprint.primaryKey())) {
|
||||
body.add(textSearch(field.name(), field.label()));
|
||||
}
|
||||
}
|
||||
@@ -516,7 +535,8 @@ public final class PageBlueprintCompiler {
|
||||
private ArrayNode treeColumns(PageBlueprint blueprint, String crudName) {
|
||||
ArrayNode columns = objectMapper.createArrayNode();
|
||||
for (PageBlueprintField field : blueprint.fields()) {
|
||||
if (!field.listVisible() || "PARENTID".equals(field.name())) {
|
||||
if (!field.listVisible() || "PARENTID".equals(field.name())
|
||||
|| isSystemColumn(field.name(), blueprint.primaryKey())) {
|
||||
continue;
|
||||
}
|
||||
ObjectNode column = columns.addObject();
|
||||
@@ -600,7 +620,8 @@ public final class PageBlueprintCompiler {
|
||||
private ArrayNode formControlsExcluding(PageBlueprint blueprint, boolean bindCurrentRow, String... excludedFields) {
|
||||
ArrayNode controls = objectMapper.createArrayNode();
|
||||
for (PageBlueprintField field : blueprint.fields()) {
|
||||
if (!field.formVisible() || isExcluded(field.name(), excludedFields)) {
|
||||
if (!field.formVisible() || isExcluded(field.name(), excludedFields)
|
||||
|| isSystemColumn(field.name(), blueprint.primaryKey())) {
|
||||
continue;
|
||||
}
|
||||
ObjectNode c = controls.addObject();
|
||||
|
||||
@@ -339,6 +339,87 @@ class PageBlueprintCompilerTest {
|
||||
assertEquals("input-text", bodyByName((ArrayNode) addForm.path("body"), "TITLE").path("type").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("排除标准审计列: 主键/VERSION/CREATETIME/UPDATETIME/CREATEBY/UPDATEBY/ISACTIVE 不进列表/表单,业务列保留;编辑表单仍带 hidden 主键")
|
||||
void excludesSystemColumnsFromFormsAndList() {
|
||||
PageBlueprint blueprint = new PageBlueprint(
|
||||
PageBlueprint.VERSION, PageBlueprint.RECIPE_MAINTENANCE_CRUD,
|
||||
"eip4ai-demo", "演示", "EIP4AI_DEMO", "演示", "EIP4AI_DEMO_ID", "TITLE",
|
||||
List.of(
|
||||
new PageBlueprintField("EIP4AI_DEMO_ID", "主键", "string", true, true, true),
|
||||
new PageBlueprintField("VERSION", "版本", "integer", true, true, true),
|
||||
new PageBlueprintField("CREATETIME", "创建时间", "datetime", true, true, true),
|
||||
new PageBlueprintField("UPDATETIME", "更新时间", "datetime", true, true, true),
|
||||
new PageBlueprintField("CREATEBY", "创建人", "string", true, true, true),
|
||||
new PageBlueprintField("UPDATEBY", "更新人", "string", true, true, true),
|
||||
new PageBlueprintField("ISACTIVE", "是否有效", "boolean", true, true, true),
|
||||
new PageBlueprintField("TITLE", "标题", "string", true, true, true)),
|
||||
true, true, true, 20);
|
||||
|
||||
ObjectNode crud = (ObjectNode) new PageBlueprintCompiler(MAPPER).compile(blueprint).path("body");
|
||||
|
||||
// 列表列:只剩业务列 TITLE(标准列全排除)。
|
||||
ArrayNode columns = (ArrayNode) crud.path("columns");
|
||||
assertEquals(1, columns.size(), "列表应只剩业务列");
|
||||
assertEquals("TITLE", columns.get(0).path("name").asText());
|
||||
|
||||
// 新增表单:只剩业务列 TITLE。
|
||||
ArrayNode header = (ArrayNode) crud.path("headerToolbar");
|
||||
ArrayNode addBody = (ArrayNode) header.get(0).path("dialog").path("body").path("body");
|
||||
assertEquals(1, addBody.size(), "新增表单应只剩业务列");
|
||||
assertEquals("TITLE", addBody.get(0).path("name").asText());
|
||||
|
||||
// 编辑表单:业务列 + hidden 主键(_UPDATE 需主键定位)。
|
||||
ArrayNode editBody = (ArrayNode) header.get(1).path("dialog").path("body").path("body");
|
||||
assertEquals("TITLE", editBody.get(0).path("name").asText());
|
||||
assertEquals("hidden", editBody.get(editBody.size() - 1).path("type").asText());
|
||||
assertEquals("EIP4AI_DEMO_ID", editBody.get(editBody.size() - 1).path("name").asText());
|
||||
assertEquals(2, editBody.size(), "编辑表单=业务列 + hidden 主键");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("排除子表标准列: 子表 input-table 只渲业务列,不渲子表主键/VERSION/审计/ISACTIVE")
|
||||
void excludesSystemColumnsFromChildInputTable() {
|
||||
PageBlueprint blueprint = new PageBlueprint(
|
||||
PageBlueprint.VERSION, PageBlueprint.RECIPE_MASTER_DETAIL,
|
||||
"eip4ai-po", "采购", "EIP4AI_PO", "采购", "EIP4AI_PO_ID", "TITLE",
|
||||
List.of(
|
||||
new PageBlueprintField("EIP4AI_PO_ID", "主键", "string", true, true, true),
|
||||
new PageBlueprintField("VERSION", "版本", "integer", true, true, true),
|
||||
new PageBlueprintField("TITLE", "标题", "string", true, true, true)),
|
||||
true, true, true, 20,
|
||||
new PageBlueprintChild("EIP4AI_PO_ITEM", "DETAILS", "ITEMNAME",
|
||||
List.of(
|
||||
new PageBlueprintField("EIP4AI_PO_ITEM_ID", "主键", "string", true, false, true),
|
||||
new PageBlueprintField("VERSION", "版本", "integer", true, false, true),
|
||||
new PageBlueprintField("CREATETIME", "创建时间", "datetime", true, false, true),
|
||||
new PageBlueprintField("UPDATEBY", "更新人", "string", true, false, true),
|
||||
new PageBlueprintField("ISACTIVE", "是否有效", "boolean", true, false, true),
|
||||
new PageBlueprintField("ITEMNAME", "物料", "string", true, false, true),
|
||||
new PageBlueprintField("QTY", "数量", "integer", false, false, true))));
|
||||
|
||||
ObjectNode crud = (ObjectNode) new PageBlueprintCompiler(MAPPER).compile(blueprint).path("body");
|
||||
ObjectNode addForm = (ObjectNode) ((ArrayNode) crud.path("headerToolbar")).get(0).path("dialog").path("body");
|
||||
ArrayNode cols = (ArrayNode) findByType((ArrayNode) addForm.path("body"), "input-table").path("columns");
|
||||
|
||||
// 子表 input-table 只剩业务列 ITEMNAME/QTY。
|
||||
assertEquals(2, cols.size(), "子表只剩业务列");
|
||||
assertEquals("ITEMNAME", cols.get(0).path("name").asText());
|
||||
assertEquals("QTY", cols.get(1).path("name").asText());
|
||||
|
||||
// 主表单也排除系统列:addForm body 里非 input-table 的控件只剩业务列 TITLE(无 主键/VERSION)。
|
||||
ArrayNode addBody = (ArrayNode) addForm.path("body");
|
||||
long masterControls = 0;
|
||||
for (int i = 0; i < addBody.size(); i++) {
|
||||
String t = addBody.get(i).path("type").asText();
|
||||
if (!"input-table".equals(t)) {
|
||||
assertEquals("TITLE", addBody.get(i).path("name").asText(), "主表单应只剩业务列 TITLE");
|
||||
masterControls++;
|
||||
}
|
||||
}
|
||||
assertEquals(1, masterControls, "主表单只 1 个业务控件");
|
||||
}
|
||||
|
||||
private static ObjectNode bodyByName(ArrayNode body, String name) {
|
||||
for (int i = 0; i < body.size(); i++) {
|
||||
if (name.equals(body.get(i).path("name").asText())) {
|
||||
|
||||
Reference in New Issue
Block a user