diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/statementStatistics/StatementStatisticsService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/statementStatistics/StatementStatisticsService.java index f358a9a11..4c93bea75 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/statementStatistics/StatementStatisticsService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/statementStatistics/StatementStatisticsService.java @@ -129,16 +129,6 @@ public class StatementStatisticsService { } List immediateInventoryPOS = materialInventoryDomainService.queryImmediateInventoryList(immediateInventoryDO); - // 库存数量合计:与列表同筛选条件、不分页统计全部库存数量,回填到每行 - if (!CollectionUtils.isEmpty(immediateInventoryPOS)) { - BigDecimal totalInventoryQuantity = materialInventoryDomainService.sumImmediateInventoryQuantity(immediateInventoryDO); - if (totalInventoryQuantity == null) { - totalInventoryQuantity = BigDecimal.ZERO; - } - BigDecimal finalTotal = totalInventoryQuantity; - immediateInventoryPOS.forEach(po -> po.setTotalInventoryQuantity(finalTotal)); - } - // 性能优化:批量获取批次属性,避免N+1查询问题 // 1. 收集所有唯一的materialBaseInfoId Set materialBaseInfoIdSet = immediateInventoryPOS.stream() @@ -173,6 +163,19 @@ public class StatementStatisticsService { return immediateInventoryPOS; } + /** + * 获取库存数量合计 + * @param immediateInventoryDO 查询参数 + * @return 库存数量合计 + */ + public BigDecimal sumImmediateInventoryQuantity(ImmediateInventoryDO immediateInventoryDO) { + BigDecimal totalInventoryQuantity = materialInventoryDomainService.sumImmediateInventoryQuantity(immediateInventoryDO); + if (totalInventoryQuantity == null) { + totalInventoryQuantity = BigDecimal.ZERO; + } + return totalInventoryQuantity; + } + /** * 为物料库存设置更多属性(从库存表中获取值) * @param materialInventoryPOList 物料库存列表 diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/inventoryAdjustmentRecord/service/InventoryAdjustmentRecordDomainService.java b/mhd_wms/src/main/java/com/mhd/wms/domain/inventoryAdjustmentRecord/service/InventoryAdjustmentRecordDomainService.java index 9bccb9db7..f728e90c8 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/domain/inventoryAdjustmentRecord/service/InventoryAdjustmentRecordDomainService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/domain/inventoryAdjustmentRecord/service/InventoryAdjustmentRecordDomainService.java @@ -7,6 +7,8 @@ import com.mhd.common.core.constant.SnowFlakeConstants; import com.mhd.common.core.domain.po.UserPo; import com.mhd.common.core.utils.OrderSequence; import com.mhd.common.core.utils.uuid.IdGenerator; +import com.mhd.common.core.utils.StringUtils; +import com.mhd.common.core.web.domain.AjaxResult; import com.mhd.common.core.web.domain.BaseVOEntity; import com.mhd.common.security.utils.SecurityUtils; import com.mhd.system.api.OmsServiceFeign; @@ -115,6 +117,17 @@ public class InventoryAdjustmentRecordDomainService { inventoryAdjustmentRecord.setCreateBy(loginUser.getUserid()); inventoryAdjustmentRecord.setCreateByName(loginUser.getUsername()); inventoryAdjustmentRecord.setCreateTime(new Date()); + if (inventoryAdjustmentRecordDO.getAdjustType() == null) { + throw new ServiceException("调整类型不能为空"); + } + if (inventoryAdjustmentRecordDO.getAdjustType() == 1 + && inventoryAdjustmentRecordDO.getMaterialInventoryId() == null) { + throw new ServiceException("请选择要调整的库存"); + } + if (inventoryAdjustmentRecordDO.getAdjustQuantity() == null + || inventoryAdjustmentRecordDO.getAdjustQuantity().compareTo(BigDecimal.ZERO) == 0) { + throw new ServiceException("调整数量不能为空且不能为0"); + } MaterialInventory materialInventory = null; //根据调整类型判断,数量调整只调整当前库存记录数量,状态调整减少当前原物料状态库存数量和可用数量,增加到现状态库存数量和可用数量 if (inventoryAdjustmentRecordDO.getAdjustType() != null && inventoryAdjustmentRecordDO.getAdjustType() == 1) { @@ -180,8 +193,8 @@ public class InventoryAdjustmentRecordDomainService { .eq(MaterialInventory::getStorageSectionId,inventoryAdjustmentRecordDO.getStorageSectionId()) .eq(MaterialInventory::getStorageLocationId,inventoryAdjustmentRecordDO.getStorageLocationId()) .eq(MaterialInventory::getMaterialStatusCode,inventoryAdjustmentRecordDO.getAdjustBeforeStatusCode()) - .eq(MaterialInventory::getBatchNumber,inventoryAdjustmentRecordDO.getBatchNumber()) - .eq(MaterialInventory::getContainerId,inventoryAdjustmentRecordDO.getContainerId()) + .eq(StringUtils.isNotBlank(inventoryAdjustmentRecordDO.getBatchNumber()),MaterialInventory::getBatchNumber,inventoryAdjustmentRecordDO.getBatchNumber()) + .eq(inventoryAdjustmentRecordDO.getContainerId() != null, MaterialInventory::getContainerId, inventoryAdjustmentRecordDO.getContainerId()) .eq(BaseVOEntity::getDelFlag, 1)); if (ObjectUtil.isNotNull(materialInventory)) { BeanUtils.copyProperties(materialInventory, inventoryAdjustmentRecord); @@ -218,6 +231,8 @@ public class InventoryAdjustmentRecordDomainService { inventoryAdjustmentRecord.setAdjustedGrossWeight(materialInventory.getGrossWeight()); inventoryAdjustmentRecord.setAdjustedVolume(materialInventory.getVolume()); inventoryAdjustmentRecord.setAdjustedArea(materialInventory.getArea()); + // ===== 新增:原状态库存扣减后立即落库,避免依赖末尾统一更新 ===== + materialInventoryService.updateById(materialInventory); } else { throw new ServiceException("根据原物料状态查询不到物料库存信息!"); } @@ -228,8 +243,8 @@ public class InventoryAdjustmentRecordDomainService { .eq(MaterialInventory::getStorageSectionId,inventoryAdjustmentRecordDO.getStorageSectionId()) .eq(MaterialInventory::getStorageLocationId,inventoryAdjustmentRecordDO.getStorageLocationId()) .eq(MaterialInventory::getMaterialStatusCode,inventoryAdjustmentRecordDO.getAdjustAfterStatusCode()) - .eq(MaterialInventory::getBatchNumber,inventoryAdjustmentRecordDO.getBatchNumber()) - .eq(MaterialInventory::getContainerId,inventoryAdjustmentRecordDO.getContainerId()) + .eq(StringUtils.isNotBlank(inventoryAdjustmentRecordDO.getBatchNumber()),MaterialInventory::getBatchNumber,inventoryAdjustmentRecordDO.getBatchNumber()) + .eq(inventoryAdjustmentRecordDO.getContainerId() != null,MaterialInventory::getContainerId,inventoryAdjustmentRecordDO.getContainerId()) .eq(BaseVOEntity::getDelFlag, 1)); if (ObjectUtil.isNotNull(materialInventory1)) { materialInventory1.setInventoryQuantity(materialInventory1.getInventoryQuantity().add(inventoryAdjustmentRecordDO.getAdjustQuantity())); @@ -245,21 +260,48 @@ public class InventoryAdjustmentRecordDomainService { inventoryAdjustmentRecord.setAdjustAfterStatusCode(inventoryAdjustmentRecordDO.getAdjustAfterStatusCode()); inventoryAdjustmentRecord.setAdjustAfterStatusName(inventoryAdjustmentRecordDO.getAdjustAfterStatusName()); } + // ===== 新增:adjustType 合法性兜底,避免异常类型导致 materialInventory 为 null 静默走完流程 ===== + if (ObjectUtil.isNull(materialInventory)) { + throw new ServiceException("不支持的调整类型:" + inventoryAdjustmentRecordDO.getAdjustType()); + } //生成库存调整追溯记录 if (ObjectUtil.isNotNull(materialInventory)){ genInventoryStandingDetail(materialInventory, inventoryAdjustmentRecordDO.getAdjustQuantity()); } - - materialInventoryService.updateById(materialInventory); + // ===== 修复:末尾更新加 null 保护,且 adjustType=2 已即时落库,只在 adjustType=1 时再更新 ===== + if (ObjectUtil.isNotNull(materialInventory) + && inventoryAdjustmentRecordDO.getAdjustType() != null + && inventoryAdjustmentRecordDO.getAdjustType().equals(1)) { + materialInventoryService.updateById(materialInventory); + } Boolean insert = inventoryAdjustmentRecordService.insert(inventoryAdjustmentRecord); //推送oms库存调整记录 - pushOms(materialInventory, inventoryAdjustmentRecordDO); + try{ + Boolean pushSuccess = pushOms(materialInventory, inventoryAdjustmentRecordDO); + if (!pushSuccess) { + throw new ServiceException("库存调整推送OMS失败,请稍后重试"); + } + }catch (Exception e){ + log.error("推送OMS库存调整记录异常,materialBaseInfoId={}, adjustDirection={}", + inventoryAdjustmentRecordDO.getMaterialBaseInfoId(), + inventoryAdjustmentRecordDO.getAdjustDirection()); + throw new ServiceException("库存调整推送OMS失败,请稍后重试"); + } + System.out.println("库存调整时间结束 ----" + System.currentTimeMillis()); return insert; } - - private void pushOms(MaterialInventory materialInventory,InventoryAdjustmentRecordDO inventoryAdjustmentRecordDO) { + /** + * 推送库存调整信息至OMS系统 + *

