Merge test fixes into dev dropship flow
This commit is contained in:
+5
-13
@@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -39,6 +38,9 @@ import java.util.Set;
|
||||
@Service
|
||||
public class WarehousePalletBatchService {
|
||||
private static final String BUSINESS_TYPE = "INBOUND_PLAN_AUTO";
|
||||
private static final BigDecimal AUTO_PALLET_CAPACITY_CBM = new BigDecimal("2.0000");
|
||||
private static final BigDecimal AUTO_PALLET_UNIT_PRICE_USD = new BigDecimal("5.00");
|
||||
private static final String AUTO_PALLET_REMARK = "自动生成";
|
||||
|
||||
@Resource private WarehousePalletBatchMapper batches;
|
||||
@Resource private WarehousePalletBatchItemMapper items;
|
||||
@@ -47,8 +49,6 @@ public class WarehousePalletBatchService {
|
||||
@Resource private WarehouseResourceLockRepository lockRecords;
|
||||
@Resource private WarehouseResourceRepository repository;
|
||||
@Resource private ObjectMapper objectMapper;
|
||||
@Value("${baiyue.pallet.auto-created-unit-price:1.00}")
|
||||
private BigDecimal autoCreatedPalletUnitPrice;
|
||||
|
||||
@Transactional
|
||||
public WarehousePalletBatchResponse ensureReserved(WarehousePalletBatchRequests.EnsureReserved request) {
|
||||
@@ -83,9 +83,8 @@ public class WarehousePalletBatchService {
|
||||
List<WarehousePalletBatchItemEntity> created = new ArrayList<>();
|
||||
for (WarehousePalletBatchRequests.Item requested : normalized.items()) {
|
||||
Long palletId = resources.createPallet(WarehouseResourceService.PUBLIC_RESOURCE_SCOPE,
|
||||
normalized.warehouseId(), new PalletRequests.SaveRequest(requested.palletCode(), requested.palletType(), null,
|
||||
requiredAutoCreatedPalletUnitPrice(), "IDLE", null,
|
||||
"Auto-created for inbound plan " + requested.inboundPlanNo(),
|
||||
normalized.warehouseId(), new PalletRequests.SaveRequest(requested.palletCode(), "WOOD",
|
||||
AUTO_PALLET_CAPACITY_CBM, AUTO_PALLET_UNIT_PRICE_USD, "IDLE", null, AUTO_PALLET_REMARK,
|
||||
requested.fbaWarehouseCode()));
|
||||
WarehousePalletEntity pallet = resources.pallet(WarehouseResourceService.PUBLIC_RESOURCE_SCOPE,
|
||||
normalized.warehouseId(), palletId);
|
||||
@@ -114,13 +113,6 @@ public class WarehousePalletBatchService {
|
||||
return response(batch, created, false);
|
||||
}
|
||||
|
||||
private BigDecimal requiredAutoCreatedPalletUnitPrice() {
|
||||
if (autoCreatedPalletUnitPrice == null || autoCreatedPalletUnitPrice.signum() <= 0) {
|
||||
throw new IllegalStateException("Auto-created pallet unit price must be greater than zero");
|
||||
}
|
||||
return autoCreatedPalletUnitPrice.setScale(2, java.math.RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public WarehousePalletBatchResponse confirm(WarehousePalletBatchRequests.Confirm request) {
|
||||
WarehousePalletBatchRequests.Confirm normalized = normalize(request);
|
||||
|
||||
+5
-6
@@ -26,7 +26,6 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@@ -63,7 +62,6 @@ class WarehousePalletBatchServiceTest {
|
||||
ReflectionTestUtils.setField(service, "lockRecords", lockRecords);
|
||||
ReflectionTestUtils.setField(service, "repository", repository);
|
||||
ReflectionTestUtils.setField(service, "objectMapper", new ObjectMapper());
|
||||
ReflectionTestUtils.setField(service, "autoCreatedPalletUnitPrice", new BigDecimal("1.00"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,11 +74,8 @@ class WarehousePalletBatchServiceTest {
|
||||
assertThat(response.status()).isEqualTo("RESERVED");
|
||||
assertThat(response.items()).extracting(item -> item.customerId()).containsExactly(CUSTOMER_A, CUSTOMER_B);
|
||||
ArgumentCaptor<Long> scope = ArgumentCaptor.forClass(Long.class);
|
||||
ArgumentCaptor<PalletRequests.SaveRequest> palletRequests = ArgumentCaptor.forClass(PalletRequests.SaveRequest.class);
|
||||
verify(resources, times(2)).createPallet(scope.capture(), anyLong(), palletRequests.capture());
|
||||
verify(resources, times(2)).createPallet(scope.capture(), anyLong(), any(PalletRequests.SaveRequest.class));
|
||||
assertThat(scope.getAllValues()).containsOnly(WarehouseResourceService.PUBLIC_RESOURCE_SCOPE);
|
||||
assertThat(palletRequests.getAllValues()).extracting(PalletRequests.SaveRequest::unitPrice)
|
||||
.containsOnly(new BigDecimal("1.00"));
|
||||
verify(batches, never()).lockByKey(WAREHOUSE, "container-1");
|
||||
ArgumentCaptor<WarehouseResourceLockRequests.ReserveRequest> reservations =
|
||||
ArgumentCaptor.forClass(WarehouseResourceLockRequests.ReserveRequest.class);
|
||||
@@ -110,6 +105,10 @@ class WarehousePalletBatchServiceTest {
|
||||
verify(resources).createPallet(org.mockito.ArgumentMatchers.eq(WarehouseResourceService.PUBLIC_RESOURCE_SCOPE),
|
||||
org.mockito.ArgumentMatchers.eq(WAREHOUSE), saves.capture());
|
||||
assertThat(saves.getValue().palletCode()).isNull();
|
||||
assertThat(saves.getValue().palletType()).isEqualTo("WOOD");
|
||||
assertThat(saves.getValue().capacityCbm()).isEqualByComparingTo("2.0000");
|
||||
assertThat(saves.getValue().unitPrice()).isEqualByComparingTo("5.00");
|
||||
assertThat(saves.getValue().remark()).isEqualTo("自动生成");
|
||||
assertThat(response.items()).extracting(value -> value.palletCode()).containsExactly("PAL-301");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user