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);
|
||||
|
||||
@@ -98,6 +98,67 @@ class TemplateTreeControllerTest {
|
||||
assertEquals("C2", c2List.get(0).get("value"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单维护树(b38737be 形态):两个 <node> 根 + SYS_MENU 条件父列。
|
||||
* SYS_MENU 行有 PARENTID 则挂父菜单(自引用),否则按 MENUROOT 挂 sys_menu_root 根分组。
|
||||
* 期望 3 级:根分组(信息站) → 目录(新闻管理) → 叶子(查看新闻)。修「菜单维护只显示 2 级」。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("构树:菜单双 node + 条件父列(PARENTID/MENUROOT) → 3 级 根分组>目录>叶子")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void tree_菜单条件父列三级() {
|
||||
JdbcTemplate j = mock(JdbcTemplate.class);
|
||||
TemplateTreeController c = new TemplateTreeController(j, mock(FlowController.class));
|
||||
String ref = "menu-ref";
|
||||
// 两个 node:node1=SYS_MENU(自引用 PARENTID, 可编辑);node2=sys_menu_root(根, levelnode 按 MENUROOT 挂 SYS_MENU)
|
||||
String xml = "<tree isshowroot='false'>"
|
||||
+ "<node entityid='EM' isroot='false' edit='true'>"
|
||||
+ "<nextnodes><levelnode entityid='EM' parentid='PARENTID'/></nextnodes></node>"
|
||||
+ "<node entityid='ER' isroot='true' edit='false'>"
|
||||
+ "<nextnodes><levelnode entityid='EM' parentid='MENUROOT'/></nextnodes></node>"
|
||||
+ "</tree>";
|
||||
when(j.queryForList(contains("view_template"), eq(String.class), eq(ref))).thenReturn(List.of(xml));
|
||||
when(j.queryForList(contains("tablename"), eq(String.class), eq("EM"))).thenReturn(List.of("SYS_MENU"));
|
||||
when(j.queryForList(contains("tablename"), eq(String.class), eq("ER"))).thenReturn(List.of("SYS_MENU_ROOT"));
|
||||
when(j.queryForList(contains("isentitydisplay"), eq(String.class), eq("SYS_MENU"))).thenReturn(List.of("NAME"));
|
||||
when(j.queryForList(contains("isentitydisplay"), eq(String.class), eq("SYS_MENU_ROOT"))).thenReturn(List.of("NAME"));
|
||||
when(j.queryForList(contains("information_schema"), eq(String.class), eq("SYS_MENU")))
|
||||
.thenReturn(List.of("SYS_MENU_ID", "NAME", "PARENTID", "MENUROOT"));
|
||||
when(j.queryForList(contains("information_schema"), eq(String.class), eq("SYS_MENU_ROOT")))
|
||||
.thenReturn(List.of("SYS_MENU_ROOT_ID", "NAME"));
|
||||
// SYS_MENU 行:目录(PARENTID 空, MENUROOT=R1) + 叶子(PARENTID=DIR1)
|
||||
List<Map<String, Object>> menuRows = new ArrayList<>();
|
||||
menuRows.add(menuRow("DIR1", "新闻管理", null, "R1"));
|
||||
menuRows.add(menuRow("LEAF1", "查看新闻", "DIR1", null));
|
||||
when((List) j.queryForList(contains("SYS_MENU_ID AS k"))).thenReturn((List) menuRows);
|
||||
// sys_menu_root 行:R1=信息站
|
||||
List<Map<String, Object>> rootRows = new ArrayList<>();
|
||||
rootRows.add(row("R1", "信息站", null));
|
||||
when((List) j.queryForList(contains("SYS_MENU_ROOT_ID AS k"))).thenReturn((List) rootRows);
|
||||
|
||||
Map<String, Object> resp = c.tree(ref);
|
||||
Map<String, Object> data = (Map<String, Object>) resp.get("data");
|
||||
List<Map<String, Object>> roots = (List<Map<String, Object>>) data.get("options");
|
||||
assertEquals(1, roots.size(), "仅 R1(信息站) 为根");
|
||||
assertEquals("R1", roots.get(0).get("value"));
|
||||
List<Map<String, Object>> dirs = (List<Map<String, Object>>) roots.get(0).get("children");
|
||||
assertEquals(1, dirs.size(), "信息站下 1 个目录");
|
||||
assertEquals("DIR1", dirs.get(0).get("value"));
|
||||
List<Map<String, Object>> leaves = (List<Map<String, Object>>) dirs.get(0).get("children");
|
||||
assertEquals(1, leaves.size(), "新闻管理下 1 个叶子");
|
||||
assertEquals("LEAF1", leaves.get(0).get("value"));
|
||||
}
|
||||
|
||||
/** 菜单行:k/lbl + PARENTID(pref) + MENUROOT(pref1) 两个候选父列。 */
|
||||
private static Map<String, Object> menuRow(String k, String lbl, String parentid, String menuroot) {
|
||||
Map<String, Object> m = new LinkedHashMap<>();
|
||||
m.put("k", k);
|
||||
m.put("lbl", lbl);
|
||||
m.put("pref", parentid); // 首个候选父列 PARENTID
|
||||
m.put("pref1", menuroot); // 次候选父列 MENUROOT
|
||||
return m;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("子树聚合:点父级 P1 → [P1,C1,C2];点中间 C1 → [C1,C2]")
|
||||
void subtree_展开后代() {
|
||||
|
||||
Reference in New Issue
Block a user