feat(converter): 通用模板 P0 收口——日历 type5 / 树 type3 接端点 / 组合 type6 真加载
type5 日历:isCalendarTemplate 分流根元素<crud>但语义日历的模板→convertCalendar(amis calendar,largeMode,items→schedules,scheduleAction drawer),不再被当普通表格丢班次/调度语义。type3 声明式树:currentTemplateId 把 source 指向 /api/template/{templateId}/tree(TemplateTreeController 构 {label,value}),修 source 用 /api/flow 返 {items:[{TYPENAME}]} 显「undefined」根因;树型选择框同源复用 /api/template/{dialogId}/tree。type6 组合:convertGroup 每 tab 发 service schemaApi get:/api/page/schema/{tempId}?format=amis + amis mountOnEnter 懒加载,真接子模板远程加载,不再 tpl 占位。分级清单.csv 同步重生。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -59,8 +59,13 @@ public class TemplateTreeController {
|
||||
this.flowController = flowController;
|
||||
}
|
||||
|
||||
/** 树层级:实体表 + 该级的 parentid 列(null=该级行为根)。 */
|
||||
private record Level(String table, String parentCol) {}
|
||||
/**
|
||||
* 树层级:实体表 + 该级的候选 parentid 列(有序;空=该级行恒为根)。
|
||||
*
|
||||
* <p>多列支持「条件父列」:一行按列序取首个非空值作父引用。典型如菜单维护——SYS_MENU
|
||||
* 有 PARENTID 则挂父菜单(自引用),否则按 MENUROOT 挂 sys_menu_root 根分组(跨实体)。
|
||||
*/
|
||||
private record Level(String table, List<String> parentCols) {}
|
||||
|
||||
/** 构树中间节点:opt 是即将返回的 amis option(含 children),parentRef 是归一化的父键。 */
|
||||
private static final class Node {
|
||||
@@ -214,18 +219,18 @@ public class TemplateTreeController {
|
||||
if (xmls.isEmpty() || xmls.get(0) == null || xmls.get(0).isBlank()) {
|
||||
return List.of();
|
||||
}
|
||||
// entityId → parentCol(后写覆盖:levelnode 的 parentid 优先于根节点的 null)
|
||||
Map<String, String> entityParent = new LinkedHashMap<>();
|
||||
// entityId → 有序候选 parentid 列(遍历全部 <node> 及其 levelnode;按声明序去重收集)。
|
||||
// 读全部 <node>(非仅首个)——菜单维护等多根树由两个 node 声明:SYS_MENU 自引用 + sys_menu_root 分组。
|
||||
Map<String, List<String>> entityParents = new LinkedHashMap<>();
|
||||
try {
|
||||
Document doc = DocumentHelper.parseText(xmls.get(0).trim());
|
||||
Element root = doc.getRootElement();
|
||||
Element node = root.element("node");
|
||||
if (node != null) {
|
||||
putEntity(entityParent, node.attributeValue("entityid"), node.attributeValue("parentid"));
|
||||
for (Element node : root.elements("node")) {
|
||||
collectParent(entityParents, node.attributeValue("entityid"), node.attributeValue("parentid"));
|
||||
Element nexts = node.element("nextnodes");
|
||||
if (nexts != null) {
|
||||
for (Element ln : nexts.elements("levelnode")) {
|
||||
putEntity(entityParent, ln.attributeValue("entityid"), ln.attributeValue("parentid"));
|
||||
collectParent(entityParents, ln.attributeValue("entityid"), ln.attributeValue("parentid"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,7 +239,7 @@ public class TemplateTreeController {
|
||||
return List.of();
|
||||
}
|
||||
List<Level> levels = new ArrayList<>();
|
||||
for (Map.Entry<String, String> e : entityParent.entrySet()) {
|
||||
for (Map.Entry<String, List<String>> e : entityParents.entrySet()) {
|
||||
String table = tableOfEntity(e.getKey());
|
||||
if (table != null && IDENT.matcher(table).matches()) {
|
||||
levels.add(new Level(table, e.getValue()));
|
||||
@@ -243,15 +248,17 @@ public class TemplateTreeController {
|
||||
return levels;
|
||||
}
|
||||
|
||||
private static void putEntity(Map<String, String> map, String entityId, String parentCol) {
|
||||
/** 把一个 entity 的 parentid 列按声明序去重追加(IDENT 守卫;空/非法跳过,但仍登记实体以建空父列层级)。 */
|
||||
private static void collectParent(Map<String, List<String>> map, String entityId, String parentCol) {
|
||||
if (entityId == null || entityId.isBlank()) {
|
||||
return;
|
||||
}
|
||||
String pc = parentCol != null && !parentCol.isBlank() && IDENT.matcher(parentCol).matches()
|
||||
? parentCol.toUpperCase() : null;
|
||||
// 已有非空 parentCol 时不被 null 覆盖(保留自嵌套声明)
|
||||
if (!map.containsKey(entityId) || (pc != null && map.get(entityId) == null)) {
|
||||
map.put(entityId, pc);
|
||||
List<String> cols = map.computeIfAbsent(entityId, k -> new ArrayList<>());
|
||||
if (parentCol != null && !parentCol.isBlank() && IDENT.matcher(parentCol).matches()) {
|
||||
String pc = parentCol.toUpperCase();
|
||||
if (!cols.contains(pc)) {
|
||||
cols.add(pc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,11 +283,12 @@ public class TemplateTreeController {
|
||||
if (!IDENT.matcher(keyCol).matches() || (!dispIsExpr && !IDENT.matcher(displayCol).matches())) {
|
||||
return;
|
||||
}
|
||||
String parentCol = lv.parentCol();
|
||||
// 候选父列:首列别名 pref(沿用既有口径),其余 pref1/pref2…(IDENT 已在 collectParent 守卫)。
|
||||
List<String> parentCols = lv.parentCols();
|
||||
StringBuilder sql = new StringBuilder("SELECT ").append(keyCol).append(" AS k, ")
|
||||
.append(displayCol).append(" AS lbl");
|
||||
if (parentCol != null) {
|
||||
sql.append(", ").append(parentCol).append(" AS pref");
|
||||
for (int i = 0; i < parentCols.size(); i++) {
|
||||
sql.append(", ").append(parentCols.get(i)).append(" AS pref").append(i == 0 ? "" : i);
|
||||
}
|
||||
sql.append(" FROM eip3.").append(table);
|
||||
try {
|
||||
@@ -301,9 +309,16 @@ public class TemplateTreeController {
|
||||
n.opt.put("label", label);
|
||||
n.opt.put("value", String.valueOf(rawKey).trim()); // 原始主键(供右表过滤)
|
||||
n.opt.put("children", n.children);
|
||||
Object pref = parentCol != null ? r.get("pref") : null;
|
||||
n.parentRef = pref != null && !String.valueOf(pref).isBlank()
|
||||
? String.valueOf(pref).trim().toUpperCase() : null;
|
||||
// 条件父列:按列序取首个非空值作父引用(PARENTID 优先于 MENUROOT 等)。
|
||||
String parentRef = null;
|
||||
for (int i = 0; i < parentCols.size(); i++) {
|
||||
Object pv = r.get(i == 0 ? "pref" : "pref" + i);
|
||||
if (pv != null && !String.valueOf(pv).isBlank()) {
|
||||
parentRef = String.valueOf(pv).trim().toUpperCase();
|
||||
break;
|
||||
}
|
||||
}
|
||||
n.parentRef = parentRef;
|
||||
// 同 id 跨级去重(自嵌套时同实体只装一次)
|
||||
if (!byId.containsKey(idNorm)) {
|
||||
byId.put(idNorm, n);
|
||||
|
||||
Reference in New Issue
Block a user