fix: reserve stable inbound code for draft label printing
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.baiyue.firstleg.client;
|
||||
|
||||
import com.baiyue.common.core.api.ApiResponse;
|
||||
import com.baiyue.firstleg.dto.OrderApprovedInboundCommand;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
@FeignClient(name = "order-service", contextId = "printableOrderInboundClient",
|
||||
url = "${baiyue.clients.order.url:}", path = "/internal/order/v1/cargoes")
|
||||
public interface PrintableOrderInboundClient {
|
||||
@PostMapping("/{tenantId}/{orderId}/printable-inbound-snapshot")
|
||||
ApiResponse<OrderApprovedInboundCommand> reserve(
|
||||
@RequestHeader("X-Internal-Service-Token") String token,
|
||||
@PathVariable long tenantId,
|
||||
@PathVariable long orderId);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.baiyue.common.core.api.ApiResponse;
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.firstleg.client.OrderCargoClient;
|
||||
import com.baiyue.firstleg.client.PrintableOrderInboundClient;
|
||||
import com.baiyue.firstleg.dto.InboundCartonLabels;
|
||||
import com.baiyue.firstleg.entity.InboundCartonLabelEntity;
|
||||
import com.baiyue.firstleg.entity.InboundOrderEntity;
|
||||
@@ -35,6 +36,7 @@ public class InboundCartonLabelService implements CartonLabelBindingResolver {
|
||||
|
||||
@Resource private InboundCartonLabelRepository repository;
|
||||
@Resource private OrderCargoClient orderCargoClient;
|
||||
@Resource private PrintableOrderInboundClient printableOrderInboundClient;
|
||||
@Resource private InboundOrderCreationService inboundOrderCreationService;
|
||||
@Value("${baiyue.security.internal-service-token}") private String internalToken;
|
||||
|
||||
@@ -101,7 +103,7 @@ public class InboundCartonLabelService implements CartonLabelBindingResolver {
|
||||
private InboundOrderEntity prepareMissingInbound(long tenantId, long orderId) {
|
||||
try {
|
||||
ApiResponse<com.baiyue.firstleg.dto.OrderApprovedInboundCommand> response =
|
||||
orderCargoClient.inboundSnapshot(internalToken, tenantId, orderId);
|
||||
printableOrderInboundClient.reserve(internalToken, tenantId, orderId);
|
||||
if (response == null || !response.successful() || response.data() == null) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "订单不存在或无法生成预入库单");
|
||||
}
|
||||
|
||||
+5
-2
@@ -3,6 +3,7 @@ package com.baiyue.firstleg.service;
|
||||
import com.baiyue.common.core.api.ApiResponse;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.firstleg.client.OrderCargoClient;
|
||||
import com.baiyue.firstleg.client.PrintableOrderInboundClient;
|
||||
import com.baiyue.firstleg.entity.InboundCartonLabelEntity;
|
||||
import com.baiyue.firstleg.entity.InboundOrderEntity;
|
||||
import com.baiyue.firstleg.repository.InboundCartonLabelRepository;
|
||||
@@ -28,6 +29,7 @@ import static org.mockito.Mockito.when;
|
||||
class InboundCartonLabelServiceTest {
|
||||
@Mock private InboundCartonLabelRepository repository;
|
||||
@Mock private OrderCargoClient orderCargoClient;
|
||||
@Mock private PrintableOrderInboundClient printableOrderInboundClient;
|
||||
@Mock private InboundOrderCreationService inboundOrderCreationService;
|
||||
private InboundCartonLabelService service;
|
||||
|
||||
@@ -36,6 +38,7 @@ class InboundCartonLabelServiceTest {
|
||||
service = new InboundCartonLabelService();
|
||||
ReflectionTestUtils.setField(service, "repository", repository);
|
||||
ReflectionTestUtils.setField(service, "orderCargoClient", orderCargoClient);
|
||||
ReflectionTestUtils.setField(service, "printableOrderInboundClient", printableOrderInboundClient);
|
||||
ReflectionTestUtils.setField(service, "inboundOrderCreationService", inboundOrderCreationService);
|
||||
ReflectionTestUtils.setField(service, "internalToken", "internal-token");
|
||||
}
|
||||
@@ -222,7 +225,7 @@ class InboundCartonLabelServiceTest {
|
||||
@Test
|
||||
void rejectsAnOrderWithoutAnOwnedPreparingInbound() {
|
||||
when(repository.findByOrder(10001L, 60001L)).thenReturn(null);
|
||||
when(orderCargoClient.inboundSnapshot("internal-token", 10001L, 60001L))
|
||||
when(printableOrderInboundClient.reserve("internal-token", 10001L, 60001L))
|
||||
.thenThrow(org.mockito.Mockito.mock(feign.FeignException.class));
|
||||
|
||||
assertThatThrownBy(() -> service.requireInboundIdByOrder(10001L, 60001L))
|
||||
@@ -239,7 +242,7 @@ class InboundCartonLabelServiceTest {
|
||||
null, null, null, 2);
|
||||
InboundOrderEntity repaired = inbound();
|
||||
when(repository.findByOrder(10001L, 60001L)).thenReturn(null, repaired);
|
||||
when(orderCargoClient.inboundSnapshot("internal-token", 10001L, 60001L))
|
||||
when(printableOrderInboundClient.reserve("internal-token", 10001L, 60001L))
|
||||
.thenReturn(ApiResponse.success(snapshot));
|
||||
|
||||
assertThat(service.requireInboundIdByOrder(10001L, 60001L)).isEqualTo(70001L);
|
||||
|
||||
Reference in New Issue
Block a user