Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
王奎兴
2026-02-27 14:09:38 +08:00
2 changed files with 29 additions and 6 deletions
@@ -1,6 +1,7 @@
package com.mhd.wms.domain.materialInventory.repository.persistence;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mhd.common.core.exception.ServiceException;
@@ -24,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.util.*;
@@ -161,7 +163,7 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
Map<String, MaterialInventory> materialInventoryAddNowMap = new HashMap<>();
// 批量获取物料基础信息,以获取货主ID(用于查询和key生成)
Map<Long, Long> materialBaseInfoIdToShipperIdMap = new HashMap<>();
Map<Long, MaterialBaseInfoPO> materialBaseInfoIdToShipperIdMap = new HashMap<>();
if (!CollectionUtils.isEmpty(materialInventoryDOList)) {
Set<Long> materialBaseInfoIds = new HashSet<>();
for (MaterialInventoryDO materialInventoryDO : materialInventoryDOList) {
@@ -178,7 +180,8 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
if (!CollectionUtils.isEmpty(materialBaseInfoList)) {
MaterialBaseInfoPO materialBaseInfoPO = materialBaseInfoList.get(0);
if (materialBaseInfoPO.getShipperId() != null) {
materialBaseInfoIdToShipperIdMap.put(materialBaseInfoId, materialBaseInfoPO.getShipperId());
// materialBaseInfoIdToShipperIdMap.put(materialBaseInfoId, materialBaseInfoPO.getShipperId());
materialBaseInfoIdToShipperIdMap.put(materialBaseInfoId, materialBaseInfoPO);
}
}
} catch (Exception e) {
@@ -191,8 +194,14 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
for (MaterialInventoryDO materialInventoryDO : materialInventoryDOList) {
// 获取货主ID(优先使用materialInventoryDO中的,如果没有则从物料基础信息中获取)
Long shipperId = materialInventoryDO.getShipperId();
String shipperName = "";
String shipperCode = "";
if (shipperId == null && materialInventoryDO.getMaterialBaseInfoId() != null) {
shipperId = materialBaseInfoIdToShipperIdMap.get(materialInventoryDO.getMaterialBaseInfoId());
// shipperId = materialBaseInfoIdToShipperIdMap.get(materialInventoryDO.getMaterialBaseInfoId());
MaterialBaseInfoPO materialBaseInfoPO = materialBaseInfoIdToShipperIdMap.get(materialInventoryDO.getMaterialBaseInfoId());
shipperId = materialBaseInfoPO.getShipperId();
shipperName = materialBaseInfoPO.getShipperName();
shipperCode = materialBaseInfoPO.getShipperCode();
}
//TODO 若数据量升级 后期优化
@@ -201,8 +210,8 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
if (materialInventoryDO.getStorageLocationId() != null && materialInventoryDO.getMaterialBaseInfoId() != null) {
// 使用 LambdaQueryWrapper 构造查询条件
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MaterialInventory> wrapper =
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MaterialInventory>()
LambdaQueryWrapper<MaterialInventory> wrapper =
new LambdaQueryWrapper<MaterialInventory>()
.eq(MaterialInventory::getStorageLocationId, materialInventoryDO.getStorageLocationId())
.eq(MaterialInventory::getMaterialBaseInfoId, materialInventoryDO.getMaterialBaseInfoId())
.eq(MaterialInventory::getDelFlag, 1);
@@ -228,6 +237,12 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
BeanUtils.copyProperties(materialInventoryDO, materialInventory);
// 确保把货主字段带到实体里
materialInventory.setShipperId(shipperId);
if (StringUtils.isEmpty(materialInventory.getShipperName())){
materialInventory.setShipperName(shipperName);
}
if (StringUtils.isEmpty(materialInventory.getShipperCode())){
materialInventory.setShipperCode(shipperCode);
}
// 如果批次号、容器ID、物料状态等字段在唯一性约束中,应该保留;否则,使用第一个值
// 由于唯一性约束只包含storage_location_id和material_base_info_id,我们保留这些字段的值
materialInventoryList.add(materialInventory);
@@ -419,8 +419,13 @@ public class ShiftManageDomainService {
shiftMaterialDetailDO.setShiftNumber(shiftNumber);
List<ShiftMaterialDetailPO> shiftMaterialDetailPOList = shiftMaterialDetailService.queryListChildren(shiftMaterialDetailDO);
for (ShiftMaterialDetailPO shiftMaterialDetailPO : shiftMaterialDetailPOList){
MaterialInventory materialInventoryOldDb = materialInventoryService.getById(shiftMaterialDetailPO.getMaterialInventoryId());
BigDecimal shiftQuantity = shiftMaterialDetailPO.getShiftQuantity();
//构建新物料库存信息
shiftMaterialDetailPO.setNetWeight(materialInventoryOldDb.getNetWeight());
shiftMaterialDetailPO.setGrossWeight(materialInventoryOldDb.getGrossWeight());
shiftMaterialDetailPO.setVolume(materialInventoryOldDb.getVolume());
shiftMaterialDetailPO.setArea(materialInventoryOldDb.getArea());
materialInventoryNowList.add(genMaterialInventory(shiftMaterialDetailPO));
List<ShiftMaterialDetailPO> shiftMaterialDetailPOChildrenList = shiftMaterialDetailPO.getChildren();
for (ShiftMaterialDetailPO shiftMaterialDetailPOChildren : shiftMaterialDetailPOChildrenList){
@@ -428,7 +433,6 @@ public class ShiftManageDomainService {
//构建新物料库存信息
materialInventoryNowList.add(genMaterialInventory(shiftMaterialDetailPOChildren));
};
MaterialInventory materialInventoryOldDb = materialInventoryService.getById(shiftMaterialDetailPO.getMaterialInventoryId());
if (materialInventoryOldDb.getInventoryQuantity().compareTo(shiftQuantity) < 0){
throw new ServiceException("物料原库位下的物料库存不足,不能进行移位");
}
@@ -525,6 +529,10 @@ public class ShiftManageDomainService {
materialInventoryDONow.setContainerTypeName(shiftMaterialDetailPO.getContainerTypeName());
materialInventoryDONow.setInventoryQuantity(shiftMaterialDetailPO.getShiftQuantity());
materialInventoryDONow.setAllocationQuantity(shiftMaterialDetailPO.getShiftQuantity());
materialInventoryDONow.setNetWeight(shiftMaterialDetailPO.getNetWeight());
materialInventoryDONow.setGrossWeight(shiftMaterialDetailPO.getGrossWeight());
materialInventoryDONow.setVolume(shiftMaterialDetailPO.getVolume());
materialInventoryDONow.setArea(shiftMaterialDetailPO.getArea());
materialInventoryDONow.setOrganizationId(loginUser.getUserPo().getOrganizationId());
materialInventoryDONow.setOrganizationName(loginUser.getUserPo().getOrganizationName());
materialInventoryDONow.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());