feat(admin): paginate tools list endpoint and console UI
- GET /tools returns ToolPageView{total,page,pageSize,records}, pageSize=0 keeps full-list mode
- App.vue adds pager below tools table; scope/audit/category pickers use allTools
- add backend pagination tests and front-end pager contract test
This commit is contained in:
@@ -162,16 +162,24 @@ public class AdminConsoleController {
|
||||
return tokenService.rotate(id, adminId(session));
|
||||
}
|
||||
|
||||
/** pageSize=0 表示不分页返回全量,供作用域配置、审计筛选等需要完整工具列表的场景使用。 */
|
||||
@GetMapping("/tools")
|
||||
public List<ToolView> tools(@RequestParam(defaultValue = "") String category,
|
||||
@RequestParam(defaultValue = "") String kind,
|
||||
@RequestParam(defaultValue = "") String keyword) {
|
||||
public ToolPageView tools(@RequestParam(defaultValue = "") String category,
|
||||
@RequestParam(defaultValue = "") String kind,
|
||||
@RequestParam(defaultValue = "") String keyword,
|
||||
@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "20") int pageSize) {
|
||||
int pageNo = Math.max(page, 1);
|
||||
int size = pageSize == 0 ? 0 : pageSize < 1 ? 20 : Math.min(pageSize, 100);
|
||||
LambdaQueryWrapper<Tool> query = new LambdaQueryWrapper<Tool>().eq(Tool::getSoftDelete, 0);
|
||||
if (!category.isBlank()) query.eq(Tool::getCategory, category);
|
||||
if (!kind.isBlank()) query.eq(Tool::getKind, kind);
|
||||
if (!keyword.isBlank()) query.and(w -> w.like(Tool::getName, keyword.trim())
|
||||
.or().like(Tool::getDescription, keyword.trim()));
|
||||
List<Tool> tools = toolMapper.selectList(query.orderByAsc(Tool::getCategory, Tool::getName));
|
||||
long total = toolMapper.selectCount(query);
|
||||
LambdaQueryWrapper<Tool> paged = query.orderByAsc(Tool::getCategory, Tool::getName);
|
||||
if (size > 0) paged.last("LIMIT " + (long) (pageNo - 1) * size + "," + size);
|
||||
List<Tool> tools = toolMapper.selectList(paged);
|
||||
Map<Long, AgentScope> scopes = scopeMapper.selectList(new LambdaQueryWrapper<AgentScope>()
|
||||
.eq(AgentScope::getSoftDelete, 0)).stream()
|
||||
.collect(Collectors.toMap(AgentScope::getId, Function.identity()));
|
||||
@@ -180,9 +188,10 @@ public class AdminConsoleController {
|
||||
.filter(r -> scopes.containsKey(r.getScopeId()))
|
||||
.collect(Collectors.groupingBy(ScopeTool::getToolId,
|
||||
Collectors.mapping(r -> scopes.get(r.getScopeId()).getName(), Collectors.toList())));
|
||||
return tools.stream().map(tool -> new ToolView(tool.getId(), tool.getName(), tool.getCategory(),
|
||||
tool.getDescription(), tool.getKind(), tool.getStatus(), tool.getModifyTime(),
|
||||
List<ToolView> records = tools.stream().map(tool -> new ToolView(tool.getId(), tool.getName(),
|
||||
tool.getCategory(), tool.getDescription(), tool.getKind(), tool.getStatus(), tool.getModifyTime(),
|
||||
scopeNames.getOrDefault(tool.getId(), List.of()))).toList();
|
||||
return new ToolPageView(total, size > 0 ? pageNo : 1, size, records);
|
||||
}
|
||||
|
||||
@PatchMapping("/tools/{id}/status")
|
||||
@@ -397,6 +406,7 @@ public class AdminConsoleController {
|
||||
public record StatusRequest(byte status) {}
|
||||
public record ToolView(Long id, String name, String category, String description, String kind,
|
||||
Byte status, Date modifyTime, List<String> scopeNames) {}
|
||||
public record ToolPageView(long total, int page, int pageSize, List<ToolView> records) {}
|
||||
public record ScopeRequest(String name, String code, String memo) {}
|
||||
public record ScopeView(Long id, String name, String code, String memo, Byte status,
|
||||
Date modifyTime, long toolCount) {}
|
||||
|
||||
Reference in New Issue
Block a user