fix(firstleg): persist ocean container allocation

This commit is contained in:
2026-08-08 21:49:41 +08:00
parent da85e30f33
commit 789d97675b
4 changed files with 75 additions and 38 deletions
@@ -4,6 +4,10 @@ import com.baiyue.common.core.exception.BizException;
import com.baiyue.firstleg.oceanbooking.dto.OceanBookingDtos.ActionRequest;
import com.baiyue.firstleg.oceanbooking.dto.OceanBookingDtos.ChangeRequest;
import com.baiyue.firstleg.oceanbooking.dto.OceanBookingDtos.Detail;
import com.baiyue.firstleg.oceanbooking.dto.OceanBookingDtos.AllocationRequest;
import com.baiyue.firstleg.entity.ContainerBookingEntity;
import com.baiyue.firstleg.oceanbooking.entity.OceanBookingContainerAllocationEntity;
import com.baiyue.firstleg.oceanbooking.entity.OceanBookingContainerRequirementEntity;
import com.baiyue.firstleg.oceanbooking.entity.OceanBookingEntity;
import com.baiyue.firstleg.oceanbooking.entity.OceanBookingOperationEntity;
import com.baiyue.firstleg.oceanbooking.entity.OceanBookingStatusHistoryEntity;
@@ -107,6 +111,44 @@ class OceanBookingServiceTest {
verify(repository, never()).find(anyLong());
}
@Test
void allocatesContainerWithExplicitTimestampAndVersionGuard() {
when(repository.find(1L)).thenReturn(booking("CONFIRMED", 5), booking("CONFIRMED", 6));
OceanBookingContainerRequirementEntity requirement = new OceanBookingContainerRequirementEntity();
requirement.setId(11L); requirement.setOceanBookingId(1L); requirement.setContainerType("40HQ");
requirement.setQuantity(1);
ContainerBookingEntity container = new ContainerBookingEntity();
container.setId(12L); container.setContainerType("40HQ");
when(repository.requirement(1L, 11L)).thenReturn(requirement);
when(repository.containerBooking(12L)).thenReturn(container);
when(repository.touchForAllocation(1L, 5, 9L, "admin")).thenReturn(1);
Detail result = service.allocate(1L, 9L, "admin", "allocate-1",
new AllocationRequest(11L, 12L, 5));
ArgumentCaptor<OceanBookingContainerAllocationEntity> allocation =
ArgumentCaptor.forClass(OceanBookingContainerAllocationEntity.class);
verify(repository).insert(allocation.capture());
assertThat(allocation.getValue().getOceanBookingId()).isEqualTo(1L);
assertThat(allocation.getValue().getRequirementId()).isEqualTo(11L);
assertThat(allocation.getValue().getContainerBookingId()).isEqualTo(12L);
assertThat(allocation.getValue().getAllocatedAt()).isNotNull();
assertThat(result.oceanBooking().getVersion()).isEqualTo(6);
}
@Test
void rejectsAllocationAfterReleaseBeforeMutation() {
when(repository.find(1L)).thenReturn(booking("RELEASED", 5));
assertThatThrownBy(() -> service.allocate(1L, 9L, "admin", "allocate-released",
new AllocationRequest(11L, 12L, 5)))
.isInstanceOf(BizException.class)
.hasMessageContaining("当前订舱状态不可分配柜次");
verify(repository, never()).touchForAllocation(anyLong(), anyInt(), anyLong(), anyString());
verify(repository, never()).insert(any(OceanBookingContainerAllocationEntity.class));
}
private String hashForSubmit() throws Exception {
var method = OceanBookingService.class.getDeclaredMethod("hash", String.class, Long.class, Object.class);
method.setAccessible(true);