修复列表页两 bug:空结果集崩溃 + ComboBox 枚举下拉空数据(用户报「加班登记」)
【bug1 空结果集列表崩溃】凡 0 行的列表页报「data.items 必须是数组」(amis CRUD)。
根因:引擎对空查询结果省略 listresult 键、仅返 {result:{pagecount:0}};FlowController.normalize
只在含 listresult 时拍平为 {items,total},空集落入通用分支 → data.items 缺失 → amis 崩。
修:normalize 触发条件加 PAGE_COUNT——含 pagecount 即视为分页查询,listresult 缺省→空 items、
pagecount→total。新增 FlowControllerTest「5b 空结果集归一化」。影响全部 0 行列表页。
【bug2 ComboBox 枚举下拉空数据】「加班类型」等下拉无选项(51 模板)。
根因:ComboBox 字段 comboboxid="" 空但 itemisenumerate="true"(选项来自列的 enumeratetype),
转换器只认 comboboxid → 生成无 source 空 select。对照:OVERTIMESTATE comboboxid=HR_HOLIDAYSTATUS
显式填了枚举类型故正常。修:UiTypeMapper.mapField 加 colMeta 入参,ComboBox 缺 comboboxid 且
itemisenumerate 时取列 enumeratetype 作 /api/poc/dict/{enumeratetype} 源;buildSearchFilter/
convertForm 经 loadColumnMeta 注入 colMeta。新增转换器测「ComboBox 缺 comboboxid 取列枚举字典」。
分级清单.csv 随重批(无枚举元数据的空 ComboBox 改记诚实降级)。
验证:converter 58 测 + FlowController 26 测 + 全模块测过;运行时 HR_OVERTIMEAPPLY_SEARCHPASS
返 {items:[],total:0};/api/poc/dict/HR_CHECKATTENDANCESTATE 返加班类型枚举;
浏览器加班登记页无报错 + 加班类型下拉出「正常/迟到/早退/旷工/年假…」。已重转+重导入 sys_page_schema 上线。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -342,11 +342,15 @@ public class FlowController {
|
||||
return toRow(p);
|
||||
}
|
||||
if (value instanceof Map<?, ?> m) {
|
||||
// listSelect 结果:{listresult:[...], pagecount:N} → amis {items, total}
|
||||
if (m.containsKey(POJOCRUDService.LIST_RESULT)) {
|
||||
// listSelect 结果:{listresult:[...], pagecount:N} → amis {items, total}。
|
||||
// 空结果集时引擎省略 listresult、仅留 pagecount(=0)——也须拍平为 {items:[], total:0},
|
||||
// 否则 data.items 缺失,amis crud 报「data.items 必须是数组」(凡 0 行列表页空态皆崩)。
|
||||
// 故触发条件含 PAGE_COUNT:有 pagecount 即视为分页查询结果,listresult 缺省 → 空 items。
|
||||
if (m.containsKey(POJOCRUDService.LIST_RESULT) || m.containsKey(POJOCRUDService.PAGE_COUNT)) {
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("items", normalize(m.get(POJOCRUDService.LIST_RESULT)));
|
||||
data.put("total", m.get(POJOCRUDService.PAGE_COUNT));
|
||||
Object list = m.get(POJOCRUDService.LIST_RESULT);
|
||||
data.put("items", list != null ? normalize(list) : new ArrayList<>());
|
||||
data.put("total", m.containsKey(POJOCRUDService.PAGE_COUNT) ? m.get(POJOCRUDService.PAGE_COUNT) : 0);
|
||||
return data;
|
||||
}
|
||||
Map<String, Object> out = new LinkedHashMap<>();
|
||||
|
||||
@@ -182,6 +182,30 @@ class FlowControllerTest {
|
||||
assertEquals("b0000000-0000-0000-0000-000000000001", items.get(0).get("_id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("5b. 空结果集归一化:{pagecount:0}(无 listresult) → {items:[],total:0}")
|
||||
void normalizeEmptyListResult() {
|
||||
// 引擎对空查询结果省略 listresult、仅留 pagecount(=0)。此前 normalize 只认 listresult,
|
||||
// 致空列表返回 {result:{pagecount:0}} → amis crud 报「data.items 必须是数组」(凡 0 行列表页崩)。
|
||||
String flowId = "F";
|
||||
Map<String, Object> emptyResult = new LinkedHashMap<>();
|
||||
emptyResult.put(POJOCRUDService.PAGE_COUNT, 0); // 仅 pagecount,无 listresult
|
||||
|
||||
Map<String, Object> output = new LinkedHashMap<>();
|
||||
output.put("result", emptyResult);
|
||||
|
||||
FlowExcuteService engine = mock(FlowExcuteService.class);
|
||||
when(engine.excute(any(), any(), any())).thenReturn(output);
|
||||
FlowController controller = new FlowController(engine, resolverReturning(flowId, uuidPassthrough()));
|
||||
|
||||
ResponseEntity<Map<String, Object>> resp = controller.executeGet(flowId, new HashMap<>());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
||||
assertInstanceOf(List.class, data.get("items"), "空结果也须有 items 数组(即使空)");
|
||||
assertEquals(0, ((List<?>) data.get("items")).size(), "空结果 items 为空数组");
|
||||
assertEquals(0, data.get("total"), "pagecount=0 → total=0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("6. 单个 GeneralPOJO 输出归一化为平面行")
|
||||
void normalizeSinglePojo() {
|
||||
|
||||
Reference in New Issue
Block a user