From 72ac1b4ff3594dfbc5844531e9798e35c19c4957 Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Thu, 18 Jan 2024 09:36:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98=E5=8F=B0=E8=B4=A6=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=A0=A1=E9=AA=8Cbug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spare/service/impl/WtSpBasicServiceImpl.java | 30 +++++++--------------- 1 file changed, 9 insertions(+), 21 deletions(-) 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 9223bb7..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())) { @@ -655,7 +644,6 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl