F2-13: 转换器 title 取 view_template.name(修 title=测试 问题)
根因:convertCrud/convertReport 等取 XML title 属性(往往为"测试"), 应取 view_template.name。 修法:convertGraded 增加 templateName 参数,BatchConvertCli 传入 view_template.name,各 convert* 方法优先用 templateName 作为 page title。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -174,7 +174,8 @@ public final class BatchConvertCli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> notes = new ArrayList<>();
|
List<String> notes = new ArrayList<>();
|
||||||
ConversionResult result = converter.convertGraded(xml, notes, pageResolver);
|
// F2-13:传 view_template.name 作为 title 来源
|
||||||
|
ConversionResult result = converter.convertGraded(xml, name, notes, pageResolver);
|
||||||
boolean gate1 = false;
|
boolean gate1 = false;
|
||||||
boolean onEventAttached = false;
|
boolean onEventAttached = false;
|
||||||
if (result.getSchema() != null) {
|
if (result.getSchema() != null) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class TemplateToAmisConverter {
|
|||||||
|
|
||||||
/** 注入 JdbcTemplate 的便捷分级入口(页面 XML 解析器走库内 view_page)。 */
|
/** 注入 JdbcTemplate 的便捷分级入口(页面 XML 解析器走库内 view_page)。 */
|
||||||
public ConversionResult convertGraded(String templateXml) {
|
public ConversionResult convertGraded(String templateXml) {
|
||||||
return convertGraded(templateXml, new ArrayList<>(), this::loadPageXml);
|
return convertGraded(templateXml, null, new ArrayList<>(), this::loadPageXml);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,6 +63,20 @@ public class TemplateToAmisConverter {
|
|||||||
*/
|
*/
|
||||||
public ConversionResult convertGraded(String templateXml, List<String> mappingNotes,
|
public ConversionResult convertGraded(String templateXml, List<String> mappingNotes,
|
||||||
Function<String, String> pageResolver) {
|
Function<String, String> pageResolver) {
|
||||||
|
return convertGraded(templateXml, null, mappingNotes, pageResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分级转换主入口(批量跑批用,含模板名称用于 title 回填)。
|
||||||
|
*
|
||||||
|
* @param templateXml view_template.xml 原文
|
||||||
|
* @param templateName view_template.name(F2-13:title 一律取此值,XML title 属性废弃)
|
||||||
|
* @param mappingNotes 映射台账累加器
|
||||||
|
* @param pageResolver pageid → view_page.xml 解析器(form EDITFORM 用;可为 null,缺则降级)
|
||||||
|
*/
|
||||||
|
public ConversionResult convertGraded(String templateXml, String templateName,
|
||||||
|
List<String> mappingNotes,
|
||||||
|
Function<String, String> pageResolver) {
|
||||||
Document doc;
|
Document doc;
|
||||||
String root;
|
String root;
|
||||||
try {
|
try {
|
||||||
@@ -74,15 +88,19 @@ public class TemplateToAmisConverter {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// F2-13:title 一律取 view_template.name,XML title 属性作降级后备
|
||||||
|
String effectiveName = (templateName != null && !templateName.isBlank())
|
||||||
|
? templateName : null;
|
||||||
|
|
||||||
ConversionResult result = new ConversionResult(root, mappingNotes);
|
ConversionResult result = new ConversionResult(root, mappingNotes);
|
||||||
try {
|
try {
|
||||||
Element rootEl = doc.getRootElement();
|
Element rootEl = doc.getRootElement();
|
||||||
switch (root) {
|
switch (root) {
|
||||||
case "crud" -> result.setSchema(convertCrud(rootEl, result));
|
case "crud" -> result.setSchema(convertCrud(rootEl, result, effectiveName));
|
||||||
case "form" -> result.setSchema(convertForm(rootEl, result, pageResolver));
|
case "form" -> result.setSchema(convertForm(rootEl, result, pageResolver, effectiveName));
|
||||||
case "tree" -> result.setSchema(convertTree(rootEl, result));
|
case "tree" -> result.setSchema(convertTree(rootEl, result, effectiveName));
|
||||||
case "report" -> result.setSchema(convertReport(rootEl, result));
|
case "report" -> result.setSchema(convertReport(rootEl, result, effectiveName));
|
||||||
case "group" -> result.setSchema(convertGroup(rootEl, result));
|
case "group" -> result.setSchema(convertGroup(rootEl, result, effectiveName));
|
||||||
default -> result.fail("不支持的根元素 <" + root + ">(非 crud/form/tree/report/group)");
|
default -> result.fail("不支持的根元素 <" + root + ">(非 crud/form/tree/report/group)");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -95,8 +113,9 @@ public class TemplateToAmisConverter {
|
|||||||
// crud(GRID 列表页)—— PoC 种子规则,强化 null-safe + 主子表识别
|
// crud(GRID 列表页)—— PoC 种子规则,强化 null-safe + 主子表识别
|
||||||
// ──────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private Map<String, Object> convertCrud(Element crud, ConversionResult result) {
|
private Map<String, Object> convertCrud(Element crud, ConversionResult result, String templateName) {
|
||||||
String title = crud.attributeValue("title", "");
|
// F2-13:title 优先取 view_template.name,XML title 属性作后备
|
||||||
|
String title = templateName != null ? templateName : crud.attributeValue("title", "");
|
||||||
String entityId = crud.attributeValue("entityid", "");
|
String entityId = crud.attributeValue("entityid", "");
|
||||||
String table = resolveTableName(entityId, result);
|
String table = resolveTableName(entityId, result);
|
||||||
|
|
||||||
@@ -253,7 +272,8 @@ public class TemplateToAmisConverter {
|
|||||||
// ──────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private Map<String, Object> convertForm(Element form, ConversionResult result,
|
private Map<String, Object> convertForm(Element form, ConversionResult result,
|
||||||
Function<String, String> pageResolver) throws Exception {
|
Function<String, String> pageResolver,
|
||||||
|
String templateName) throws Exception {
|
||||||
String entityId = form.attributeValue("entityid", "");
|
String entityId = form.attributeValue("entityid", "");
|
||||||
String table = resolveTableName(entityId, result);
|
String table = resolveTableName(entityId, result);
|
||||||
String pageId = form.attributeValue("pageid", "");
|
String pageId = form.attributeValue("pageid", "");
|
||||||
@@ -296,27 +316,29 @@ public class TemplateToAmisConverter {
|
|||||||
}
|
}
|
||||||
noteFormScripts(form, result);
|
noteFormScripts(form, result);
|
||||||
|
|
||||||
|
// F2-13:form title 也取 view_template.name
|
||||||
|
String formTitle = templateName != null ? templateName : "";
|
||||||
Map<String, Object> formSchema = new LinkedHashMap<>();
|
Map<String, Object> formSchema = new LinkedHashMap<>();
|
||||||
formSchema.put("type", "form");
|
formSchema.put("type", "form");
|
||||||
formSchema.put("title", "");
|
formSchema.put("title", formTitle);
|
||||||
formSchema.put("api", "/api/entity/" + table + "/save");
|
formSchema.put("api", "/api/entity/" + table + "/save");
|
||||||
formSchema.put("body", formItems);
|
formSchema.put("body", formItems);
|
||||||
if (!actions.isEmpty()) {
|
if (!actions.isEmpty()) {
|
||||||
formSchema.put("actions", actions);
|
formSchema.put("actions", actions);
|
||||||
}
|
}
|
||||||
return page("", formSchema);
|
return page(formTitle, formSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────
|
||||||
// tree(树 / 树+grid)
|
// tree(树 / 树+grid)
|
||||||
// ──────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private Map<String, Object> convertTree(Element tree, ConversionResult result) {
|
private Map<String, Object> convertTree(Element tree, ConversionResult result, String templateName) {
|
||||||
// type=4:树+grid 引用式(<treetemplate ref/> + <gridtemplate ref/>)
|
// type=4:树+grid 引用式(<treetemplate ref/> + <gridtemplate ref/>)
|
||||||
Element treeTemplate = tree.element("treetemplate");
|
Element treeTemplate = tree.element("treetemplate");
|
||||||
Element gridTemplate = tree.element("gridtemplate");
|
Element gridTemplate = tree.element("gridtemplate");
|
||||||
if (treeTemplate != null || gridTemplate != null) {
|
if (treeTemplate != null || gridTemplate != null) {
|
||||||
return convertTreeGrid(tree, treeTemplate, gridTemplate, result);
|
return convertTreeGrid(tree, treeTemplate, gridTemplate, result, templateName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// type=3:声明式树(含 <node entityid selectservice>)
|
// type=3:声明式树(含 <node entityid selectservice>)
|
||||||
@@ -345,12 +367,14 @@ public class TemplateToAmisConverter {
|
|||||||
} else {
|
} else {
|
||||||
result.degrade("tree 无 <node> 声明 → 空树壳");
|
result.degrade("tree 无 <node> 声明 → 空树壳");
|
||||||
}
|
}
|
||||||
String rootName = tree.attributeValue("rootname");
|
// F2-13:tree title 优先取 view_template.name
|
||||||
return page(rootName != null ? rootName : "树", treeSchema);
|
String treeTitle = templateName != null ? templateName
|
||||||
|
: (tree.attributeValue("rootname") != null ? tree.attributeValue("rootname") : "树");
|
||||||
|
return page(treeTitle, treeSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> convertTreeGrid(Element tree, Element treeTemplate, Element gridTemplate,
|
private Map<String, Object> convertTreeGrid(Element tree, Element treeTemplate, Element gridTemplate,
|
||||||
ConversionResult result) {
|
ConversionResult result, String templateName) {
|
||||||
Map<String, Object> treeSchema = new LinkedHashMap<>();
|
Map<String, Object> treeSchema = new LinkedHashMap<>();
|
||||||
treeSchema.put("type", "input-tree");
|
treeSchema.put("type", "input-tree");
|
||||||
treeSchema.put("name", "tree");
|
treeSchema.put("name", "tree");
|
||||||
@@ -375,15 +399,19 @@ public class TemplateToAmisConverter {
|
|||||||
hbox.put("items", List.of(
|
hbox.put("items", List.of(
|
||||||
Map.of("md", 3, "body", treeSchema),
|
Map.of("md", 3, "body", treeSchema),
|
||||||
Map.of("md", 9, "body", gridSchema)));
|
Map.of("md", 9, "body", gridSchema)));
|
||||||
return page("树+列表", hbox);
|
// F2-13:title 优先取 view_template.name
|
||||||
|
String treeGridTitle = templateName != null ? templateName : "树+列表";
|
||||||
|
return page(treeGridTitle, hbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────
|
||||||
// report(A 类表格式报表)—— 报表迁移方案口径
|
// report(A 类表格式报表)—— 报表迁移方案口径
|
||||||
// ──────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private Map<String, Object> convertReport(Element report, ConversionResult result) {
|
private Map<String, Object> convertReport(Element report, ConversionResult result, String templateName) {
|
||||||
String title = UiTypeMapper.firstNonBlank(report.attributeValue("title"),
|
// F2-13:title 优先取 view_template.name,XML 属性作后备
|
||||||
|
String title = templateName != null ? templateName
|
||||||
|
: UiTypeMapper.firstNonBlank(report.attributeValue("title"),
|
||||||
attrOf(report.element("search"), "reporttitle"), "报表");
|
attrOf(report.element("search"), "reporttitle"), "报表");
|
||||||
String entityId = report.attributeValue("entityid", "");
|
String entityId = report.attributeValue("entityid", "");
|
||||||
resolveTableName(entityId, result);
|
resolveTableName(entityId, result);
|
||||||
@@ -452,7 +480,7 @@ public class TemplateToAmisConverter {
|
|||||||
// group(分组容器)—— 子模板跨引用
|
// group(分组容器)—— 子模板跨引用
|
||||||
// ──────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private Map<String, Object> convertGroup(Element group, ConversionResult result) {
|
private Map<String, Object> convertGroup(Element group, ConversionResult result, String templateName) {
|
||||||
List<Map<String, Object>> tabs = new ArrayList<>();
|
List<Map<String, Object>> tabs = new ArrayList<>();
|
||||||
for (Element t : group.elements("template")) {
|
for (Element t : group.elements("template")) {
|
||||||
String tempId = t.attributeValue("tempid", "");
|
String tempId = t.attributeValue("tempid", "");
|
||||||
@@ -465,10 +493,12 @@ public class TemplateToAmisConverter {
|
|||||||
result.note("group@template " + name + "(tempid=" + tempId + ") → tab 占位(子模板跨引用)");
|
result.note("group@template " + name + "(tempid=" + tempId + ") → tab 占位(子模板跨引用)");
|
||||||
}
|
}
|
||||||
result.degrade("group 分组容器仅转 tabs 壳 → 各 tab 子模板需跨模板联动加载(本批不联动)");
|
result.degrade("group 分组容器仅转 tabs 壳 → 各 tab 子模板需跨模板联动加载(本批不联动)");
|
||||||
|
// F2-13:title 优先取 view_template.name
|
||||||
|
String groupTitle = templateName != null ? templateName : "分组";
|
||||||
Map<String, Object> tabsSchema = new LinkedHashMap<>();
|
Map<String, Object> tabsSchema = new LinkedHashMap<>();
|
||||||
tabsSchema.put("type", "tabs");
|
tabsSchema.put("type", "tabs");
|
||||||
tabsSchema.put("tabs", tabs);
|
tabsSchema.put("tabs", tabs);
|
||||||
return page("分组", tabsSchema);
|
return page(groupTitle, tabsSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user