main
HuangHai 2 months ago
parent 52a6704106
commit cce29db8ca

@ -121,8 +121,7 @@ public class CallDeepSeek {
e.printStackTrace(); e.printStackTrace();
return null; return null;
}); });
future.join();
future.join(); // 等待异步操作完成对于main线程的简单示例是必要的
} catch (Exception e) { } catch (Exception e) {
listener.onError("发生意外错误: " + e.getMessage()); listener.onError("发生意外错误: " + e.getMessage());
@ -144,7 +143,7 @@ public class CallDeepSeek {
System.out.println("文件已存在,跳过生成:" + outputPath); System.out.println("文件已存在,跳过生成:" + outputPath);
return; return;
} }
String prompt = "你是一个数据库SQL的血缘关系分析专家我将提供SQL语句给你帮我整理数据血缘关系,并且绘制HTML页面以展示最终的可视化展现。"; String prompt = "你是一个数据库SQL的血缘关系分析专家帮我整理数据血缘关系绘制HTML页面可视化展现。";
callDeepSeekStream(prompt + "\n" + sqlContent, new SSEListener() { callDeepSeekStream(prompt + "\n" + sqlContent, new SSEListener() {
@Override @Override
@ -163,11 +162,6 @@ public class CallDeepSeek {
System.err.println("错误: " + error); System.err.println("错误: " + error);
} }
}); });
// 移除 Thread.sleep(30000);
// 如果主线程需要等待SSE完成可以考虑使用更优雅的同步机制
// 例如 CountDownLatch或者让 callDeepSeekStream 方法返回一个 Future。
// 但对于简单的控制台流式输出演示,移除休眠即可观察到流式效果。
} }
public interface SSEListener { public interface SSEListener {

@ -0,0 +1,84 @@
package com.dsideal.Res.Test;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream;
import java.io.IOException;
public class MetadataTemplateGenerator {
public static void main(String[] args) {
// 创建工作簿
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("元数据模板");
// 创建标题行样式
CellStyle headerStyle = workbook.createCellStyle();
Font headerFont = workbook.createFont();
headerFont.setBold(true);
headerStyle.setFont(headerFont);
headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
headerStyle.setBorderTop(BorderStyle.THIN);
headerStyle.setBorderBottom(BorderStyle.THIN);
headerStyle.setBorderLeft(BorderStyle.THIN);
headerStyle.setBorderRight(BorderStyle.THIN);
// 创建数据单元格样式
CellStyle dataStyle = workbook.createCellStyle();
dataStyle.setAlignment(HorizontalAlignment.CENTER);
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);
dataStyle.setBorderTop(BorderStyle.THIN);
dataStyle.setBorderBottom(BorderStyle.THIN);
dataStyle.setBorderLeft(BorderStyle.THIN);
dataStyle.setBorderRight(BorderStyle.THIN);
// 创建标题行
String[] headers = {"系统名称", "表名", "字段名", "数据类型", "长度", "是否为空", "是否主键", "默认值", "描述", "创建时间", "更新时间", "负责人"};
Row headerRow = sheet.createRow(0);
headerRow.setHeightInPoints(20);
// 先设置所有列宽为44原22的两倍
for (int i = 0; i < headers.length; i++) {
sheet.setColumnWidth(i, 44 * 256); // 44个字符宽度
}
// 再创建单元格
for (int i = 0; i < headers.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(headers[i]);
cell.setCellStyle(headerStyle);
}
// 设置数据行样式
for (int i = 1; i <= 1000; i++) {
Row row = sheet.createRow(i);
row.setHeightInPoints(20); // 设置行高
for (int j = 0; j < headers.length; j++) {
Cell cell = row.createCell(j);
cell.setCellStyle(dataStyle);
}
}
// 设置数据验证(是否为空、是否主键)
DataValidationHelper validationHelper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = validationHelper.createExplicitListConstraint(new String[]{"是", "否"});
CellRangeAddressList addressList = new CellRangeAddressList(1, 1000, 5, 6);
DataValidation validation = validationHelper.createValidation(constraint, addressList);
sheet.addValidationData(validation);
// 自动调整列宽
for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i);
}
// 保存文件
try (FileOutputStream outputStream = new FileOutputStream("c:/元数据采集模板.xlsx")) {
workbook.write(outputStream);
System.out.println("Excel模板生成成功");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading…
Cancel
Save