fix(lastleg): restore dispatch returns from immutable pick source and expose customer receipts
This commit is contained in:
+103
@@ -0,0 +1,103 @@
|
||||
package com.baiyue.lastleg.inventory.command;
|
||||
|
||||
import com.baiyue.lastleg.inventory.command.mapper.InventoryCommandMapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/** Execute the production source query rather than mocking a successful source lookup. */
|
||||
class DispatchShipmentSourceQueryTest {
|
||||
private Connection database() throws Exception {
|
||||
Connection connection = DriverManager.getConnection("jdbc:h2:mem:" + UUID.randomUUID() + ";MODE=MySQL");
|
||||
execute(connection, "CREATE TABLE ll_inventory_ledger (id BIGINT PRIMARY KEY, customer_id VARCHAR, position_id BIGINT, overseas_warehouse_id VARCHAR, sku_code VARCHAR, business_type VARCHAR, delta_packages BIGINT, business_order_no VARCHAR, outbound_order_no VARCHAR, idempotency_key VARCHAR)");
|
||||
execute(connection, "CREATE TABLE ll_outbound_order (id BIGINT PRIMARY KEY, customer_id VARCHAR, outbound_no VARCHAR, overseas_warehouse_id VARCHAR, status VARCHAR, outbound_type VARCHAR, dispatch_no VARCHAR, dispatch_order_id BIGINT)");
|
||||
execute(connection, "CREATE TABLE ll_dispatch_pda_task (id BIGINT PRIMARY KEY, customer_id VARCHAR, warehouse_id VARCHAR, dispatch_order_id BIGINT)");
|
||||
execute(connection, "CREATE TABLE ll_dispatch_pda_pick (id BIGINT PRIMARY KEY, customer_id VARCHAR, task_id BIGINT, dispatch_item_id BIGINT, inventory_position_id BIGINT, packages BIGINT, idempotency_key VARCHAR)");
|
||||
execute(connection, "INSERT INTO ll_dispatch_pda_task VALUES (11,'100','WH-1',1)");
|
||||
execute(connection, "INSERT INTO ll_dispatch_pda_pick VALUES (21,'100',11,31,41,8,'pick-1')");
|
||||
return connection;
|
||||
}
|
||||
|
||||
private void execute(Connection connection, String sql) throws Exception {
|
||||
try (var statement = connection.createStatement()) { statement.execute(sql); }
|
||||
}
|
||||
|
||||
private long shipped(Connection connection, String customerId, long positionId, String outboundNo, String sku) throws Exception {
|
||||
String sql = String.join(" ", InventoryCommandMapper.class.getMethod("shippedPackages",
|
||||
String.class, Long.class, String.class, String.class).getAnnotation(Select.class).value())
|
||||
.replace("#{outboundNo}", "?").replace("#{customerId}", "?")
|
||||
.replace("#{positionId}", "?").replace("#{skuCode}", "?");
|
||||
try (var statement = connection.prepareStatement(sql)) {
|
||||
statement.setString(1, outboundNo); statement.setString(2, customerId);
|
||||
statement.setLong(3, positionId); statement.setString(4, sku);
|
||||
try (var result = statement.executeQuery()) { result.next(); return result.getLong(1); }
|
||||
}
|
||||
}
|
||||
|
||||
private void scan(Connection connection) throws Exception {
|
||||
execute(connection, "INSERT INTO ll_inventory_ledger VALUES (51,'100',41,'WH-1','SKU-1','SHIP',-8,'DS-1','DS-1','DISPATCH:DS-1:31:pick-1:SHIP')");
|
||||
}
|
||||
|
||||
private void transfer(Connection connection) throws Exception {
|
||||
execute(connection, "INSERT INTO ll_outbound_order VALUES (61,'100','OB-1','WH-1','OUTBOUNDED','DISPATCH_DELIVERY','DS-1',1)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesOriginalScanFactsForBothTransferOrdersWithoutChangingTheLedger() throws Exception {
|
||||
for (boolean scanFirst : new boolean[]{true, false}) {
|
||||
try (Connection connection = database()) {
|
||||
if (scanFirst) { scan(connection); transfer(connection); }
|
||||
else { transfer(connection); scan(connection); }
|
||||
assertEquals(8, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
assertEquals(8, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
try (var statement = connection.createStatement(); var rows = statement.executeQuery("SELECT outbound_order_no, delta_packages FROM ll_inventory_ledger")) {
|
||||
rows.next(); assertEquals("DS-1", rows.getString(1)); assertEquals(-8, rows.getLong(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void requiresExactCustomerWarehousePositionSkuAndPickCommandIdentity() throws Exception {
|
||||
try (Connection connection = database()) {
|
||||
scan(connection); transfer(connection);
|
||||
assertEquals(0, shipped(connection, "200", 41, "OB-1", "SKU-1"));
|
||||
assertEquals(0, shipped(connection, "100", 42, "OB-1", "SKU-1"));
|
||||
assertEquals(0, shipped(connection, "100", 41, "OB-1", "SKU-2"));
|
||||
assertEquals(0, shipped(connection, "100", 41, "OB-2", "SKU-1"));
|
||||
execute(connection, "UPDATE ll_dispatch_pda_pick SET idempotency_key='different-command'");
|
||||
assertEquals(0, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
execute(connection, "UPDATE ll_dispatch_pda_pick SET idempotency_key='pick-1', packages=9");
|
||||
assertEquals(0, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
execute(connection, "UPDATE ll_dispatch_pda_pick SET packages=8");
|
||||
execute(connection, "UPDATE ll_dispatch_pda_task SET customer_id='200'");
|
||||
assertEquals(0, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
execute(connection, "UPDATE ll_dispatch_pda_task SET customer_id='100',warehouse_id='WH-2'");
|
||||
assertEquals(0, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
execute(connection, "UPDATE ll_dispatch_pda_task SET warehouse_id='WH-1',dispatch_order_id=2");
|
||||
assertEquals(0, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
execute(connection, "UPDATE ll_dispatch_pda_task SET dispatch_order_id=1");
|
||||
execute(connection, "UPDATE ll_outbound_order SET status='WAIT_OUTBOUND'");
|
||||
assertEquals(0, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
execute(connection, "UPDATE ll_outbound_order SET status='OUTBOUNDED'");
|
||||
execute(connection, "UPDATE ll_outbound_order SET overseas_warehouse_id='WH-2'");
|
||||
assertEquals(0, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void independentOutboundUsesItsOwnNumberAndDoesNotAcceptADispatchAlias() throws Exception {
|
||||
try (Connection connection = database()) {
|
||||
scan(connection);
|
||||
execute(connection, "INSERT INTO ll_outbound_order VALUES (61,'100','OB-1','WH-1','OUTBOUNDED','WAREHOUSE_TRANSFER','DS-1',1)");
|
||||
assertEquals(0, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
execute(connection, "INSERT INTO ll_inventory_ledger VALUES (52,'100',41,'WH-1','SKU-1','SHIP',-3,'TRANSFER-1','OB-1','transfer-ship-1')");
|
||||
assertEquals(3, shipped(connection, "100", 41, "OB-1", "SKU-1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -432,7 +432,9 @@ class InventoryCommandServiceTest {
|
||||
String shippedSql = String.join(" ", InventoryCommandMapper.class.getMethod("shippedPackages",
|
||||
String.class, Long.class, String.class, String.class).getAnnotation(Select.class).value());
|
||||
assertTrue(shippedSql.contains("position_id=#{positionId}"));
|
||||
assertTrue(shippedSql.contains("outbound_order_no=#{outboundNo}"));
|
||||
assertTrue(shippedSql.contains("o.outbound_no=#{outboundNo}"));
|
||||
assertTrue(shippedSql.contains("p.inventory_position_id=l.position_id"));
|
||||
assertTrue(shippedSql.contains("p.idempotency_key,':SHIP'"));
|
||||
assertTrue(shippedSql.contains("business_type='SHIP'"));
|
||||
String restoredSql = String.join(" ", InventoryCommandMapper.class.getMethod("restoredPackages",
|
||||
String.class, String.class, String.class).getAnnotation(Select.class).value());
|
||||
|
||||
Reference in New Issue
Block a user