Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
haungxing 11 months ago
parent
commit
3d44062d0c
  1. 36
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java

36
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<WtSpBasicMapper, WtSpB
}
List entityList = excelToolListener.getDataList();
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()
.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 {
for (WtSpBasicEntity libraryExcel : data) {
Integer counter = 2;
//数据校验
R<String> r = this.validExcel(libraryExcel, codeList, counter);
if ( !r.isSuccess()) {
return r;
final List<WtSpBasicEntity> finalData = data;
IntStream.iterate(0, index -> index + 1).limit(data.size()).forEach(index -> {
R<String> 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<WtSpBasicMapper, WtSpB
List<WtSpBasicEntity> wtSpBasicEntityList = this.list(Wrappers.<WtSpBasicEntity>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<WtSpBasicMapper, WtSpB
if (StringUtils.isBlank(libraryExcel.getUnit())) {
errors.add("物品单位不能为空");
}
if (ObjectUtil.isEmpty(libraryExcel.getUpperLimit()) && libraryExcel.getUpperLimit() < 0) {
if (ObjectUtil.isEmpty(libraryExcel.getUpperLimit()) || libraryExcel.getUpperLimit() < 0) {
errors.add("库存上限不能为空");
}
if (ObjectUtil.isEmpty(libraryExcel.getLowerLimit()) && libraryExcel.getLowerLimit() < 0) {
if (ObjectUtil.isEmpty(libraryExcel.getLowerLimit()) || libraryExcel.getLowerLimit() < 0) {
errors.add("库存下限不能为空");
}
if (ObjectUtil.isEmpty(libraryExcel.getLowerLimit()) && ObjectUtil.isEmpty(libraryExcel.getLowerLimit())) {
if (ObjectUtil.isNotEmpty(libraryExcel.getLowerLimit()) && ObjectUtil.isNotEmpty(libraryExcel.getLowerLimit())) {
if (libraryExcel.getLowerLimit() > libraryExcel.getLowerLimit()) {
errors.add("库存下限不能大于库存上限");
}
@ -655,7 +644,6 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
if (ObjectUtil.isEmpty(libraryExcel.getPrice())) {
errors.add("单价不能为空");
}
counter++;
if (CollectionUtils.isEmpty(errors)) {
return R.success("OK");
} else {

Loading…
Cancel
Save