Browse Source

库存台账导入校验bug修复

zhongwei
ty 10 months ago
parent
commit
72ac1b4ff3
  1. 28
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java

28
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.net.URLEncoder;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static com.hnac.hzims.spare.utils.ExcelUtil.asyncReadModel; import static com.hnac.hzims.spare.utils.ExcelUtil.asyncReadModel;
@ -551,29 +552,17 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
} }
List entityList = excelToolListener.getDataList(); List entityList = excelToolListener.getDataList();
List<WtSpBasicEntity> data = new ArrayList<>(); List<WtSpBasicEntity> data = new ArrayList<>();
List<WtSpBasicEntity> 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() data = JSONArray.parseArray(JSON.toJSONString(entityList), WtSpBasicEntity.class).stream()
.filter(entity -> Func.isNotEmpty(entity.getCode())).collect(Collectors.toList()); .filter(entity -> Func.isNotEmpty(entity.getCode())).collect(Collectors.toList());
Assert.isTrue(CollectionUtil.isEmpty(error), () -> {
throw new ServiceException("填入工器具编码不能为空");
});
// List<WtSpBasicEntity> data = ExcelImportUtil.importExcel(file.getInputStream(), WtSpBasicEntity.class, params);
// List<WtSpBasicEntity> data = ExcelImportUtil.importExcel(file.getInputStream(), WtSpBasicEntity.class, params);
try { try {
for (WtSpBasicEntity libraryExcel : data) { final List<WtSpBasicEntity> finalData = data;
Integer counter = 2; IntStream.iterate(0, index -> index + 1).limit(data.size()).forEach(index -> {
//数据校验 R<String> r = this.validExcel(finalData.get(index), codeList, index + 1);
R<String> r = this.validExcel(libraryExcel, codeList, counter);
if (!r.isSuccess()) { if (!r.isSuccess()) {
return r; throw new ServiceException(r.getMsg());
} }
} });
boolean flag = this.saveBatch(data); return R.status(this.saveBatch(data));
return R.status(flag);
} catch (Exception ex) { } catch (Exception ex) {
log.error("导入数据异常:", ex); log.error("导入数据异常:", ex);
throw new ServiceException(ex.getMessage()); throw new ServiceException(ex.getMessage());
@ -606,7 +595,7 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
List<WtSpBasicEntity> wtSpBasicEntityList = this.list(Wrappers.<WtSpBasicEntity>lambdaQuery() List<WtSpBasicEntity> wtSpBasicEntityList = this.list(Wrappers.<WtSpBasicEntity>lambdaQuery()
.eq(WtSpBasicEntity::getCode, libraryExcel.getCode())); .eq(WtSpBasicEntity::getCode, libraryExcel.getCode()));
Assert.isTrue(CollectionUtil.isEmpty(wtSpBasicEntityList), () -> { Assert.isTrue(CollectionUtil.isEmpty(wtSpBasicEntityList), () -> {
throw new ServiceException("物资台账物品编码不能重复,保存失败!"); throw new ServiceException("物品编码不能重复");
}); });
if (StringUtils.isBlank(libraryExcel.getCode())) { if (StringUtils.isBlank(libraryExcel.getCode())) {
@ -655,7 +644,6 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
if (ObjectUtil.isEmpty(libraryExcel.getPrice())) { if (ObjectUtil.isEmpty(libraryExcel.getPrice())) {
errors.add("单价不能为空"); errors.add("单价不能为空");
} }
counter++;
if (CollectionUtils.isEmpty(errors)) { if (CollectionUtils.isEmpty(errors)) {
return R.success("OK"); return R.success("OK");
} else { } else {

Loading…
Cancel
Save