main
HuangHai 1 month ago
parent 689e864a6f
commit 12b4f2bb94

@ -18,14 +18,15 @@ import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.text.SimpleDateFormat;
import java.util.Date;
import cn.hutool.core.io.FileUtil;
import java.io.File;
import java.util.Scanner;
import com.dsideal.base.AI.Generator.WordGenerator;
public class TestMax32K {
private static final int MAX_CHUNK_SIZE = 8000; // 8000字符限制
private static boolean dataSubmitted = false; // 标记数据是否已提交
private static final String[] regions = {"楚雄州", "文山州"}; // 或者根据需要设置具体的地区
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
@ -86,7 +87,6 @@ public class TestMax32K {
}
// 添加获取参数的代码
String[] regions = { "楚雄州","文山州"}; // 或者根据需要设置具体的地区
String sql = "select table_name as TABLE_NAME from core_dataset_table where dataset_group_id in (select id from core_dataset_group where pid='1036317909951057920')";
List<Record> tableList = Db.use(DataEaseModel.DB_NAME).find(sql);
@ -176,9 +176,7 @@ public class TestMax32K {
try {
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String fileName = "analysis_report_" + timestamp + ".docx";
// 使用WordGenerator生成Word文档
String[] regions = {"云南省"}; // 或者根据实际情况设置地区
WordGenerator.generateWordDocument(wordContent.toString(), fileName, regions);
System.out.println("Word报告已保存至: WebRoot/upload/" + fileName);
@ -394,105 +392,6 @@ public class TestMax32K {
return chunks;
}
public static String generateComprehensiveReport(String[] regions) {
String sql = "select table_name as TABLE_NAME from core_dataset_table where dataset_group_id in (select id from core_dataset_group where pid='1036317909951057920')";
List<Record> tableList = Db.use(DataEaseModel.DB_NAME).find(sql);
// 获取分块数据
String[] dataChunks = getDataChunks(regions, tableList);
System.out.println("开始逐步提交 " + dataChunks.length + " 个数据块...");
final StringBuilder finalReport = new StringBuilder();
final CountDownLatch finalLatch = new CountDownLatch(1);
// 逐步提交数据块
for (int i = 0; i < dataChunks.length; i++) {
final int chunkIndex = i;
final boolean isLastChunk = (i == dataChunks.length - 1);
String prompt;
if (isLastChunk) {
// 最后一个数据块:要求返回完整分析报告
prompt = "这是最后一部分教育数据请基于之前提交的所有数据生成一份完整的综合分析报告3000字以内\n" + dataChunks[i];
} else {
// 中间数据块:只提交数据,不要求返回分析
prompt = "这是第" + (i + 1) + "部分教育数据,共" + dataChunks.length + "部分,请接收并记录,暂不需要分析:\n" + dataChunks[i];
}
System.out.println("\n=== 提交第 " + (i + 1) + "/" + dataChunks.length + " 个数据块 ===");
final CountDownLatch chunkLatch = new CountDownLatch(1);
CallDeepSeek.callDeepSeekStream(prompt, new CallDeepSeek.SSEListener() {
@Override
public void onData(String data) {
if (isLastChunk) {
// 只有最后一个数据块才显示和保存返回内容
System.out.print(data);
finalReport.append(data);
} else {
// 中间数据块的响应不显示(或只显示确认信息)
// System.out.print("."); // 可选:显示进度点
}
}
@Override
public void onComplete(String fullResponse) {
if (isLastChunk) {
System.out.println("\n\n=== 综合分析报告生成完成 ===");
// 保存报告到文件
try {
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String fileName = "教育数据综合分析报告_" + timestamp + ".txt";
String filePath = "WebRoot/upload/" + fileName;
FileUtil.writeString(finalReport.toString(), new File(filePath), "UTF-8");
System.out.println("报告已保存到: " + filePath);
} catch (Exception e) {
System.err.println("保存报告时出错: " + e.getMessage());
}
finalLatch.countDown();
} else {
System.out.println("第 " + (chunkIndex + 1) + " 个数据块已提交");
}
chunkLatch.countDown();
}
@Override
public void onError(String error) {
System.err.println("提交第 " + (chunkIndex + 1) + " 个数据块时出错: " + error);
if (isLastChunk) {
finalReport.append("生成失败: ").append(error);
finalLatch.countDown();
}
chunkLatch.countDown();
}
});
try {
// 等待当前块处理完成
chunkLatch.await();
if (!isLastChunk) {
Thread.sleep(1000); // 中间块之间稍微延迟
}
} catch (InterruptedException e) {
System.err.println("等待数据块处理时被中断: " + e.getMessage());
}
}
try {
finalLatch.await();
} catch (InterruptedException e) {
System.err.println("等待最终报告时被中断: " + e.getMessage());
}
return finalReport.toString();
}
/**
*
*/
@ -501,8 +400,8 @@ public class TestMax32K {
StringBuilder currentChunk = new StringBuilder();
String header = "数据说明: 以下是云南省教育数据的压缩格式\n" +
"格式: 表名 -> 字段列表 -> 数据行(数组格式)\n" +
"地区范围: " + String.join(",", regions) + "\n\n";
"格式: 表名 -> 字段列表 -> 数据行(数组格式)\n" +
"地区范围: " + String.join(",", regions) + "\n\n";
currentChunk.append(header);
// 遍历所有相关数据表

Loading…
Cancel
Save