F2-14b: 流查询输出拍平对齐 amis crud 契约(data.result.items→data.items)
一层之差导致全部列表页空态(数据实际已返回)。仅单输出 result 且为 {items,total}
查询形态时拍平;其他流输出原样。实证:通知管理页 266 条真实数据上屏(27 页分页);
e2e 34/34 不回归。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -128,10 +128,25 @@ public class FlowController {
|
|||||||
Map<String, Object> resp = new LinkedHashMap<>();
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
resp.put("status", 0);
|
resp.put("status", 0);
|
||||||
resp.put("msg", "");
|
resp.put("msg", "");
|
||||||
resp.put("data", normalize(output));
|
resp.put("data", unwrapCrudResult(normalize(output)));
|
||||||
return ResponseEntity.ok(resp);
|
return ResponseEntity.ok(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* F2-14b:流输出变量名为 result(DefaultFlowHelper 默认搜索流口径),查询结果被包成
|
||||||
|
* {result:{items,total}},而 amis crud 契约读 data.items/data.total——一层之差导致
|
||||||
|
* 全部列表页空态(数据实际已返回)。仅当 result 恰为 {items,total} 查询形态时拍平;
|
||||||
|
* 其他流输出(多变量/非查询)原样保留,不破坏既有消费方。
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private Object unwrapCrudResult(Object data) {
|
||||||
|
if (data instanceof Map<?, ?> m && m.size() == 1 && m.get("result") instanceof Map<?, ?> r
|
||||||
|
&& r.containsKey("items") && r.containsKey("total")) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
private static String sanitize(String id) {
|
private static String sanitize(String id) {
|
||||||
if (id == null) return "";
|
if (id == null) return "";
|
||||||
return id.replaceAll("[^A-Za-z0-9_\\-]", "?");
|
return id.replaceAll("[^A-Za-z0-9_\\-]", "?");
|
||||||
|
|||||||
@@ -160,10 +160,10 @@ class FlowControllerTest {
|
|||||||
FlowController controller = new FlowController(engine, resolverReturning(flowId, uuidPassthrough()));
|
FlowController controller = new FlowController(engine, resolverReturning(flowId, uuidPassthrough()));
|
||||||
|
|
||||||
ResponseEntity<Map<String, Object>> resp = controller.executeGet(flowId, new HashMap<>());
|
ResponseEntity<Map<String, Object>> resp = controller.executeGet(flowId, new HashMap<>());
|
||||||
|
// F2-14b:单输出 result 且为 {items,total} 查询形态时拍平到 data 顶层(amis crud 契约
|
||||||
|
// data.items/data.total;原 data.result.items 一层之差导致全部列表页空态)
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
Map<String, Object> result = (Map<String, Object>) resp.getBody().get("data");
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> result = (Map<String, Object>) data.get("result");
|
|
||||||
assertEquals(1, result.get("total"), "pagecount → total");
|
assertEquals(1, result.get("total"), "pagecount → total");
|
||||||
assertInstanceOf(List.class, result.get("items"), "listresult → items");
|
assertInstanceOf(List.class, result.get("items"), "listresult → items");
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
Reference in New Issue
Block a user