优化
This commit is contained in:
+3
-35
@@ -9,30 +9,23 @@ import com.baiyue.warehouse.security.OverseasWarehousePermissions;
|
||||
import com.baiyue.warehouse.dto.PalletRequests;
|
||||
import com.baiyue.warehouse.entity.WarehousePalletEntity;
|
||||
import com.baiyue.warehouse.service.WarehouseResourceService;
|
||||
import com.baiyue.warehouse.service.DomesticWarehouseDirectory;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Exposes the domestic authoritative directory as read-only overseas resource options. */
|
||||
/** Cross-warehouse queries for overseas resources; warehouse masters belong to Warehouse. */
|
||||
@RestController
|
||||
@RequestMapping("/api/platform/v1/warehouse-admin")
|
||||
@RequestMapping("/api/platform/v1/overseas-warehouse-resources")
|
||||
@Tag(name = "Platform overseas warehouse directory")
|
||||
public class PlatformWarehouseDirectoryController {
|
||||
private final DomesticWarehouseDirectory directory;
|
||||
private final WarehouseResourceService resources;
|
||||
|
||||
public PlatformWarehouseDirectoryController(DomesticWarehouseDirectory directory,
|
||||
WarehouseResourceService resources) {
|
||||
this.directory = directory;
|
||||
public PlatformWarehouseDirectoryController(WarehouseResourceService resources) {
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
@@ -56,29 +49,6 @@ public class PlatformWarehouseDirectoryController {
|
||||
return ApiResponse.success(resources.publicPalletSummary(WarehouseResourceService.PUBLIC_RESOURCE_SCOPE, query));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('" + OverseasWarehousePermissions.WAREHOUSE_LIST + "')")
|
||||
@Operation(summary = "Page shared overseas receiving warehouses",
|
||||
description = "Required authority: " + OverseasWarehousePermissions.WAREHOUSE_LIST)
|
||||
public ApiResponse<PageResult<WarehouseOption>> warehouses(
|
||||
@AuthenticationPrincipal AuthenticatedUser user,
|
||||
@RequestParam(defaultValue = "1") long page,
|
||||
@RequestParam(defaultValue = "200") long size) {
|
||||
requirePlatform(user);
|
||||
if (page < 1 || size < 1 || size > 200) {
|
||||
throw new BizException(ResultCode.BAD_REQUEST, "分页参数无效");
|
||||
}
|
||||
List<WarehouseOption> all = directory.options().stream()
|
||||
.map(value -> new WarehouseOption(value.warehouseId(), 0L, value.warehouseCode(),
|
||||
value.warehouseName(), "OVERSEAS", value.status()))
|
||||
.toList();
|
||||
long from = Math.min((page - 1) * size, all.size());
|
||||
long to = Math.min(from + size, all.size());
|
||||
long pages = all.isEmpty() ? 0 : (all.size() + size - 1) / size;
|
||||
return ApiResponse.success(new PageResult<>(all.subList((int) from, (int) to),
|
||||
page, size, all.size(), pages));
|
||||
}
|
||||
|
||||
private static void requirePlatform(AuthenticatedUser user) {
|
||||
if (user == null || !"PLATFORM".equals(user.appCode())
|
||||
|| user.tenantId() == null || user.tenantId() != 0L) {
|
||||
@@ -86,6 +56,4 @@ public class PlatformWarehouseDirectoryController {
|
||||
}
|
||||
}
|
||||
|
||||
public record WarehouseOption(long id, long customerId, String warehouseCode,
|
||||
String warehouseName, String warehouseType, String status) { }
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Validated
|
||||
@RestController
|
||||
@RequestMapping("/api/platform/v1/warehouse-admin/{warehouseId}")
|
||||
@RequestMapping("/api/platform/v1/overseas-warehouse-resources/{warehouseId}")
|
||||
@Tag(name = "Platform overseas warehouse resources")
|
||||
public class PlatformWarehouseResourceController {
|
||||
@Resource private WarehouseResourceService service;
|
||||
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package com.baiyue.warehouse.controller;
|
||||
|
||||
import com.baiyue.common.core.api.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 仓库微服务可用性接口,向平台端暴露服务逻辑状态。
|
||||
*/
|
||||
@Tag(name = "Warehouse service status / 仓储服务状态", description = "Warehouse service availability API. / 仓储服务可用性接口。")
|
||||
@RestController
|
||||
@RequestMapping("/api/platform/v1/warehouses")
|
||||
public class WarehouseHealthController {
|
||||
@Operation(summary = "Get service status / 查询服务状态", description = "Returns the logical status of warehouse-overseas-service. / 返回 warehouse-overseas-service 的逻辑运行状态。")
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "Service is available / 服务可用")
|
||||
@GetMapping("/status")
|
||||
public ApiResponse<Map<String, String>> status() {
|
||||
return ApiResponse.success(Map.of("service", "warehouse-overseas-service", "status", "UP"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ baiyue:
|
||||
token: ${INTERNAL_SERVICE_TOKEN:phase1-local-internal-token-at-least-32-bytes}
|
||||
security:
|
||||
jwt-mode: jwks
|
||||
session-mode: gateway
|
||||
session-mode: redis
|
||||
issuer: ${JWT_ISSUER:auth-service}
|
||||
audience: ${JWT_AUDIENCE:lastleg-api}
|
||||
jwk-set-uri: ${JWT_JWK_SET_URI:http://127.0.0.1:9100/api/auth/.well-known/jwks.json}
|
||||
jwk-set-uri: ${JWT_JWKS_URI:http://auth-service:9100/api/auth/.well-known/jwks.json}
|
||||
|
||||
@@ -3,7 +3,7 @@ info:
|
||||
title: Overseas pallet label
|
||||
version: 1.0.0
|
||||
paths:
|
||||
/api/platform/v1/warehouse-admin/{warehouseId}/pallets/{id}/label:
|
||||
/api/platform/v1/overseas-warehouse-resources/{warehouseId}/pallets/{id}/label:
|
||||
get:
|
||||
operationId: printOverseasPalletLabel
|
||||
summary: 下载指定托盘的一页标签 PDF
|
||||
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
package com.baiyue.warehouse.controller;
|
||||
|
||||
import com.baiyue.common.security.AuthenticatedUser;
|
||||
import com.baiyue.warehouse.dto.SharedWarehouseReference;
|
||||
import com.baiyue.warehouse.service.DomesticWarehouseDirectory;
|
||||
import com.baiyue.warehouse.service.WarehouseResourceService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class PlatformWarehouseDirectoryControllerTest {
|
||||
@Test
|
||||
void pagesPublicSharedWarehouseOptions() {
|
||||
DomesticWarehouseDirectory directory = mock(DomesticWarehouseDirectory.class);
|
||||
when(directory.options()).thenReturn(List.of(
|
||||
new SharedWarehouseReference(21L, "US-LAX", "洛杉矶仓", "ACTIVE")));
|
||||
var controller = new PlatformWarehouseDirectoryController(directory, mock(WarehouseResourceService.class));
|
||||
var user = new AuthenticatedUser(1L, 0L, 0L, 2L,
|
||||
"tester", "PLATFORM", "PLATFORM", Set.of());
|
||||
|
||||
var page = controller.warehouses(user, 1, 200).data();
|
||||
|
||||
assertEquals(1, page.total());
|
||||
assertEquals(21L, page.records().get(0).id());
|
||||
assertEquals(0L, page.records().get(0).customerId());
|
||||
assertEquals("OVERSEAS", page.records().get(0).warehouseType());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -34,10 +34,10 @@ class WarehouseResourcePermissionContractTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void warehouseDirectoryUsesCanonicalListAuthority() throws Exception {
|
||||
void crossWarehousePalletDirectoryUsesCanonicalListAuthority() throws Exception {
|
||||
assertPermission(PlatformWarehouseDirectoryController.class.getDeclaredMethod(
|
||||
"warehouses", com.baiyue.common.security.AuthenticatedUser.class, long.class, long.class),
|
||||
PREFIX + "warehouse:list");
|
||||
"pallets", com.baiyue.common.security.AuthenticatedUser.class, com.baiyue.warehouse.dto.PalletRequests.QueryRequest.class),
|
||||
PREFIX + "pallet:list");
|
||||
}
|
||||
|
||||
private static void assertPermission(Method method, String authority) {
|
||||
|
||||
Reference in New Issue
Block a user