优化
This commit is contained in:
+5
-6
@@ -89,8 +89,8 @@ public class PlatformWarehouseController {
|
||||
}
|
||||
|
||||
@Operation(
|
||||
summary = "List tenant warehouses / 查询租户仓库",
|
||||
description = "Returns a tenant-scoped warehouse page with optional country, capability and status filters. / 按租户分页查询仓库,可按国家、能力和状态筛选。"
|
||||
summary = "List platform warehouses / 查询平台仓库",
|
||||
description = "Returns all platform warehouses by default; customer ID is an optional compatibility filter. / 默认分页查询平台全部仓库,客户 ID 仅作为兼容筛选条件。"
|
||||
)
|
||||
@ApiResponses({
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "Query succeeded / 查询成功"),
|
||||
@@ -101,11 +101,11 @@ public class PlatformWarehouseController {
|
||||
@PreAuthorize("hasAuthority('platform:warehouse:list')")
|
||||
public ApiResponse<PageResult<WarehouseEntity>> page(
|
||||
@AuthenticationPrincipal AuthenticatedUser user,
|
||||
@Parameter(description = "Target tenant ID / 目标租户 ID", example = "10001", required = true)
|
||||
@RequestParam @NotNull Long tenantId,
|
||||
@Parameter(description = "Optional customer ID / 可选客户 ID", example = "10001")
|
||||
@RequestParam(required = false) Long tenantId,
|
||||
@Valid WarehouseRequests.QueryRequest request) {
|
||||
requirePlatform(user);
|
||||
requireTenant(tenantId);
|
||||
if (tenantId != null) requireTenant(tenantId);
|
||||
return ApiResponse.success(service.page(tenantId, request));
|
||||
}
|
||||
|
||||
@@ -169,4 +169,3 @@ public class PlatformWarehouseController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,9 +56,9 @@ public class WarehouseRepository {
|
||||
.ne(excludedId != null, WarehouseEntity::getId, excludedId)) > 0;
|
||||
}
|
||||
|
||||
public PageResult<WarehouseEntity> page(long tenantId, WarehouseRequests.QueryRequest query) {
|
||||
public PageResult<WarehouseEntity> page(Long tenantId, WarehouseRequests.QueryRequest query) {
|
||||
LambdaQueryWrapper<WarehouseEntity> wrapper = new LambdaQueryWrapper<WarehouseEntity>()
|
||||
.eq(WarehouseEntity::getTenantId, tenantId)
|
||||
.eq(tenantId != null, WarehouseEntity::getTenantId, tenantId)
|
||||
.eq(StringUtils.hasText(query.status()), WarehouseEntity::getStatus, query.status())
|
||||
.eq(StringUtils.hasText(query.warehouseType()), WarehouseEntity::getWarehouseType, query.warehouseType())
|
||||
.eq(StringUtils.hasText(query.countryCode()), WarehouseEntity::getCountryCode, query.countryCode())
|
||||
@@ -67,7 +67,7 @@ public class WarehouseRepository {
|
||||
if (StringUtils.hasText(query.capabilityCode())) {
|
||||
List<Long> ids = capabilities.selectList(new LambdaQueryWrapper<ServiceCapabilityEntity>()
|
||||
.select(ServiceCapabilityEntity::getWarehouseId)
|
||||
.eq(ServiceCapabilityEntity::getTenantId, tenantId)
|
||||
.eq(tenantId != null, ServiceCapabilityEntity::getTenantId, tenantId)
|
||||
.eq(ServiceCapabilityEntity::getCapabilityCode, query.capabilityCode())
|
||||
.eq(ServiceCapabilityEntity::getEnabled, true))
|
||||
.stream()
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ public class WarehouseApplicationService {
|
||||
insertChildren(tenantId, id, request.address(), request.capabilities());
|
||||
}
|
||||
|
||||
public PageResult<WarehouseEntity> page(long tenantId, WarehouseRequests.QueryRequest query) {
|
||||
public PageResult<WarehouseEntity> page(Long tenantId, WarehouseRequests.QueryRequest query) {
|
||||
return repository.page(tenantId, query);
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -45,6 +46,13 @@ class PlatformMasterDataControllerContractTest {
|
||||
assertWarehouseMethod("create", PostMapping.class, "platform:warehouse:create");
|
||||
assertWarehouseMethod("update", PutMapping.class, "platform:warehouse:edit");
|
||||
assertWarehouseMethod("status", PatchMapping.class, "platform:warehouse:status");
|
||||
|
||||
Method page = java.util.Arrays.stream(PlatformWarehouseController.class.getDeclaredMethods())
|
||||
.filter(candidate -> candidate.getName().equals("page"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
assertThat(page.getParameterTypes()[1]).isEqualTo(Long.class);
|
||||
assertThat(page.getParameters()[1].getAnnotation(RequestParam.class).required()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+10
@@ -4,6 +4,8 @@ import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.warehouse.entity.WarehouseEntity;
|
||||
import com.baiyue.warehouse.repository.WarehouseRepository;
|
||||
import com.baiyue.warehouse.dto.WarehouseRequests;
|
||||
import com.baiyue.common.core.api.PageResult;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
@@ -36,4 +38,12 @@ class WarehouseApplicationServiceTest {
|
||||
assertThatThrownBy(() -> service.activeDetail(10001,1)).isInstanceOf(BizException.class)
|
||||
.extracting(exception -> ((BizException) exception).getResultCode()).isEqualTo(ResultCode.CONFLICT);
|
||||
}
|
||||
@Test
|
||||
void pagesAllPlatformWarehousesWithoutCustomerFilter() {
|
||||
WarehouseRequests.QueryRequest query = new WarehouseRequests.QueryRequest(1, 200, null, null, null, null);
|
||||
when(repository.page(null, query)).thenReturn(new PageResult<>(java.util.List.of(), 1, 200, 0, 0));
|
||||
|
||||
assertThat(service.page(null, query).records()).isEmpty();
|
||||
verify(repository).page(null, query);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user