提交
This commit is contained in:
+3
-6
@@ -90,8 +90,8 @@ public class PlatformWarehouseController {
|
||||
}
|
||||
|
||||
@Operation(
|
||||
summary = "List tenant warehouses / 查询租户仓库",
|
||||
description = "Required authority: " + OverseasWarehousePermissions.WAREHOUSE_LIST + ". Returns a customer-scoped warehouse page with optional filters."
|
||||
summary = "List warehouses / 查询仓库",
|
||||
description = "Required authority: " + OverseasWarehousePermissions.WAREHOUSE_LIST + ". Returns all warehouses with optional filters."
|
||||
)
|
||||
@ApiResponses({
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "Query succeeded / 查询成功"),
|
||||
@@ -102,12 +102,9 @@ public class PlatformWarehouseController {
|
||||
@PreAuthorize("hasAuthority('" + OverseasWarehousePermissions.WAREHOUSE_LIST + "')")
|
||||
public ApiResponse<PageResult<WarehouseEntity>> page(
|
||||
@AuthenticationPrincipal AuthenticatedUser user,
|
||||
@Parameter(description = "Target tenant ID / 目标租户 ID", example = "10001", required = true)
|
||||
@RequestParam @NotNull Long customerId,
|
||||
@Valid WarehouseRequests.QueryRequest request) {
|
||||
requirePlatform(user);
|
||||
requireTenant(customerId);
|
||||
return ApiResponse.success(service.page(customerId, request));
|
||||
return ApiResponse.success(service.pageAll(request));
|
||||
}
|
||||
|
||||
@Operation(
|
||||
|
||||
+23
@@ -85,6 +85,29 @@ public class WarehouseRepository {
|
||||
return PageResult.from(warehouses.selectPage(new Page<>(query.page(), query.size()), wrapper));
|
||||
}
|
||||
|
||||
public PageResult<WarehouseEntity> pageAll(WarehouseRequests.QueryRequest query) {
|
||||
LambdaQueryWrapper<WarehouseEntity> wrapper = new LambdaQueryWrapper<WarehouseEntity>()
|
||||
.eq(StringUtils.hasText(query.status()), WarehouseEntity::getStatus, query.status())
|
||||
.eq(StringUtils.hasText(query.countryCode()), WarehouseEntity::getCountryCode, query.countryCode())
|
||||
.orderByDesc(WarehouseEntity::getCreatedAt);
|
||||
|
||||
if (StringUtils.hasText(query.capabilityCode())) {
|
||||
List<Long> ids = capabilities.selectList(new LambdaQueryWrapper<ServiceCapabilityEntity>()
|
||||
.select(ServiceCapabilityEntity::getWarehouseId)
|
||||
.eq(ServiceCapabilityEntity::getCapabilityCode, query.capabilityCode())
|
||||
.eq(ServiceCapabilityEntity::getEnabled, true))
|
||||
.stream()
|
||||
.map(ServiceCapabilityEntity::getWarehouseId)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (ids.isEmpty()) {
|
||||
return new PageResult<>(List.of(), query.page(), query.size(), 0, 0);
|
||||
}
|
||||
wrapper.in(WarehouseEntity::getId, ids);
|
||||
}
|
||||
return PageResult.from(warehouses.selectPage(new Page<>(query.page(), query.size()), wrapper));
|
||||
}
|
||||
|
||||
public List<WarehouseAddressEntity> findAddresses(long customerId, long warehouseId) {
|
||||
return addresses.selectList(new LambdaQueryWrapper<WarehouseAddressEntity>()
|
||||
.eq(WarehouseAddressEntity::getCustomerId, customerId)
|
||||
|
||||
+4
@@ -87,6 +87,10 @@ public class WarehouseApplicationService {
|
||||
return repository.page(customerId, query);
|
||||
}
|
||||
|
||||
public PageResult<WarehouseEntity> pageAll(WarehouseRequests.QueryRequest query) {
|
||||
return repository.pageAll(query);
|
||||
}
|
||||
|
||||
public WarehouseDetailResponse detail(long customerId, long id) {
|
||||
WarehouseEntity warehouse = owned(customerId, id);
|
||||
List<WarehouseAddressEntity> addresses = repository.findAddresses(customerId, id);
|
||||
|
||||
@@ -18,17 +18,17 @@ spring:
|
||||
- optional:nacos:${spring.application.name}.yml?group=BAIYUE&refreshEnabled=true
|
||||
cloud:
|
||||
nacos:
|
||||
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8848}
|
||||
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8858}
|
||||
username: ${NACOS_USERNAME:nacos}
|
||||
password: ${NACOS_PASSWORD:nacos}
|
||||
discovery:
|
||||
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8848}
|
||||
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8858}
|
||||
enabled: ${NACOS_DISCOVERY_ENABLED:true}
|
||||
register-enabled: ${NACOS_REGISTER_ENABLED:true}
|
||||
group: ${NACOS_GROUP:BAIYUE}
|
||||
namespace: ${NACOS_NAMESPACE:public}
|
||||
config:
|
||||
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8848}
|
||||
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8858}
|
||||
namespace: ${NACOS_NAMESPACE:public}
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.baiyue.warehouse.controller;
|
||||
|
||||
import com.baiyue.common.core.api.PageResult;
|
||||
import com.baiyue.common.security.AuthenticatedUser;
|
||||
import com.baiyue.warehouse.dto.WarehouseRequests;
|
||||
import com.baiyue.warehouse.service.WarehouseApplicationService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class PlatformWarehouseControllerTest {
|
||||
@Test
|
||||
void platformPageQueriesAllWarehousesWithoutCustomerId() {
|
||||
WarehouseApplicationService service = mock(WarehouseApplicationService.class);
|
||||
PlatformWarehouseController controller = new PlatformWarehouseController();
|
||||
ReflectionTestUtils.setField(controller, "service", service);
|
||||
WarehouseRequests.QueryRequest query = new WarehouseRequests.QueryRequest(1, 20, "ACTIVE", null, null);
|
||||
when(service.pageAll(query)).thenReturn(new PageResult<>(List.of(), 1, 20, 0, 0));
|
||||
|
||||
controller.page(platform(), query);
|
||||
|
||||
verify(service).pageAll(query);
|
||||
}
|
||||
|
||||
private static AuthenticatedUser platform() {
|
||||
return new AuthenticatedUser(1L, 0L, 0L, 1L, "operator", "PLATFORM", "WEB", Set.of());
|
||||
}
|
||||
}
|
||||
+11
@@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class WarehouseApplicationServiceTest {
|
||||
@@ -48,6 +49,16 @@ class WarehouseApplicationServiceTest {
|
||||
assertThat(location.getValue().getStatus()).isEqualTo("ACTIVE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void platformWarehousePageUsesGlobalRepositoryQuery() {
|
||||
WarehouseRequests.QueryRequest query = new WarehouseRequests.QueryRequest(1, 20, "ACTIVE", "US", null);
|
||||
when(repository.pageAll(query)).thenReturn(new com.baiyue.common.core.api.PageResult<>(List.of(), 1, 20, 0, 0));
|
||||
|
||||
service.pageAll(query);
|
||||
|
||||
verify(repository).pageAll(query);
|
||||
}
|
||||
|
||||
private static WarehouseRequests.SaveRequest request() {
|
||||
WarehouseRequests.AddressRequest address = new WarehouseRequests.AddressRequest(
|
||||
"WAREHOUSE", "US", "CA", "Los Angeles", null, "90001",
|
||||
|
||||
Reference in New Issue
Block a user