|
|
@ -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()) { |
|
|
|
throw new ServiceException(r.getMsg()); |
|
|
|
return r; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
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())) { |
|
|
@ -638,13 +627,13 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB |
|
|
|
if (StringUtils.isBlank(libraryExcel.getUnit())) { |
|
|
|
if (StringUtils.isBlank(libraryExcel.getUnit())) { |
|
|
|
errors.add("物品单位不能为空"); |
|
|
|
errors.add("物品单位不能为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (ObjectUtil.isEmpty(libraryExcel.getUpperLimit()) && libraryExcel.getUpperLimit() < 0) { |
|
|
|
if (ObjectUtil.isEmpty(libraryExcel.getUpperLimit()) || libraryExcel.getUpperLimit() < 0) { |
|
|
|
errors.add("库存上限不能为空"); |
|
|
|
errors.add("库存上限不能为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (ObjectUtil.isEmpty(libraryExcel.getLowerLimit()) && libraryExcel.getLowerLimit() < 0) { |
|
|
|
if (ObjectUtil.isEmpty(libraryExcel.getLowerLimit()) || libraryExcel.getLowerLimit() < 0) { |
|
|
|
errors.add("库存下限不能为空"); |
|
|
|
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()) { |
|
|
|
if (libraryExcel.getLowerLimit() > libraryExcel.getLowerLimit()) { |
|
|
|
errors.add("库存下限不能大于库存上限"); |
|
|
|
errors.add("库存下限不能大于库存上限"); |
|
|
|
} |
|
|
|
} |
|
|
@ -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 { |
|
|
|