feat(meta): 建实体支持「所属分类」entitytype + GET /api/meta/entity-types 分类目录
用户反馈建模器缺「实体所属分类」。根因:createEntity 克隆 SYS_USERGROUP → 新实体继承其 entitytype(错分类)。修:createEntity 接 entitytype(SYS_ENTITYTYPE.id)覆盖克隆值; 新增 GET /api/meta/entity-types 列 221 个分类供建模器选择器。live 验:建实体 entitytype 正确落库。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -89,6 +89,12 @@ public class MetaController {
|
|||||||
entityMap.put("TABLENAME", table);
|
entityMap.put("TABLENAME", table);
|
||||||
entityMap.put("NAME", String.valueOf(req.getOrDefault("name", table)));
|
entityMap.put("NAME", String.valueOf(req.getOrDefault("name", table)));
|
||||||
entityMap.put("DESCRIPTION", resolveDescription(req));
|
entityMap.put("DESCRIPTION", resolveDescription(req));
|
||||||
|
// 所属分类:调用方指定 entitytype(SYS_ENTITYTYPE.id) 时覆盖克隆源(SYS_USERGROUP)的分类,
|
||||||
|
// 否则保留克隆值(向后兼容)。建模器应传入正确分类,避免新实体误归到「用户组」分类。
|
||||||
|
Object entityType = req.get("entitytype");
|
||||||
|
if (entityType != null && !String.valueOf(entityType).isBlank()) {
|
||||||
|
entityMap.put("ENTITYTYPE", String.valueOf(entityType).trim());
|
||||||
|
}
|
||||||
GeneralPOJO newEntity = (GeneralPOJO) dataDicService.save(entityMap, ctx);
|
GeneralPOJO newEntity = (GeneralPOJO) dataDicService.save(entityMap, ctx);
|
||||||
String entityId = newEntity.get_ID();
|
String entityId = newEntity.get_ID();
|
||||||
|
|
||||||
@@ -183,6 +189,24 @@ public class MetaController {
|
|||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "实体分类目录:列出 SYS_ENTITYTYPE(供建模器「所属分类」选择器)")
|
||||||
|
@GetMapping("/api/meta/entity-types")
|
||||||
|
public Map<String, Object> entityTypes() {
|
||||||
|
List<Map<String, Object>> data = jdbcTemplate.query(
|
||||||
|
"SELECT TRIM(SYS_ENTITYTYPE_ID) AS ID, NAME FROM SYS_ENTITYTYPE "
|
||||||
|
+ "WHERE ISACTIVE=1 ORDER BY NAME",
|
||||||
|
(rs, i) -> {
|
||||||
|
Map<String, Object> m = new LinkedHashMap<>();
|
||||||
|
m.put("id", rs.getString("ID"));
|
||||||
|
m.put("name", rs.getString("NAME"));
|
||||||
|
return m;
|
||||||
|
});
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("status", 0);
|
||||||
|
resp.put("data", data);
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "列出某表的列(类型/显示名)并标出引用列目标表与显示列(建模器/recipe 用)")
|
@Operation(summary = "列出某表的列(类型/显示名)并标出引用列目标表与显示列(建模器/recipe 用)")
|
||||||
@GetMapping("/api/meta/entity/{table}/attributes")
|
@GetMapping("/api/meta/entity/{table}/attributes")
|
||||||
public Map<String, Object> attributes(@PathVariable String table) {
|
public Map<String, Object> attributes(@PathVariable String table) {
|
||||||
|
|||||||
@@ -125,4 +125,23 @@ class MetaCatalogControllerTest {
|
|||||||
assertEquals("string", title.get("type"));
|
assertEquals("string", title.get("type"));
|
||||||
assertTrue(title.get("referenceTable") == null);
|
assertTrue(title.get("referenceTable") == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("entityTypes() 返回 SYS_ENTITYTYPE 分类目录 {id,name}(建模器「所属分类」数据源)")
|
||||||
|
void entityTypesReturnsCatalog() {
|
||||||
|
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||||
|
Map<String, Object> row = new LinkedHashMap<>();
|
||||||
|
row.put("id", "t-1");
|
||||||
|
row.put("name", "OA 办公");
|
||||||
|
when(jdbc.query(contains("SYS_ENTITYTYPE"), (RowMapper) org.mockito.ArgumentMatchers.any()))
|
||||||
|
.thenReturn(List.of(row));
|
||||||
|
|
||||||
|
Map<String, Object> resp = newController(jdbc).entityTypes();
|
||||||
|
|
||||||
|
assertEquals(0, resp.get("status"));
|
||||||
|
List<Map<String, Object>> data = (List<Map<String, Object>>) resp.get("data");
|
||||||
|
assertEquals(1, data.size());
|
||||||
|
assertEquals("t-1", data.get(0).get("id"));
|
||||||
|
assertEquals("OA 办公", data.get(0).get("name"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user