PDA容器移位生成调整记录
This commit is contained in:
+3
-2
@@ -579,13 +579,14 @@ public class ShiftManageDomainService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean appMoveContainShift(List<ContainerShiftDO> containerShiftDOList){
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
List<ShiftMaterialDetailDO> shiftMaterialDetailDOList = shiftMaterialDetailService.appMoveContainShift(containerShiftDOList);
|
||||
String shiftNumber = OrderSequence.getOrderCode("YW");
|
||||
List<ShiftMaterialDetailDO> 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);
|
||||
|
||||
+6
-1
@@ -74,7 +74,12 @@ public interface IShiftMaterialDetailService extends IService<ShiftMaterialDetai
|
||||
public ShiftMaterialDetailPO getShiftMaterialDetail(ShiftMaterialDetailDO shiftMaterialDetailDO);
|
||||
|
||||
|
||||
public List<ShiftMaterialDetailDO> appMoveContainShift(List<ContainerShiftDO> containerShiftDOList);
|
||||
/**
|
||||
* 容器移位,需传入移位单号用于生成库存调整记录
|
||||
* @param containerShiftDOList 容器移位明细
|
||||
* @param shiftNumber 移位单号(关联库存调整记录)
|
||||
*/
|
||||
public List<ShiftMaterialDetailDO> appMoveContainShift(List<ContainerShiftDO> containerShiftDOList, String shiftNumber);
|
||||
|
||||
/**
|
||||
* @description 批量修改物料信息
|
||||
|
||||
+161
-1
@@ -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<ShiftMaterialDetailMapp
|
||||
@Autowired
|
||||
private InventoryAdjustmentRecordMapper inventoryAdjustmentRecordMapper;
|
||||
|
||||
@Autowired
|
||||
private IMaterialBaseInfoService materialBaseInfoService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询移位物料明细列表
|
||||
@@ -221,7 +227,7 @@ public class ShiftMaterialDetailImpl extends ServiceImpl<ShiftMaterialDetailMapp
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<ShiftMaterialDetailDO> appMoveContainShift(List<ContainerShiftDO> containerShiftDOList) {
|
||||
public List<ShiftMaterialDetailDO> appMoveContainShift(List<ContainerShiftDO> containerShiftDOList, String shiftNumber) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
List<MaterialInventoryDO> materialInventoryOldList = new ArrayList<>();
|
||||
List<MaterialInventoryDO> materialInventoryNowList = new ArrayList<>();
|
||||
@@ -378,6 +384,21 @@ public class ShiftMaterialDetailImpl extends ServiceImpl<ShiftMaterialDetailMapp
|
||||
parentDO.setChildren(children);
|
||||
shiftMaterialDetailDOList.add(parentDO);
|
||||
}
|
||||
// 生成库存调整记录(在库存变更前插入,与按单移位 batchShiftUpdate 一致)
|
||||
if (StringUtils.isNotBlank(shiftNumber)) {
|
||||
for (ContainerShiftDO containerShiftDO : containerShiftDOList) {
|
||||
List<ShiftMoveMaterialQuantityPO> 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<ShiftMaterialDetailMapp
|
||||
return shiftMaterialDetailDOList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 容器移位生成库存调整记录:原库位减少记录 + 各目标库位增加记录
|
||||
*/
|
||||
private void genContainerShiftInventoryAdjustmentRecord(ContainerShiftDO containerShiftDO,
|
||||
MaterialInventory materialInventoryOldDb, BigDecimal totalShiftQuantity,
|
||||
List<ShiftMoveMaterialQuantityPO> 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<MaterialInventory> 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
|
||||
|
||||
Reference in New Issue
Block a user