fix(lastleg): use reassigned FBA destination in inbound plans
This commit is contained in:
+3
-2
@@ -38,7 +38,8 @@ public interface InboundPlanOrderMapper {
|
||||
"o.inbound_order_no AS inboundOrderNo,o.container_no AS containerNo,COALESCE(o.pallet_count,0) AS recommendedPalletCount," +
|
||||
"COALESCE(o.package_count,0) AS packageCount,COALESCE(o.volume_cbm,0) AS volumeCbm," +
|
||||
"o.overseas_warehouse_id AS overseasWarehouseId,o.overseas_warehouse_code AS overseasWarehouseCode," +
|
||||
"o.overseas_warehouse_name AS overseasWarehouseName,o.fba_warehouse_code AS fbaWarehouseCode," +
|
||||
"o.overseas_warehouse_name AS overseasWarehouseName," +
|
||||
"COALESCE(NULLIF(o.transfer_warehouse_code,''),NULLIF(o.fba_warehouse_code,'')) AS fbaWarehouseCode," +
|
||||
"COALESCE(NULLIF(o.transfer_warehouse_id,''),(SELECT MIN(NULLIF(d.destination_warehouse_id,'')) FROM ll_order_detail d WHERE d.order_id=o.id)) AS destinationWarehouseId," +
|
||||
"COALESCE(NULLIF(o.transfer_warehouse_code,''),(SELECT MIN(NULLIF(d.destination_warehouse_code,'')) FROM ll_order_detail d WHERE d.order_id=o.id)) AS destinationWarehouseCode," +
|
||||
"COALESCE(NULLIF(o.transfer_warehouse_name,''),(SELECT MIN(NULLIF(d.destination_warehouse_name,'')) FROM ll_order_detail d WHERE d.order_id=o.id)) AS destinationWarehouseName," +
|
||||
@@ -92,7 +93,7 @@ public interface InboundPlanOrderMapper {
|
||||
"COALESCE(o.volume_cbm,0) AS volumeCbm,COALESCE(o.package_count,0) AS packageCount," +
|
||||
"COALESCE(o.pallet_count,0) AS recommendedPalletCount,o.overseas_warehouse_id AS overseasWarehouseId," +
|
||||
"o.overseas_warehouse_code AS overseasWarehouseCode,o.overseas_warehouse_name AS overseasWarehouseName," +
|
||||
"NULLIF(o.fba_warehouse_code,'') AS fbaWarehouseCode," +
|
||||
"COALESCE(NULLIF(o.transfer_warehouse_code,''),NULLIF(o.fba_warehouse_code,'')) AS fbaWarehouseCode," +
|
||||
"COALESCE(NULLIF(o.transfer_warehouse_id,''),MIN(NULLIF(d.destination_warehouse_id,''))) AS destinationWarehouseId," +
|
||||
"COALESCE(NULLIF(o.transfer_warehouse_code,''),MIN(NULLIF(d.destination_warehouse_code,''))) AS destinationWarehouseCode," +
|
||||
"COALESCE(NULLIF(o.transfer_warehouse_name,''),MIN(NULLIF(d.destination_warehouse_name,''))) AS destinationWarehouseName," +
|
||||
|
||||
+54
@@ -2,10 +2,64 @@ package com.baiyue.lastleg.inboundplan.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class InboundPlanOrderMapperContractTest {
|
||||
@Test
|
||||
void reassignedDestinationUsesOneFbaCodeForPlanAndDispatch() throws Exception {
|
||||
var jdbc = new JdbcTemplate(new DriverManagerDataSource(
|
||||
"jdbc:h2:mem:" + UUID.randomUUID() + ";MODE=MySQL;DB_CLOSE_DELAY=-1", "sa", ""));
|
||||
jdbc.execute("""
|
||||
CREATE TABLE ll_order (id BIGINT, customer_id VARCHAR(32), container_no VARCHAR(32),
|
||||
inbound_code VARCHAR(32), current_status VARCHAR(32), inbound_order_no VARCHAR(32),
|
||||
volume_cbm DECIMAL(12,3), package_count INT, pallet_count INT,
|
||||
overseas_warehouse_id VARCHAR(32), overseas_warehouse_code VARCHAR(32),
|
||||
overseas_warehouse_name VARCHAR(64), fba_warehouse_code VARCHAR(32),
|
||||
transfer_warehouse_id VARCHAR(32), transfer_warehouse_code VARCHAR(32),
|
||||
transfer_warehouse_name VARCHAR(64), detained BOOLEAN, version BIGINT)
|
||||
""");
|
||||
jdbc.execute("""
|
||||
CREATE TABLE ll_order_detail (order_id BIGINT, destination_warehouse_id VARCHAR(32),
|
||||
destination_warehouse_code VARCHAR(32), destination_warehouse_name VARCHAR(64))
|
||||
""");
|
||||
jdbc.update("""
|
||||
INSERT INTO ll_order (id,customer_id,fba_warehouse_code,transfer_warehouse_id,
|
||||
transfer_warehouse_code,transfer_warehouse_name) VALUES (1,'C1','ABE3','22','ABE2','New FBA')
|
||||
""");
|
||||
jdbc.update("INSERT INTO ll_order_detail VALUES (1,'22','ABE2','New FBA')");
|
||||
String sql = String.join(" ", InboundPlanOrderMapper.class
|
||||
.getMethod("lockOrder", String.class, Long.class).getAnnotation(Select.class).value())
|
||||
.replace("#{customerId}", "?").replace("#{orderId}", "?");
|
||||
// H2 cannot lock grouped queries; exercise the production projection and scope here.
|
||||
sql = sql.replace(" FOR UPDATE", "");
|
||||
var row = jdbc.queryForMap(sql, "C1", 1L);
|
||||
assertEquals("ABE2", row.get("fbaWarehouseCode"));
|
||||
assertEquals(row.get("destinationWarehouseCode"), row.get("fbaWarehouseCode"));
|
||||
assertEquals("22", row.get("destinationWarehouseId"));
|
||||
assertTrue(jdbc.queryForList(sql, "OTHER", 1L).isEmpty());
|
||||
jdbc.update("UPDATE ll_order SET transfer_warehouse_id=NULL,transfer_warehouse_code='',transfer_warehouse_name=NULL WHERE id=1");
|
||||
jdbc.update("UPDATE ll_order_detail SET destination_warehouse_id='33',destination_warehouse_code='ABE3' WHERE order_id=1");
|
||||
row = jdbc.queryForMap(sql, "C1", 1L);
|
||||
assertEquals("ABE3", row.get("fbaWarehouseCode"));
|
||||
assertEquals(row.get("destinationWarehouseCode"), row.get("fbaWarehouseCode"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void containerPreviewAndLockedSnapshotUseTheSameEffectiveFbaDestination() throws Exception {
|
||||
for (var method : InboundPlanOrderMapper.class.getMethods()) {
|
||||
if (!method.getName().equals("lockOrder") && !method.getName().equals("containerPreviewOrders")) continue;
|
||||
String sql = String.join(" ", method.getAnnotation(Select.class).value());
|
||||
assertTrue(sql.contains("COALESCE(NULLIF(o.transfer_warehouse_code,''),NULLIF(o.fba_warehouse_code,'')) AS fbaWarehouseCode"),
|
||||
method.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void transferWarehouseIsTheEffectivePalletDestination() throws Exception {
|
||||
Select select = InboundPlanOrderMapper.class
|
||||
|
||||
Reference in New Issue
Block a user