diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementInfoController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementInfoController.java index c9a50b03..867e2955 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementInfoController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementInfoController.java @@ -1907,8 +1907,15 @@ public class SltAgreementInfoController extends BaseController { String fileName = ""; String unitName = ""; String projectName = ""; - unitName = agreementInfo.getUnitName(); - projectName = agreementInfo.getProjectName(); + // 清理非法字符(Windows文件名不允许: \ / : * ? " < > |) + unitName = cleanFileName(agreementInfo.getUnitName()); + projectName = cleanFileName(agreementInfo.getProjectName()); + String agreementCode = cleanFileName(agreementInfo.getAgreementCode()); + + // 构建安全的文件名(限制总长度不超过150字符) + String rawFileName = agreementCode + "-" + unitName + "-" + projectName + "_结算单.xls"; + fileName = rawFileName.length() > 150 ? + rawFileName.substring(0, 150) + ".xls" : rawFileName; //租赁费用明细 BigDecimal totalCostLease = BigDecimal.valueOf(0.00); @@ -2055,7 +2062,7 @@ public class SltAgreementInfoController extends BaseController { List headersScrap = receiveDetailsHeader(4,1); List headersReduction = receiveDetailsHeader(5,1); - fileName = agreementInfo.getAgreementCode() + "-" + unitName + "-" + projectName+ "_结算单.xls" ; +// fileName = agreementInfo.getAgreementCode() + "-" + unitName + "-" + projectName+ "_结算单.xls" ; // 导出单个Excel文件 String filePath = tempDir + File.separator + fileName; try (FileOutputStream fos = new FileOutputStream(filePath)) { @@ -2093,5 +2100,20 @@ public class SltAgreementInfoController extends BaseController { } } + // 添加文件名清理工具方法 + private String cleanFileName(String name) { + if (name == null) { + return "未知"; // 空值默认处理 + } + // 1. 替换所有非法字符(含控制字符:制表符、回车、换行) + String cleaned = name.replaceAll("[\\\\/:*?\"<>|\\t\\r\\n]", "_") + .trim(); // 去除首尾空格 + // 2. 截断过长字符串(单个部分最长50字符) + if (cleaned.length() > 50) { + cleaned = cleaned.substring(0, 50) + "_"; + } + + return cleaned; + } }