+ * 根据调整方向(1=增加库存,2=减少库存)分别构造入库调整单或出库调整单, + * 并通过Feign接口推送至OMS系统,同时推送对应的物料明细信息。 + * + * @param materialInventory 调整涉及的物料库存信息,包含仓库、库区、库位、货主等上下文数据 + * @param inventoryAdjustmentRecordDO 库存调整记录,包含调整方向、调整数量、物料编码等数据 + */ + private Boolean pushOms(MaterialInventory materialInventory,InventoryAdjustmentRecordDO inventoryAdjustmentRecordDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); UserPo userPo = loginUser.getUserPo(); MaterialBaseInfo materialBaseInfo = materialBaseInfoService.getById(materialInventory.getMaterialBaseInfoId()); @@ -327,8 +369,16 @@ public class InventoryAdjustmentRecordDomainService { inMaterialDetail.setStorageLocationCode(materialInventory.getStorageLocationCode()); inMaterialDetail.setStorageLocationName(materialInventory.getStorageLocationName()); inMaterialDetail.setSingleGrossWeight(materialBaseInfo.getWeightLimit()); - omsServiceFeign.pushInOrder(stockInOrder); - omsServiceFeign.pushInOrderDetail(inMaterialDetail); + AjaxResult inOrderResult = omsServiceFeign.pushInOrder(stockInOrder); + AjaxResult inOrderDetailResult = omsServiceFeign.pushInOrderDetail(inMaterialDetail); + if (inOrderResult == null || inOrderDetailResult == null + || !"200".equals(String.valueOf(inOrderResult.get("code"))) + || !"200".equals(String.valueOf(inOrderDetailResult.get("code"))) + ) { + log.error("推送OMS入库调整单失败,pushInOrder={}, pushInOrderDetail={}", + inOrderResult, inOrderDetailResult); + return false; + } } else { StockOutOrderTZPD stockOutOrder = new StockOutOrderTZPD(); stockOutOrder.setOrganizationId(loginUser.getUserPo().getOrganizationId()); @@ -391,9 +441,18 @@ public class InventoryAdjustmentRecordDomainService { outMaterialDetail.setStorageLocationCode(materialInventory.getStorageLocationCode()); outMaterialDetail.setStorageLocationName(materialInventory.getStorageLocationName()); outMaterialDetail.setSingleGrossWeight(materialBaseInfo.getWeightLimit()); - omsServiceFeign.pushOutOrder(stockOutOrder); - omsServiceFeign.pushOutOrderDetail(outMaterialDetail); + AjaxResult inOrderResult = omsServiceFeign.pushOutOrder(stockOutOrder); + AjaxResult inOrderDetailResult = omsServiceFeign.pushOutOrderDetail(outMaterialDetail); + if (inOrderResult == null || inOrderDetailResult == null + || !"200".equals(String.valueOf(inOrderResult.get("code"))) + || !"200".equals(String.valueOf(inOrderDetailResult.get("code"))) + ) { + log.error("推送OMS入库调整单失败,pushInOrder={}, pushInOrderDetail={}", + inOrderResult, inOrderDetailResult); + return false; + } } + return true; } /** diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/statementStatistics/po/ImmediateInventoryPO.java b/mhd_wms/src/main/java/com/mhd/wms/domain/statementStatistics/po/ImmediateInventoryPO.java index 8d9f51786..0c8f09f62 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/domain/statementStatistics/po/ImmediateInventoryPO.java +++ b/mhd_wms/src/main/java/com/mhd/wms/domain/statementStatistics/po/ImmediateInventoryPO.java @@ -50,10 +50,6 @@ public class ImmediateInventoryPO { @Excel(name = "库存数量") private BigDecimal inventoryQuantity; - @ApiModelProperty("库存数量合计(当前查询条件下所有库存数量之和)") - @Excel(name = "库存数量合计") - private BigDecimal totalInventoryQuantity; - @ApiModelProperty("可用数量 ") @Excel(name = "可用数量 ") private BigDecimal allocationQuantity; diff --git a/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/statementStatistics/StatementStatisticsApi.java b/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/statementStatistics/StatementStatisticsApi.java index f4b7232de..8f9d46883 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/statementStatistics/StatementStatisticsApi.java +++ b/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/statementStatistics/StatementStatisticsApi.java @@ -23,6 +23,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.HashMap; import java.util.List; /** @@ -48,13 +50,14 @@ public class StatementStatisticsApi { */ @ApiOperation("查询即时库存列表") @GetMapping("/queryImmediateInventoryList") - public TableDataInfo queryImmediateInventoryList(ImmediateInventoryDTO immediateInventoryDTO) + public HashMap queryImmediateInventoryList(ImmediateInventoryDTO immediateInventoryDTO) { //转换实体 ImmediateInventoryDO immediateInventoryDO = immediateInventoryAssembler.toDO(immediateInventoryDTO); startPage(); List list = statementStatisticsService.queryImmediateInventoryList(immediateInventoryDO); - return getDataTable(list); + BigDecimal bigDecimal = statementStatisticsService.sumImmediateInventoryQuantity(immediateInventoryDO); + return getDataTableWarehouse(list,bigDecimal); } /** * 分页查询入库日报表列表 @@ -129,4 +132,18 @@ public class StatementStatisticsApi { rspData.setTotal(new PageInfo(list).getTotal()); return rspData; } + + /** + * 响应请求分页、仓库数量 数据 + */ + protected HashMap getDataTableWarehouse(List list,BigDecimal bigDecimal) + { + HashMap stringObjectHashMap = new HashMap<>(); + stringObjectHashMap.put("data",list); + stringObjectHashMap.put("total",new PageInfo(list).getTotal()); + stringObjectHashMap.put("code",HttpStatus.SUCCESS); + stringObjectHashMap.put("msg","查询成功"); + stringObjectHashMap.put("totalInventoryQuantity",bigDecimal); + return stringObjectHashMap; + } } diff --git a/mhd_wms/src/main/resources/mapper/materialInventory/MaterialInventoryMapper.xml b/mhd_wms/src/main/resources/mapper/materialInventory/MaterialInventoryMapper.xml index 5a5708903..767c0ba16 100644 --- a/mhd_wms/src/main/resources/mapper/materialInventory/MaterialInventoryMapper.xml +++ b/mhd_wms/src/main/resources/mapper/materialInventory/MaterialInventoryMapper.xml @@ -1054,7 +1054,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" -