From 1ee50cdfedf512cabaa0379aaeba382e887f5fc4 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, 14 Mar 2026 18:41:02 +0800 Subject: [PATCH] =?UTF-8?q?PDA=E5=AE=B9=E5=99=A8=E7=A7=BB=E4=BD=8D?= =?UTF-8?q?=E7=94=9F=E6=88=90=E8=B0=83=E6=95=B4=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ShiftManageDomainService.java | 5 +- .../facade/IShiftMaterialDetailService.java | 7 +- .../persistence/ShiftMaterialDetailImpl.java | 162 +++++++++++++++++- 3 files changed, 170 insertions(+), 4 deletions(-) diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/shiftManage/service/ShiftManageDomainService.java b/mhd_wms/src/main/java/com/mhd/wms/domain/shiftManage/service/ShiftManageDomainService.java index 743e4ef77..f24ee0b24 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/domain/shiftManage/service/ShiftManageDomainService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/domain/shiftManage/service/ShiftManageDomainService.java @@ -579,13 +579,14 @@ public class ShiftManageDomainService { @Transactional(rollbackFor = Exception.class) public Boolean appMoveContainShift(List containerShiftDOList){ LoginUser loginUser = SecurityUtils.getLoginUser(); - List shiftMaterialDetailDOList = shiftMaterialDetailService.appMoveContainShift(containerShiftDOList); + String shiftNumber = OrderSequence.getOrderCode("YW"); + List shiftMaterialDetailDOList = shiftMaterialDetailService.appMoveContainShift(containerShiftDOList, shiftNumber); ShiftManageDO shiftManageDO = new ShiftManageDO(); AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); shiftManageDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId()); shiftManageDO.setWarehouseCode(associationWarehouseCacheDO.getWarehouseCode()); shiftManageDO.setWarehouseName(associationWarehouseCacheDO.getWarehouseName()); - shiftManageDO.setShiftNumber(OrderSequence.getOrderCode("YW")); + shiftManageDO.setShiftNumber(shiftNumber); shiftManageDO.setRemark("容器移位生成"); shiftManageDO.setShiftStatus(4);//默认以为完成 shiftManageDO.setAuditStatus(3); diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/shiftMaterialDetail/repository/facade/IShiftMaterialDetailService.java b/mhd_wms/src/main/java/com/mhd/wms/domain/shiftMaterialDetail/repository/facade/IShiftMaterialDetailService.java index f9326b62f..7fcb83295 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/domain/shiftMaterialDetail/repository/facade/IShiftMaterialDetailService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/domain/shiftMaterialDetail/repository/facade/IShiftMaterialDetailService.java @@ -74,7 +74,12 @@ public interface IShiftMaterialDetailService extends IService appMoveContainShift(List containerShiftDOList); + /** + * 容器移位,需传入移位单号用于生成库存调整记录 + * @param containerShiftDOList 容器移位明细 + * @param shiftNumber 移位单号(关联库存调整记录) + */ + public List appMoveContainShift(List containerShiftDOList, String shiftNumber); /** * @description 批量修改物料信息 diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/shiftMaterialDetail/repository/persistence/ShiftMaterialDetailImpl.java b/mhd_wms/src/main/java/com/mhd/wms/domain/shiftMaterialDetail/repository/persistence/ShiftMaterialDetailImpl.java index 4a54af722..27b1e5aae 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/domain/shiftMaterialDetail/repository/persistence/ShiftMaterialDetailImpl.java +++ b/mhd_wms/src/main/java/com/mhd/wms/domain/shiftMaterialDetail/repository/persistence/ShiftMaterialDetailImpl.java @@ -5,12 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.mhd.common.core.domain.po.UserPo; import com.mhd.common.core.exception.ServiceException; +import com.mhd.common.core.utils.StringUtils; import com.mhd.common.core.utils.IgnoreNullUtil; import com.mhd.common.security.utils.SecurityUtils; import com.mhd.system.api.domain.cache.SystemServiceCacheUtil; import com.mhd.system.api.model.LoginUser; import com.mhd.wms.domain.inventoryAdjustmentRecord.entity.InventoryAdjustmentRecord; import com.mhd.wms.domain.inventoryAdjustmentRecord.repository.mapper.InventoryAdjustmentRecordMapper; +import com.mhd.wms.domain.materialBaseInfo.repository.facade.IMaterialBaseInfoService; +import com.mhd.wms.domain.materialBaseInfo.repository.po.MaterialBaseInfoPO; import com.mhd.wms.domain.investigetionManageDetail.repository.todo.InvestigetionManageDetailDO; import com.mhd.wms.domain.materialInventory.entity.MaterialInventory; import com.mhd.wms.domain.materialInventory.repository.facade.IMaterialInventoryService; @@ -63,6 +66,9 @@ public class ShiftMaterialDetailImpl extends ServiceImpl appMoveContainShift(List containerShiftDOList) { + public List appMoveContainShift(List containerShiftDOList, String shiftNumber) { LoginUser loginUser = SecurityUtils.getLoginUser(); List materialInventoryOldList = new ArrayList<>(); List materialInventoryNowList = new ArrayList<>(); @@ -378,6 +384,21 @@ public class ShiftMaterialDetailImpl extends ServiceImpl shiftMoveMaterialQuantityList = containerShiftDO.getChildren(); + if (CollectionUtils.isEmpty(shiftMoveMaterialQuantityList)) continue; + BigDecimal totalShiftQuantity = shiftMoveMaterialQuantityList.stream() + .filter(c -> c.getShiftQuantity() != null && c.getShiftQuantity().compareTo(BigDecimal.ZERO) > 0) + .map(ShiftMoveMaterialQuantityPO::getShiftQuantity).reduce(BigDecimal.ZERO, BigDecimal::add); + if (totalShiftQuantity.compareTo(BigDecimal.ZERO) <= 0) continue; + MaterialInventory materialInventoryOldDb = materialInventoryMapper.selectById(containerShiftDO.getMaterialInventoryId()); + if (materialInventoryOldDb == null) continue; + genContainerShiftInventoryAdjustmentRecord(containerShiftDO, materialInventoryOldDb, totalShiftQuantity, + shiftMoveMaterialQuantityList, shiftNumber); + } + } if (!CollectionUtils.isEmpty(materialInventoryNowList)){ materialInventoryService.updateMaterialInventoryInfo(materialInventoryNowList, 1); } @@ -387,6 +408,145 @@ public class ShiftMaterialDetailImpl extends ServiceImpl shiftMoveMaterialQuantityList, String shiftNumber) { + LoginUser loginUser = SecurityUtils.getLoginUser(); + MaterialBaseInfoPO materialBaseInfo = materialBaseInfoService.getInfo(containerShiftDO.getMaterialBaseInfoId()); + String materialCode = materialBaseInfo != null ? materialBaseInfo.getMaterialCode() : ""; + String materialName = materialBaseInfo != null ? materialBaseInfo.getMaterialName() : ""; + String barCode = materialBaseInfo != null ? materialBaseInfo.getBarCode() : ""; + BigDecimal oldQty = materialInventoryOldDb.getInventoryQuantity() != null ? materialInventoryOldDb.getInventoryQuantity() : BigDecimal.ZERO; + BigDecimal oldAlloc = materialInventoryOldDb.getAllocationQuantity() != null ? materialInventoryOldDb.getAllocationQuantity() : BigDecimal.ZERO; + BigDecimal newQty = oldQty.subtract(totalShiftQuantity).max(BigDecimal.ZERO); + BigDecimal newAlloc = oldAlloc.subtract(totalShiftQuantity).max(BigDecimal.ZERO); + // 原库位减少的净重/毛重/体积/面积:优先用子项汇总,无则按原库存比例 + BigDecimal adjNet = BigDecimal.ZERO, adjGross = BigDecimal.ZERO, adjVol = BigDecimal.ZERO, adjArea = BigDecimal.ZERO; + for (ShiftMoveMaterialQuantityPO c : shiftMoveMaterialQuantityList) { + if (c.getShiftQuantity() != null && c.getShiftQuantity().compareTo(BigDecimal.ZERO) > 0) { + if (c.getNetWeight() != null) adjNet = adjNet.add(c.getNetWeight()); + if (c.getGrossWeight() != null) adjGross = adjGross.add(c.getGrossWeight()); + if (c.getVolume() != null) adjVol = adjVol.add(c.getVolume()); + if (c.getArea() != null) adjArea = adjArea.add(c.getArea()); + } + } + if (adjNet.compareTo(BigDecimal.ZERO) == 0 && adjGross.compareTo(BigDecimal.ZERO) == 0 && adjVol.compareTo(BigDecimal.ZERO) == 0 && adjArea.compareTo(BigDecimal.ZERO) == 0 + && oldQty.compareTo(BigDecimal.ZERO) > 0) { + java.math.RoundingMode rm = java.math.RoundingMode.HALF_UP; + BigDecimal ratio = totalShiftQuantity.divide(oldQty, 10, rm); + if (materialInventoryOldDb.getNetWeight() != null) adjNet = materialInventoryOldDb.getNetWeight().multiply(ratio); + if (materialInventoryOldDb.getGrossWeight() != null) adjGross = materialInventoryOldDb.getGrossWeight().multiply(ratio); + if (materialInventoryOldDb.getVolume() != null) adjVol = materialInventoryOldDb.getVolume().multiply(ratio); + if (materialInventoryOldDb.getArea() != null) adjArea = materialInventoryOldDb.getArea().multiply(ratio); + } + // 原库位减少记录(adjusted 为移出量,取负表示减少) + InventoryAdjustmentRecord recordOld = buildInventoryAdjustmentRecord(loginUser, containerShiftDO, materialInventoryOldDb, + materialCode, materialName, barCode, shiftNumber, + materialInventoryOldDb.getWarehouseId(), materialInventoryOldDb.getWarehouseCode(), materialInventoryOldDb.getWarehouseName(), + materialInventoryOldDb.getStorageSectionId(), materialInventoryOldDb.getStorageCode(), materialInventoryOldDb.getStorageName(), + materialInventoryOldDb.getStorageLocationId(), materialInventoryOldDb.getStorageLocationCode(), materialInventoryOldDb.getStorageLocationName(), + materialInventoryOldDb.getMaterialInventoryId(), oldQty, oldAlloc, newQty, newAlloc, + materialInventoryOldDb.getNetWeight(), materialInventoryOldDb.getGrossWeight(), materialInventoryOldDb.getVolume(), materialInventoryOldDb.getArea(), + adjNet.negate(), adjGross.negate(), adjVol.negate(), adjArea.negate()); + inventoryAdjustmentRecordMapper.insert(recordOld); + // 各目标库位增加记录 + for (ShiftMoveMaterialQuantityPO c : shiftMoveMaterialQuantityList) { + if (c.getShiftQuantity() == null || c.getShiftQuantity().compareTo(BigDecimal.ZERO) <= 0) continue; + LambdaQueryWrapper qw = new LambdaQueryWrapper<>(); + qw.eq(MaterialInventory::getWarehouseId, SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()).getWarehouseId()); + qw.eq(MaterialInventory::getStorageSectionId, c.getNewStorageSectionId()); + qw.eq(MaterialInventory::getStorageLocationId, c.getNewStorageLocationId()); + qw.eq(MaterialInventory::getMaterialBaseInfoId, containerShiftDO.getMaterialBaseInfoId()); + qw.eq(MaterialInventory::getBatchNumber, containerShiftDO.getBatchNumber()); + qw.eq(MaterialInventory::getMaterialStatusCode, containerShiftDO.getMaterialStatusCode()); + if (c.getContainerId() != null) qw.eq(MaterialInventory::getContainerId, c.getContainerId()); + MaterialInventory materialInventoryDb = materialInventoryMapper.selectOne(qw); + BigDecimal beforeQty = materialInventoryDb != null && materialInventoryDb.getInventoryQuantity() != null + ? materialInventoryDb.getInventoryQuantity() : BigDecimal.ZERO; + BigDecimal beforeAlloc = materialInventoryDb != null && materialInventoryDb.getAllocationQuantity() != null + ? materialInventoryDb.getAllocationQuantity() : BigDecimal.ZERO; + BigDecimal afterQty = beforeQty.add(c.getShiftQuantity()); + BigDecimal afterAlloc = beforeAlloc.add(c.getShiftQuantity()); + Long newInvId = materialInventoryDb != null ? materialInventoryDb.getMaterialInventoryId() : null; + Long whId = materialInventoryDb != null ? materialInventoryDb.getWarehouseId() + : (SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()) != null + ? SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()).getWarehouseId() : containerShiftDO.getWarehouseId()); + String whCode = materialInventoryDb != null ? materialInventoryDb.getWarehouseCode() : (containerShiftDO.getWarehouseCode() != null ? containerShiftDO.getWarehouseCode() : ""); + String whName = materialInventoryDb != null ? materialInventoryDb.getWarehouseName() : (containerShiftDO.getWarehouseName() != null ? containerShiftDO.getWarehouseName() : ""); + InventoryAdjustmentRecord recordNew = buildInventoryAdjustmentRecord(loginUser, containerShiftDO, materialInventoryOldDb, + materialCode, materialName, barCode, shiftNumber, + whId, whCode, whName, + c.getNewStorageSectionId(), c.getNewStorageCode(), c.getNewStorageName(), + c.getNewStorageLocationId(), c.getNewStorageLocationCode(), c.getNewStorageLocationName(), + newInvId, beforeQty, beforeAlloc, afterQty, afterAlloc, + BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, + c.getNetWeight() != null ? c.getNetWeight() : BigDecimal.ZERO, + c.getGrossWeight() != null ? c.getGrossWeight() : BigDecimal.ZERO, + c.getVolume() != null ? c.getVolume() : BigDecimal.ZERO, + c.getArea() != null ? c.getArea() : BigDecimal.ZERO); + inventoryAdjustmentRecordMapper.insert(recordNew); + } + } + + private InventoryAdjustmentRecord buildInventoryAdjustmentRecord(LoginUser loginUser, ContainerShiftDO containerShiftDO, + MaterialInventory materialInventoryOldDb, String materialCode, String materialName, String barCode, String shiftNumber, + Long warehouseId, String warehouseCode, String warehouseName, + Long storageSectionId, String storageCode, String storageName, + Long storageLocationId, String storageLocationCode, String storageLocationName, + Long materialInventoryId, BigDecimal inventoryBefore, BigDecimal allocationBefore, + BigDecimal inventoryAfter, BigDecimal allocationAfter, + BigDecimal netWeight, BigDecimal grossWeight, BigDecimal volume, BigDecimal area, + BigDecimal adjustedNetWeight, BigDecimal adjustedGrossWeight, BigDecimal adjustedVolume, BigDecimal adjustedArea) { + InventoryAdjustmentRecord r = new InventoryAdjustmentRecord(); + r.setAdjustAction("容器移位"); + r.setRelateNo(shiftNumber); + r.setAdjustType(1L); + r.setOrganizationId(materialInventoryOldDb.getOrganizationId()); + r.setOrganizationName(materialInventoryOldDb.getOrganizationName()); + r.setTopOrganizationId(materialInventoryOldDb.getTopOrganizationId()); + r.setMaterialBaseInfoId(containerShiftDO.getMaterialBaseInfoId()); + r.setMaterialCode(materialCode); + r.setMaterialName(materialName); + r.setBarCode(barCode); + r.setShipperId(materialInventoryOldDb.getShipperId()); + r.setShipperName(materialInventoryOldDb.getShipperName()); + r.setWarehouseId(warehouseId); + r.setWarehouseCode(warehouseCode); + r.setWarehouseName(warehouseName); + r.setStorageSectionId(storageSectionId); + r.setStorageCode(storageCode); + r.setStorageName(storageName); + r.setStorageLocationId(storageLocationId); + r.setStorageLocationCode(storageLocationCode); + r.setStorageLocationName(storageLocationName); + r.setMaterialInventoryId(materialInventoryId); + r.setInventoryBeforeQuantity(inventoryBefore); + r.setAllocationBeforeQuantity(allocationBefore); + r.setInventoryAfterQuantity(inventoryAfter); + r.setAllocationAfterQuantity(allocationAfter); + r.setFreezeBeforeQuantity(materialInventoryOldDb.getFreezeQuantity() != null ? materialInventoryOldDb.getFreezeQuantity() : BigDecimal.ZERO); + r.setFreezeAfterQuantity(materialInventoryOldDb.getFreezeQuantity() != null ? materialInventoryOldDb.getFreezeQuantity() : BigDecimal.ZERO); + r.setAdjustBeforeStatusCode(materialInventoryOldDb.getMaterialStatusCode() != null ? materialInventoryOldDb.getMaterialStatusCode() : ""); + r.setAdjustBeforeStatusName(materialInventoryOldDb.getMaterialStatusName() != null ? materialInventoryOldDb.getMaterialStatusName() : ""); + r.setAdjustAfterStatusCode(materialInventoryOldDb.getMaterialStatusCode() != null ? materialInventoryOldDb.getMaterialStatusCode() : ""); + r.setAdjustAfterStatusName(materialInventoryOldDb.getMaterialStatusName() != null ? materialInventoryOldDb.getMaterialStatusName() : ""); + r.setNetWeight(netWeight); + r.setGrossWeight(grossWeight); + r.setVolume(volume); + r.setArea(area); + r.setAdjustedNetWeight(adjustedNetWeight); + r.setAdjustedGrossWeight(adjustedGrossWeight); + r.setAdjustedVolume(adjustedVolume); + r.setAdjustedArea(adjustedArea); + r.setCreateBy(loginUser.getUserid()); + if (loginUser.getUserPo() != null) r.setCreateByName(loginUser.getUserPo().getUserName()); + r.setCreateTime(new Date()); + return r; + } + /** * @description 批量修改物料信息 * @author ZhouGY