增加文件导出缓存的配置目录,方便自由指定

This commit is contained in:
jishenghua 2026-03-25 22:23:01 +08:00
parent f820451d07
commit c1ec053c29
6 changed files with 25 additions and 8 deletions

View File

@ -19,6 +19,7 @@ import jxl.Workbook;
import jxl.write.WritableWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
@ -79,6 +80,9 @@ public class DepotHeadService {
@Resource
private LogService logService;
@Value(value="${file.exportTmp}")
private String fileExportTmp;
public DepotHead getDepotHead(long id)throws Exception {
DepotHead result=null;
try{
@ -1526,7 +1530,7 @@ public class DepotHeadService {
}
//生成Excel文件
String fileName = "单据信息";
File file = new File("/opt/"+ fileName);
File file = new File(fileExportTmp + fileName);
WritableWorkbook wtwb = Workbook.createWorkbook(file);
String oneTip = "";
String sheetOneStr = "";

View File

@ -75,6 +75,9 @@ public class MaterialService {
@Value(value="${file.uploadType}")
private Long fileUploadType;
@Value(value="${file.exportTmp}")
private String fileExportTmp;
private static final Integer EXPORT_LIMIT = 10000;
public Material getMaterial(long id)throws Exception {
@ -483,7 +486,7 @@ public class MaterialService {
List<MaterialVo4Unit> dataList = materialMapperEx.exportExcel(materialParam, color, materialOther, weight, expiryNum, enabled, enableSerialNumber,
enableBatchNumber, remark, idList);
if (null != dataList && dataList.size() > EXPORT_LIMIT) {
File file = ExcelUtils.exportObjectsOneSheet(title, "单次导出条数超出限制1万条", new String[0], title, new ArrayList<>());
File file = ExcelUtils.exportObjectsOneSheet(fileExportTmp, title, "单次导出条数超出限制1万条", new String[0], title, new ArrayList<>());
ExcelUtils.downloadExcel(file, file.getName(), response);
return;
}
@ -558,7 +561,7 @@ public class MaterialService {
objects.add(objs);
}
}
File file = ExcelUtils.exportObjectsOneSheet(title, "*导入时本行内容请勿删除,切记!", names, title, objects);
File file = ExcelUtils.exportObjectsOneSheet(fileExportTmp, title, "*导入时本行内容请勿删除,切记!", names, title, objects);
ExcelUtils.downloadExcel(file, file.getName(), response);
}

View File

@ -14,6 +14,7 @@ import jxl.Sheet;
import jxl.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
@ -53,6 +54,9 @@ public class SupplierService {
@Resource
private UserBusinessMapper userBusinessMapper;
@Value(value="${file.exportTmp}")
private String fileExportTmp;
public Supplier getSupplier(long id)throws Exception {
Supplier result=null;
try{
@ -612,7 +616,7 @@ public class SupplierService {
objects.add(objs);
}
}
return ExcelUtils.exportObjectsOneSheet(title, "*导入时本行内容请勿删除,切记!", names, title, objects);
return ExcelUtils.exportObjectsOneSheet(fileExportTmp, title, "*导入时本行内容请勿删除,切记!", names, title, objects);
}
}
@ -652,7 +656,7 @@ public class SupplierService {
objects.add(objs);
}
}
return ExcelUtils.exportObjectsOneSheet(title, "*导入时本行内容请勿删除,切记!", names, title, objects);
return ExcelUtils.exportObjectsOneSheet(fileExportTmp, title, "*导入时本行内容请勿删除,切记!", names, title, objects);
}
/**

View File

@ -62,6 +62,9 @@ public class SystemConfigService {
@Value(value="${file.path}")
private String filePath;
@Value(value="${file.exportTmp}")
private String fileExportTmp;
private static String DELETED = "deleted";
public SystemConfig getSystemConfig(long id)throws Exception {
@ -678,7 +681,7 @@ public class SystemConfigService {
objects.add(objs);
}
}
File file = ExcelUtils.exportObjectsOneSheet(title, tip, names, title, objects);
File file = ExcelUtils.exportObjectsOneSheet(fileExportTmp, title, tip, names, title, objects);
ExcelUtils.downloadExcel(file, file.getName(), response);
}
}

View File

@ -112,9 +112,10 @@ public class ExcelUtils {
* @throws Exception
*/
public static File exportObjectsOneSheet(String fileName, String tip,
public static File exportObjectsOneSheet(String path, String fileName, String tip,
String[] names, String title, List<Object[]> objects) throws Exception {
File excelFile = new File("/opt/"+ fileName);
FileUtils.makedir(path);
File excelFile = new File(path + File.separator + fileName);
WritableWorkbook wtwb = Workbook.createWorkbook(excelFile);
WritableSheet sheet = wtwb.createSheet(title, 0);
sheet.getSettings().setDefaultColumnWidth(12);

View File

@ -53,3 +53,5 @@ file:
uploadType: 1
# 文件上传根目录
path: /opt/jshERP/upload
# 文件导出缓存
exportTmp: /opt/jshERP/export