fix(lastleg): resolve actual overseas receiving warehouse

This commit is contained in:
2026-08-30 18:07:38 +08:00
parent ca9e7b60e8
commit ff6a8498a6
5 changed files with 47 additions and 18 deletions
@@ -12,14 +12,11 @@ public interface InboundCodeRelationshipMapper {
@Select("SELECT o.customer_id AS customerId,o.customer_name AS customerName,o.order_no AS orderNo," +
"o.current_status AS orderStatus,p.plan_no AS planNo,p.status AS planStatus," +
"COALESCE(p.status,o.current_status) AS receivingStatus," +
"COALESCE(b.overseas_warehouse_id,o.overseas_warehouse_id,CAST(p.overseas_warehouse_id AS CHAR)) AS overseasWarehouseId," +
"b.overseas_warehouse_code AS overseasWarehouseCode," +
"COALESCE(b.overseas_warehouse_name,o.overseas_warehouse_name) AS overseasWarehouseName " +
"CAST(p.overseas_warehouse_id AS CHAR) AS overseasWarehouseId " +
"FROM ll_order o " +
"LEFT JOIN ll_inbound_plan_line l ON l.customer_id=o.customer_id AND l.order_id=o.id AND l.inbound_code=o.inbound_code " +
"LEFT JOIN ll_inbound_plan p ON p.customer_id=o.customer_id AND p.id=l.plan_id " +
"LEFT JOIN ll_inventory_balance b ON b.customer_id=o.customer_id AND b.inbound_order_id=o.id AND b.inbound_code=o.inbound_code " +
"WHERE o.inbound_code=#{inboundCode} ORDER BY o.customer_id,o.id,p.id,b.id")
"WHERE o.inbound_code=#{inboundCode} ORDER BY o.customer_id,o.id,p.id")
List<InboundCodeRelationshipRows.Base> bases(@Param("inboundCode") String inboundCode);
@Select("SELECT DISTINCT r.pallet_no FROM ll_inbound_stock_receipt r " +
@@ -15,8 +15,6 @@ public final class InboundCodeRelationshipRows {
private String planStatus;
private String receivingStatus;
private String overseasWarehouseId;
private String overseasWarehouseCode;
private String overseasWarehouseName;
}
@Data
@@ -3,6 +3,7 @@ package com.baiyue.lastleg.inventory.query.service;
import com.baiyue.lastleg.inventory.query.dto.InboundCodeRelationshipResponse;
import com.baiyue.lastleg.inventory.query.mapper.InboundCodeRelationshipMapper;
import com.baiyue.lastleg.inventory.query.model.InboundCodeRelationshipRows;
import com.baiyue.lastleg.inboundplan.pda.gateway.WarehouseResourceGateway;
import jakarta.annotation.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@@ -14,6 +15,7 @@ import java.util.Objects;
@Service
public class InboundCodeRelationshipService {
@Resource private InboundCodeRelationshipMapper mapper;
@Resource private WarehouseResourceGateway warehouse;
public InboundCodeRelationshipResponse find(String inboundCode) {
String normalized = required(inboundCode);
@@ -30,10 +32,6 @@ public class InboundCodeRelationshipService {
"customer name");
String warehouseId = unique(bases.stream().map(InboundCodeRelationshipRows.Base::getOverseasWarehouseId).toList(),
"overseas warehouse ID");
String warehouseCode = unique(bases.stream().map(InboundCodeRelationshipRows.Base::getOverseasWarehouseCode).toList(),
"overseas warehouse code");
String warehouseName = unique(bases.stream().map(InboundCodeRelationshipRows.Base::getOverseasWarehouseName).toList(),
"overseas warehouse name");
List<InboundCodeRelationshipResponse.TaillegOrder> orders = bases.stream()
.filter(value -> trim(value.getOrderNo()) != null)
.map(value -> new InboundCodeRelationshipResponse.TaillegOrder(
@@ -50,14 +48,26 @@ public class InboundCodeRelationshipService {
value.getProductNameZh(), value.getProductNameEn(), number(value.getPackageCount()))).toList();
String status = unique(bases.stream().map(InboundCodeRelationshipRows.Base::getReceivingStatus).toList(),
"overseas receiving status");
InboundCodeRelationshipResponse.OverseasWarehouse warehouse = warehouseId == null
&& warehouseCode == null && warehouseName == null ? null
: new InboundCodeRelationshipResponse.OverseasWarehouse(warehouseId, warehouseCode, warehouseName);
InboundCodeRelationshipResponse.OverseasWarehouse warehouseView = resolveWarehouse(warehouseId);
return new InboundCodeRelationshipResponse(normalized, true,
new InboundCodeRelationshipResponse.Customer(customerId, customerName), warehouse, status,
new InboundCodeRelationshipResponse.Customer(customerId, customerName), warehouseView, status,
orders, plans, mapper.palletCodes(customerId, normalized), inventory);
}
private InboundCodeRelationshipResponse.OverseasWarehouse resolveWarehouse(String warehouseId) {
if (warehouseId == null) return null;
final long id;
try {
id = Long.parseLong(warehouseId);
} catch (NumberFormatException exception) {
throw new ResponseStatusException(HttpStatus.CONFLICT,
"Inbound code has invalid overseas warehouse ID snapshot");
}
WarehouseResourceGateway.WarehouseReference value = warehouse.requireActiveSharedWarehouse(id);
return new InboundCodeRelationshipResponse.OverseasWarehouse(
String.valueOf(value.warehouseId()), value.warehouseCode(), value.warehouseName());
}
private static InboundCodeRelationshipResponse empty(String inboundCode) {
return new InboundCodeRelationshipResponse(inboundCode, false, null, null, null,
List.of(), List.of(), List.of(), List.of());