| | |
| | | */ |
| | | private Platform getOrCreatePlatform(String domain,String platformName) { |
| | | // 1. 先尝试查询已存在的平台 |
| | | Platform platform = platformService.getPlatformByDomain(domain,platformName); |
| | | |
| | | Platform platform = platformService.getPlatformByDomain(domain); |
| | | if (platform != null) { |
| | | return platform; |
| | | } |
| | |
| | | } catch (DuplicateKeyException e) { |
| | | // 3. 若捕获到重复键异常,说明并发创建了,重新查询即可(此时数据库中已存在该平台) |
| | | log.warn("平台domain={}已存在,无需重复创建", domain, e); |
| | | return platformService.getPlatformByDomain(domain,platformName); // 重新查询,一定能获取到 |
| | | return platformService.getPlatformByDomain(domain); // 重新查询,一定能获取到 |
| | | } catch (Exception e) { |
| | | // 处理其他异常(如数据库连接失败等) |
| | | log.error("创建平台失败,domain={}", domain, e); |
| | |
| | | List<Reference> allReferences = new ArrayList<>(); |
| | | List<Reference> resultList = new ArrayList<>(); |
| | | |
| | | // 4. 新增:统计所有提问词的结果状态 |
| | | boolean allEmptyReferences = true; // 所有提问词引用数据为空 |
| | | boolean allSystemBusy = true; // 所有提问词系统繁忙 |
| | | // 遍历结果 |
| | | for (UserResult userResult : result.getResults()) { |
| | | //更新账号状态 |
| | | if ( "failed".equals(userResult.getStatus())){ |
| | | if (userResult.getError().contains("登录失败")){ |
| | | LambdaUpdateWrapper<User> userWrapper = new LambdaUpdateWrapper<>(); |
| | | userWrapper.eq(User::getUser_email, userResult.getUser_email()); |
| | | userWrapper.set(User::getStatus, "无法登录"); |
| | | userService.update(userWrapper); |
| | | //更新所有提问词的状态 |
| | | questionService.update(new LambdaUpdateWrapper<Question>().eq(Question::getKeyword_id, keyword.getKeyword_id()) |
| | | .set(Question::getStatus, "failed") |
| | | .set(Question::getError, "账户登录失败")); |
| | | |
| | | }else if (userResult.getError().contains("信息错误")){ |
| | | LambdaUpdateWrapper<User> userWrapper = new LambdaUpdateWrapper<>(); |
| | | userWrapper.eq(User::getUser_email, userResult.getUser_email()); |
| | | userWrapper.set(User::getStatus, "信息错误"); |
| | | userService.update(userWrapper); |
| | | } |
| | | } |
| | | for (QuestionResult questionResult : userResult.getQuestions_results()) { |
| | | try { |
| | | Question question = questionMap.get(questionResult.getQuestion()); |
| | |
| | | String finalStatus = determineFinalStatus(allResults); |
| | | if ("success".equals(finalStatus)){ |
| | | question.setStatus("success"); |
| | | question.setError(""); |
| | | }else if ("no_results".equals(finalStatus)){ |
| | | question.setStatus("failed"); |
| | | question.setStatus("success"); |
| | | question.setError("采集结果无引用数据"); |
| | | }else if ("busyness".equals(finalStatus)){ |
| | | question.setStatus("failed"); |
| | | question.setError("DeepSeek繁忙,请稍后尝试"); |
| | | }else if ("failed".equals(finalStatus)){ |
| | | question.setStatus("failed"); |
| | | question.setError("所有账号登录失败"); |
| | | } |
| | | |
| | | // 更新问题对象 |
| | |
| | | System.out.println("处理问题结果失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | //更新账号状态 |
| | | if ( "failed".equals(userResult.getStatus())){ |
| | | if (userResult.getError().contains("登录失败")){ |
| | | LambdaUpdateWrapper<User> userWrapper = new LambdaUpdateWrapper<>(); |
| | | userWrapper.eq(User::getUser_email, userResult.getUser_email()); |
| | | userWrapper.set(User::getStatus, "无法登录"); |
| | | userService.update(userWrapper); |
| | | //更新所有提问词的状态 |
| | | questionService.update(new LambdaUpdateWrapper<Question>().eq(Question::getKeyword_id, keyword.getKeyword_id()) |
| | | .set(Question::getStatus, "failed") |
| | | .set(Question::getError, "账户登录失败")); |
| | | |
| | | }else if (userResult.getError().contains("信息错误")){ |
| | | LambdaUpdateWrapper<User> userWrapper = new LambdaUpdateWrapper<>(); |
| | | userWrapper.eq(User::getUser_email, userResult.getUser_email()); |
| | | userWrapper.set(User::getStatus, "信息错误"); |
| | | userService.update(userWrapper); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | int totalCount = results.size(); |
| | | int emptyResponseCount = 0; |
| | | int systemBusyCount = 0; |
| | | int failedCount = 0; |
| | | |
| | | for (QuestionResultList result : results) { |
| | | // 判断回答是否为空 |
| | |
| | | if ("success".equals(result.getStatus()) && (result.getResponse().isEmpty()|| result.getResponse().contains("WebDriver连接中断") || result.getResponse().contains("响应超时"))) { |
| | | systemBusyCount++; |
| | | } |
| | | if ("failed".equals(result.getStatus()) && result.getError().contains("登录失败")){ |
| | | failedCount++; |
| | | } |
| | | |
| | | } |
| | | |
| | | // 全返回系统繁忙 |
| | |
| | | if (emptyResponseCount == totalCount) { |
| | | return "no_results"; |
| | | } |
| | | if (failedCount == totalCount) { |
| | | return "failed"; |
| | | } |
| | | |
| | | |
| | | // 系统繁忙比例超过阈值(可配置,这里设为70%) |
| | | // double busyRate = (double) systemBusyCount / totalCount; |