This commit is contained in:
Timer
2026-03-31 09:22:04 +08:00
parent c3babf2c4d
commit f33f57f6a7
4 changed files with 60 additions and 14 deletions

View File

@ -777,13 +777,26 @@ public class RptCreateController {
@RequestMapping("/getSheet.do") @RequestMapping("/getSheet.do")
public String getSheet(HttpServletRequest request, Model model, public String getSheet(HttpServletRequest request, Model model,
@RequestParam(value = "id") String id) { @RequestParam(value = "id") String id) {
String path = "";
String name = "";
Result_Report result1 = new Result_Report(); Result_Report result1 = new Result_Report();
RptCreate rptCreate = this.rptCreateService.selectById(id); RptCreate rptCreate = this.rptCreateService.selectById(id);
if (rptCreate != null) {//报表生成中的预览 if (rptCreate != null) {//报表生成中的预览
// 优先使用数据库中存储的文件路径,如果没有则构造路径(兼容旧数据)
if (rptCreate.getAbspath() != null && !rptCreate.getAbspath().isEmpty()) {
path = rptCreate.getAbspath();
} else {
path = rptCreate.getRptname() + rptCreate.getId() + ".xls";
}
// 获取文件扩展名
String extension = ".xls";
if (path.toLowerCase().endsWith(".xlsx")) {
extension = ".xlsx";
}
String sourcePath = rptCreate.getRptname() + extension;
List<RptInfoSetSheet> list = rptInfoSetSheetService.selectListByWhere("where rptInfoSet_id = '" + rptCreate.getRptsetId() + "'"); List<RptInfoSetSheet> list = rptInfoSetSheetService.selectListByWhere("where rptInfoSet_id = '" + rptCreate.getRptsetId() + "'");
try { try {
String sourcePath = rptCreate.getRptname(); byte[] isb = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptCreateFile.getNameSpace(), path);
byte[] isb = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptCreateFile.getNameSpace(), CommUtil.fixRptCreateFileName(rptCreate.getRptname() + rptCreate.getId()));
if (isb == null || isb.length == 0) { if (isb == null || isb.length == 0) {
result1 = Result_Report.failed("文件不存在或已被删除"); result1 = Result_Report.failed("文件不存在或已被删除");
model.addAttribute("result", CommUtil.toJson(result1)); model.addAttribute("result", CommUtil.toJson(result1));
@ -801,7 +814,7 @@ public class RptCreateController {
List<RptInfoSetSheet> list = rptInfoSetSheetService.selectListByWhere("where rptInfoSet_id = '" + rptInfoSetFile.getMasterid() + "'"); List<RptInfoSetSheet> list = rptInfoSetSheetService.selectListByWhere("where rptInfoSet_id = '" + rptInfoSetFile.getMasterid() + "'");
try { try {
String sourcePath = ""; String sourcePath = "";
String path = rptInfoSetFile.getAbspath(); path = rptInfoSetFile.getAbspath();
// path = path.replaceAll("\\.xlsx", "").replaceAll("\\.xls", ""); // path = path.replaceAll("\\.xlsx", "").replaceAll("\\.xls", "");
// byte[] isb = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptInfoSetFile.getNameSpace(), CommUtil.fixRptCreateFileName(path)); // byte[] isb = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptInfoSetFile.getNameSpace(), CommUtil.fixRptCreateFileName(path));
byte[] isb = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptInfoSetFile.getNameSpace(), path); byte[] isb = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptInfoSetFile.getNameSpace(), path);
@ -877,8 +890,18 @@ public class RptCreateController {
String name = ""; String name = "";
RptCreate rptCreate = this.rptCreateService.selectById(id); RptCreate rptCreate = this.rptCreateService.selectById(id);
if (rptCreate != null) { if (rptCreate != null) {
// 优先使用数据库中存储的文件路径,如果没有则构造路径(兼容旧数据)
if (rptCreate.getAbspath() != null && !rptCreate.getAbspath().isEmpty()) {
path = rptCreate.getAbspath();
} else {
path = rptCreate.getRptname() + rptCreate.getId() + ".xls"; path = rptCreate.getRptname() + rptCreate.getId() + ".xls";
name = rptCreate.getRptname() + ".xls"; }
// 获取文件扩展名
String extension = ".xls";
if (path.toLowerCase().endsWith(".xlsx")) {
extension = ".xlsx";
}
name = rptCreate.getRptname() + extension;
} }
byte[] bytes = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptCreateFile.getNameSpace(), path); byte[] bytes = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptCreateFile.getNameSpace(), path);
if (bytes == null || bytes.length == 0) { if (bytes == null || bytes.length == 0) {

View File

@ -343,8 +343,6 @@ public class SafetyExternalCertificateController {
int result = 0; int result = 0;
for (String id : ids) { for (String id : ids) {
result += service.deleteById(id); result += service.deleteById(id);
}
for (String id : ids) {
safetyFilesService.deleteByBizId(id); safetyFilesService.deleteByBizId(id);
} }
model.addAttribute("result", result); model.addAttribute("result", result);

View File

@ -351,6 +351,8 @@ public class CommonFileServiceImpl implements CommonFileService {
String errorMsg = e.getMessage(); String errorMsg = e.getMessage();
if (errorMsg != null && errorMsg.contains("NoSuchKey")) { if (errorMsg != null && errorMsg.contains("NoSuchKey")) {
logger.error("MinIO文件不存在: bucketName={}, objectName={}", nameSpace, filePath); logger.error("MinIO文件不存在: bucketName={}, objectName={}", nameSpace, filePath);
} else if (errorMsg != null && errorMsg.contains("NoSuchBucket")) {
logger.error("MinIO存储桶不存在: bucketName={}, objectName={}", nameSpace, filePath);
} else { } else {
logger.error("获取MinIO文件失败: bucketName={}, objectName={}, 错误: {}", nameSpace, filePath, errorMsg, e); logger.error("获取MinIO文件失败: bucketName={}, objectName={}, 错误: {}", nameSpace, filePath, errorMsg, e);
} }

View File

@ -837,6 +837,20 @@ public class RptCreateServiceImpl implements RptCreateService {
// System.out.println("rptdt==============================================================" + rptdt); // System.out.println("rptdt==============================================================" + rptdt);
String rpttype = rptInfoSet.getRpttype();//报表类型 String rpttype = rptInfoSet.getRpttype();//报表类型
String bucketName = "rptinfosetfile"; String bucketName = "rptinfosetfile";
String endtype = ".xls"; // 默认文件扩展名
// 首先确保report bucket存在
try {
MinioClient minioClient = new MinioClient(minioProp.getEndPoint(), minioProp.getAccessKey(), minioProp.getSecretKey());
boolean isExist = minioClient.bucketExists("report");
if (!isExist) {
minioClient.makeBucket("report");
logger.info("Created MinIO bucket: report");
}
} catch (Exception e) {
logger.error("Failed to create report bucket", e);
}
List<RptInfoSetFile> filelist = this.rptInfoSetFileService.selectListByWhere(" where masterid='" + rptInfoSet.getId() + "' "); List<RptInfoSetFile> filelist = this.rptInfoSetFileService.selectListByWhere(" where masterid='" + rptInfoSet.getId() + "' ");
String path = ""; String path = "";
try { try {
@ -847,7 +861,11 @@ public class RptCreateServiceImpl implements RptCreateService {
rptInfoSetFile.setAbspath(obj); rptInfoSetFile.setAbspath(obj);
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println(e); logger.error("Failed to get template file from MinIO", e);
}
if (filelist == null || filelist.size() == 0) {
logger.error("No template file configured for report: {}", rptInfoSet.getId());
return null;
} }
if (filelist != null && filelist.size() > 0) { if (filelist != null && filelist.size() > 0) {
// 设定Excel文件所在路径 // 设定Excel文件所在路径
@ -858,7 +876,7 @@ public class RptCreateServiceImpl implements RptCreateService {
byte[] bytes_m = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptInfoSetFile.getNameSpace(), path); byte[] bytes_m = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptInfoSetFile.getNameSpace(), path);
// Check if bytes_m is null or empty // Check if bytes_m is null or empty
if (bytes_m == null || bytes_m.length == 0) { if (bytes_m == null || bytes_m.length == 0) {
logger.error("Excel file is empty or not found: " + path); logger.error("Excel template file is empty or not found: {}", path);
return null; return null;
} }
// 直接从本地文件创建Workbook, 从输入流创建Workbook // 直接从本地文件创建Workbook, 从输入流创建Workbook
@ -870,7 +888,8 @@ public class RptCreateServiceImpl implements RptCreateService {
logger.error("Failed to create workbook from file: " + path, e); logger.error("Failed to create workbook from file: " + path, e);
e.printStackTrace(); e.printStackTrace();
} }
String endtype = path.toLowerCase().endsWith(".xlsx") ? ".xlsx" : ".xls"; // 更新文件扩展名(根据模板文件)
endtype = path.toLowerCase().endsWith(".xlsx") ? ".xlsx" : ".xls";
// 生成一个样式,用在表格数据 // 生成一个样式,用在表格数据
CellStyle listStyle = null; CellStyle listStyle = null;
listStyle = workbook.createCellStyle(); listStyle = workbook.createCellStyle();
@ -1378,6 +1397,10 @@ public class RptCreateServiceImpl implements RptCreateService {
//删除文件 只保留minio中的文件 //删除文件 只保留minio中的文件
File file = new File(file3);//根据指定的文件名创建File对象 File file = new File(file3);//根据指定的文件名创建File对象
file.delete(); file.delete();
// 保存文件路径到数据库
rptCreate.setAbspath(showname + endtype);
rptCreateDao.updateByPrimaryKeySelective(rptCreate);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {