From d641a757f6122fa3df225cc4b1554032aa6aaf81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=B8=BF=E5=B1=95?= <18031053041@163.com> Date: Sat, 24 Jan 2026 11:34:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E5=BA=93=E7=AE=A1=E7=90=86bug?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StockInOrderApplicationService.java | 350 ++++++++++++++---- .../StockShelfOrderApplicationService.java | 21 +- .../service/StockShelfOrderDomainService.java | 21 +- .../StockInOrderImportRowDTO.java | 2 +- 4 files changed, 306 insertions(+), 88 deletions(-) diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockInOrder/StockInOrderApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockInOrder/StockInOrderApplicationService.java index 04c6cefbb..977b288b0 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockInOrder/StockInOrderApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockInOrder/StockInOrderApplicationService.java @@ -188,66 +188,129 @@ public class StockInOrderApplicationService { // 明细表的列名在第13行(索引12),数据从第14行开始 int detailTitleRowIndex = 12; // 第13行(索引从0开始) - // 先读取表头信息(第1-12行),提取委托编号NO、客户名称等信息 - String headerConsignmentNo = null; - String headerCustomerName = null; + // 先读取表头信息(第1-12行),提取所有表头字段 + StockInOrderImportRowDTO headerInfo = new StockInOrderImportRowDTO(); try (InputStream isForHeader = file.getInputStream()) { Workbook wb = WorkbookFactory.create(isForHeader); Sheet sheet = wb.getSheetAt(0); - // 从表头部分(第1-12行)读取关键信息 + // 从表头部分(第1-12行)读取所有字段信息 for (int rowIdx = 0; rowIdx < 12; rowIdx++) { Row row = sheet.getRow(rowIdx); if (row != null) { for (int colIdx = 0; colIdx < row.getPhysicalNumberOfCells(); colIdx++) { - Cell cell = row.getCell(colIdx); - if (cell != null) { - String cellValue = getCellValueAsString(cell); - if (StringUtils.isNotBlank(cellValue)) { - // 查找"委托编号"相关字段 - if (cellValue.contains("委托编号")) { - // 尝试下一个单元格 - Cell valueCell = row.getCell(colIdx + 1); - if (valueCell != null) { - String consignmentNo = getCellValueAsString(valueCell); - if (StringUtils.isNotBlank(consignmentNo) && !consignmentNo.contains("委托编号") && !consignmentNo.contains("NO")) { - headerConsignmentNo = consignmentNo; - log.info("从表头第{}行读取到委托编号NO: {}", rowIdx + 1, consignmentNo); - } - } - // 也尝试当前单元格是否包含值(格式可能是"委托编号NO: 001") - if (headerConsignmentNo == null && cellValue.contains(":")) { - String[] parts = cellValue.split(":"); - if (parts.length > 1) { - String consignmentNo = parts[1].trim(); - if (StringUtils.isNotBlank(consignmentNo) && !consignmentNo.contains("委托编号") && !consignmentNo.contains("NO")) { - headerConsignmentNo = consignmentNo; - log.info("从表头第{}行读取到委托编号NO(从同一单元格): {}", rowIdx + 1, consignmentNo); - } - } + Cell labelCell = row.getCell(colIdx); + if (labelCell != null) { + String labelValue = getCellValueAsString(labelCell); + if (StringUtils.isNotBlank(labelValue)) { + // 尝试下一个单元格作为值 + Cell valueCell = row.getCell(colIdx + 1); + String value = null; + if (valueCell != null) { + value = getCellValueAsString(valueCell); + } + + // 如果当前单元格包含冒号,尝试从同一单元格提取值 + if (StringUtils.isBlank(value) && labelValue.contains(":")) { + String[] parts = labelValue.split(":", 2); + if (parts.length > 1) { + value = parts[1].trim(); } } - // 查找"客户名称"相关字段 - if (cellValue.contains("客户名称")) { - // 尝试下一个单元格 - Cell valueCell = row.getCell(colIdx + 1); - if (valueCell != null) { - String customerName = getCellValueAsString(valueCell); - if (StringUtils.isNotBlank(customerName) && !customerName.contains("客户")) { - headerCustomerName = customerName; - log.info("从表头第{}行读取到客户名称: {}", rowIdx + 1, customerName); + + // 根据标签匹配字段 + if (StringUtils.isNotBlank(value)) { + if (labelValue.contains("委托编号") && StringUtils.isBlank(headerInfo.getConsignmentNo())) { + if (!value.contains("委托编号") && !value.contains("NO")) { + headerInfo.setConsignmentNo(value); + log.info("从表头第{}行读取到委托编号NO: {}", rowIdx + 1, value); } - } - // 也尝试当前单元格是否包含值(格式可能是"客户名称: 客户") - if (headerCustomerName == null && cellValue.contains(":")) { - String[] parts = cellValue.split(":"); - if (parts.length > 1) { - String customerName = parts[1].trim(); - if (StringUtils.isNotBlank(customerName) && !customerName.contains("客户")) { - headerCustomerName = customerName; - log.info("从表头第{}行读取到客户名称(从同一单元格): {}", rowIdx + 1, customerName); - } + } else if (labelValue.contains("客户名称") && StringUtils.isBlank(headerInfo.getCustomerName())) { + if (!value.contains("客户")) { + headerInfo.setCustomerName(value); + log.info("从表头第{}行读取到客户名称: {}", rowIdx + 1, value); } + } else if (labelValue.contains("To") && StringUtils.isBlank(headerInfo.getTo())) { + headerInfo.setTo(value); + log.info("从表头第{}行读取到To: {}", rowIdx + 1, value); + } else if (labelValue.contains("联系人") && StringUtils.isBlank(headerInfo.getContactPerson())) { + headerInfo.setContactPerson(value); + log.info("从表头第{}行读取到联系人: {}", rowIdx + 1, value); + } else if ((labelValue.contains("车型") || labelValue.contains("车牌")) && StringUtils.isBlank(headerInfo.getVehicleInfo())) { + headerInfo.setVehicleInfo(value); + log.info("从表头第{}行读取到车型及车牌: {}", rowIdx + 1, value); + } else if (labelValue.contains("承运方") || labelValue.contains("承运商") && StringUtils.isBlank(headerInfo.getCarrier())) { + headerInfo.setCarrier(value); + log.info("从表头第{}行读取到承运方: {}", rowIdx + 1, value); + } else if (labelValue.contains("Tel") && StringUtils.isBlank(headerInfo.getTel())) { + headerInfo.setTel(value); + log.info("从表头第{}行读取到Tel: {}", rowIdx + 1, value); + } else if (labelValue.contains("司机签名") && StringUtils.isBlank(headerInfo.getDriverSignature())) { + headerInfo.setDriverSignature(value); + log.info("从表头第{}行读取到司机签名: {}", rowIdx + 1, value); + } else if (labelValue.contains("入仓日期") && StringUtils.isBlank(headerInfo.getWarehouseDate())) { + headerInfo.setWarehouseDate(value); + log.info("从表头第{}行读取到入仓日期: {}", rowIdx + 1, value); + } else if (labelValue.contains("Fax") && StringUtils.isBlank(headerInfo.getFax())) { + headerInfo.setFax(value); + log.info("从表头第{}行读取到Fax: {}", rowIdx + 1, value); + } else if (labelValue.contains("申报地关区") && StringUtils.isBlank(headerInfo.getDeclarationArea())) { + headerInfo.setDeclarationArea(value); + log.info("从表头第{}行读取到申报地关区: {}", rowIdx + 1, value); + } else if (labelValue.contains("生产商") && StringUtils.isBlank(headerInfo.getManufacturer())) { + headerInfo.setManufacturer(value); + log.info("从表头第{}行读取到生产商: {}", rowIdx + 1, value); + } else if (labelValue.contains("报关员") && StringUtils.isBlank(headerInfo.getCustomsBrokerInfo())) { + headerInfo.setCustomsBrokerInfo(value); + log.info("从表头第{}行读取到报关员姓名及联系方式: {}", rowIdx + 1, value); + } else if (labelValue.contains("送货地址") && StringUtils.isBlank(headerInfo.getDeliveryAddress())) { + headerInfo.setDeliveryAddress(value); + log.info("从表头第{}行读取到送货地址: {}", rowIdx + 1, value); + } else if (labelValue.contains("进出境关别") && StringUtils.isBlank(headerInfo.getEntryExitCustoms())) { + headerInfo.setEntryExitCustoms(value); + log.info("从表头第{}行读取到进出境关别: {}", rowIdx + 1, value); + } else if (labelValue.contains("起运") || labelValue.contains("运抵国") && StringUtils.isBlank(headerInfo.getOriginDestinationCountry())) { + headerInfo.setOriginDestinationCountry(value); + log.info("从表头第{}行读取到起运/运抵国(地区): {}", rowIdx + 1, value); + } else if (labelValue.contains("柜号") && StringUtils.isBlank(headerInfo.getContainerNo())) { + headerInfo.setContainerNo(value); + log.info("从表头第{}行读取到柜号: {}", rowIdx + 1, value); + } else if (labelValue.contains("运输方式") && StringUtils.isBlank(headerInfo.getTransportMethod())) { + headerInfo.setTransportMethod(value); + log.info("从表头第{}行读取到运输方式: {}", rowIdx + 1, value); + } else if (labelValue.contains("监管方式") && StringUtils.isBlank(headerInfo.getSupervisionMethod())) { + headerInfo.setSupervisionMethod(value); + log.info("从表头第{}行读取到监管方式: {}", rowIdx + 1, value); + } else if (labelValue.contains("海关是否查验货物")) { + if (value.contains("是") || value.equals("1")) { + headerInfo.setCustomsInspection(1); + } else if (value.contains("否") || value.equals("0")) { + headerInfo.setCustomsInspection(0); + } + log.info("从表头第{}行读取到海关是否查验货物: {}", rowIdx + 1, value); + } else if (labelValue.contains("是否需要报关")) { + if (value.contains("是") || value.equals("1")) { + headerInfo.setNeedCustomsDeclaration(1); + } else if (value.contains("否") || value.equals("0")) { + headerInfo.setNeedCustomsDeclaration(0); + } + log.info("从表头第{}行读取到是否需要报关: {}", rowIdx + 1, value); + } else if (labelValue.contains("是否需要运输")) { + if (value.contains("是") || value.equals("1")) { + headerInfo.setNeedTransport(1); + } else if (value.contains("否") || value.equals("0")) { + headerInfo.setNeedTransport(0); + } + log.info("从表头第{}行读取到是否需要运输: {}", rowIdx + 1, value); + } else if (labelValue.contains("完成时间") && StringUtils.isBlank(headerInfo.getCompletionTime())) { + headerInfo.setCompletionTime(value); + log.info("从表头第{}行读取到完成时间: {}", rowIdx + 1, value); + } else if (labelValue.contains("下单日期") && StringUtils.isBlank(headerInfo.getOrderDate())) { + headerInfo.setOrderDate(value); + log.info("从表头第{}行读取到下单日期: {}", rowIdx + 1, value); + } else if (labelValue.contains("备注") && StringUtils.isBlank(headerInfo.getRemark())) { + headerInfo.setRemark(value); + log.info("从表头第{}行读取到备注: {}", rowIdx + 1, value); } } } @@ -255,11 +318,15 @@ public class StockInOrderApplicationService { } } } - log.info("表头信息读取完成 - 委托编号NO: {}, 客户名称: {}", headerConsignmentNo, headerCustomerName); + log.info("表头信息读取完成 - 委托编号NO: {}, 客户名称: {}", headerInfo.getConsignmentNo(), headerInfo.getCustomerName()); } catch (Exception e) { log.error("读取Excel表头信息失败", e); // 不抛出异常,继续尝试从明细行读取 } + + // 为了兼容旧代码,保留这两个变量 + String headerConsignmentNo = headerInfo.getConsignmentNo(); + String headerCustomerName = headerInfo.getCustomerName(); ExcelUtil util = new ExcelUtil<>(StockInOrderImportRowDTO.class); // 从第13行(索引12)读取明细数据 @@ -279,12 +346,79 @@ public class StockInOrderApplicationService { for (StockInOrderImportRowDTO row : rows) { if (row != null) { // 应用表头中的委托编号NO - if (StringUtils.isBlank(row.getConsignmentNo()) && StringUtils.isNotBlank(headerConsignmentNo)) { - row.setConsignmentNo(headerConsignmentNo); + if (StringUtils.isBlank(row.getConsignmentNo()) && StringUtils.isNotBlank(headerInfo.getConsignmentNo())) { + row.setConsignmentNo(headerInfo.getConsignmentNo()); } // 应用表头中的客户名称(表头有客户名称时,强制应用到所有明细行) - if (StringUtils.isNotBlank(headerCustomerName)) { - row.setCustomerName(headerCustomerName); + if (StringUtils.isNotBlank(headerInfo.getCustomerName())) { + row.setCustomerName(headerInfo.getCustomerName()); + } + // 应用其他表头字段(如果明细行为空,则使用表头值) + if (StringUtils.isBlank(row.getTo()) && StringUtils.isNotBlank(headerInfo.getTo())) { + row.setTo(headerInfo.getTo()); + } + if (StringUtils.isBlank(row.getContactPerson()) && StringUtils.isNotBlank(headerInfo.getContactPerson())) { + row.setContactPerson(headerInfo.getContactPerson()); + } + if (StringUtils.isBlank(row.getVehicleInfo()) && StringUtils.isNotBlank(headerInfo.getVehicleInfo())) { + row.setVehicleInfo(headerInfo.getVehicleInfo()); + } + if (StringUtils.isBlank(row.getCarrier()) && StringUtils.isNotBlank(headerInfo.getCarrier())) { + row.setCarrier(headerInfo.getCarrier()); + } + if (StringUtils.isBlank(row.getTel()) && StringUtils.isNotBlank(headerInfo.getTel())) { + row.setTel(headerInfo.getTel()); + } + if (StringUtils.isBlank(row.getDriverSignature()) && StringUtils.isNotBlank(headerInfo.getDriverSignature())) { + row.setDriverSignature(headerInfo.getDriverSignature()); + } + if (StringUtils.isBlank(row.getFax()) && StringUtils.isNotBlank(headerInfo.getFax())) { + row.setFax(headerInfo.getFax()); + } + if (StringUtils.isBlank(row.getDeclarationArea()) && StringUtils.isNotBlank(headerInfo.getDeclarationArea())) { + row.setDeclarationArea(headerInfo.getDeclarationArea()); + } + if (StringUtils.isBlank(row.getManufacturer()) && StringUtils.isNotBlank(headerInfo.getManufacturer())) { + row.setManufacturer(headerInfo.getManufacturer()); + } + if (StringUtils.isBlank(row.getCustomsBrokerInfo()) && StringUtils.isNotBlank(headerInfo.getCustomsBrokerInfo())) { + row.setCustomsBrokerInfo(headerInfo.getCustomsBrokerInfo()); + } + if (StringUtils.isBlank(row.getDeliveryAddress()) && StringUtils.isNotBlank(headerInfo.getDeliveryAddress())) { + row.setDeliveryAddress(headerInfo.getDeliveryAddress()); + } + if (StringUtils.isBlank(row.getEntryExitCustoms()) && StringUtils.isNotBlank(headerInfo.getEntryExitCustoms())) { + row.setEntryExitCustoms(headerInfo.getEntryExitCustoms()); + } + if (StringUtils.isBlank(row.getOriginDestinationCountry()) && StringUtils.isNotBlank(headerInfo.getOriginDestinationCountry())) { + row.setOriginDestinationCountry(headerInfo.getOriginDestinationCountry()); + } + if (StringUtils.isBlank(row.getContainerNo()) && StringUtils.isNotBlank(headerInfo.getContainerNo())) { + row.setContainerNo(headerInfo.getContainerNo()); + } + if (StringUtils.isBlank(row.getTransportMethod()) && StringUtils.isNotBlank(headerInfo.getTransportMethod())) { + row.setTransportMethod(headerInfo.getTransportMethod()); + } + if (StringUtils.isBlank(row.getSupervisionMethod()) && StringUtils.isNotBlank(headerInfo.getSupervisionMethod())) { + row.setSupervisionMethod(headerInfo.getSupervisionMethod()); + } + if (row.getCustomsInspection() == null && headerInfo.getCustomsInspection() != null) { + row.setCustomsInspection(headerInfo.getCustomsInspection()); + } + if (row.getNeedCustomsDeclaration() == null && headerInfo.getNeedCustomsDeclaration() != null) { + row.setNeedCustomsDeclaration(headerInfo.getNeedCustomsDeclaration()); + } + if (row.getNeedTransport() == null && headerInfo.getNeedTransport() != null) { + row.setNeedTransport(headerInfo.getNeedTransport()); + } + if (StringUtils.isBlank(row.getCompletionTime()) && StringUtils.isNotBlank(headerInfo.getCompletionTime())) { + row.setCompletionTime(headerInfo.getCompletionTime()); + } + if (StringUtils.isBlank(row.getOrderDate()) && StringUtils.isNotBlank(headerInfo.getOrderDate())) { + row.setOrderDate(headerInfo.getOrderDate()); + } + if (StringUtils.isBlank(row.getRemark()) && StringUtils.isNotBlank(headerInfo.getRemark())) { + row.setRemark(headerInfo.getRemark()); } } } @@ -316,14 +450,14 @@ public class StockInOrderApplicationService { } warehouseId = associationWarehouseCacheDO.getWarehouseId(); - // 客户名称应该从表头获取 - String customerName = StringUtils.isNotBlank(headerCustomerName) ? headerCustomerName : h.getCustomerName(); + // 客户名称应该从表头获取(优先使用表头,如果表头为空则使用明细行) + String customerName = StringUtils.isNotBlank(headerInfo.getCustomerName()) ? headerInfo.getCustomerName() : h.getCustomerName(); if (StringUtils.isBlank(customerName)) { throw new ServiceException("导入失败:客户名称不能为空(委托编号NO=" + h.getConsignmentNo() + ")。请确保Excel表头(第1-12行)中包含'客户名称'字段"); } // 如果明细行的客户名称为空,使用表头的客户名称 - if (StringUtils.isBlank(h.getCustomerName()) && StringUtils.isNotBlank(headerCustomerName)) { - h.setCustomerName(headerCustomerName); + if (StringUtils.isBlank(h.getCustomerName()) && StringUtils.isNotBlank(headerInfo.getCustomerName())) { + h.setCustomerName(headerInfo.getCustomerName()); } StockInOrderDO order = new StockInOrderDO(); @@ -346,39 +480,42 @@ public class StockInOrderApplicationService { order.setConsignmentNo(h.getConsignmentNo()); order.setRemark(h.getRemark()); - // 报关表头字段 - order.setTo(h.getTo()); - order.setContactPerson(h.getContactPerson()); - order.setVehicleInfo(h.getVehicleInfo()); - order.setTel(h.getTel()); - order.setDriverSignature(h.getDriverSignature()); - order.setFax(h.getFax()); - order.setDeclarationArea(h.getDeclarationArea()); - order.setManufacturer(h.getManufacturer()); - order.setCustomsBrokerInfo(h.getCustomsBrokerInfo()); - order.setDeliveryAddress(h.getDeliveryAddress()); - order.setEntryExitCustoms(h.getEntryExitCustoms()); - order.setOriginDestinationCountry(h.getOriginDestinationCountry()); - order.setCarrier(h.getCarrier()); - order.setContainerNo(h.getContainerNo()); - order.setTransportMethod(h.getTransportMethod()); - order.setSupervisionMethod(h.getSupervisionMethod()); + // 报关表头字段(优先使用表头字段,如果表头为空则使用明细行字段) + order.setTo(StringUtils.isNotBlank(headerInfo.getTo()) ? headerInfo.getTo() : h.getTo()); + order.setContactPerson(StringUtils.isNotBlank(headerInfo.getContactPerson()) ? headerInfo.getContactPerson() : h.getContactPerson()); + order.setVehicleInfo(StringUtils.isNotBlank(headerInfo.getVehicleInfo()) ? headerInfo.getVehicleInfo() : h.getVehicleInfo()); + order.setTel(StringUtils.isNotBlank(headerInfo.getTel()) ? headerInfo.getTel() : h.getTel()); + order.setDriverSignature(StringUtils.isNotBlank(headerInfo.getDriverSignature()) ? headerInfo.getDriverSignature() : h.getDriverSignature()); + order.setFax(StringUtils.isNotBlank(headerInfo.getFax()) ? headerInfo.getFax() : h.getFax()); + order.setDeclarationArea(StringUtils.isNotBlank(headerInfo.getDeclarationArea()) ? headerInfo.getDeclarationArea() : h.getDeclarationArea()); + order.setManufacturer(StringUtils.isNotBlank(headerInfo.getManufacturer()) ? headerInfo.getManufacturer() : h.getManufacturer()); + order.setCustomsBrokerInfo(StringUtils.isNotBlank(headerInfo.getCustomsBrokerInfo()) ? headerInfo.getCustomsBrokerInfo() : h.getCustomsBrokerInfo()); + order.setDeliveryAddress(StringUtils.isNotBlank(headerInfo.getDeliveryAddress()) ? headerInfo.getDeliveryAddress() : h.getDeliveryAddress()); + order.setEntryExitCustoms(StringUtils.isNotBlank(headerInfo.getEntryExitCustoms()) ? headerInfo.getEntryExitCustoms() : h.getEntryExitCustoms()); + order.setOriginDestinationCountry(StringUtils.isNotBlank(headerInfo.getOriginDestinationCountry()) ? headerInfo.getOriginDestinationCountry() : h.getOriginDestinationCountry()); + order.setCarrier(StringUtils.isNotBlank(headerInfo.getCarrier()) ? headerInfo.getCarrier() : h.getCarrier()); + order.setContainerNo(StringUtils.isNotBlank(headerInfo.getContainerNo()) ? headerInfo.getContainerNo() : h.getContainerNo()); + order.setTransportMethod(StringUtils.isNotBlank(headerInfo.getTransportMethod()) ? headerInfo.getTransportMethod() : h.getTransportMethod()); + order.setSupervisionMethod(StringUtils.isNotBlank(headerInfo.getSupervisionMethod()) ? headerInfo.getSupervisionMethod() : h.getSupervisionMethod()); - // 报关字段默认值 - if (h.getCustomsInspection() == null) { + // 报关字段默认值(优先使用表头字段) + Integer customsInspection = headerInfo.getCustomsInspection() != null ? headerInfo.getCustomsInspection() : h.getCustomsInspection(); + if (customsInspection == null) { order.setCustomsInspection(0); // 默认:否 } else { - order.setCustomsInspection(h.getCustomsInspection()); + order.setCustomsInspection(customsInspection); } - if (h.getNeedCustomsDeclaration() == null) { + Integer needCustomsDeclaration = headerInfo.getNeedCustomsDeclaration() != null ? headerInfo.getNeedCustomsDeclaration() : h.getNeedCustomsDeclaration(); + if (needCustomsDeclaration == null) { order.setNeedCustomsDeclaration(1); // 默认:是 } else { - order.setNeedCustomsDeclaration(h.getNeedCustomsDeclaration()); + order.setNeedCustomsDeclaration(needCustomsDeclaration); } - if (h.getNeedTransport() == null) { + Integer needTransport = headerInfo.getNeedTransport() != null ? headerInfo.getNeedTransport() : h.getNeedTransport(); + if (needTransport == null) { order.setNeedTransport(0); // 默认:否 } else { - order.setNeedTransport(h.getNeedTransport()); + order.setNeedTransport(needTransport); } // 明细 @@ -386,6 +523,57 @@ public class StockInOrderApplicationService { for (StockInOrderImportRowDTO r : groupRows) { // 根据明细表中的字段查询物料基础信息(优先:料号 > 商品SKU码 > 商品名称) Long materialBaseInfoId = null; + LoginUser currentLoginUser = SecurityUtils.getLoginUser(); + Long topOrganizationId = currentLoginUser != null && currentLoginUser.getUserPo() != null + ? currentLoginUser.getUserPo().getTopOrganizationId() : null; + + // 优先使用料号查询 + if (StringUtils.isNotBlank(r.getMaterialCode())) { + MaterialBaseInfoDO queryDO = new MaterialBaseInfoDO(); + queryDO.setMaterialCode(r.getMaterialCode()); + if (topOrganizationId != null) { + queryDO.setTopOrganizationId(topOrganizationId); + } + List materialList = materialBaseInfoService.queryList(queryDO); + if (materialList != null && !materialList.isEmpty()) { + materialBaseInfoId = materialList.get(0).getMaterialBaseInfoId(); + log.info("通过料号查询到物料基础信息,料号: {}, 物料ID: {}", r.getMaterialCode(), materialBaseInfoId); + } + } + + // 如果料号查询不到,使用商品SKU码查询 + if (materialBaseInfoId == null && StringUtils.isNotBlank(r.getSkuCode())) { + MaterialBaseInfoDO queryDO = new MaterialBaseInfoDO(); + queryDO.setBarCode(r.getSkuCode()); + if (topOrganizationId != null) { + queryDO.setTopOrganizationId(topOrganizationId); + } + List materialList = materialBaseInfoService.queryList(queryDO); + if (materialList != null && !materialList.isEmpty()) { + materialBaseInfoId = materialList.get(0).getMaterialBaseInfoId(); + log.info("通过商品SKU码查询到物料基础信息,SKU码: {}, 物料ID: {}", r.getSkuCode(), materialBaseInfoId); + } + } + + // 如果料号和SKU码都查询不到,使用商品名称查询 + if (materialBaseInfoId == null && StringUtils.isNotBlank(r.getMaterialName())) { + MaterialBaseInfoDO queryDO = new MaterialBaseInfoDO(); + queryDO.setMaterialName(r.getMaterialName()); + if (topOrganizationId != null) { + queryDO.setTopOrganizationId(topOrganizationId); + } + List materialList = materialBaseInfoService.queryList(queryDO); + if (materialList != null && !materialList.isEmpty()) { + materialBaseInfoId = materialList.get(0).getMaterialBaseInfoId(); + log.info("通过商品名称查询到物料基础信息,商品名称: {}, 物料ID: {}", r.getMaterialName(), materialBaseInfoId); + } + } + + // 如果都查询不到,记录警告但不阻止导入(允许后续手动关联) + if (materialBaseInfoId == null) { + log.warn("未查询到物料基础信息,料号: {}, SKU码: {}, 商品名称: {},将使用null值,后续可能需要手动关联", + r.getMaterialCode(), r.getSkuCode(), r.getMaterialName()); + } // 使用仓库数量 BigDecimal quantity = r.getWarehouseQuantity(); diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockShelfOrder/StockShelfOrderApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockShelfOrder/StockShelfOrderApplicationService.java index 49392d4dc..1ce4c2667 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockShelfOrder/StockShelfOrderApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockShelfOrder/StockShelfOrderApplicationService.java @@ -326,11 +326,26 @@ public class StockShelfOrderApplicationService { * @param shelfMaterialDetailDO */ private void setStorageLocationInfo(ShelfMaterialDetailDO shelfMaterialDetailDO){ + if (shelfMaterialDetailDO.getStorageLocationId() == null) { + throw new ServiceException("库位ID不能为空"); + } AjaxResult storageLocationResult = systemServiceFeign.getStorageLocationInfoByStorageLocationId(shelfMaterialDetailDO.getStorageLocationId()); - if(!"200".equals(String.valueOf(storageLocationResult.get("code")))){ - throw new ServiceException("获取上架库位信息失败"); + if (storageLocationResult == null) { + throw new ServiceException("获取上架库位信息失败:返回结果为空"); + } + Object codeObj = storageLocationResult.get("code"); + if (codeObj == null || !"200".equals(String.valueOf(codeObj))) { + String errorMsg = storageLocationResult.get("msg") != null ? String.valueOf(storageLocationResult.get("msg")) : "未知错误"; + throw new ServiceException("获取上架库位信息失败,库位ID:" + shelfMaterialDetailDO.getStorageLocationId() + ",错误信息:" + errorMsg); + } + Object dataObj = storageLocationResult.get("data"); + if (dataObj == null) { + throw new ServiceException("获取上架库位信息失败:返回数据为空,库位ID:" + shelfMaterialDetailDO.getStorageLocationId()); + } + StorageLocationFeignPO storageLocationFeignPO = JSON.parseObject(JSONObject.toJSONString(dataObj), StorageLocationFeignPO.class); + if (storageLocationFeignPO == null) { + throw new ServiceException("获取上架库位信息失败:数据解析失败,库位ID:" + shelfMaterialDetailDO.getStorageLocationId()); } - StorageLocationFeignPO storageLocationFeignPO = JSON.parseObject(JSONObject.toJSONString(storageLocationResult.get("data")), StorageLocationFeignPO.class); shelfMaterialDetailDO.setWarehouseId(storageLocationFeignPO.getWarehouseId()); shelfMaterialDetailDO.setWarehouseCode(storageLocationFeignPO.getWarehouseCode()); shelfMaterialDetailDO.setWarehouseName(storageLocationFeignPO.getWarehouseName()); diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/stockShelfOrder/service/StockShelfOrderDomainService.java b/mhd_wms/src/main/java/com/mhd/wms/domain/stockShelfOrder/service/StockShelfOrderDomainService.java index a7c613f01..f9987b1ef 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/domain/stockShelfOrder/service/StockShelfOrderDomainService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/domain/stockShelfOrder/service/StockShelfOrderDomainService.java @@ -55,6 +55,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; @@ -300,14 +301,17 @@ public class StockShelfOrderDomainService { StockShelfOrder stockShelfOrder = new StockShelfOrder(); stockShelfOrder.setShelfOrderId(stockShelfOrderDO.getShelfOrderId()); stockShelfOrder.setStatus(2); - stockShelfOrder.setShelvesQuantity(stockShelfOrderPO.getShelvesQuantity().add(stockShelfOrderDO.getActualQuantity())); + BigDecimal currentShelvesQuantity = stockShelfOrderPO.getShelvesQuantity() != null ? stockShelfOrderPO.getShelvesQuantity() : BigDecimal.ZERO; + BigDecimal actualQuantity = stockShelfOrderDO.getActualQuantity() != null ? stockShelfOrderDO.getActualQuantity() : BigDecimal.ZERO; + stockShelfOrder.setShelvesQuantity(currentShelvesQuantity.add(actualQuantity)); stockShelfOrder.setShelvesMaterialQuantity(stockShelfOrderPO.getShelvesMaterialQuantity() + stockShelfOrderDO.getActualReceiptMaterialQuantity()); stockShelfOrder.setUpdateBy(loginUser.getUserid()); stockShelfOrder.setUpdateByName(loginUser.getUsername()); stockShelfOrder.setUpdateTime(new Date()); stockShelfOrderService.updateById(stockShelfOrder); //上架数量大于等于计划数量 直接完成上架 - if (stockShelfOrder.getShelvesQuantity().compareTo(stockShelfOrderPO.getReceiptQuantity()) >= 0){ + BigDecimal receiptQuantity = stockShelfOrderPO.getReceiptQuantity() != null ? stockShelfOrderPO.getReceiptQuantity() : BigDecimal.ZERO; + if (stockShelfOrder.getShelvesQuantity().compareTo(receiptQuantity) >= 0){ completeUpShelf(stockShelfOrderPO.getShelfOrderId()); } return true; @@ -351,7 +355,9 @@ public class StockShelfOrderDomainService { throw new ServiceException("上架单【" + stockShelfOrderPO.getReceiptOrderNumber() + "】已完成上架,请重新选择"); } int abnormal = 2; - if (stockShelfOrderPO.getShelvesQuantity().compareTo(stockShelfOrderPO.getQuantity()) != 0){ + BigDecimal shelvesQuantity = stockShelfOrderPO.getShelvesQuantity() != null ? stockShelfOrderPO.getShelvesQuantity() : BigDecimal.ZERO; + BigDecimal quantity = stockShelfOrderPO.getQuantity() != null ? stockShelfOrderPO.getQuantity() : BigDecimal.ZERO; + if (shelvesQuantity.compareTo(quantity) != 0){ abnormal = 1; } LoginUser loginUser = SecurityUtils.getLoginUser(); @@ -418,7 +424,16 @@ public class StockShelfOrderDomainService { public void updateSerialNumberforInventory(List shelfMaterialDetailList){ for (ShelfMaterialDetail shelfMaterialDetail : shelfMaterialDetailList){ + if (shelfMaterialDetail.getMaterialDetailId() == null) { + continue; + } MaterialInventory one = materialInventoryService.getOne(new QueryWrapper().lambda().eq(MaterialInventory::getMaterialDetailId, shelfMaterialDetail.getMaterialDetailId())); + if (one == null) { + continue; + } + if (one.getMaterialInventoryId() == null) { + continue; + } iSerialNumberService.update(new UpdateWrapper().lambda().eq(SerialNumber::getMaterialDetailId, one.getMaterialDetailId()).set(SerialNumber::getMaterialInventoryId, one.getMaterialInventoryId())); } } diff --git a/mhd_wms/src/main/java/com/mhd/wms/interfaces/dto/stockInOrder/StockInOrderImportRowDTO.java b/mhd_wms/src/main/java/com/mhd/wms/interfaces/dto/stockInOrder/StockInOrderImportRowDTO.java index 035191d01..0dd4dadc1 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/interfaces/dto/stockInOrder/StockInOrderImportRowDTO.java +++ b/mhd_wms/src/main/java/com/mhd/wms/interfaces/dto/stockInOrder/StockInOrderImportRowDTO.java @@ -126,7 +126,7 @@ public class StockInOrderImportRowDTO { @Excel(name = "规格型号/ITEM") private String specificationModel; - @Excel(name = "SKU码") + @Excel(name = "商品SKU码") private String skuCode; @Excel(name = "Invoice No.")