贴标申请,仓储转运

This commit is contained in:
2026-10-12 15:57:47 +08:00
parent a1cd47dabd
commit 6c4ee2bfde
7 changed files with 189 additions and 18 deletions
@@ -39,7 +39,7 @@ public final class RelabelResponses {
long availablePackages, long version, List<InventoryPosition> positions,
String sourceType, Long returnCartonId, String cartonMark,
List<SkuItem> skuItems, long relabelledPackages, String relabelStatus,
long relabelledQuantity, long relabelReservedQuantity) {
long relabelledQuantity, long relabelReservedQuantity, Long stockQuantity, String inventoryStatus, String occupiedRelabelNo, List<String> mergedIntoCartonMarks, boolean hasOutbound) {
public InventoryCandidate(Long inventoryBalanceId, Long inboundOrderId, String inboundOrderNo, String inboundCode,
String overseasWarehouseId, String overseasWarehouseCode, String overseasWarehouseName,
String destinationFbaWarehouseCode, String destinationFbaWarehouseName, String skuCode, String productNameZh,
@@ -48,7 +48,7 @@ public final class RelabelResponses {
this(inventoryBalanceId, inboundOrderId, inboundOrderNo, inboundCode, overseasWarehouseId,
overseasWarehouseCode, overseasWarehouseName, destinationFbaWarehouseCode, destinationFbaWarehouseName,
skuCode, productNameZh, availablePackages, version, positions, sourceType, returnCartonId, cartonMark,
skuItems, relabelledPackages, null, relabelledPackages, 0);
skuItems, relabelledPackages, null, relabelledPackages, 0, null, null, null, List.of(), false);
}
}
public record HistoricalOrder(Long id, String orderNo, String sourceOrderNo, String outboundOrderNo,
@@ -94,6 +94,7 @@ public class RelabelApplicationService implements WalletResultHandler {
@Resource private ReturnInventoryCartonMapper returnCartons;
@Resource private ReturnInventoryCartonItemMapper returnCartonItems;
@Resource private ReturnOrderMapper returnOrders;
@Resource private com.baiyue.lastleg.returnreceipt.mapper.ReturnPackingTraceMapper returnPackingTraces;
@Resource private RelabelDocumentFileGateway documentFiles;
@Resource private PdaRelabelTaskMapper pdaTasks;
@Resource private RelabelPhotoFileGateway photoFiles;
@@ -269,7 +270,11 @@ public class RelabelApplicationService implements WalletResultHandler {
if (StringUtils.hasText(keyword)
&& !containsIgnoreCase(carton.getCartonMark(), keyword)
&& !containsIgnoreCase(carton.getSourceReturnNo(), keyword)) continue;
List<RelabelResponses.SkuItem> cartonSkus = returnCartonItems.listCarton(carton.getId()).stream()
var cartonLines = returnCartonItems.listCarton(carton.getId());
String productNames = cartonLines.stream().filter(item -> value(item.getQuantity()) > 0)
.map(item -> trim(item.getProductNameZh())).filter(StringUtils::hasText).distinct()
.collect(Collectors.joining("、"));
List<RelabelResponses.SkuItem> cartonSkus = cartonLines.stream()
.filter(item -> value(item.getQuantity()) > 0)
.map(item -> {
long remaining = "AVAILABLE".equals(carton.getStatus())
@@ -277,7 +282,7 @@ public class RelabelApplicationService implements WalletResultHandler {
return new RelabelResponses.SkuItem(item.getSkuCode(), null,
Math.toIntExact(Math.max(remaining, 0)), null);
}).toList();
if (cartonSkus.isEmpty()) continue;
if (cartonSkus.isEmpty() && !java.util.Set.of("MERGED", "OUTBOUNDED").contains(carton.getStatus())) continue;
String skuCodes = cartonSkus.stream().map(RelabelResponses.SkuItem::skuCode)
.collect(Collectors.joining(","));
long availablePackages = cartonSkus.stream().mapToLong(RelabelResponses.SkuItem::quantity).sum();
@@ -285,9 +290,12 @@ public class RelabelApplicationService implements WalletResultHandler {
long reserved = returnCartons.relabelReservedQuantity(carton.getId());
result.add(new RelabelResponses.InventoryCandidate(null, null, carton.getSourceReturnNo(),
null, carton.getOverseasWarehouseId(), null, null, carton.getDestinationWarehouseCode(),
carton.getDestinationWarehouseName(), skuCodes, "退货入库库存", availablePackages, 0, List.of(),
carton.getDestinationWarehouseName(), skuCodes, productNames, availablePackages, 0, List.of(),
"PARCEL".equals(carton.getSourceUnitType()) ? "RETURN_PARCEL" : "RETURN_CARTON", carton.getId(), carton.getCartonMark(), cartonSkus, relabelledPackages,
com.baiyue.lastleg.returnreceipt.service.ReturnRelabelProgress.status(value(carton.getTotalQuantity()), relabelledPackages, reserved), relabelledPackages, reserved));
com.baiyue.lastleg.returnreceipt.service.ReturnRelabelProgress.status(value(carton.getTotalQuantity()), relabelledPackages, reserved), relabelledPackages, reserved, java.util.Set.of("MERGED", "OUTBOUNDED").contains(carton.getStatus()) ? 0L : value(carton.getTotalQuantity()), carton.getStatus(), carton.getRelabelNo(),
returnPackingTraces.listCartonHistory(customerId, carton.getCartonMark()).stream()
.filter(history -> carton.getCartonMark().equals(history.sourceCartonMark()))
.map(history -> history.targetCartonMark()).distinct().toList(), returnCartons.hasOutbound(carton.getId())));
}
return result;
}
@@ -679,10 +687,10 @@ public class RelabelApplicationService implements WalletResultHandler {
// Reviewing/processing a return relabel must not move the already
// completed inbound order back to assignment or relabel waiting.
if ("RETURN_RELABEL".equals(order.getOrderType())) {
orderStatus = "INBOUND_COMPLETED";
orderStatus = orderBefore;
}
order.setCurrentStatus(orderStatus);
order.setSubOrderStatus("RELABEL:" + next);
if (!"RETURN_RELABEL".equals(order.getOrderType())) order.setSubOrderStatus("RELABEL:" + next);
order.setRelabelStatus(businessRelabelStatus(next));
order.setUpdatedAt(now);
orders.updateById(order);
@@ -794,7 +802,7 @@ public class RelabelApplicationService implements WalletResultHandler {
applications.updateById(application);
for (LastlegOrder order : tailOrders(application)) {
order.setRelabelStatus(PENDING_REVIEW);
order.setSubOrderStatus("RELABEL:" + PENDING_REVIEW);
if (!"RETURN_RELABEL".equals(order.getOrderType())) order.setSubOrderStatus("RELABEL:" + PENDING_REVIEW);
order.setUpdatedAt(now);
orders.updateById(order);
}
@@ -813,7 +821,8 @@ public class RelabelApplicationService implements WalletResultHandler {
application.setUpdatedAt(LocalDateTime.now()); applications.updateById(application);
for (LastlegOrder order : tailOrders(application)) {
if ("RETURN_RELABEL".equals(order.getOrderType()) && !Objects.equals(order.getRelabelOrderNo(), application.getRelabelNo())) continue;
order.setRelabelStatus("PROCESSING"); order.setSubOrderStatus("RELABEL:PROCESSING");
order.setRelabelStatus("PROCESSING");
if (!"RETURN_RELABEL".equals(order.getOrderType())) order.setSubOrderStatus("RELABEL:PROCESSING");
order.setUpdatedAt(LocalDateTime.now()); orders.updateById(order);
}
insertHistory(customerId, application.getId(), before, "PROCESSING", operatorId, remark, LocalDateTime.now());
@@ -930,9 +939,9 @@ public class RelabelApplicationService implements WalletResultHandler {
String orderBefore = order.getCurrentStatus();
// 换标确认时货物已经完成入库,不得退回最初建单的“待分配”。
// 独立换标先进入待出库;仓储转运会在下方按目的仓进一步收敛为待排车或待确认目的仓。
order.setCurrentStatus("RETURN_RELABEL".equals(order.getOrderType()) ? "INBOUND_COMPLETED"
order.setCurrentStatus("RETURN_RELABEL".equals(order.getOrderType()) ? orderBefore
: requiresOutbound ? "WAIT_OUTBOUND" : "COMPLETED");
order.setSubOrderStatus("RELABEL:" + application.getFulfillmentStatus());
if (!"RETURN_RELABEL".equals(order.getOrderType())) order.setSubOrderStatus("RELABEL:" + application.getFulfillmentStatus());
order.setRelabelStatus("COMPLETED");
order.setUpdatedAt(now);
orders.updateById(order);
@@ -1235,7 +1244,6 @@ public class RelabelApplicationService implements WalletResultHandler {
.last("LIMIT 1"));
if (existingReturn != null) {
existingReturn.setRelabelOrderNo(relabelNo); existingReturn.setRelabelStatus(PENDING_REVIEW);
existingReturn.setSubOrderStatus("RETURN_RELABEL:" + PENDING_REVIEW); existingReturn.setPackageCount(packageCount);
existingReturn.setUpdatedAt(now); orders.updateById(existingReturn); return existingReturn;
}
LastlegOrder order = new LastlegOrder();
@@ -1265,7 +1273,7 @@ public class RelabelApplicationService implements WalletResultHandler {
// A linked warehouse-transfer relabel can cover only part of the
// transfer. Keep the authoritative whole-order package count so later
// dispatches can attribute the remaining cartons correctly.
if (!"WAREHOUSE_TRANSFER".equals(order.getOrderType())) order.setPackageCount(packageCount);
if (!"WAREHOUSE_TRANSFER".equals(order.getOrderType()) && !"RETURN_RELABEL".equals(order.getOrderType())) order.setPackageCount(packageCount);
order.setUpdatedAt(now); orders.updateById(order);
return order;
}
@@ -10,6 +10,8 @@ import java.util.List;
@Mapper
public interface ReturnInventoryCartonMapper extends BaseMapper<ReturnInventoryCarton> {
@Select("SELECT EXISTS(SELECT 1 FROM ll_return_inventory_outbound_movement WHERE carton_id=#{cartonId} AND quantity>0)")
boolean hasOutbound(@Param("cartonId") long cartonId);
@Update("UPDATE ll_return_inventory_carton SET relabel_application_id=NULL,relabel_no=NULL,relabel_status=NULL WHERE id=#{id}")
int clearRelabel(@Param("id") long id);
@Select("SELECT * FROM ll_return_inventory_carton WHERE source_receipt_id=#{receiptId} ORDER BY id FOR UPDATE")
@@ -40,7 +42,7 @@ public interface ReturnInventoryCartonMapper extends BaseMapper<ReturnInventoryC
"ORDER BY created_at DESC,id DESC LIMIT 500</script>")
List<ReturnInventoryCarton> findAvailable(@Param("customerId") String customerId, @Param("warehouseId") String warehouseId);
@Select("SELECT * FROM ll_return_inventory_carton WHERE customer_id=#{customerId} AND overseas_warehouse_id=#{warehouseId} " +
"AND count_status='CONFIRMED' AND status IN ('AVAILABLE','RELABEL_PENDING','PACKING_RESERVED') ORDER BY created_at DESC,id DESC LIMIT 500")
"AND count_status='CONFIRMED' AND status IN ('AVAILABLE','RELABEL_PENDING','PACKING_RESERVED','MERGED','OUTBOUNDED','OUTBOUND_PENDING','DISCARD_PENDING') ORDER BY created_at DESC,id DESC LIMIT 500")
List<ReturnInventoryCarton> findRelabelCandidates(@Param("customerId") String customerId, @Param("warehouseId") String warehouseId);
@Select("SELECT * FROM ll_return_inventory_carton WHERE carton_mark=#{cartonMark} LIMIT 1")
ReturnInventoryCarton findMark(@Param("cartonMark") String cartonMark);
@@ -444,9 +444,8 @@ public class ReturnReceiptService {
// Do not create a second independent tail order or overwrite the inbound status.
tail.setRelabelOrderNo(relabelNo);
tail.setRelabelStatus("PENDING_REVIEW");
tail.setSubOrderStatus("RETURN_RELABEL:PENDING_REVIEW");
tail.setCurrentStatus("RETURN_RELABEL".equals(tail.getOrderType()) ? "INBOUND_COMPLETED" : tail.getCurrentStatus());
if (!"RETURN_RELABEL".equals(tail.getOrderType())) {
tail.setSubOrderStatus("RETURN_RELABEL:PENDING_REVIEW");
tail.setPackageCount(Math.toIntExact(totalQuantity));
tail.setProductQuantity(Math.toIntExact(totalQuantity));
}