按客户预约库存分配库存;

This commit is contained in:
王奎兴
2026-07-09 16:00:11 +08:00
parent 9a58a7b41c
commit fa5f8d68cc
3 changed files with 33 additions and 31 deletions
@@ -85,7 +85,7 @@ public class RemoteWmsFallbackFactory implements FallbackFactory<WmsServiceFeign
@Override
public AjaxResult execution(StockOutOrderDTO stockOutOrderDTO) {
return null;
return AjaxResult.error(cause.getMessage());
}
@Override
@@ -251,9 +251,15 @@ public class ReservationStockOutOrderApplicationService {
shipperParam(stockOutOrderDO);
//设置客户信息
//customerParam(stockOutOrderDO);
stockOutOrderDO.setOrderTypeCode("pu_tong_chu_ku");
stockOutOrderDO.setBusinessType("pu_tong_chu_ku");
stockOutOrderDO.setOrderTypeName("普通出库");
if (stockOutOrderDO.getOrderTypeCode() == null) {
stockOutOrderDO.setOrderTypeCode("pu_tong_chu_ku");
}
if (stockOutOrderDO.getBusinessType() == null) {
stockOutOrderDO.setBusinessType("pu_tong_chu_ku");
}
if (stockOutOrderDO.getOrderTypeName() == null) {
stockOutOrderDO.setOrderTypeName("普通出库");
}
//设置数据字典键值
//setDataDict(stockOutOrderDO);
return stockOutOrderDomainService.insert(stockOutOrderDO);
@@ -989,36 +989,32 @@ public class StockOutOrderApplicationService {
// if (materialInventories == null || materialInventories.isEmpty()) {
// throw new ServiceException("库存不存在:" + batchRefNo + " " + sheetRefNo + " " + boxPalletNo);
// }
Long materialInventoryId = detail.getMaterialInventoryId();
MaterialInventory materialInventory = materialInventoryMapper.selectById(materialInventoryId);
BigDecimal remainingQuantity = detail.getQuantity(); // 计划数量
for (MaterialInventory materialInventory : materialInventories) {
if (remainingQuantity.compareTo(BigDecimal.ZERO) <= 0) {
break;
}
// 当前物料的可用库存
BigDecimal availableStock = materialInventory.getAllocationQuantity();
// 如果当前物料没有库存,跳过
if (availableStock == null || availableStock.compareTo(BigDecimal.ZERO) <= 0) {
continue;
}
// 计算本次能扣减的数量:取 剩余计划 和 当前库存 的较小值
BigDecimal deductQuantity = remainingQuantity.compareTo(availableStock) <= 0
? remainingQuantity // 剩余计划 <= 库存,扣剩余计划
: availableStock; // 剩余计划 > 库存,扣全部库存
detail.setMaterialInventoryId(materialInventory.getMaterialInventoryId());
detail.setStorageLocationId(materialInventory.getStorageLocationId());
detail.setStorageLocationName(materialInventory.getStorageLocationName());
detail.setStorageLocationCode(materialInventory.getStorageLocationCode());
detail.setStorageSectionId(materialInventory.getStorageSectionId());
detail.setStorageName(materialInventory.getStorageName());
detail.setStorageCode(materialInventory.getStorageCode());
detail.setInventoryQuantity(materialInventory.getInventoryQuantity());
detail.setAllocationQuantity(deductQuantity);
materialDetailList2.add(detail);
// 更新剩余计划数量
remainingQuantity = remainingQuantity.subtract(deductQuantity);
// 当前物料的可用库存
BigDecimal availableStock = materialInventory.getAllocationQuantity();
// 如果当前物料没有库存,跳过
if (availableStock == null || availableStock.compareTo(BigDecimal.ZERO) <= 0) {
continue;
}
if (availableStock.compareTo(remainingQuantity) < 0) {
throw new RuntimeException(
String.format("可用库存不足,计划数量:%s,当前可用库存:%s",
remainingQuantity, availableStock)
);
}
// detail.setMaterialInventoryId(materialInventory.getMaterialInventoryId());
detail.setStorageLocationId(materialInventory.getStorageLocationId());
detail.setStorageLocationName(materialInventory.getStorageLocationName());
detail.setStorageLocationCode(materialInventory.getStorageLocationCode());
detail.setStorageSectionId(materialInventory.getStorageSectionId());
detail.setStorageName(materialInventory.getStorageName());
detail.setStorageCode(materialInventory.getStorageCode());
detail.setInventoryQuantity(materialInventory.getInventoryQuantity());
detail.setAllocationQuantity(remainingQuantity);
materialDetailList2.add(detail);
}
stockOutOrderD.setMaterialDetailList(materialDetailList2);
StockOutOrderDO assembleStockOutOrderDO = assembleParamByOutOrder(stockOutOrderD);