fix: check released bookings only for active loading allocations
This commit is contained in:
+5
-1
@@ -4,7 +4,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
/** SQL-backed hard gate for every loading plan linked to an inbound. */
|
/** SQL-backed hard gate for loading plans with an active allocation to the inbound. */
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface LoadingCompletionGateMapper {
|
public interface LoadingCompletionGateMapper {
|
||||||
@Select("""
|
@Select("""
|
||||||
@@ -16,6 +16,10 @@ public interface LoadingCompletionGateMapper {
|
|||||||
FROM fl_preload_loading_plan_link l
|
FROM fl_preload_loading_plan_link l
|
||||||
JOIN fl_loading_plan p ON p.id=l.loading_plan_id
|
JOIN fl_loading_plan p ON p.id=l.loading_plan_id
|
||||||
WHERE l.tenant_id=#{tenantId} AND l.inbound_id=#{inboundId}
|
WHERE l.tenant_id=#{tenantId} AND l.inbound_id=#{inboundId}
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1 FROM fl_loading_plan_item i
|
||||||
|
WHERE i.loading_plan_id=l.loading_plan_id AND i.account_id=l.tenant_id
|
||||||
|
AND i.inbound_id=l.inbound_id AND i.deleted=0 AND i.package_count>0)
|
||||||
""")
|
""")
|
||||||
GateSnapshot snapshot(@Param("tenantId") long tenantId, @Param("inboundId") long inboundId);
|
GateSnapshot snapshot(@Param("tenantId") long tenantId, @Param("inboundId") long inboundId);
|
||||||
|
|
||||||
|
|||||||
+3
@@ -19,6 +19,9 @@ class LoadingCompletionGateSqlContractTest {
|
|||||||
.contains("b.status='RELEASED'")
|
.contains("b.status='RELEASED'")
|
||||||
.doesNotContain("fl_truck_appointment", "truckReady", "t.status='COMPLETED'")
|
.doesNotContain("fl_truck_appointment", "truckReady", "t.status='COMPLETED'")
|
||||||
.contains("l.tenant_id=#{tenantId} AND l.inbound_id=#{inboundId}")
|
.contains("l.tenant_id=#{tenantId} AND l.inbound_id=#{inboundId}")
|
||||||
|
.contains("SELECT 1 FROM fl_loading_plan_item i")
|
||||||
|
.contains("i.loading_plan_id=l.loading_plan_id AND i.account_id=l.tenant_id")
|
||||||
|
.contains("i.inbound_id=l.inbound_id AND i.deleted=0 AND i.package_count>0")
|
||||||
.doesNotContain("fl_customs_case", "fl_customs_receipt", "customsReady")
|
.doesNotContain("fl_customs_case", "fl_customs_receipt", "customsReady")
|
||||||
.doesNotContain("<", ">");
|
.doesNotContain("<", ">");
|
||||||
}
|
}
|
||||||
|
|||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package com.baiyue.firstleg.loading.service;
|
||||||
|
|
||||||
|
import com.baiyue.firstleg.loading.mapper.LoadingCompletionGateMapper;
|
||||||
|
import com.baiyue.firstleg.loading.mapper.LoadingCompletionGateMapper.GateSnapshot;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class LoadingCompletionGateServiceTest {
|
||||||
|
@Mock LoadingCompletionGateMapper mapper;
|
||||||
|
@InjectMocks LoadingCompletionGateService service;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void acceptsAllActivelyAllocatedContainersWithReleasedBookings() {
|
||||||
|
when(mapper.snapshot(10L, 20L)).thenReturn(new GateSnapshot(2, 2));
|
||||||
|
service.requireReleasedBooking(10L, 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void blocksAnyActivelyAllocatedContainerWithoutReleasedBooking() {
|
||||||
|
when(mapper.snapshot(10L, 20L)).thenReturn(new GateSnapshot(2, 1));
|
||||||
|
assertThatThrownBy(() -> service.requireReleasedBooking(10L, 20L))
|
||||||
|
.hasMessageContaining("订舱尚未完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void noActiveAllocationDoesNotVacuouslyPass() {
|
||||||
|
when(mapper.snapshot(10L, 20L)).thenReturn(new GateSnapshot(0, 0));
|
||||||
|
assertThatThrownBy(() -> service.requireReleasedBooking(10L, 20L))
|
||||||
|
.hasMessageContaining("未找到有效柜次关联");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user