修改execl导入校验

This commit is contained in:
lcj
2025-12-02 17:43:59 +08:00
parent 45702ef838
commit f0802432ed
2 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package org.dromara.cailiaoshebei.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
@ -239,7 +240,14 @@ public class BusTotalsupplyplanServiceImpl extends ServiceImpl<BusTotalsupplypla
}
// 关闭读取器
excelReader.finish();
if (allData.isEmpty()) {
if (CollUtil.isEmpty(allData)) {
throw new ServiceException("未读取到有效数据", HttpStatus.BAD_REQUEST);
}
// 过滤 id 为空的数据
allData = allData.stream()
.filter(Objects::nonNull)
.filter(data -> data.getId() != null).toList();
if (CollUtil.isEmpty(allData)) {
throw new ServiceException("未读取到有效数据", HttpStatus.BAD_REQUEST);
}
// 处理导入的数据
@ -248,7 +256,7 @@ public class BusTotalsupplyplanServiceImpl extends ServiceImpl<BusTotalsupplypla
return this.updateBatchById(list);
} catch (Exception e) {
log.error("物资供货总计划导入Excel文件失败", e);
throw new ServiceException("导入失败: " + e.getMessage(), HttpStatus.ERROR);
throw new ServiceException("导入失败, " + e.getMessage(), HttpStatus.ERROR);
}
}

View File

@ -147,7 +147,9 @@ public class BusLandBlockController extends BaseController {
if (listener.hasError()) {
throw new ServiceException("Excel导入失败");
}
if (listener.getSuccessCount() <= 0) {
return R.fail("未读取到有效数据");
}
log.info("地块数据导入完成,成功: {},失败: {}",
listener.getSuccessCount(), listener.getFailCount());
} catch (IOException e) {