This commit is contained in:
2026-08-04 21:01:53 +08:00
parent 7e544780b4
commit 9b7b08665e
21 changed files with 268 additions and 32 deletions
@@ -35,7 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/** 平台库位管理接口;当前数据模型中企业边界即目标 tenantId。 */
/** 平台库位管理接口;分页支持跨企业查询,写操作仍以目标 tenantId 隔离。 */
@Validated
@RestController
@RequestMapping("/api/platform/v1/locations")
@@ -49,14 +49,16 @@ public class PlatformLocationController {
@GetMapping
@PreAuthorize("hasAuthority('platform:location:list')")
@Operation(summary = "分页查询库位", description = "按目标企业租户、仓库、库区、编码、类型和状态分页查询")
@Operation(summary = "分页查询库位",
description = "默认分页查询全部企业库位;可按目标企业租户、仓库、库区、编码、类型和状态筛选")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "需要 platform:location:list 权限,且仓库须属于目标企业租户")
})
public ApiResponse<PageResult<LocationEntity>> page(
@AuthenticationPrincipal AuthenticatedUser user,
@RequestParam @Min(1) long tenantId,
@Parameter(description = "可选目标企业租户ID;不传时查询全部企业")
@RequestParam(required = false) @Min(1) Long tenantId,
@Valid @ParameterObject PageQuery query) {
requirePlatform(user);
return ApiResponse.success(service.page(tenantId, query));
@@ -8,6 +8,7 @@ import com.baiyue.common.security.AuthenticatedUser;
import com.baiyue.warehouse.dto.PalletRequests;
import com.baiyue.warehouse.service.PalletApplicationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@@ -40,10 +41,11 @@ public class PlatformPalletController {
@GetMapping
@PreAuthorize("hasAuthority('platform:pallet:list')")
@Operation(summary = "分页查询托盘")
@Operation(summary = "分页查询托盘", description = "默认查询全部企业;可按企业、仓库、托盘编码和类型筛选")
@ApiResponses(@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "需要 platform:pallet:list 权限"))
public ApiResponse<PageResult<PalletRequests.View>> page(@AuthenticationPrincipal AuthenticatedUser user,
@RequestParam @Min(1) long tenantId,
@Parameter(description = "目标企业租户ID;不传时查询全部企业")
@RequestParam(required = false) @Min(1) Long tenantId,
@Valid @ParameterObject PalletRequests.PageQuery query) {
requirePlatform(user);
return ApiResponse.success(service.page(tenantId, query));
@@ -23,9 +23,9 @@ public final class LocationDtos {
@Schema(name = "LocationPageQuery", description = "库位分页查询条件")
public record PageQuery(
@Min(1) long page,
@Min(1) @Max(200) long size,
@NotNull @Min(1) Long warehouseId,
@Min(1) @Schema(description = "页码", defaultValue = "1") long page,
@Min(1) @Max(200) @Schema(description = "每页条数", defaultValue = "20") long size,
@Min(1) @Schema(description = "可选仓库ID;不传时不限制仓库") Long warehouseId,
@Size(max = 50) String zoneCode,
@Size(max = 50) String locationCode,
@Pattern(regexp = "^(SHELF|PALLET|FLOOR|FLOW_RACK)$") String locationType,
@@ -41,7 +41,7 @@ public final class PalletRequests {
public record PageQuery(
@Min(1) @Schema(description = "页码", defaultValue = "1") long page,
@Min(1) @Max(200) @Schema(description = "每页条数", defaultValue = "20") long size,
@Min(1) @Schema(description = "仓库ID") Long warehouseId,
@Min(1) @Schema(description = "仓库ID;不传时不限制仓库") Long warehouseId,
@Size(max = 50) @Schema(description = "托盘编码,支持模糊查询") String palletCode,
@Size(max = 32) @Schema(description = "托盘类型") String palletType
) {
@@ -20,9 +20,13 @@ public interface LocationMapper extends BaseMapper<LocationEntity> {
FROM wh_location l
JOIN wh_warehouse w
ON w.id = l.warehouse_id AND w.tenant_id = l.tenant_id AND w.deleted = 0
WHERE l.tenant_id = #{tenantId}
WHERE l.deleted = 0
<if test="tenantId != null">
AND l.tenant_id = #{tenantId}
</if>
<if test="warehouseId != null">
AND l.warehouse_id = #{warehouseId}
AND l.deleted = 0
</if>
<if test="zoneCode != null and zoneCode != ''">
AND l.zone_code = #{zoneCode}
</if>
@@ -39,8 +43,8 @@ public interface LocationMapper extends BaseMapper<LocationEntity> {
</script>
""")
Page<LocationEntity> selectLocationPage(Page<LocationEntity> page,
@Param("tenantId") long tenantId,
@Param("warehouseId") long warehouseId,
@Param("tenantId") Long tenantId,
@Param("warehouseId") Long warehouseId,
@Param("zoneCode") String zoneCode,
@Param("locationCode") String locationCode,
@Param("locationType") String locationType,
@@ -18,7 +18,7 @@ import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
/** 强制使用租户、仓库联合条件的库位持久化边界。 */
/** 库位持久化边界;平台分页条件可选,资源读写继续强制租户、仓库联合条件。 */
@Repository
public class LocationRepository {
private final LocationMapper locations;
@@ -47,7 +47,7 @@ public class LocationRepository {
.eq(LocationEntity::getId, id));
}
public PageResult<LocationEntity> page(long tenantId, PageQuery query) {
public PageResult<LocationEntity> page(Long tenantId, PageQuery query) {
Page<LocationEntity> result = locations.selectLocationPage(new Page<>(query.page(), query.size()),
tenantId, query.warehouseId(), query.zoneCode(), query.locationCode(), query.locationType(), query.status());
return PageResult.from(result);
@@ -13,7 +13,7 @@ import org.springframework.util.StringUtils;
import java.util.Collection;
import java.util.List;
/** 托盘持久化仓储,所有业务查询均显式包含租户和仓库边界。 */
/** 托盘持久化仓储;平台分页支持跨租户筛选,资源操作始终包含租户和仓库边界。 */
@Repository
public class PalletRepository {
private final PalletMapper mapper;
@@ -22,9 +22,9 @@ public class PalletRepository {
this.mapper = mapper;
}
public PageResult<PalletEntity> page(long tenantId, PalletRequests.PageQuery query) {
public PageResult<PalletEntity> page(Long tenantId, PalletRequests.PageQuery query) {
LambdaQueryWrapper<PalletEntity> wrapper = new LambdaQueryWrapper<PalletEntity>()
.eq(PalletEntity::getTenantId, tenantId)
.eq(tenantId != null, PalletEntity::getTenantId, tenantId)
.eq(query.warehouseId() != null, PalletEntity::getWarehouseId, query.warehouseId())
.like(StringUtils.hasText(query.palletCode()), PalletEntity::getPalletCode, query.palletCode())
.eq(StringUtils.hasText(query.palletType()), PalletEntity::getPalletType, query.palletType())
@@ -16,7 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/** 库位基础资料应用服务,负责 CRUD、租户仓库隔离和启停/删除约束。 */
/** 库位基础资料应用服务,负责平台分页、CRUD、租户仓库隔离和启停/删除约束。 */
@Service
public class LocationApplicationService {
private final LocationRepository repository;
@@ -25,8 +25,7 @@ public class LocationApplicationService {
this.repository = repository;
}
public PageResult<LocationEntity> page(long tenantId, PageQuery query) {
requireWarehouse(tenantId, query.warehouseId(), false);
public PageResult<LocationEntity> page(Long tenantId, PageQuery query) {
return repository.page(tenantId, query);
}
@@ -23,7 +23,7 @@ public class PalletApplicationService {
this.warehouseRepository = warehouseRepository;
}
public PageResult<PalletRequests.View> page(long tenantId, PalletRequests.PageQuery query) {
public PageResult<PalletRequests.View> page(Long tenantId, PalletRequests.PageQuery query) {
PageResult<PalletEntity> source = repository.page(tenantId, query);
return new PageResult<>(source.records().stream().map(PalletApplicationService::view).toList(),
source.page(), source.size(), source.total(), source.pages());