This commit is contained in:
2026-08-27 13:35:52 +08:00
parent 3975759458
commit a79999d97c
9 changed files with 155 additions and 1 deletions
@@ -0,0 +1,82 @@
package com.baiyue.warehouse.controller;
import com.baiyue.common.core.api.ApiResponse;
import com.baiyue.common.core.api.PageResult;
import com.baiyue.common.core.api.ResultCode;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.common.security.AuthenticatedUser;
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. */
@RestController
@RequestMapping("/api/platform/v1/warehouse-admin")
@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;
this.resources = resources;
}
@GetMapping("/pallets")
@PreAuthorize("hasAuthority('" + OverseasWarehousePermissions.PALLET_LIST + "')")
@Operation(summary = "Page public pallets across warehouses",
description = "Required authority: " + OverseasWarehousePermissions.PALLET_LIST)
public ApiResponse<PageResult<WarehousePalletEntity>> pallets(
@AuthenticationPrincipal AuthenticatedUser user,
@Valid PalletRequests.QueryRequest query) {
requirePlatform(user);
return ApiResponse.success(resources.publicPallets(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) {
throw new BizException(ResultCode.FORBIDDEN, "仅允许平台端访问");
}
}
public record WarehouseOption(long id, long customerId, String warehouseCode,
String warehouseName, String warehouseType, String status) { }
}
@@ -146,6 +146,18 @@ public class WarehouseResourceRepository {
return PageResult.from(pallets.selectPage(new Page<>(query.page(), query.size()), wrapper));
}
public PageResult<WarehousePalletEntity> pagePublicPallets(long customerId,
PalletRequests.QueryRequest query) {
var wrapper = new LambdaQueryWrapper<WarehousePalletEntity>()
.eq(WarehousePalletEntity::getCustomerId, customerId)
.eq(StringUtils.hasText(query.palletType()), WarehousePalletEntity::getPalletType, query.palletType())
.eq(StringUtils.hasText(query.status()), WarehousePalletEntity::getStatus, query.status())
.eq(query.locationId() != null, WarehousePalletEntity::getLocationId, query.locationId())
.like(StringUtils.hasText(query.keyword()), WarehousePalletEntity::getPalletCode, query.keyword())
.orderByDesc(WarehousePalletEntity::getCreatedAt);
return PageResult.from(pallets.selectPage(new Page<>(query.page(), query.size()), wrapper));
}
public void deletePallet(long id) {
pallets.deleteById(id);
}
@@ -218,6 +218,11 @@ public class WarehouseResourceService {
return repository.pagePallets(customerId, warehouseId, query);
}
public PageResult<WarehousePalletEntity> publicPallets(long customerId,
PalletRequests.QueryRequest query) {
return repository.pagePublicPallets(customerId, query);
}
@Transactional
public void deletePallet(long customerId, long warehouseId, long id) {
WarehousePalletEntity pallet = requirePallet(customerId, warehouseId, id);