fix: restore entity type filtering for treegrid views
Some checks failed
ci / build-test-parity (push) Has been cancelled
Some checks failed
ci / build-test-parity (push) Has been cancelled
This commit is contained in:
@@ -50,6 +50,11 @@ public class TemplateTreeController {
|
|||||||
private static final Pattern IDENT = Pattern.compile("^[A-Za-z0-9_]+$");
|
private static final Pattern IDENT = Pattern.compile("^[A-Za-z0-9_]+$");
|
||||||
private static final int MAX_NODES = 5000;
|
private static final int MAX_NODES = 5000;
|
||||||
private static final String[] NAME_FALLBACKS = {"NAME", "SORT_NAME", "FULLNAME", "TITLE", "SUBJECT", "DISPLAYNAME"};
|
private static final String[] NAME_FALLBACKS = {"NAME", "SORT_NAME", "FULLNAME", "TITLE", "SUBJECT", "DISPLAYNAME"};
|
||||||
|
private static final Map<String, EntityListJoin> ENTITYS_LIST_JOINS = Map.of(
|
||||||
|
"VIEW_TEMPLATE", new EntityListJoin("VIEW_TEMPLATE_ID", "VIEW_TEMPLATEENTITY", "TEMPLATEID", "ENTITYID"),
|
||||||
|
"VIEW_PAGE", new EntityListJoin("VIEW_PAGE_ID", "VIEW_PAGEENTITY", "PAGEID", "ENTITYID"),
|
||||||
|
"SYS_SCHEDULEJOB", new EntityListJoin("SYS_SCHEDULEJOB_ID", "SYS_SCHEDULEJOBENTITY",
|
||||||
|
"SYS_SCHEDULEJOBID", "SYS_ENTITYID"));
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final FlowController flowController;
|
private final FlowController flowController;
|
||||||
@@ -67,6 +72,8 @@ public class TemplateTreeController {
|
|||||||
*/
|
*/
|
||||||
private record Level(String table, List<String> parentCols) {}
|
private record Level(String table, List<String> parentCols) {}
|
||||||
|
|
||||||
|
private record EntityListJoin(String idColumn, String joinTable, String ownerColumn, String entityColumn) {}
|
||||||
|
|
||||||
/** 构树中间节点:opt 是即将返回的 amis option(含 children),parentRef 是归一化的父键。 */
|
/** 构树中间节点:opt 是即将返回的 amis option(含 children),parentRef 是归一化的父键。 */
|
||||||
private static final class Node {
|
private static final class Node {
|
||||||
final Map<String, Object> opt = new LinkedHashMap<>();
|
final Map<String, Object> opt = new LinkedHashMap<>();
|
||||||
@@ -143,7 +150,15 @@ public class TemplateTreeController {
|
|||||||
ids = List.of(node.trim()); // 退化为精确匹配自身,绝不放空成「全部」
|
ids = List.of(node.trim()); // 退化为精确匹配自身,绝不放空成「全部」
|
||||||
}
|
}
|
||||||
if (!ids.isEmpty()) {
|
if (!ids.isEmpty()) {
|
||||||
body.put(rcol, ids); // List → 引擎 get_SearchWhereClause 构 IN(已转义)
|
String tableUpper = gridTable.toUpperCase();
|
||||||
|
String rcolUpper = rcol.toUpperCase();
|
||||||
|
EntityListJoin join = ENTITYS_LIST_JOINS.get(tableUpper);
|
||||||
|
if ("ENTITYTYPE".equals(rcolUpper) && join != null) {
|
||||||
|
List<String> rowIds = rowIdsByEntityTypes(join, ids);
|
||||||
|
body.put(join.idColumn(), rowIds.isEmpty() ? List.of("__EIP4_NO_MATCH__") : rowIds);
|
||||||
|
} else {
|
||||||
|
body.put(rcolUpper, ids); // List → 引擎 get_SearchWhereClause 构 IN(已转义)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (page != null) {
|
if (page != null) {
|
||||||
@@ -161,6 +176,38 @@ public class TemplateTreeController {
|
|||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能/视图/定时任务三页的老 engineclass 并不按右表物理列 {@code ENTITYTYPE} 过滤;源码实际是
|
||||||
|
* {@code setDataFilter("ENTITYS" -> {"ENTITYTYPE": treeNode})}。这里把伪列过滤翻译成主键 IN:
|
||||||
|
* 关联表 → SYS_ENTITY → ENTITYTYPE 属于所选子树。
|
||||||
|
*/
|
||||||
|
private List<String> rowIdsByEntityTypes(EntityListJoin join, List<String> entityTypeIds) {
|
||||||
|
if (entityTypeIds == null || entityTypeIds.isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
List<String> params = new ArrayList<>();
|
||||||
|
for (String id : entityTypeIds) {
|
||||||
|
if (id != null && !id.isBlank()) {
|
||||||
|
params.add(id.trim().toUpperCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (params.isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
String placeholders = String.join(",", java.util.Collections.nCopies(params.size(), "?"));
|
||||||
|
String sql = "SELECT DISTINCT j." + join.ownerColumn()
|
||||||
|
+ " FROM eip3." + join.joinTable() + " j"
|
||||||
|
+ " JOIN eip3.SYS_ENTITY e ON UPPER(e.SYS_ENTITY_ID) = UPPER(j." + join.entityColumn() + ")"
|
||||||
|
+ " WHERE UPPER(e.ENTITYTYPE) IN (" + placeholders + ")";
|
||||||
|
try {
|
||||||
|
return jdbcTemplate.queryForList(sql, String.class, params.toArray());
|
||||||
|
} catch (DataAccessException ex) {
|
||||||
|
log.warn("[TREEGRID] ENTITYS 关联过滤失败 table={} owner={}: {}",
|
||||||
|
join.joinTable(), join.ownerColumn(), ex.getMessage());
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 给 treegrid 右表响应每行补 {@code _label}(= 网格实体显示列值),供 type=4 选择框 picker
|
* 给 treegrid 右表响应每行补 {@code _label}(= 网格实体显示列值),供 type=4 选择框 picker
|
||||||
* ({@code labelField=_label})显选中项人可读名。显示列复用 {@link #displayColumn}(与左树节点 label 同源);
|
* ({@code labelField=_label})显选中项人可读名。显示列复用 {@link #displayColumn}(与左树节点 label 同源);
|
||||||
|
|||||||
@@ -197,6 +197,25 @@ class TemplateTreeControllerTest {
|
|||||||
assertEquals("10", body.get("perPage"));
|
assertEquals("10", body.get("perPage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("treegrid 端点:VIEW_TEMPLATE 伪 ENTITYTYPE → 关联 ENTITYS 转主键 IN")
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
void treeGrid_实体分类伪列转关联表主键过滤() {
|
||||||
|
when((List) jdbc.queryForList(contains("FROM eip3.VIEW_TEMPLATEENTITY"), eq(String.class), any(Object[].class)))
|
||||||
|
.thenReturn(List.of("TPL1", "TPL2"));
|
||||||
|
when(flow.executePost(eq("VIEW_TEMPLATE_SEARCH"), any(), any()))
|
||||||
|
.thenReturn(ResponseEntity.ok(Map.of("status", 0)));
|
||||||
|
|
||||||
|
controller.treeGrid(TREE_REF, "VIEW_TEMPLATE", "ENTITYTYPE", "P1", "1", "10", Map.of());
|
||||||
|
|
||||||
|
ArgumentCaptor<Map<String, Object>> cap = ArgumentCaptor.forClass(Map.class);
|
||||||
|
verify(flow).executePost(eq("VIEW_TEMPLATE_SEARCH"), any(), cap.capture());
|
||||||
|
Map<String, Object> body = cap.getValue();
|
||||||
|
assertEquals(List.of("TPL1", "TPL2"), body.get("VIEW_TEMPLATE_ID"),
|
||||||
|
"ENTITYTYPE 伪列应翻译成 VIEW_TEMPLATE_ID IN,而不是把不存在的 ENTITYTYPE 交给搜索流");
|
||||||
|
assertFalse(body.containsKey("ENTITYTYPE"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("treegrid 端点:查询过滤参数透传给搜索流(IDENT 白名单),非法列名跳过")
|
@DisplayName("treegrid 端点:查询过滤参数透传给搜索流(IDENT 白名单),非法列名跳过")
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
Reference in New Issue
Block a user