feat: add AI tree CRUD recipe
This commit is contained in:
@@ -9,5 +9,16 @@ public record AiFeatureRequest(
|
||||
String entityName,
|
||||
String templateId,
|
||||
String menuName,
|
||||
List<AiFeatureField> fields) {
|
||||
List<AiFeatureField> fields,
|
||||
String pageRecipe) {
|
||||
|
||||
public AiFeatureRequest(String objective,
|
||||
String featureName,
|
||||
String tableName,
|
||||
String entityName,
|
||||
String templateId,
|
||||
String menuName,
|
||||
List<AiFeatureField> fields) {
|
||||
this(objective, featureName, tableName, entityName, templateId, menuName, fields, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,10 +81,12 @@ public class AiFeatureDraftGenerator {
|
||||
private PageBlueprint pageBlueprint(FeatureSpec spec) {
|
||||
List<PageBlueprintField> fields = new ArrayList<>();
|
||||
for (FieldSpec field : spec.fields()) {
|
||||
boolean treeParentField = PageBlueprint.RECIPE_TREE_CRUD.equals(spec.pageRecipe())
|
||||
&& "PARENTID".equals(field.column());
|
||||
fields.add(new PageBlueprintField(field.column(), field.label(), field.type(),
|
||||
field.required(), true, true));
|
||||
field.required(), !treeParentField, true));
|
||||
}
|
||||
return new PageBlueprint(PageBlueprint.VERSION, PageBlueprint.RECIPE_MAINTENANCE_CRUD,
|
||||
return new PageBlueprint(PageBlueprint.VERSION, spec.pageRecipe(),
|
||||
spec.templateId(), spec.featureName(), spec.tableName(), spec.entityName(),
|
||||
spec.tableName() + "_ID", displayColumn(spec), fields,
|
||||
true, true, true, 20);
|
||||
@@ -129,7 +131,12 @@ public class AiFeatureDraftGenerator {
|
||||
root.put("publishTarget", "local-smoke");
|
||||
ArrayNode tests = root.putArray("smokeTests");
|
||||
addSmoke(tests, "page-schema", "GET", "/api/page/schema/" + spec.templateId(), 200);
|
||||
addSmoke(tests, "entity-list", "GET", "/api/entity/" + spec.tableName() + "/list?page=1&perPage=20", 200);
|
||||
if (PageBlueprint.RECIPE_TREE_CRUD.equals(spec.pageRecipe())) {
|
||||
addSmoke(tests, "entity-tree", "GET", "/api/entity/" + spec.tableName()
|
||||
+ "/tree?parentKey=PARENTID&idKey=" + spec.tableName() + "_ID&perPage=2000", 200);
|
||||
} else {
|
||||
addSmoke(tests, "entity-list", "GET", "/api/entity/" + spec.tableName() + "/list?page=1&perPage=20", 200);
|
||||
}
|
||||
addSmoke(tests, "flow-search", "GET", "/api/flow/" + spec.tableName() + "_SEARCH?page=1&perPage=20", 200);
|
||||
ObjectNode create = addSmoke(tests, "entity-create", "POST",
|
||||
"/api/entity/" + spec.tableName() + "/save", 200);
|
||||
@@ -152,7 +159,9 @@ public class AiFeatureDraftGenerator {
|
||||
private ObjectNode sampleEntityBody(FeatureSpec spec) {
|
||||
ObjectNode body = objectMapper.createObjectNode();
|
||||
for (FieldSpec field : spec.fields()) {
|
||||
switch (field.type()) {
|
||||
if ("PARENTID".equals(field.column())) {
|
||||
body.put(field.column(), "");
|
||||
} else switch (field.type()) {
|
||||
case "integer" -> body.put(field.column(), 1);
|
||||
case "number" -> body.put(field.column(), 1.0);
|
||||
case "date" -> body.put(field.column(), "2026-01-01");
|
||||
@@ -173,11 +182,12 @@ public class AiFeatureDraftGenerator {
|
||||
String entityName = firstText(request == null ? null : request.entityName(), feature, table);
|
||||
String templateId = normalizeTemplateId(request == null ? null : request.templateId(), table);
|
||||
String menuName = firstText(request == null ? null : request.menuName(), feature);
|
||||
List<FieldSpec> fields = normalizeFields(request == null ? null : request.fields());
|
||||
return new FeatureSpec(feature, table, entityName, templateId, menuName, fields);
|
||||
String pageRecipe = normalizePageRecipe(request == null ? null : request.pageRecipe());
|
||||
List<FieldSpec> fields = normalizeFields(request == null ? null : request.fields(), pageRecipe);
|
||||
return new FeatureSpec(feature, table, entityName, templateId, menuName, pageRecipe, fields);
|
||||
}
|
||||
|
||||
private List<FieldSpec> normalizeFields(List<AiFeatureField> input) {
|
||||
private List<FieldSpec> normalizeFields(List<AiFeatureField> input, String pageRecipe) {
|
||||
List<AiFeatureField> raw = input == null ? List.of() : input;
|
||||
List<FieldSpec> out = new ArrayList<>();
|
||||
Set<String> seen = new LinkedHashSet<>();
|
||||
@@ -195,9 +205,24 @@ public class AiFeatureDraftGenerator {
|
||||
out.add(new FieldSpec("NAME", "名称", "string", 100, true));
|
||||
out.add(new FieldSpec("DESCRIPTION", "描述", "string", 500, false));
|
||||
}
|
||||
if (PageBlueprint.RECIPE_TREE_CRUD.equals(pageRecipe) && seen.add("PARENTID")) {
|
||||
out.add(new FieldSpec("PARENTID", "上级", "string", 64, false));
|
||||
}
|
||||
return List.copyOf(out);
|
||||
}
|
||||
|
||||
private static String normalizePageRecipe(String raw) {
|
||||
String recipe = raw == null ? "" : raw.trim();
|
||||
if (recipe.isBlank()) {
|
||||
return PageBlueprint.RECIPE_MAINTENANCE_CRUD;
|
||||
}
|
||||
if (PageBlueprint.RECIPE_MAINTENANCE_CRUD.equals(recipe)
|
||||
|| PageBlueprint.RECIPE_TREE_CRUD.equals(recipe)) {
|
||||
return recipe;
|
||||
}
|
||||
throw new IllegalArgumentException("Unsupported pageRecipe: " + recipe);
|
||||
}
|
||||
|
||||
private static String normalizeTable(String raw, String seed) {
|
||||
String table = raw == null ? "" : raw.trim().toUpperCase(Locale.ROOT);
|
||||
table = table.replaceAll("[^A-Z0-9_]", "_").replaceAll("_+", "_");
|
||||
@@ -302,6 +327,7 @@ public class AiFeatureDraftGenerator {
|
||||
String entityName,
|
||||
String templateId,
|
||||
String menuName,
|
||||
String pageRecipe,
|
||||
List<FieldSpec> fields) {
|
||||
}
|
||||
|
||||
|
||||
@@ -6,35 +6,35 @@ compiler: com.eip4.platform.metadata.schema.blueprint.PageBlueprintCompiler
|
||||
amis:
|
||||
rootType: page
|
||||
body:
|
||||
- type: crud
|
||||
syncLocation: false
|
||||
perPage: 20
|
||||
apiPattern: /api/entity/{tableName}/list?page=${page}&perPage=${perPage}
|
||||
headerToolbar:
|
||||
- addButton:
|
||||
label: 新增
|
||||
level: primary
|
||||
icon: fa fa-plus
|
||||
type: crud
|
||||
syncLocation: false
|
||||
perPage: 20
|
||||
apiPattern: /api/entity/{tableName}/list?page=${page}&perPage=${perPage}
|
||||
headerToolbar:
|
||||
- addButton:
|
||||
label: 新增
|
||||
level: primary
|
||||
icon: fa fa-plus
|
||||
actionType: dialog
|
||||
formApiPattern: post:/api/entity/{tableName}/save
|
||||
- pagination
|
||||
footerToolbar:
|
||||
- statistics
|
||||
- pagination
|
||||
operationColumn:
|
||||
label: 操作
|
||||
width: 180
|
||||
actions:
|
||||
- edit:
|
||||
level: link
|
||||
actionType: dialog
|
||||
formApiPattern: post:/api/entity/{tableName}/save
|
||||
- pagination
|
||||
footerToolbar:
|
||||
- statistics
|
||||
- pagination
|
||||
operationColumn:
|
||||
label: 操作
|
||||
width: 180
|
||||
actions:
|
||||
- edit:
|
||||
level: link
|
||||
actionType: dialog
|
||||
formApiPattern: post:/api/entity/{tableName}/save
|
||||
- delete:
|
||||
level: link
|
||||
className: text-danger
|
||||
actionType: ajax
|
||||
confirmText: 确认删除该记录?
|
||||
apiPattern: /api/entity/{tableName}/delete
|
||||
- delete:
|
||||
level: link
|
||||
className: text-danger
|
||||
actionType: ajax
|
||||
confirmText: 确认删除该记录?
|
||||
apiPattern: /api/entity/{tableName}/delete
|
||||
fieldMappings:
|
||||
string: input-text
|
||||
integer: input-number
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
schemaVersion: 1
|
||||
recipe: tree-crud-v1
|
||||
title: EIP4 tree CRUD page
|
||||
purpose: 自引用层级实体维护页,覆盖树形列表、新增顶级、加子项、编辑、删除。
|
||||
compiler: com.eip4.platform.metadata.schema.blueprint.PageBlueprintCompiler
|
||||
requirements:
|
||||
parentField: PARENTID
|
||||
childrenColumnName: children
|
||||
amis:
|
||||
rootType: page
|
||||
body:
|
||||
type: crud
|
||||
syncLocation: false
|
||||
childrenColumnName: children
|
||||
apiPattern: /api/entity/{tableName}/tree?parentKey=PARENTID&idKey={primaryKey}&perPage=2000
|
||||
headerToolbar:
|
||||
- addRootButton:
|
||||
labelPattern: 新增顶级{entityName}
|
||||
level: primary
|
||||
icon: fa fa-plus
|
||||
actionType: dialog
|
||||
formApiPattern: post:/api/entity/{tableName}/save
|
||||
- reloadButton:
|
||||
label: 刷新
|
||||
level: link
|
||||
icon: fa fa-refresh
|
||||
actionType: reload
|
||||
targetPattern: "{crudName}"
|
||||
footerToolbar: []
|
||||
operationColumn:
|
||||
label: 操作
|
||||
width: 240
|
||||
actions:
|
||||
- addChild:
|
||||
labelPattern: 加子{entityName}
|
||||
level: link
|
||||
actionType: dialog
|
||||
parentBinding: PARENTID=${primaryKey}
|
||||
formApiPattern: post:/api/entity/{tableName}/save
|
||||
- edit:
|
||||
level: link
|
||||
actionType: dialog
|
||||
formApiPattern: post:/api/entity/{tableName}/save
|
||||
- delete:
|
||||
level: link
|
||||
className: text-danger
|
||||
actionType: ajax
|
||||
confirmText: 确认删除该记录?
|
||||
apiPattern: /api/entity/{tableName}/delete
|
||||
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
|
||||
Reference in New Issue
Block a user