防止导入OOM

v1.4.1
Parker 4 years ago
parent 5d850b59d5
commit 2f72667631

@ -221,8 +221,12 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
boolean ret = IService.insertBatch(modelList); boolean ret = IService.insertBatch(modelList);
if(!ret){ if(!ret){
// 清空 list
modelList.clear();
throw new ExcelPluginException(CoreMsg.EXCEL_IMPORT_NO); throw new ExcelPluginException(CoreMsg.EXCEL_IMPORT_NO);
} }
// 清空 list
modelList.clear();
// 花费毫秒数 // 花费毫秒数
long timerCount = timer.interval(); long timerCount = timer.interval();
// 提示信息 // 提示信息
@ -298,8 +302,8 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
TimeInterval timer = DateUtil.timer(); TimeInterval timer = DateUtil.timer();
String msgInfo = ""; String msgInfo = "";
ResultVo<?> resultVo; ResultVo<?> resultVo;
List<E> modelList = Lists.newArrayList();
try { try {
List<E> modelList = Lists.newArrayList();
if(queryWrapper != null){ if(queryWrapper != null){
// 获得数量 大于 阈值 禁止导出, 防止OOM // 获得数量 大于 阈值 禁止导出, 防止OOM
int count = IService.count(queryWrapper); int count = IService.count(queryWrapper);
@ -330,6 +334,9 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
msgInfo = StrUtil.format(CoreMsg.EXCEL_EXPORT_ERROR.getMessage(), DateUtil.formatBetween(timerCount), e.getMessage()); msgInfo = StrUtil.format(CoreMsg.EXCEL_EXPORT_ERROR.getMessage(), DateUtil.formatBetween(timerCount), e.getMessage());
// 导出失败 // 导出失败
resultVo = ResultVo.error(CoreMsg.EXCEL_EXPORT_ERROR.getCode(), msgInfo); resultVo = ResultVo.error(CoreMsg.EXCEL_EXPORT_ERROR.getCode(), msgInfo);
}finally {
// 清空list
modelList.clear();
} }
// 记录导出日志 // 记录导出日志
log.info(msgInfo); log.info(msgInfo);

Loading…
Cancel
Save