F2-9: 选择窗完整化——searchable搜索、树形模板picker修复、部门树amis-tree端点
- UiTypeMapper: SelectDialog/MultiSelectDialog 生成 searchable:true + source 带 ?q=\${term}&page&perPage(F2-9搜索)
- PickerController: resolveByViewTemplate 支持 <tree> 根元素,取第一个 <node entityid> 解析实体(修复138b7ca7树形模板返回"非法实体")
- OrgController: 新增 GET /api/org/depart-tree/{orgId}/amis-tree,返回 {label,value,children} 嵌套格式供 amis select-tree 消费
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -111,6 +111,59 @@ public class OrgController {
|
||||
return okList(rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* F2-9:部门树——amis tree-select 消费格式。
|
||||
*
|
||||
* <p>返回 {@code [{label, value, children:[...]}]} 嵌套结构,供 amis {@code select-tree} 的
|
||||
* {@code source=/api/org/depart-tree/{orgId}/amis-tree} 直接消费。
|
||||
* path 字段即部门名称(VIEW_DEPART_TREE.path 无父路径前缀时为叶节点名),parentid 空串视为根节点。
|
||||
*/
|
||||
@Operation(summary = "部门树(amis tree-select 格式,{label,value,children}嵌套)")
|
||||
@GetMapping("/api/org/depart-tree/{orgId}/amis-tree")
|
||||
public Map<String, Object> departTreeAmis(
|
||||
@Parameter(description = "SYS_ORG.SYS_ORG_ID 公司 ID") @PathVariable String orgId) {
|
||||
List<Map<String, Object>> flat = jdbcTemplate.query(
|
||||
"SELECT trim(view_depart_id) AS id, COALESCE(trim(parentid),'') AS parentid, path, seq "
|
||||
+ "FROM eip3.view_depart_tree WHERE orgid = ? ORDER BY seq",
|
||||
(rs, i) -> {
|
||||
Map<String, Object> m = new LinkedHashMap<>();
|
||||
m.put("id", rs.getString("id"));
|
||||
m.put("parentId", rs.getString("parentid"));
|
||||
// path 字段为"总经理室 > 秘书室"格式;取最后一段作为 label
|
||||
String path = rs.getString("path");
|
||||
String label = path;
|
||||
if (path != null && path.contains(">")) {
|
||||
label = path.substring(path.lastIndexOf(">") + 1).trim();
|
||||
}
|
||||
m.put("label", label);
|
||||
m.put("value", rs.getString("id"));
|
||||
return m;
|
||||
}, orgId);
|
||||
// 构建嵌套树
|
||||
Map<String, Map<String, Object>> byId = new java.util.LinkedHashMap<>();
|
||||
for (Map<String, Object> node : flat) {
|
||||
node.put("children", new java.util.ArrayList<>());
|
||||
byId.put((String) node.get("id"), node);
|
||||
}
|
||||
List<Map<String, Object>> roots = new java.util.ArrayList<>();
|
||||
for (Map<String, Object> node : flat) {
|
||||
String pid = (String) node.get("parentId");
|
||||
if (pid == null || pid.isBlank()) {
|
||||
roots.add(node);
|
||||
} else {
|
||||
Map<String, Object> parent = byId.get(pid);
|
||||
if (parent != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> children = (List<Map<String, Object>>) parent.get("children");
|
||||
children.add(node);
|
||||
} else {
|
||||
roots.add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
return okData(roots);
|
||||
}
|
||||
|
||||
@Operation(summary = "某公司的部门树(VIEW_DEPART_TREE 层级,经引擎 organizationService.getDepartTreeByOrgId)")
|
||||
@GetMapping("/api/org/depart-tree/{orgId}")
|
||||
public Map<String, Object> departTree(
|
||||
|
||||
@@ -207,7 +207,23 @@ public class PickerController {
|
||||
String entityId;
|
||||
try {
|
||||
Document doc = DocumentHelper.parseText(xml.trim());
|
||||
entityId = doc.getRootElement().attributeValue("entityid");
|
||||
org.dom4j.Element root = doc.getRootElement();
|
||||
entityId = root.attributeValue("entityid");
|
||||
// F2-9:树形模板(<tree> 根无 entityid)→ 取第一个 <node entityid="..."> 的 entityid
|
||||
// 树形模板按节点顺序取根节点(isroot="true")或第一个 node,代表弹窗数据源实体
|
||||
if ((entityId == null || entityId.isBlank()) && "tree".equals(root.getName())) {
|
||||
// 优先取 isroot="true" 的节点
|
||||
for (org.dom4j.Element node : root.elements("node")) {
|
||||
if ("true".equalsIgnoreCase(node.attributeValue("isroot"))) {
|
||||
entityId = node.attributeValue("entityid");
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 回退取第一个 node
|
||||
if ((entityId == null || entityId.isBlank()) && !root.elements("node").isEmpty()) {
|
||||
entityId = root.elements("node").get(0).attributeValue("entityid");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user