diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java index 6f40e06..700ad53 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java @@ -66,6 +66,7 @@ import java.io.InputStream; import java.net.URLEncoder; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.IntStream; import static com.hnac.hzims.spare.utils.ExcelUtil.asyncReadModel; @@ -551,29 +552,17 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl data = new ArrayList<>(); - List error = new ArrayList<>(); - error = JSONArray.parseArray(JSON.toJSONString(entityList), WtSpBasicEntity.class).stream() - .filter(entity -> Func.isEmpty(entity.getCode())).collect(Collectors.toList()); data = JSONArray.parseArray(JSON.toJSONString(entityList), WtSpBasicEntity.class).stream() .filter(entity -> Func.isNotEmpty(entity.getCode())).collect(Collectors.toList()); - Assert.isTrue(CollectionUtil.isEmpty(error), () -> { - throw new ServiceException("填入工器具编码不能为空"); - }); -// List data = ExcelImportUtil.importExcel(file.getInputStream(), WtSpBasicEntity.class, params); -// List data = ExcelImportUtil.importExcel(file.getInputStream(), WtSpBasicEntity.class, params); - - try { - for (WtSpBasicEntity libraryExcel : data) { - Integer counter = 2; - //数据校验 - R r = this.validExcel(libraryExcel, codeList, counter); - if ( !r.isSuccess()) { - return r; + final List finalData = data; + IntStream.iterate(0, index -> index + 1).limit(data.size()).forEach(index -> { + R r = this.validExcel(finalData.get(index), codeList, index + 1); + if (!r.isSuccess()) { + throw new ServiceException(r.getMsg()); } - } - boolean flag = this.saveBatch(data); - return R.status(flag); + }); + return R.status(this.saveBatch(data)); } catch (Exception ex) { log.error("导入数据异常:", ex); throw new ServiceException(ex.getMessage()); @@ -606,7 +595,7 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl wtSpBasicEntityList = this.list(Wrappers.lambdaQuery() .eq(WtSpBasicEntity::getCode, libraryExcel.getCode())); Assert.isTrue(CollectionUtil.isEmpty(wtSpBasicEntityList), () -> { - throw new ServiceException("物资台账物品编码不能重复,保存失败!"); + throw new ServiceException("物品编码不能重复"); }); if (StringUtils.isBlank(libraryExcel.getCode())) { @@ -638,13 +627,13 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl libraryExcel.getLowerLimit()) { errors.add("库存下限不能大于库存上限"); } @@ -655,7 +644,6 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl