fix: preserve dropship pallets in container plans

This commit is contained in:
2026-09-02 01:17:00 +08:00
parent fd9a070efc
commit cc02037f78
3 changed files with 67 additions and 15 deletions
@@ -12,9 +12,11 @@ import java.util.List;
@Mapper
public interface InboundPlanOrderMapper {
record ContainerOrderRef(String customerId, Long orderId, String currentStatus, String containerNo) { }
record ContainerOrderRef(String customerId, Long orderId, String currentStatus, String containerNo,
String orderType) { }
@Select("SELECT customer_id AS customerId,id AS orderId,current_status AS currentStatus,container_no AS containerNo " +
@Select("SELECT customer_id AS customerId,id AS orderId,current_status AS currentStatus,container_no AS containerNo," +
"order_type AS orderType " +
"FROM ll_order WHERE source_container_booking_id=#{sourceContainerBookingId} ORDER BY customer_id,id FOR UPDATE")
List<ContainerOrderRef> lockContainerOrders(@Param("sourceContainerBookingId") String sourceContainerBookingId);
@@ -20,6 +20,8 @@ import com.baiyue.lastleg.inboundplan.mapper.InboundPlanPalletMapper;
import com.baiyue.lastleg.inboundplan.mapper.InboundPlanQueryMapper;
import com.baiyue.lastleg.inboundplan.model.SourceOrderSnapshot;
import com.baiyue.lastleg.inventory.mapper.InventoryBalanceMapper;
import com.baiyue.lastleg.dropship.model.DropshipPalletSnapshot;
import com.baiyue.lastleg.dropship.service.DropshipOrderService;
import com.baiyue.common.event.ContainerNumbers;
import jakarta.annotation.Resource;
import org.springframework.http.HttpStatus;
@@ -47,6 +49,7 @@ public class InboundPlanService {
@Resource private InboundPlanOrderMapper orderMapper;
@Resource private InboundPlanQueryMapper queryMapper;
@Resource private InventoryBalanceMapper inventoryBalanceMapper;
@Resource private DropshipOrderService dropshipOrders;
@Transactional(readOnly = true)
public PageResult<InboundPlanListResponse> page(String customerId, InboundPlanRequests.Query query) {
@@ -206,6 +209,7 @@ public class InboundPlanService {
}
List<List<SourceOrderSnapshot>> snapshots = new ArrayList<>(refs.size());
List<List<WholePalletInput>> wholePallets = new ArrayList<>(refs.size());
for (InboundPlanOrderMapper.ContainerOrderRef ref : refs) {
List<SourceOrderSnapshot> orders = orderMapper.lockOrder(ref.customerId(), ref.orderId());
if (orders == null || orders.isEmpty()) {
@@ -217,16 +221,33 @@ public class InboundPlanService {
throw new ResponseStatusException(HttpStatus.CONFLICT, "来源柜内尾程订单柜号不一致");
}
snapshots.add(orders);
List<WholePalletInput> sourcePallets = "ONE_CLICK_DROPSHIP".equals(ref.orderType())
? dropshipOrders.palletSnapshots(ref.customerId(), ref.orderId()).stream()
.map(this::wholePallet).toList()
: null;
if (sourcePallets != null) {
if (sourcePallets.isEmpty()) {
throw new ResponseStatusException(HttpStatus.CONFLICT,
"一件代发订单缺少不可变来源托盘快照");
}
validateWholePallets(orders, sourcePallets);
}
wholePallets.add(sourcePallets);
}
List<InboundPlanResponse> created = new ArrayList<>(refs.size());
for (int index = 0; index < refs.size(); index++) {
InboundPlanOrderMapper.ContainerOrderRef ref = refs.get(index);
created.add(createPlan(ref.customerId(), ref.orderId(), snapshots.get(index), List.of(), null));
created.add(createPlan(ref.customerId(), ref.orderId(), snapshots.get(index), List.of(),
wholePallets.get(index)));
}
return List.copyOf(created);
}
private WholePalletInput wholePallet(DropshipPalletSnapshot pallet) {
return new WholePalletInput(pallet.sourcePalletNo(), Math.toIntExact(pallet.packageCount()));
}
private String requiredContainerNo(String value) {
try {
return ContainerNumbers.requireCanonical(value);