bug
This commit is contained in:
@ -375,7 +375,7 @@ public class RptCreateController {
|
||||
public String doadd(HttpServletRequest request, Model model) {
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
String rptsetId = request.getParameter("rptsetId");
|
||||
|
||||
|
||||
// 权限验证:检查用户是否有报表生成权限
|
||||
if (rptsetId != null && !rptsetId.isEmpty()) {
|
||||
if (!this.rptCreateService.checkGeneratePermission(rptsetId, cu)) {
|
||||
@ -383,7 +383,7 @@ public class RptCreateController {
|
||||
return "result";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
request.setAttribute("userId", cu.getId());
|
||||
request.setAttribute("userName", cu.getCaption());
|
||||
request.setAttribute("id", CommUtil.getUUID());
|
||||
@ -563,7 +563,7 @@ public class RptCreateController {
|
||||
User cu = (User) request.getSession().getAttribute("cu");
|
||||
String rptsetId = request.getParameter("rptsetId");
|
||||
int result = 0;
|
||||
|
||||
|
||||
// 权限验证:检查用户是否有报表生成权限
|
||||
if (rptCreate.getRptsetId() != null && !rptCreate.getRptsetId().isEmpty()) {
|
||||
if (!this.rptCreateService.checkGeneratePermission(rptCreate.getRptsetId(), cu)) {
|
||||
@ -571,7 +571,7 @@ public class RptCreateController {
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RptInfoSet rptInfoSet = rptInfoSetService.selectById(rptCreate.getRptsetId());
|
||||
if (rptInfoSet != null) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
@ -777,13 +777,26 @@ public class RptCreateController {
|
||||
@RequestMapping("/getSheet.do")
|
||||
public String getSheet(HttpServletRequest request, Model model,
|
||||
@RequestParam(value = "id") String id) {
|
||||
String path = "";
|
||||
String name = "";
|
||||
Result_Report result1 = new Result_Report();
|
||||
RptCreate rptCreate = this.rptCreateService.selectById(id);
|
||||
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() + "'");
|
||||
try {
|
||||
String sourcePath = rptCreate.getRptname();
|
||||
byte[] isb = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptCreateFile.getNameSpace(), CommUtil.fixRptCreateFileName(rptCreate.getRptname() + rptCreate.getId()));
|
||||
byte[] isb = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptCreateFile.getNameSpace(), path);
|
||||
if (isb == null || isb.length == 0) {
|
||||
result1 = Result_Report.failed("文件不存在或已被删除");
|
||||
model.addAttribute("result", CommUtil.toJson(result1));
|
||||
@ -801,7 +814,7 @@ public class RptCreateController {
|
||||
List<RptInfoSetSheet> list = rptInfoSetSheetService.selectListByWhere("where rptInfoSet_id = '" + rptInfoSetFile.getMasterid() + "'");
|
||||
try {
|
||||
String sourcePath = "";
|
||||
String path = rptInfoSetFile.getAbspath();
|
||||
path = rptInfoSetFile.getAbspath();
|
||||
// path = path.replaceAll("\\.xlsx", "").replaceAll("\\.xls", "");
|
||||
// byte[] isb = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptInfoSetFile.getNameSpace(), CommUtil.fixRptCreateFileName(path));
|
||||
byte[] isb = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptInfoSetFile.getNameSpace(), path);
|
||||
@ -877,8 +890,18 @@ public class RptCreateController {
|
||||
String name = "";
|
||||
RptCreate rptCreate = this.rptCreateService.selectById(id);
|
||||
if (rptCreate != null) {
|
||||
path = rptCreate.getRptname() + rptCreate.getId() + ".xls";
|
||||
name = rptCreate.getRptname() + ".xls";
|
||||
// 优先使用数据库中存储的文件路径,如果没有则构造路径(兼容旧数据)
|
||||
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";
|
||||
}
|
||||
name = rptCreate.getRptname() + extension;
|
||||
}
|
||||
byte[] bytes = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptCreateFile.getNameSpace(), path);
|
||||
if (bytes == null || bytes.length == 0) {
|
||||
|
||||
@ -343,8 +343,6 @@ public class SafetyExternalCertificateController {
|
||||
int result = 0;
|
||||
for (String id : ids) {
|
||||
result += service.deleteById(id);
|
||||
}
|
||||
for (String id : ids) {
|
||||
safetyFilesService.deleteByBizId(id);
|
||||
}
|
||||
model.addAttribute("result", result);
|
||||
|
||||
@ -351,6 +351,8 @@ public class CommonFileServiceImpl implements CommonFileService {
|
||||
String errorMsg = e.getMessage();
|
||||
if (errorMsg != null && errorMsg.contains("NoSuchKey")) {
|
||||
logger.error("MinIO文件不存在: bucketName={}, objectName={}", nameSpace, filePath);
|
||||
} else if (errorMsg != null && errorMsg.contains("NoSuchBucket")) {
|
||||
logger.error("MinIO存储桶不存在: bucketName={}, objectName={}", nameSpace, filePath);
|
||||
} else {
|
||||
logger.error("获取MinIO文件失败: bucketName={}, objectName={}, 错误: {}", nameSpace, filePath, errorMsg, e);
|
||||
}
|
||||
|
||||
@ -837,6 +837,20 @@ public class RptCreateServiceImpl implements RptCreateService {
|
||||
// System.out.println("rptdt==============================================================" + rptdt);
|
||||
String rpttype = rptInfoSet.getRpttype();//报表类型
|
||||
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() + "' ");
|
||||
String path = "";
|
||||
try {
|
||||
@ -847,7 +861,11 @@ public class RptCreateServiceImpl implements RptCreateService {
|
||||
rptInfoSetFile.setAbspath(obj);
|
||||
}
|
||||
} 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) {
|
||||
// 设定Excel文件所在路径
|
||||
@ -858,7 +876,7 @@ public class RptCreateServiceImpl implements RptCreateService {
|
||||
byte[] bytes_m = commonFileService.getInputStreamBytes(FileNameSpaceEnum.RptInfoSetFile.getNameSpace(), path);
|
||||
// Check if bytes_m is null or empty
|
||||
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;
|
||||
}
|
||||
// 直接从本地文件创建Workbook, 从输入流创建Workbook
|
||||
@ -870,7 +888,8 @@ public class RptCreateServiceImpl implements RptCreateService {
|
||||
logger.error("Failed to create workbook from file: " + path, e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
String endtype = path.toLowerCase().endsWith(".xlsx") ? ".xlsx" : ".xls";
|
||||
// 更新文件扩展名(根据模板文件)
|
||||
endtype = path.toLowerCase().endsWith(".xlsx") ? ".xlsx" : ".xls";
|
||||
// 生成一个样式,用在表格数据
|
||||
CellStyle listStyle = null;
|
||||
listStyle = workbook.createCellStyle();
|
||||
@ -1378,6 +1397,10 @@ public class RptCreateServiceImpl implements RptCreateService {
|
||||
//删除文件 只保留minio中的文件
|
||||
File file = new File(file3);//根据指定的文件名创建File对象
|
||||
file.delete();
|
||||
|
||||
// 保存文件路径到数据库
|
||||
rptCreate.setAbspath(showname + endtype);
|
||||
rptCreateDao.updateByPrimaryKeySelective(rptCreate);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user