F2-17根因: 列表搜索流分页修复(page/perPage→引擎 PAGE_START/PAGE_SIZE)
FlowController 把 amis page/perPage 原样当过滤条件,而合成搜索流 listSelect 认的是 PAGE_START/PAGE_SIZE,导致永远返回全表(实测 page1=page2,total=266)。 翻译为引擎分页键并剔除原始键;过滤与分页共存(TITLE=放假 266→42 实测)。14 单测。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -62,12 +62,16 @@ public class FlowController {
|
||||
this.flowNameResolver = flowNameResolver;
|
||||
}
|
||||
|
||||
/** amis crud 默认每页条数(与前端 amis 默认 perPage 一致)。 */
|
||||
private static final int DEFAULT_PER_PAGE = 10;
|
||||
|
||||
/** GET 执行:query 参数透传为服务流入参 map(保留原始大小写键,交由流脚本/服务节点消费)。 */
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "执行服务流(GET):query 参数作为入参 map,返回流输出 JSON。报表 D 类查询入口")
|
||||
public ResponseEntity<Map<String, Object>> executeGet(@PathVariable String id,
|
||||
@RequestParam Map<String, String> allParams) {
|
||||
Map<String, Object> map = new HashMap<>(allParams);
|
||||
applyPaging(map);
|
||||
return run(id, map);
|
||||
}
|
||||
|
||||
@@ -77,9 +81,45 @@ public class FlowController {
|
||||
public ResponseEntity<Map<String, Object>> executePost(@PathVariable String id,
|
||||
@RequestBody(required = false) Map<String, Object> body) {
|
||||
Map<String, Object> map = body == null ? new HashMap<>() : new HashMap<>(body);
|
||||
applyPaging(map);
|
||||
return run(id, map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把 amis crud 的字面分页参数 {@code page}/{@code perPage} 翻译成合成搜索流引擎
|
||||
* ({@code POJOCRUDService.listSelect})认得的分页键 {@link POJOCRUDService#PAGE_START}/
|
||||
* {@link POJOCRUDService#PAGE_SIZE},并从入参 map 中剔除原始 {@code page}/{@code perPage}
|
||||
* (否则被引擎当作不存在的列名拼进 where,命名/报表流亦同——剔除即可,无副作用)。
|
||||
*
|
||||
* <p>缺省:page=1,perPage={@value #DEFAULT_PER_PAGE}(amis 默认)。键类型与 PickerController
|
||||
* 一致放 int({@code (page-1)*perPage} 与 {@code perPage})。其它 query 参数(如 TITLE)原样保留为过滤条件。
|
||||
* 仅当显式带 page/perPage 时才翻译,避免给无分页语义的流凭空注入分页键。
|
||||
*/
|
||||
private void applyPaging(Map<String, Object> map) {
|
||||
boolean hasPage = map.containsKey("page");
|
||||
boolean hasPerPage = map.containsKey("perPage");
|
||||
if (!hasPage && !hasPerPage) {
|
||||
return;
|
||||
}
|
||||
int page = parsePositiveInt(map.remove("page"), 1);
|
||||
int perPage = parsePositiveInt(map.remove("perPage"), DEFAULT_PER_PAGE);
|
||||
map.put(POJOCRUDService.PAGE_START, (page - 1) * perPage);
|
||||
map.put(POJOCRUDService.PAGE_SIZE, perPage);
|
||||
}
|
||||
|
||||
/** 解析分页参数为正整数;缺省/空白/非法/非正 → 回退默认值(page/perPage 至少为 1)。 */
|
||||
private static int parsePositiveInt(Object raw, int fallback) {
|
||||
if (raw == null) {
|
||||
return fallback;
|
||||
}
|
||||
try {
|
||||
int v = Integer.parseInt(String.valueOf(raw).trim());
|
||||
return v > 0 ? v : fallback;
|
||||
} catch (NumberFormatException e) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一执行 + 响应封装(F2-14 三级解析)。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user