|
|
|
@ -3,35 +3,148 @@ 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.jfinal.plugin.activerecord.Db;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class AiGenerate {
|
|
|
|
|
public static DataEaseModel dm = new DataEaseModel();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
//加载配置文件
|
|
|
|
|
String configFile = "application.yaml";
|
|
|
|
|
BaseApplication.PropKit = new YamlProp(configFile);
|
|
|
|
|
LocalMysqlConnectUtil.Init();
|
|
|
|
|
|
|
|
|
|
// 查询教育资源配置发展预测相关表
|
|
|
|
|
String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dataease' AND TABLE_NAME LIKE 'excel_报告-教育资源配置发展预测%';";
|
|
|
|
|
List<Record> tableList = Db.find(sql);
|
|
|
|
|
|
|
|
|
|
String[] biJiao = new String[]{"文山州", "楚雄州"};
|
|
|
|
|
StringBuilder dataContent = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
// 收集两个州的数据
|
|
|
|
|
dataContent.append("# 教育资源配置发展预测数据对比分析\n\n");
|
|
|
|
|
dataContent.append("## 对比州市:").append(String.join(" vs ", biJiao)).append("\n\n");
|
|
|
|
|
|
|
|
|
|
for (Record record : tableList) {
|
|
|
|
|
String tableName = record.getStr("TABLE_NAME");
|
|
|
|
|
dataContent.append("### 数据表:").append(tableName).append("\n");
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < biJiao.length; j++) {
|
|
|
|
|
sql = "select * from `" + tableName + "` where `行政区划`=?";
|
|
|
|
|
List<Record> listConetent = Db.use(DataEaseModel.DB_NAME).find(sql, biJiao[j]);
|
|
|
|
|
if (!listConetent.isEmpty()) {
|
|
|
|
|
System.out.println(listConetent);
|
|
|
|
|
List<Record> listContent = Db.use(DataEaseModel.DB_NAME).find(sql, biJiao[j]);
|
|
|
|
|
|
|
|
|
|
if (!listContent.isEmpty()) {
|
|
|
|
|
dataContent.append("\n#### ").append(biJiao[j]).append("数据:\n");
|
|
|
|
|
for (Record dataRecord : listContent) {
|
|
|
|
|
dataContent.append(JSONUtil.toJsonPrettyStr(dataRecord.getColumns())).append("\n");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
dataContent.append("\n#### ").append(biJiao[j]).append(":无相关数据\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dataContent.append("\n---\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建分析提示词
|
|
|
|
|
String analysisPrompt = createAnalysisPrompt(dataContent.toString());
|
|
|
|
|
|
|
|
|
|
// 生成输出文件路径
|
|
|
|
|
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
|
|
|
|
String outputPath = "教育资源对比分析报告_" + timestamp + ".docx";
|
|
|
|
|
|
|
|
|
|
System.out.println("开始调用DeepSeek进行数据分析...");
|
|
|
|
|
|
|
|
|
|
// 调用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=== 分析完成 ===");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 将分析结果保存为Word文档格式的内容
|
|
|
|
|
String wordContent = convertToWordFormat(fullResponse.toString());
|
|
|
|
|
FileUtil.writeString(wordContent, new File(outputPath), "UTF-8");
|
|
|
|
|
System.out.println("分析报告已保存到: " + outputPath);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("保存文件时出错: " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onError(String error) {
|
|
|
|
|
System.err.println("DeepSeek分析出错: " + error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建分析提示词
|
|
|
|
|
*/
|
|
|
|
|
private static String createAnalysisPrompt(String dataContent) {
|
|
|
|
|
return "你是一位专业的教育数据分析专家,请基于以下数据对文山州和楚雄州的教育资源配置情况进行深入对比分析。\n\n" +
|
|
|
|
|
"请按照以下结构进行分析并生成专业的分析报告:\n\n" +
|
|
|
|
|
"1. **执行摘要**\n" +
|
|
|
|
|
" - 简要概述两州教育资源配置的整体情况\n" +
|
|
|
|
|
" - 主要发现和结论\n\n" +
|
|
|
|
|
"2. **数据概览**\n" +
|
|
|
|
|
" - 两州基本教育数据对比\n" +
|
|
|
|
|
" - 关键指标汇总\n\n" +
|
|
|
|
|
"3. **详细对比分析**\n" +
|
|
|
|
|
" - 教育资源配置水平对比\n" +
|
|
|
|
|
" - 发展趋势分析\n" +
|
|
|
|
|
" - 优势与不足分析\n\n" +
|
|
|
|
|
"4. **问题识别**\n" +
|
|
|
|
|
" - 存在的主要问题\n" +
|
|
|
|
|
" - 资源配置不均衡情况\n\n" +
|
|
|
|
|
"5. **建议与对策**\n" +
|
|
|
|
|
" - 针对性改进建议\n" +
|
|
|
|
|
" - 资源优化配置方案\n\n" +
|
|
|
|
|
"6. **结论**\n" +
|
|
|
|
|
" - 总体评价\n" +
|
|
|
|
|
" - 未来发展方向\n\n" +
|
|
|
|
|
"请确保分析客观、专业,数据引用准确,建议具有可操作性。\n\n" +
|
|
|
|
|
"=== 原始数据 ===\n" + dataContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将分析结果转换为Word文档格式
|
|
|
|
|
*/
|
|
|
|
|
private static String convertToWordFormat(String analysisResult) {
|
|
|
|
|
StringBuilder wordContent = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
// 添加文档头部
|
|
|
|
|
wordContent.append("文山州与楚雄州教育资源配置对比分析报告\n");
|
|
|
|
|
wordContent.append("=".repeat(50)).append("\n\n");
|
|
|
|
|
wordContent.append("生成时间:").append(new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date())).append("\n");
|
|
|
|
|
wordContent.append("分析工具:DeepSeek AI\n\n");
|
|
|
|
|
|
|
|
|
|
// 添加分析内容
|
|
|
|
|
wordContent.append(analysisResult);
|
|
|
|
|
|
|
|
|
|
// 添加文档尾部
|
|
|
|
|
wordContent.append("\n\n").append("=".repeat(50)).append("\n");
|
|
|
|
|
wordContent.append("报告结束\n");
|
|
|
|
|
|
|
|
|
|
return wordContent.toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|