fix: 按物理箱贯通一件代发履约箱数
This commit is contained in:
+33
-9
@@ -42,9 +42,11 @@ import com.baiyue.lastleg.inventory.mapper.InventoryBalanceMapper;
|
||||
import com.baiyue.lastleg.inventory.mapper.InventoryPositionMapper;
|
||||
import com.baiyue.lastleg.dropship.entity.DropshipOrderProfile;
|
||||
import com.baiyue.lastleg.dropship.entity.DropshipCarton;
|
||||
import com.baiyue.lastleg.dropship.entity.DropshipCartonSku;
|
||||
import com.baiyue.lastleg.dropship.model.DropshipOutboundCandidate;
|
||||
import com.baiyue.lastleg.dropship.mapper.DropshipOrderProfileMapper;
|
||||
import com.baiyue.lastleg.dropship.mapper.DropshipCartonMapper;
|
||||
import com.baiyue.lastleg.dropship.mapper.DropshipCartonSkuMapper;
|
||||
import com.baiyue.lastleg.dropship.mapper.DropshipSkuInventoryMapper;
|
||||
import com.baiyue.lastleg.returnreceipt.entity.ReturnInventoryCarton;
|
||||
import com.baiyue.lastleg.returnreceipt.mapper.ReturnInventoryCartonMapper;
|
||||
@@ -97,6 +99,7 @@ public class DeliveryTransferService {
|
||||
@Resource private WarehouseTransferPalletMapper warehouseTransferPallets;
|
||||
@Resource private DropshipOrderProfileMapper dropshipProfiles;
|
||||
@Resource private DropshipCartonMapper dropshipCartons;
|
||||
@Resource private DropshipCartonSkuMapper dropshipCartonSkus;
|
||||
@Resource private DropshipSkuInventoryMapper dropshipSkuInventory;
|
||||
@Resource private ReturnInventoryCartonMapper returnCartons;
|
||||
@Resource private InboundPlanPalletAllocationMapper planAllocations;
|
||||
@@ -396,6 +399,7 @@ public class DeliveryTransferService {
|
||||
String warehouseId = null;
|
||||
Map<String, Long> requestedPackages = new LinkedHashMap<>();
|
||||
Map<String, DropshipOutboundCandidate> candidates = new HashMap<>();
|
||||
Set<String> requestedMarks = new HashSet<>();
|
||||
for (DeliveryRequests.OneClickItem input : items) {
|
||||
String sku = input.sku().trim();
|
||||
DropshipOutboundCandidate candidate = dropshipProfiles.lockOutboundCandidate(customerId,
|
||||
@@ -414,8 +418,11 @@ public class DeliveryTransferService {
|
||||
if (input.cartonMarks().size() != input.packages() || new HashSet<>(input.cartonMarks()).size() != input.cartonMarks().size()) {
|
||||
throw conflict("Specified carton marks must be unique and equal the package count");
|
||||
}
|
||||
if (input.cartonMarks().stream().map(String::trim).anyMatch(mark -> !requestedMarks.add(mark))) {
|
||||
throw conflict("同一物理箱不能在一张出库单中重复选择");
|
||||
}
|
||||
List<DropshipCarton> selected = dropshipCartons.listProfile(customerId, candidate.getProfileId()).stream()
|
||||
.filter(carton -> "AVAILABLE".equals(carton.getStatus()) && input.sku().trim().equals(carton.getSkuCode())
|
||||
.filter(carton -> "AVAILABLE".equals(carton.getStatus())
|
||||
&& input.cartonMarks().contains(carton.getCartonMark())).toList();
|
||||
if (selected.size() != input.cartonMarks().size()) throw conflict("Specified carton marks are unavailable");
|
||||
}
|
||||
@@ -426,8 +433,8 @@ public class DeliveryTransferService {
|
||||
if (requested.getValue() > value(candidate.getAvailablePackages())) {
|
||||
throw conflict("一件代发可用箱数不足:" + candidate.getPalletNo() + " / " + sku);
|
||||
}
|
||||
List<DropshipCarton> cartons = dropshipCartons.lockAvailable(customerId,
|
||||
candidate.getProfileId(), sku, requested.getValue());
|
||||
List<DropshipCarton> cartons = dropshipCartons.lockAvailablePhysical(customerId,
|
||||
candidate.getProfileId(), requested.getValue());
|
||||
if (cartons.size() != requested.getValue()) {
|
||||
throw conflict("一件代发可用箱数不足:" + candidate.getPalletNo() + " / " + sku);
|
||||
}
|
||||
@@ -560,19 +567,31 @@ public class DeliveryTransferService {
|
||||
List<DropshipCarton> cartons = !selectedMarks.isEmpty()
|
||||
? selectedMarks.stream()
|
||||
.map(mark -> dropshipCartons.findByProfileAndMark(customerId, profile.getId(), mark)).filter(Objects::nonNull)
|
||||
.filter(carton -> "AVAILABLE".equals(carton.getStatus()) && item.getSkuCode().equals(carton.getSkuCode())).toList()
|
||||
: dropshipCartons.lockAvailable(customerId, profile.getId(), item.getSkuCode(), request.packages());
|
||||
.filter(carton -> "AVAILABLE".equals(carton.getStatus())).toList()
|
||||
: dropshipCartons.lockAvailablePhysical(customerId, profile.getId(), request.packages());
|
||||
if (cartons.size() != request.packages()) throw conflict("Insufficient available one-click dropship cartons");
|
||||
InventoryCommandRequests.Move move = new InventoryCommandRequests.Move(request.inventoryPositionId(), request.packages(), outbound.getOutboundNo(), outbound.getOutboundNo(), null, request.idempotencyKey() + ":ALLOCATE", null);
|
||||
inventoryCommands.allocate(customerId, operatorId, move);
|
||||
inventoryCommands.pick(customerId, operatorId, new InventoryCommandRequests.Move(request.inventoryPositionId(), request.packages(), outbound.getOutboundNo(), outbound.getOutboundNo(), null, request.idempotencyKey() + ":PICK", null));
|
||||
inventoryCommands.ship(customerId, operatorId, new InventoryCommandRequests.Move(request.inventoryPositionId(), request.packages(), outbound.getOutboundNo(), outbound.getOutboundNo(), null, request.idempotencyKey() + ":SHIP", null));
|
||||
long productQuantity = 0;
|
||||
Map<String, SkuShipment> shippedSkus = new LinkedHashMap<>();
|
||||
for (DropshipCarton carton : cartons) {
|
||||
if (carton.getProductQuantity() == null || carton.getProductQuantity() <= 0) throw conflict("出库箱唛缺少逐箱实收件数");
|
||||
productQuantity = Math.addExact(productQuantity, carton.getProductQuantity());
|
||||
List<DropshipCartonSku> cartonFacts = dropshipCartonSkus.listCarton(customerId, carton.getId());
|
||||
if (cartonFacts.isEmpty()) {
|
||||
shippedSkus.merge(carton.getSkuCode(), new SkuShipment(1, carton.getProductQuantity()), SkuShipment::add);
|
||||
} else {
|
||||
for (DropshipCartonSku fact : cartonFacts) {
|
||||
shippedSkus.merge(fact.getSkuCode(), new SkuShipment(1, value(fact.getProductQuantity())), SkuShipment::add);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, SkuShipment> shipment : shippedSkus.entrySet()) {
|
||||
if (dropshipSkuInventory.deduct(customerId, profile.getId(), shipment.getKey(),
|
||||
shipment.getValue().packages(), shipment.getValue().quantity()) != 1) {
|
||||
throw conflict("Insufficient one-click dropship SKU inventory: " + shipment.getKey());
|
||||
}
|
||||
}
|
||||
if (dropshipSkuInventory.deduct(customerId, profile.getId(), item.getSkuCode(), request.packages(), productQuantity) != 1) throw conflict("Insufficient one-click dropship SKU inventory");
|
||||
for (DropshipCarton carton : cartons) { carton.setStatus("SHIPPED"); carton.setOutboundOrderNo(outbound.getOutboundNo()); carton.setVersion((carton.getVersion() == null ? 0 : carton.getVersion()) + 1); carton.setUpdatedAt(LocalDateTime.now()); dropshipCartons.updateById(carton); }
|
||||
OutboundPdaPick pick = new OutboundPdaPick(); pick.setId(IdWorker.getId()); pick.setCustomerId(customerId); pick.setTaskId(task.getId()); pick.setOutboundPalletItemId(item.getId()); pick.setInventoryPositionId(request.inventoryPositionId()); pick.setPackages(request.packages()); pick.setIdempotencyKey(request.idempotencyKey().trim()); pick.setPickedAt(LocalDateTime.now()); pdaPicks.insert(pick);
|
||||
item.setPickedPackageCount(value(item.getPickedPackageCount()) + request.packages().intValue()); item.setStatus(item.getPickedPackageCount() >= item.getPackageCount() ? "PICKED" : "PARTIAL_PICKED"); outboundPallets.updateById(item);
|
||||
@@ -778,7 +797,6 @@ public class DeliveryTransferService {
|
||||
DropshipOrderProfile profile = dropshipProfiles.findPosition(customerId, position.getId());
|
||||
List<String> marks = profile == null ? List.of() : dropshipCartons.listProfile(customerId, profile.getId())
|
||||
.stream().filter(carton -> "AVAILABLE".equals(carton.getStatus()))
|
||||
.filter(carton -> Objects.equals(item.getSkuCode(), carton.getSkuCode()))
|
||||
.filter(carton -> !StringUtils.hasText(item.getCartonMarks()) || frozenMarks.contains(carton.getCartonMark()))
|
||||
.map(DropshipCarton::getCartonMark).filter(StringUtils::hasText).distinct().limit(available).toList();
|
||||
if (profile != null && marks.isEmpty()) continue;
|
||||
@@ -983,6 +1001,12 @@ public class DeliveryTransferService {
|
||||
}
|
||||
private record PalletPickPlan(Long itemId, Long positionId, long packages,
|
||||
List<String> cartonMarks, int sequence) {}
|
||||
private record SkuShipment(long packages, long quantity) {
|
||||
private SkuShipment add(SkuShipment other) {
|
||||
return new SkuShipment(Math.addExact(packages, other.packages),
|
||||
Math.addExact(quantity, other.quantity));
|
||||
}
|
||||
}
|
||||
private BigDecimal totalWeight(String customerId, List<DispatchItem> items) {
|
||||
List<Long> palletIds = items.stream().map(DispatchItem::getWarehousePalletId)
|
||||
.filter(Objects::nonNull).distinct().toList();
|
||||
|
||||
Reference in New Issue
Block a user