feat(meta): GET /api/meta/entities 实体目录端点(引用列选择器数据源)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -147,6 +148,25 @@ public class MetaController {
|
||||
return resp;
|
||||
}
|
||||
|
||||
@Operation(summary = "实体目录:列出 ISACTIVE=1 且 ISVIEW=0 的实体(供引用列选择器)")
|
||||
@GetMapping("/api/meta/entities")
|
||||
public Map<String, Object> entities() {
|
||||
List<Map<String, Object>> data = jdbcTemplate.query(
|
||||
"SELECT SYS_ENTITY_ID, TABLENAME, NAME FROM SYS_ENTITY "
|
||||
+ "WHERE ISACTIVE=1 AND ISVIEW=0 ORDER BY TABLENAME",
|
||||
(rs, i) -> {
|
||||
Map<String, Object> m = new LinkedHashMap<>();
|
||||
m.put("entityId", rs.getString("SYS_ENTITY_ID"));
|
||||
m.put("tablename", rs.getString("TABLENAME"));
|
||||
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 = "删除实体:drop 物理表并清除元数据(仅限 EIP4AI_ 前缀,防误删)")
|
||||
@DeleteMapping("/api/meta/entity/{table}")
|
||||
public Map<String, Object> dropEntity(@PathVariable String table) {
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.eip4.platform.metadata.web;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.contains;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.eip4.platform.metadata.perf.BacklogIndexScriptGenerator;
|
||||
import com.eip4.platform.metadata.perf.IndexEnhancer;
|
||||
import com.eip4.platform.metadata.perf.PoInfoCacheInvalidator;
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
class MetaCatalogControllerTest {
|
||||
|
||||
private MetaController newController(JdbcTemplate jdbc) {
|
||||
return new MetaController(
|
||||
mock(DataDicService.class),
|
||||
mock(POJOCRUDService.class),
|
||||
jdbc,
|
||||
mock(IndexEnhancer.class),
|
||||
mock(PoInfoCacheInvalidator.class),
|
||||
mock(BacklogIndexScriptGenerator.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("entities() 返回 ISACTIVE=1 AND ISVIEW=0 的实体目录 {entityId,tablename,name}")
|
||||
void entitiesReturnsCatalog() {
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("entityId", "e-1");
|
||||
row.put("tablename", "EIP4_ORDER");
|
||||
row.put("name", "订单");
|
||||
when(jdbc.query(contains("FROM SYS_ENTITY"), (RowMapper) org.mockito.ArgumentMatchers.any()))
|
||||
.thenReturn(List.of(row));
|
||||
|
||||
Map<String, Object> resp = newController(jdbc).entities();
|
||||
|
||||
assertEquals(0, resp.get("status"));
|
||||
List<Map<String, Object>> data = (List<Map<String, Object>>) resp.get("data");
|
||||
assertEquals(1, data.size());
|
||||
assertEquals("EIP4_ORDER", data.get(0).get("tablename"));
|
||||
assertEquals("订单", data.get(0).get("name"));
|
||||
assertEquals("e-1", data.get(0).get("entityId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("entities() 的 SQL 过滤 ISACTIVE=1 AND ISVIEW=0")
|
||||
void entitiesSqlFiltersActiveNonView() {
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
final String[] captured = new String[1];
|
||||
when(jdbc.query(anyString(), (RowMapper) org.mockito.ArgumentMatchers.any()))
|
||||
.thenAnswer(inv -> { captured[0] = inv.getArgument(0); return List.of(); });
|
||||
|
||||
newController(jdbc).entities();
|
||||
|
||||
assertTrue(captured[0].toUpperCase().contains("ISACTIVE=1")
|
||||
|| captured[0].toUpperCase().contains("ISACTIVE = 1"));
|
||||
assertTrue(captured[0].toUpperCase().contains("ISVIEW=0")
|
||||
|| captured[0].toUpperCase().contains("ISVIEW = 0"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user