|
|
package com.dsideal.base.Tools;
|
|
|
|
|
|
import com.dsideal.base.BaseApplication;
|
|
|
import com.dsideal.base.DataEase.Model.DataEaseModel;
|
|
|
import com.dsideal.base.Plugin.YamlProp;
|
|
|
import com.dsideal.base.Tools.Util.CallDeepSeek;
|
|
|
import com.dsideal.base.Tools.Util.LocalMysqlConnectUtil;
|
|
|
import com.dsideal.base.Tools.Util.PptAIKit;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
|
|
|
/**
|
|
|
* AI生成器主类 - 协调数据获取、Word生成和PPT生成
|
|
|
*/
|
|
|
public class AiGenerate {
|
|
|
public static DataEaseModel dm = new DataEaseModel();
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
try {
|
|
|
// 初始化配置
|
|
|
initializeConfiguration();
|
|
|
|
|
|
// 定义对比地区
|
|
|
String[] regions = {"文山州", "楚雄州"};
|
|
|
|
|
|
// 第一步:数据获取
|
|
|
String dataContent = DataCollector.collectEducationData(regions);
|
|
|
String analysisPrompt = DataCollector.createAnalysisPrompt(dataContent, regions);
|
|
|
|
|
|
// 第二步:AI分析并生成Word文档
|
|
|
generateWordReport(analysisPrompt, regions);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("程序执行出错: " + e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 初始化配置
|
|
|
*/
|
|
|
private static void initializeConfiguration() {
|
|
|
String configFile = "application.yaml";
|
|
|
BaseApplication.PropKit = new YamlProp(configFile);
|
|
|
LocalMysqlConnectUtil.Init();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成Word报告
|
|
|
*/
|
|
|
private static void generateWordReport(String analysisPrompt, String[] regions) {
|
|
|
// 生成输出文件名(不包含路径)
|
|
|
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
|
|
|
|
|
// 构建区域名称
|
|
|
String regionName = String.join("与", regions);
|
|
|
|
|
|
// 调用DeepSeek进行分析
|
|
|
CallDeepSeek.callDeepSeekStream(analysisPrompt, new CallDeepSeek.SSEListener() {
|
|
|
private StringBuilder fullResponse = new StringBuilder();
|
|
|
|
|
|
@Override
|
|
|
public void onData(String data) {
|
|
|
System.out.print(data);
|
|
|
System.out.flush();
|
|
|
fullResponse.append(data);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onComplete(String response) {
|
|
|
System.out.println("\n\n=== Word文档分析完成 ===");
|
|
|
|
|
|
try {
|
|
|
// 使用完整的分析结果
|
|
|
String analysisResult = fullResponse.toString();
|
|
|
|
|
|
// 生成Word文档
|
|
|
String wordOutputPath = "D:\\dsWork\\YunNanDsBase\\WebRoot\\upload\\" + regionName + "_教育分析报告_" + timestamp + ".docx";
|
|
|
String wordFilePath = WordGenerator.generateWordDocument(analysisResult, wordOutputPath, regions);
|
|
|
if (wordFilePath != null) {
|
|
|
System.out.println("Word文档生成完成: " + wordFilePath);
|
|
|
}
|
|
|
|
|
|
// 生成HTML报告
|
|
|
String htmlOutputPath = "D:\\dsWork\\YunNanDsBase\\WebRoot\\upload\\" + regionName + "_教育分析报告_" + timestamp + ".html";
|
|
|
String htmlFilePath = HtmlGenerator.generateHtmlReport(analysisResult, htmlOutputPath, regionName);
|
|
|
if (htmlFilePath != null) {
|
|
|
System.out.println("HTML报告生成完成: " + htmlFilePath);
|
|
|
}
|
|
|
|
|
|
// 生成PPT
|
|
|
String token = PptAIKit.createApiToken("dsideal", 1000);
|
|
|
String pptFilePath = PptGenerator.generatePptPresentation(analysisResult, regions, token);
|
|
|
if (pptFilePath != null) {
|
|
|
System.out.println("PPT演示文稿生成完成: " + pptFilePath);
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
System.err.println("保存文件时出错: " + e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(String error) {
|
|
|
System.err.println("DeepSeek分析出错: " + error);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|