| | |
| | | private PlatformService platformService; |
| | | @Autowired |
| | | private TypeService typeService; |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | |
| | | /* @PostMapping("/search") |
| | |
| | | log.warn(errorMsg); |
| | | return Mono.just(ResponseResult.error(503, errorMsg)); |
| | | } |
| | | Integer keywordId = searchTaskRequest.getKeyword_id(); |
| | | |
| | | int maxConcurrentUsers = searchTaskRequest.getConfig() != null ? |
| | | searchTaskRequest.getConfig().getMax_concurrent_users() : 3; |
| | | List<List<UserDto>> userBatches = splitUsersIntoBatches(searchTaskRequest.getUsers(), maxConcurrentUsers); |
| | | List<List<UserDto>> userBatches = splitUsersIntoBatches(searchTaskRequest.getUsers(), maxConcurrentUsers,keywordId); |
| | | |
| | | // 获取 keywordId |
| | | Integer keywordId = searchTaskRequest.getKeyword_id(); |
| | | |
| | | //分割 |
| | | |
| | | |
| | |
| | | .onStatus(HttpStatus::isError, response -> response.bodyToMono(TaskCancelResponse.class) |
| | | .flatMap(errorBody -> Mono.error(new RuntimeException(errorBody.getDetail())))) |
| | | .bodyToMono(TaskCancelResponse.class) |
| | | .flatMap(cancelResponse -> { |
| | | // 更新关键词状态 |
| | | Mono<Void> updateKeyword = Mono.fromRunnable(() -> { |
| | | LambdaUpdateWrapper<Keyword> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(Keyword::getTask_id, taskId); |
| | | updateWrapper.set(Keyword::getStatus, "canceled"); // 统一使用"canceled" |
| | | keywordService.update(updateWrapper); |
| | | }) |
| | | .subscribeOn(Schedulers.boundedElastic()) |
| | | .then(); |
| | | |
| | | // 更新关键词任务状态 |
| | | Mono<Void> updateKeywordTask = Mono.fromRunnable(() -> { |
| | | LambdaUpdateWrapper<KeywordTask> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(KeywordTask::getTask_id, taskId); |
| | | updateWrapper.set(KeywordTask::getStatus, "canceled"); // 统一使用"canceled" |
| | | keywordTaskService.update(updateWrapper); |
| | | }) |
| | | .subscribeOn(Schedulers.boundedElastic()) |
| | | .then(); |
| | | |
| | | // 并行执行两个更新操作,并在完成后返回cancelResponse |
| | | return Mono.when(updateKeyword, updateKeywordTask) |
| | | .thenReturn(cancelResponse); |
| | | }) |
| | | .map(data -> ResponseResult.success(data)) |
| | | .onErrorResume(e -> { |
| | | if (e.getMessage().contains("任务不存在")) { |
| | | return Mono.just(ResponseResult.error(200, "任务不存在")); |
| | | return Mono.just(ResponseResult.error(200, e.getMessage())); |
| | | } else if (e.getMessage().contains("无法取消")) { |
| | | return Mono.just(ResponseResult.error(200, "任务已完成,无法取消")); |
| | | return Mono.just(ResponseResult.error(200, e.getMessage())); |
| | | } |
| | | return Mono.just(ResponseResult.error(500, "取消任务失败: " + e.getMessage())); |
| | | return Mono.just(ResponseResult.error(500, e.getMessage())); |
| | | }); |
| | | } |
| | | |
| | |
| | | }) |
| | | .onErrorResume(e -> { |
| | | System.out.println("获取任务结果失败"); |
| | | TaskResultResponse result = new TaskResultResponse(); |
| | | if (e.getMessage().contains("登陆失败")){ |
| | | |
| | | } |
| | | TaskResultResponse result = new TaskResultResponse(); |
| | | result.setDetail("获取任务结果失败: " + e.getMessage()); |
| | | return Mono.just(result); |
| | | }); |
| | |
| | | private Mono<Void> updateQuestionAndReference(TaskResultResponse result) { |
| | | return Mono.fromRunnable(() -> { |
| | | try { |
| | | //查看每个账号信息的status是否正常 |
| | | |
| | | // 1. 根据KeywordTask更新关键词状态 |
| | | // 查询关键词ID |
| | | LambdaQueryWrapper<KeywordTask> keywordTaskWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | throw new Exception("未找到关联的关键词,task_id: " + result.getTask_id()); |
| | | // return; |
| | | } |
| | | keyword.setStatus("completed"); |
| | | keywordService.updateById(keyword); |
| | | LambdaQueryWrapper<KeywordTask> keywordTaskWrapper2 = new LambdaQueryWrapper<>(); |
| | | keywordTaskWrapper2.eq(KeywordTask::getKeyword_id, keyword.getKeyword_id()); |
| | | List<KeywordTask> keywordTasks = keywordTaskService.list(keywordTaskWrapper2); |
| | | |
| | | // 定义状态优先级:canceled > false > completed |
| | | String finalStatus = "completed"; // 默认状态为 completed |
| | | |
| | | for (KeywordTask task : keywordTasks) { |
| | | String status = task.getStatus(); |
| | | if ("canceled".equals(status)) { |
| | | finalStatus = "canceled"; |
| | | break; // 遇到 canceled 直接跳出循环,因为优先级最高 |
| | | } else if ("false".equals(status)) { |
| | | finalStatus = "false"; |
| | | // 不跳出循环,继续检查是否存在 canceled |
| | | } |
| | | } |
| | | |
| | | // 更新关键词状态 |
| | | if (!finalStatus.equals(keyword.getStatus())) { |
| | | keyword.setStatus(finalStatus); |
| | | keywordService.updateById(keyword); |
| | | } |
| | | |
| | | // 2. 批量查询所有问题 |
| | | LambdaQueryWrapper<Question> queryWrapper = new LambdaQueryWrapper<>(); |