二期内容提交:客户端订单列表
This commit is contained in:
+19
@@ -4,6 +4,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.dto.OrderApprovedInboundCommand;
|
||||
import com.baiyue.firstleg.dto.InboundOrderReference;
|
||||
import com.baiyue.firstleg.service.InboundOrderCreationService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -11,6 +12,9 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
@@ -41,4 +45,19 @@ public class InternalInboundOrderController {
|
||||
}
|
||||
return ApiResponse.success(service.createFromApprovedOrder(command));
|
||||
}
|
||||
|
||||
@PostMapping("/order-references")
|
||||
public ApiResponse<List<InboundOrderReference.Item>> references(
|
||||
@RequestHeader(value = "X-Internal-Service-Token", required = false) String token,
|
||||
@Valid @RequestBody InboundOrderReference.BatchRequest request) {
|
||||
requireToken(token);
|
||||
return ApiResponse.success(service.findReferences(
|
||||
request.tenantId(), request.orderIds().stream().distinct().toList()));
|
||||
}
|
||||
|
||||
private void requireToken(String token) {
|
||||
if (token == null || !MessageDigest.isEqual(expectedToken, token.getBytes(StandardCharsets.UTF_8))) {
|
||||
throw new BizException(ResultCode.FORBIDDEN, "内部服务凭证无效");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baiyue.firstleg.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 订单服务批量读取头程入库引用的内部契约。 */
|
||||
public final class InboundOrderReference {
|
||||
private InboundOrderReference() {
|
||||
}
|
||||
|
||||
public record BatchRequest(@Positive long tenantId,
|
||||
@NotEmpty @Size(max = 200) List<@Positive Long> orderIds) {
|
||||
}
|
||||
|
||||
public record Item(Long orderId, Long inboundId, String inboundCode, String processStatus) {
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.baiyue.firstleg.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baiyue.firstleg.dto.OrderApprovedInboundCommand;
|
||||
import com.baiyue.firstleg.dto.InboundOrderReference;
|
||||
import com.baiyue.firstleg.entity.InboundOrderEntity;
|
||||
import com.baiyue.firstleg.entity.InboundStatusHistoryEntity;
|
||||
import com.baiyue.firstleg.mapper.InboundOrderMapper;
|
||||
@@ -10,6 +11,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/** 将已审核的订单快照幂等转换为待测量入库单。 */
|
||||
@Service
|
||||
@@ -86,4 +88,16 @@ public class InboundOrderCreationService {
|
||||
histories.insert(history);
|
||||
return inbound.getId();
|
||||
}
|
||||
|
||||
public List<InboundOrderReference.Item> findReferences(long tenantId, List<Long> orderIds) {
|
||||
if (orderIds.isEmpty()) return List.of();
|
||||
return orders.selectList(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<InboundOrderEntity>()
|
||||
.eq(InboundOrderEntity::getTenantId, tenantId)
|
||||
.in(InboundOrderEntity::getOrderId, orderIds)
|
||||
.orderByDesc(InboundOrderEntity::getCreatedAt))
|
||||
.stream()
|
||||
.map(inbound -> new InboundOrderReference.Item(
|
||||
inbound.getOrderId(), inbound.getId(), inbound.getInboundCode(), inbound.getProcessStatus()))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.baiyue.firstleg.controller;
|
||||
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.firstleg.dto.InboundOrderReference;
|
||||
import com.baiyue.firstleg.service.InboundOrderCreationService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class InternalInboundOrderReferenceControllerTest {
|
||||
private final InboundOrderCreationService service = mock(InboundOrderCreationService.class);
|
||||
private final InternalInboundOrderController controller =
|
||||
new InternalInboundOrderController(service, "internal-token");
|
||||
|
||||
@Test
|
||||
void 使用内部令牌按租户批量查询订单入仓编码() {
|
||||
var request = new InboundOrderReference.BatchRequest(10001L, List.of(77L, 77L, 78L));
|
||||
when(service.findReferences(10001L, List.of(77L, 78L))).thenReturn(List.of(
|
||||
new InboundOrderReference.Item(77L, 88L, "RK-77", "WAIT_MEASURE")));
|
||||
|
||||
var response = controller.references("internal-token", request);
|
||||
|
||||
assertThat(response.data()).extracting(InboundOrderReference.Item::inboundCode)
|
||||
.containsExactly("RK-77");
|
||||
verify(service).findReferences(10001L, List.of(77L, 78L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void 错误内部令牌不能查询任意租户的入仓编码() {
|
||||
var request = new InboundOrderReference.BatchRequest(10001L, List.of(77L));
|
||||
assertThatThrownBy(() -> controller.references("bad-token", request))
|
||||
.isInstanceOf(BizException.class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user