|
|
@@ -1265,30 +1265,44 @@ public class MainController {
|
|
|
private void handleGenerateAnalysis() {
|
|
|
analysisResult.setText("正在生成分析报告...");
|
|
|
generateBtn.setDisable(true);
|
|
|
+ generateBtn.setText("生成中...");
|
|
|
aiService.streamAnalysis(
|
|
|
token -> Platform.runLater(() -> {
|
|
|
- if ("正在生成分析报告...".equals(analysisResult.getText())) {
|
|
|
+ if ("正在生成分析报告...".equals(analysisResult.getText())
|
|
|
+ || "AI 服务不可用,正在尝试本地模式...".equals(analysisResult.getText())) {
|
|
|
analysisResult.setText("");
|
|
|
}
|
|
|
analysisResult.appendText(token);
|
|
|
}),
|
|
|
() -> Platform.runLater(() -> {
|
|
|
generateBtn.setDisable(false);
|
|
|
- showInfo("分析完成");
|
|
|
+ generateBtn.setText("生成分析报告");
|
|
|
+ if (!analysisResult.getText().startsWith("==========")) {
|
|
|
+ showInfo("AI 分析完成");
|
|
|
+ }
|
|
|
}),
|
|
|
error -> Platform.runLater(() -> {
|
|
|
- generateBtn.setDisable(false);
|
|
|
+ analysisResult.setText("AI 服务不可用,正在尝试本地模式...");
|
|
|
fallbackGenerateAnalysis();
|
|
|
})
|
|
|
);
|
|
|
}
|
|
|
|
|
|
private void fallbackGenerateAnalysis() {
|
|
|
- R<String> result = aiService.getAnalysis();
|
|
|
- if (result.getCode() == 200 && result.getData() != null) {
|
|
|
- analysisResult.setText(result.getData());
|
|
|
- } else {
|
|
|
- showAlert(result.getMessage());
|
|
|
+ try {
|
|
|
+ R<String> result = aiService.getAnalysis();
|
|
|
+ if (result.getCode() == 200 && result.getData() != null) {
|
|
|
+ analysisResult.setText(result.getData());
|
|
|
+ showInfo("使用本地模式生成分析报告");
|
|
|
+ } else {
|
|
|
+ String msg = result.getMessage() != null ? result.getMessage() : "未知错误";
|
|
|
+ analysisResult.setText("生成失败:" + msg + "\n\n请检查配置后点击「生成分析报告」重试。");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ analysisResult.setText("生成失败:" + e.getMessage() + "\n\n请检查配置后点击「生成分析报告」重试。");
|
|
|
+ } finally {
|
|
|
+ generateBtn.setDisable(false);
|
|
|
+ generateBtn.setText("生成分析报告");
|
|
|
}
|
|
|
}
|
|
|
|