fix(lastleg): group same-code FBA cargo with optional internal warehouse reference

This commit is contained in:
2026-10-23 04:47:33 +08:00
parent f6c83125c9
commit b92f7fe991
2 changed files with 34 additions and 2 deletions
@@ -59,16 +59,26 @@ public class DeliveryCargoGroups {
var rows=entry.getValue().stream().sorted(Comparator.comparing(CargoLine::dispatchItemId)
.thenComparing(CargoLine::attributionId)).toList();
var first=rows.get(0);
if (rows.stream().anyMatch(row->!Objects.equals(row.destination(),first.destination())))
// FBA以真实仓码分组;外接来货可缺内部仓ID,只沿同组已知ID核对,不能覆盖冲突值。
var destination=rows.stream().map(CargoLine::destination)
.filter(value->!blank(value.warehouseId())).findFirst().orElse(first.destination());
if (rows.stream().anyMatch(row->!Objects.equals(withKnownFbaWarehouseId(row.destination(),destination.warehouseId()),destination)))
throw conflict("同组货物的目的地信息不一致,请核对后安排");
long packages=rows.stream().mapToLong(CargoLine::packages).reduce(0,Math::addExact);
long pallets=rows.stream().map(CargoLine::warehousePalletId).filter(Objects::nonNull).distinct().count();
result.add(new Group(entry.getKey(),first.customerId(),first.customerName(),first.destination(),
result.add(new Group(entry.getKey(),first.customerId(),first.customerName(),destination,
hash(rows),rows,packages,pallets));
}
return List.copyOf(result);
}
/** 仅补同一分组FBA缺失的内部引用,其他目的地事实必须保持完全一致。 */
private Destination withKnownFbaWarehouseId(Destination value,String warehouseId) {
if (!"FBA".equals(value.type()) || !blank(value.warehouseId()) || blank(warehouseId)) return value;
return new Destination(value.key(),value.type(),warehouseId,value.warehouseCode(),value.warehouseName(),
value.address(),value.postalCode(),value.contactName(),value.contactPhone());
}
/** 客户是组身份的一部分,同目的仓的其他客户永不合单。 */
public String groupKey(String customerId,Destination destination) {
return hash(List.of(customerId,destination.key()));