|
|
|
|
@ -25,6 +25,8 @@ |
|
|
|
|
*/ |
|
|
|
|
package org.springblade.desk.energy.controller; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
import cn.hutool.core.exceptions.ExceptionUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
|
|
|
|
@ -185,12 +187,54 @@ public class BsDosingRecController extends BladeController { |
|
|
|
|
if (checkR != null) { |
|
|
|
|
return checkR; |
|
|
|
|
} |
|
|
|
|
List<BsDosingRecEntity> importList = ExcelUtil.read( |
|
|
|
|
file, 0, 1, BsDosingRecEntity.class |
|
|
|
|
); |
|
|
|
|
importList.forEach(x->{ |
|
|
|
|
x.setDorType(dorType); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
List<BsDosingRecEntity> importList; |
|
|
|
|
try { |
|
|
|
|
importList = ExcelUtil.read( |
|
|
|
|
file, 0, 1, BsDosingRecEntity.class |
|
|
|
|
); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
// 捕获Excel读取时的类型转换异常
|
|
|
|
|
String errorMsg = ExceptionUtil.getMessage(e); |
|
|
|
|
throw new RuntimeException("Excel数据格式错误:请检查日期、数字等字段格式是否正确"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(importList)){ |
|
|
|
|
return R.fail("导入数据为空"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 数据校验
|
|
|
|
|
StringBuilder errorMsg = new StringBuilder(); |
|
|
|
|
for (int i = 0; i < importList.size(); i++) { |
|
|
|
|
BsDosingRecEntity entity = importList.get(i); |
|
|
|
|
int rowNum = i + 2; // Excel行号(从第2行开始,第1行是表头)
|
|
|
|
|
|
|
|
|
|
// 校验设施字段
|
|
|
|
|
if (entity.getDevice() == null || entity.getDevice().trim().isEmpty()) { |
|
|
|
|
errorMsg.append("第").append(rowNum).append("行:设施不能为空;\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 校验药品字段
|
|
|
|
|
if (entity.getDrug() == null || entity.getDrug().trim().isEmpty()) { |
|
|
|
|
errorMsg.append("第").append(rowNum).append("行:药品不能为空;\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 校验剂量字段
|
|
|
|
|
if (entity.getDose() == null) { |
|
|
|
|
errorMsg.append("第").append(rowNum).append("行:剂量不能为空;\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 校验加药时间字段
|
|
|
|
|
if (entity.getDosingTime() == null) { |
|
|
|
|
errorMsg.append("第").append(rowNum).append("行:加药时间不能为空或格式不正确(应为:yyyy-MM-dd HH:mm:ss);\n"); |
|
|
|
|
} |
|
|
|
|
entity.setDorType(dorType); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (errorMsg.length() > 0) { |
|
|
|
|
throw new RuntimeException("数据格式错误:\n" + errorMsg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return R.status(bsDosingRecService.saveBatch(importList)); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
|