导入导出数量限制优化

v1.4.1
Parker 5 years ago
parent 3c78fc706e
commit 73937605b1

@ -198,15 +198,20 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
try { try {
List<E> modelList = ExcelUtil.getInstance().readExcel(files.get(0), modelClazz); List<E> modelList = ExcelUtil.getInstance().readExcel(files.get(0), modelClazz);
if(CollUtil.isNotEmpty(modelList)){ if(CollUtil.isNotEmpty(modelList)){
if(modelList.size() > globalProperties.getExcel().getImportMaxCount()){ // 导入数量限制 -1 为无限制
String maxError = StrUtil.format(CoreMsg.EXCEL_HANDLE_MAX.getMessage(), modelList.size(), Integer importMaxCount = globalProperties.getExcel().getImportMaxCount();
globalProperties.getExcel().getImportMaxCount()); if(importMaxCount != null && importMaxCount > -1){
// 清空 list if(modelList.size() > importMaxCount){
modelList.clear(); String maxError = StrUtil.format(CoreMsg.EXCEL_HANDLE_MAX.getMessage(), modelList.size(),
// 超出最大导出数量 importMaxCount);
throw new ExcelPluginException(CoreMsg.EXCEL_HANDLE_MAX.getCode(), maxError); // 清空 list
modelList.clear();
// 超出最大导出数量
throw new ExcelPluginException(CoreMsg.EXCEL_HANDLE_MAX.getCode(), maxError);
}
} }
boolean ret = IService.insertBatch(modelList); boolean ret = IService.insertBatch(modelList);
if(!ret){ if(!ret){
// 清空 list // 清空 list
@ -293,15 +298,20 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
List<E> modelList = Lists.newArrayList(); List<E> modelList = Lists.newArrayList();
try { try {
if(queryWrapper != null){ if(queryWrapper != null){
// 获得数量 大于 阈值 禁止导出, 防止OOM // 导出数量限制 -1 为无限制
int count = IService.count(queryWrapper); Integer exportMaxCount = globalProperties.getExcel().getExportMaxCount();
if(count > globalProperties.getExcel().getExportMaxCount()){ if(exportMaxCount != null && exportMaxCount > -1){
String maxError = StrUtil.format(CoreMsg.EXCEL_HANDLE_MAX.getMessage(), count, // 获得数量 大于 阈值 禁止导出, 防止OOM
globalProperties.getExcel().getExportMaxCount()); int count = IService.count(queryWrapper);
// 超出最大导出数量 if(count > exportMaxCount){
throw new ExcelPluginException(CoreMsg.EXCEL_HANDLE_MAX.getCode(), maxError); String maxError = StrUtil.format(CoreMsg.EXCEL_HANDLE_MAX.getMessage(), count,
exportMaxCount);
// 超出最大导出数量
throw new ExcelPluginException(CoreMsg.EXCEL_HANDLE_MAX.getCode(), maxError);
}
} }
List<T> entityList = IService.findList(queryWrapper); List<T> entityList = IService.findList(queryWrapper);
// 转化类型 // 转化类型
modelList = WrapperUtil.transformInstance(entityList, modelClazz); modelList = WrapperUtil.transformInstance(entityList, modelClazz);

@ -211,7 +211,7 @@ opsli:
# Excel # Excel
excel: excel:
# Excel 最大导入操作数量 防止OOM # Excel 最大导入操作数量 防止OOM -1为无限制
import-max-count: 5000 import-max-count: 5000
# Excel 最大导出操作数量 防止OOM # Excel 最大导出操作数量 防止OOM -1为无限制
export-max-count: 50000 export-max-count: 50000

Loading…
Cancel
Save