|
|
package com.dsideal.base.AI.Model;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.dsideal.base.AI.Generator.HtmlGenerator;
|
|
|
import com.dsideal.base.AI.Generator.WordGenerator;
|
|
|
import com.dsideal.base.DataEase.Model.DataEaseModel;
|
|
|
import com.dsideal.base.Util.CallDeepSeek;
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
public class YunNanModel {
|
|
|
/**
|
|
|
* 收集指定地区的教育资源配置数据
|
|
|
*
|
|
|
* @param regions 要对比的地区数组
|
|
|
* @return 格式化的数据内容
|
|
|
*/
|
|
|
public String collectEducationData(String[] regions) {
|
|
|
// 查询教育资源配置发展预测相关表
|
|
|
String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dataease' AND TABLE_NAME LIKE 'excel_报告-教育资源配置发展预测%';";
|
|
|
List<com.jfinal.plugin.activerecord.Record> tableList = Db.find(sql);
|
|
|
|
|
|
StringBuilder dataContent = new StringBuilder();
|
|
|
|
|
|
// 构建数据标题
|
|
|
dataContent.append("教育资源配置发展预测数据对比分析\n\n");
|
|
|
dataContent.append("对比州市:").append(String.join(" vs ", regions)).append("\n\n");
|
|
|
|
|
|
// 遍历所有相关数据表
|
|
|
for (com.jfinal.plugin.activerecord.Record record : tableList) {
|
|
|
String tableName = record.getStr("TABLE_NAME");
|
|
|
dataContent.append("数据表:").append(tableName).append("\n");
|
|
|
|
|
|
// 为每个地区收集数据
|
|
|
for (String region : regions) {
|
|
|
sql = "select * from `" + tableName + "` where `行政区划`=?";
|
|
|
List<com.jfinal.plugin.activerecord.Record> listContent = Db.use(DataEaseModel.DB_NAME).find(sql, region);
|
|
|
|
|
|
if (!listContent.isEmpty()) {
|
|
|
dataContent.append("\n").append(region).append("数据:\n");
|
|
|
for (Record dataRecord : listContent) {
|
|
|
dataContent.append(JSONUtil.toJsonPrettyStr(dataRecord.getColumns())).append("\n");
|
|
|
}
|
|
|
} else {
|
|
|
dataContent.append("\n").append(region).append(":无相关数据\n");
|
|
|
}
|
|
|
}
|
|
|
dataContent.append("\n----------------------------------------\n\n");
|
|
|
}
|
|
|
|
|
|
return dataContent.toString();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建分析提示词
|
|
|
*
|
|
|
* @param dataContent 数据内容
|
|
|
* @param regions 对比地区
|
|
|
* @return 分析提示词
|
|
|
*/
|
|
|
public String createAnalysisPrompt(String dataContent, String[] regions) {
|
|
|
String regionNames = String.join("和", regions);
|
|
|
return "你是一位专业的教育数据分析专家,请基于以下数据对" + regionNames + "的教育资源配置情况进行深入对比分析。\n\n" +
|
|
|
"重要要求:请生成结构化的Markdown格式报告,使用标准的Markdown语法,包括标题、列表、粗体等格式。\n\n" +
|
|
|
"请按照以下结构进行分析并生成专业的分析报告:\n\n" +
|
|
|
"## 1. 执行摘要\n" +
|
|
|
"简要概述两州教育资源配置的整体情况和主要发现\n\n" +
|
|
|
"## 2. 数据概览\n" +
|
|
|
"两州基本教育数据对比和关键指标汇总\n\n" +
|
|
|
"## 3. 详细对比分析\n" +
|
|
|
"教育资源配置水平对比、发展趋势分析、优势与不足分析\n\n" +
|
|
|
"## 4. 问题识别\n" +
|
|
|
"存在的主要问题和资源配置不均衡情况\n\n" +
|
|
|
"## 5. 建议与对策\n" +
|
|
|
"针对性改进建议和资源优化配置方案\n\n" +
|
|
|
"## 6. 结论\n" +
|
|
|
"总体评价和未来发展方向\n\n" +
|
|
|
"请确保分析客观、专业,数据引用准确,建议具有可操作性。\n\n" +
|
|
|
"=== 原始数据 ===\n" + dataContent;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成Word报告
|
|
|
*/
|
|
|
public void generateWordReport(String analysisPrompt, String[] regions, String path) {
|
|
|
// 生成输出文件名(不包含路径)
|
|
|
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 = path + "/" + regionName + "_教育分析报告_" + timestamp + ".docx";
|
|
|
WordGenerator.generateWordDocument(analysisResult, wordOutputPath, regions);
|
|
|
System.out.println("Word文档生成完成: " + wordOutputPath);
|
|
|
|
|
|
// 生成HTML报告
|
|
|
// String htmlOutputPath = path + "/" + 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);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|