| | |
| | | |
| | | private final TaskService taskService; |
| | | |
| | | @Tool(name = "rsf_query_task_list", description = "按任务号、状态、任务类型、源站点、目标站点等条件查询任务列表。") |
| | | @Tool(name = "rsf_query_task_list", description = "只读查询工具。按任务号、状态、任务类型、源站点、目标站点等条件查询任务列表。") |
| | | public List<Map<String, Object>> queryTaskList( |
| | | @ToolParam(description = "任务号,可模糊查询") String taskCode, |
| | | @ToolParam(description = "任务状态,可选") Integer taskStatus, |
| | |
| | | @ToolParam(description = "源站点,可选") String orgSite, |
| | | @ToolParam(description = "目标站点,可选") String targSite, |
| | | @ToolParam(description = "返回条数,默认 10,最大 50") Integer limit) { |
| | | String normalizedTaskCode = BuiltinToolGovernanceSupport.sanitizeQueryText(taskCode, "任务号", 64); |
| | | String normalizedOrgSite = BuiltinToolGovernanceSupport.sanitizeQueryText(orgSite, "源站点", 64); |
| | | String normalizedTargSite = BuiltinToolGovernanceSupport.sanitizeQueryText(targSite, "目标站点", 64); |
| | | BuiltinToolGovernanceSupport.requireAnyFilter("任务列表查询至少需要提供一个过滤条件", |
| | | normalizedTaskCode, normalizedOrgSite, normalizedTargSite, |
| | | taskStatus == null ? null : String.valueOf(taskStatus), |
| | | taskType == null ? null : String.valueOf(taskType)); |
| | | LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<>(); |
| | | int finalLimit = normalizeLimit(limit, 10, 50); |
| | | if (StringUtils.hasText(taskCode)) { |
| | | queryWrapper.like(Task::getTaskCode, taskCode); |
| | | int finalLimit = BuiltinToolGovernanceSupport.normalizeLimit(limit, 10, 50); |
| | | if (StringUtils.hasText(normalizedTaskCode)) { |
| | | queryWrapper.like(Task::getTaskCode, normalizedTaskCode); |
| | | } |
| | | if (taskStatus != null) { |
| | | queryWrapper.eq(Task::getTaskStatus, taskStatus); |
| | |
| | | if (taskType != null) { |
| | | queryWrapper.eq(Task::getTaskType, taskType); |
| | | } |
| | | if (StringUtils.hasText(orgSite)) { |
| | | queryWrapper.eq(Task::getOrgSite, orgSite); |
| | | if (StringUtils.hasText(normalizedOrgSite)) { |
| | | queryWrapper.eq(Task::getOrgSite, normalizedOrgSite); |
| | | } |
| | | if (StringUtils.hasText(targSite)) { |
| | | queryWrapper.eq(Task::getTargSite, targSite); |
| | | if (StringUtils.hasText(normalizedTargSite)) { |
| | | queryWrapper.eq(Task::getTargSite, normalizedTargSite); |
| | | } |
| | | queryWrapper.orderByDesc(Task::getCreateTime).last("LIMIT " + finalLimit); |
| | | List<Task> tasks = taskService.list(queryWrapper); |
| | |
| | | return result; |
| | | } |
| | | |
| | | @Tool(name = "rsf_query_task_detail", description = "根据任务 ID 或任务号查询任务详情。") |
| | | @Tool(name = "rsf_query_task_detail", description = "只读查询工具。根据任务 ID 或任务号查询任务详情。") |
| | | public Map<String, Object> queryTaskDetail( |
| | | @ToolParam(description = "任务 ID") Long taskId, |
| | | @ToolParam(description = "任务号") String taskCode) { |
| | | if (taskId == null && !StringUtils.hasText(taskCode)) { |
| | | String normalizedTaskCode = BuiltinToolGovernanceSupport.sanitizeQueryText(taskCode, "任务号", 64); |
| | | if (taskId == null && !StringUtils.hasText(normalizedTaskCode)) { |
| | | throw new CoolException("任务 ID 和任务号至少需要提供一个"); |
| | | } |
| | | Task task; |
| | | if (taskId != null) { |
| | | task = taskService.getById(taskId); |
| | | } else { |
| | | task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getTaskCode, taskCode)); |
| | | task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getTaskCode, normalizedTaskCode)); |
| | | } |
| | | if (task == null) { |
| | | throw new CoolException("未查询到任务"); |
| | |
| | | return item; |
| | | } |
| | | |
| | | private int normalizeLimit(Integer limit, int defaultValue, int maxValue) { |
| | | if (limit == null) { |
| | | return defaultValue; |
| | | } |
| | | if (limit < 1 || limit > maxValue) { |
| | | throw new CoolException("limit 必须在 1 到 " + maxValue + " 之间"); |
| | | } |
| | | return limit; |
| | | } |
| | | } |