feat(wms):出入库导入增加料号与规格型号/SKU码一致性校验

- 按料号查物料档案后逐项比对,任何一项不符直接报对应错误:规格型号/SKU码必须与档案完全一致(trim后比较)
- Excel留空而档案有值、或Excel填值而档案为空,均视为不一致报错(提示Excel:空/档案:空)
- SKU码以档案条码(bar_code)为比对基准;出库料号已填写但货主下查不到时直接报错,不再被SKU码/商品名称静默兜底(与入库对齐
This commit is contained in:
rcx
2026-08-26 16:56:27 +08:00
parent 9eb2f347f7
commit 353300b643
2 changed files with 27 additions and 37 deletions
@@ -1827,8 +1827,6 @@ public class StockInOrderApplicationService {
.collect(Collectors.groupingBy(r -> StringUtils.isBlank(r.getConsignmentNo()) ? "__EMPTY_CONSIGNMENT__" : r.getConsignmentNo()));
List<StockInOrderDO> orderList = new ArrayList<>();
// 收集"料号与规格型号/SKU码不一致"的错误行,最后统一抛出,避免用户修一行导一次
List<String> consistencyErrors = new ArrayList<>();
for (Map.Entry<String, List<StockInOrderImportRowDTO>> entry : groupMap.entrySet()) {
List<StockInOrderImportRowDTO> groupRows = entry.getValue();
StockInOrderImportRowDTO h = groupRows.get(0);
@@ -2047,20 +2045,21 @@ public class StockInOrderApplicationService {
log.error(errorMsg);
throw new ServiceException(errorMsg);
}
// 校验料号与规格型号/SKU码一致性:档案有值就必须一致(Excel留空视为不一致);档案为空则跳过该项
// 校验料号与规格型号/SKU码一致性:按料号查到档案后逐项比对,任何一项不符直接报对应错误
// 双方(trim后)必须完全一致:Excel留空而档案有值、或Excel填了值而档案为空,均视为不一致报错
String excelSpec = StringUtils.trimToEmpty(r.getSpecificationModel());
if (StringUtils.isNotBlank(materialBaseInfoPO.getSpecificationModel())
&& !excelSpec.equals(materialBaseInfoPO.getSpecificationModel().trim())) {
consistencyErrors.add(String.format("料号[%s](商品名称:%s)规格型号与物料档案不一致(Excel:%s / 档案:%s",
String dbSpec = StringUtils.trimToEmpty(materialBaseInfoPO.getSpecificationModel());
if (!excelSpec.equals(dbSpec)) {
throw new ServiceException(String.format("导入失败:料号[%s](商品名称:%s)规格型号与物料档案不一致(Excel:%s / 档案:%s",
r.getMaterialCode(), r.getMaterialName(),
excelSpec.isEmpty() ? "" : excelSpec, materialBaseInfoPO.getSpecificationModel().trim()));
excelSpec.isEmpty() ? "" : excelSpec, dbSpec.isEmpty() ? "" : dbSpec));
}
String excelSku = StringUtils.trimToEmpty(r.getSkuCode());
if (StringUtils.isNotBlank(materialBaseInfoPO.getBarCode())
&& !excelSku.equals(materialBaseInfoPO.getBarCode().trim())) {
consistencyErrors.add(String.format("料号[%s](商品名称:%s)SKU码与物料档案不一致(Excel:%s / 档案:%s",
String dbSku = StringUtils.trimToEmpty(materialBaseInfoPO.getBarCode());
if (!excelSku.equals(dbSku)) {
throw new ServiceException(String.format("导入失败:料号[%s](商品名称:%s)SKU码与物料档案不一致(Excel:%s / 档案:%s",
r.getMaterialCode(), r.getMaterialName(),
excelSku.isEmpty() ? "" : excelSku, materialBaseInfoPO.getBarCode().trim()));
excelSku.isEmpty() ? "" : excelSku, dbSku.isEmpty() ? "" : dbSku));
}
// 数量已在前面检查过,这里直接使用
@@ -2203,11 +2202,6 @@ public class StockInOrderApplicationService {
if (orderList.isEmpty()) {
throw new ServiceException("导入失败:所有入库单的明细行都因数据不完整(数量为空或物料基础信息缺失)被跳过,请检查Excel数据");
}
// 存在料号与规格型号/SKU码不一致的明细行时,拒绝导入并一次性提示全部问题行
if (!consistencyErrors.isEmpty()) {
throw new ServiceException("导入失败,以下明细行的规格型号/SKU码与物料档案不一致,请修正后重新导入:\n"
+ String.join("\n", consistencyErrors));
}
return stockInOrderDomainService.batchInsert(orderList);
@@ -112,8 +112,7 @@ public class ExcelParseService {
LoginUser loginUser = SecurityUtils.getLoginUser();
Long topOrganizationId = loginUser != null && loginUser.getUserPo() != null
? loginUser.getUserPo().getTopOrganizationId() : null;
StringBuilder materialConsistencyErrors = new StringBuilder();
initList(itemList, warehouseId, warehouseCode, warehouseName, shipperId, topOrganizationId, materialConsistencyErrors);
initList(itemList, warehouseId, warehouseCode, warehouseName, shipperId, topOrganizationId);
stockOutOrder.setMaterialDetailList(itemList);
stockOutOrder.setWarehouseName(warehouseName);
stockOutOrder.setWarehouseCode(warehouseCode);
@@ -171,10 +170,6 @@ public class ExcelParseService {
for (String dateError : headerListener.getDateParseErrors()) {
errorMsg.append(dateError).append("; ");
}
// 物料一致性校验错误与必填校验错误合并任一有错都不落库
if (materialConsistencyErrors.length() > 0) {
errorMsg.insert(0, materialConsistencyErrors);
}
if (errorMsg.length() > 0) {
return errorMsg;
} else {
@@ -425,7 +420,8 @@ public class ExcelParseService {
* @param shipperId 货主ID用于过滤物料基础信息确保查询到的是该货主绑定的物料
* @param topOrganizationId 一级组织ID用于过滤物料基础信息
*/
private void initList(List<OutMaterialDetailDO> outMaterialDetailDOList, Long warehouseId, String warehouseCode, String warehouseName, Long shipperId, Long topOrganizationId, StringBuilder materialConsistencyErrors) { for (OutMaterialDetailDO outMaterialDetailDO : outMaterialDetailDOList) {
private void initList(List<OutMaterialDetailDO> outMaterialDetailDOList, Long warehouseId, String warehouseCode, String warehouseName, Long shipperId, Long topOrganizationId) {
for (OutMaterialDetailDO outMaterialDetailDO : outMaterialDetailDOList) {
outMaterialDetailDO.setWarehouseId(warehouseId);
outMaterialDetailDO.setWarehouseCode(warehouseCode);
outMaterialDetailDO.setWarehouseName(warehouseName);
@@ -457,25 +453,25 @@ public class ExcelParseService {
if (materialList != null && !materialList.isEmpty()) {
materialBaseInfoPO = materialList.get(0);
materialBaseInfoId = materialBaseInfoPO.getMaterialBaseInfoId();
// ==== 新增料号与规格型号/SKU码一致性校验档案有值就必须一致Excel留空视为不一致档案为空跳过====
BigDecimal unitPrice = materialBaseInfoPO.getUnitPrice();
outMaterialDetailDO.setUnitPrice(unitPrice);
// ==== 料号与规格型号/SKU码一致性校验任何一项不符直接报对应错误 ====
// 双方trim后必须完全一致Excel留空而档案有值或Excel填了值而档案为空均视为不一致报错
String excelSpec = StringUtils.trimToEmpty(outMaterialDetailDO.getSpecificationModel());
if (StringUtils.isNotBlank(materialBaseInfoPO.getSpecificationModel())
&& !excelSpec.equals(materialBaseInfoPO.getSpecificationModel().trim())) {
materialConsistencyErrors.append("料号「").append(outMaterialDetailDO.getMaterialNo())
.append("」规格型号与物料档案不一致(Excel:").append(excelSpec.isEmpty() ? "" : excelSpec)
.append(" / 档案:").append(materialBaseInfoPO.getSpecificationModel().trim()).append("; ");
String dbSpec = StringUtils.trimToEmpty(materialBaseInfoPO.getSpecificationModel());
if (!excelSpec.equals(dbSpec)) {
throw new ServiceException(String.format("导入失败:料号「%s」规格型号与物料档案不一致(Excel:%s / 档案:%s",
materialNo, excelSpec.isEmpty() ? "" : excelSpec, dbSpec.isEmpty() ? "" : dbSpec));
}
String excelSku = StringUtils.trimToEmpty(outMaterialDetailDO.getSkucode());
if (StringUtils.isNotBlank(materialBaseInfoPO.getBarCode())
&& !excelSku.equals(materialBaseInfoPO.getBarCode().trim())) {
materialConsistencyErrors.append("料号「").append(outMaterialDetailDO.getMaterialNo())
.append("」SKU码与物料档案不一致(Excel:").append(excelSku.isEmpty() ? "" : excelSku)
.append(" / 档案:").append(materialBaseInfoPO.getBarCode().trim()).append("; ");
String dbSku = StringUtils.trimToEmpty(materialBaseInfoPO.getBarCode());
if (!excelSku.equals(dbSku)) {
throw new ServiceException(String.format("导入失败:料号「%s」SKU码与物料档案不一致(Excel:%s / 档案:%s",
materialNo, excelSku.isEmpty() ? "" : excelSku, dbSku.isEmpty() ? "" : dbSku));
}
}else {
} else {
// 料号已填写但在该货主下查不到 直接报错与入库导入一致不再被SKU码/商品名称静默兜底
materialConsistencyErrors.append("料号「").append(materialNo)
.append("」在当前客户(货主)下不存在,请核对料号或在物料管理中维护;");
throw new ServiceException(String.format("导入失败:料号「%s」在当前客户(货主)下不存在,请核对料号或在物料管理中维护", materialNo));
}
}