This commit is contained in:
2026-09-29 17:55:54 +08:00
parent 41d8387cd5
commit 54ad26c607
111 changed files with 1837 additions and 962 deletions
@@ -0,0 +1,51 @@
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.service.WarehouseApplicationService;
import io.swagger.v3.oas.annotations.Operation;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/** Read-only resource options, without granting warehouse master maintenance permissions. */
@RestController
public class PlatformOverseasReceivingOptionsController {
private final WarehouseApplicationService service;
public PlatformOverseasReceivingOptionsController(WarehouseApplicationService service) {
this.service = service;
}
@GetMapping("/api/platform/v1/warehouse-admin/overseas-receiving-options")
@PreAuthorize("hasAuthority('platform:overseas-warehouse:warehouse:list')")
@Operation(summary = "Page active shared overseas receiving warehouse options",
description = "Requires platform:overseas-warehouse:warehouse:list; only public OVERSEAS/ACTIVE/RECEIVING warehouses.")
public ApiResponse<PageResult<WarehouseOption>> warehouses(
@AuthenticationPrincipal AuthenticatedUser user,
@RequestParam(defaultValue = "1") long page,
@RequestParam(defaultValue = "200") long size) {
if (user == null || !"PLATFORM".equals(user.appCode())
|| user.tenantId() == null || user.tenantId() != 0L) {
throw new BizException(ResultCode.FORBIDDEN, "仅允许平台端访问");
}
if (page < 1 || size < 1 || size > 200) throw new BizException(ResultCode.BAD_REQUEST, "分页参数无效");
List<WarehouseOption> all = service.activeSharedOverseasWarehouses().stream()
.map(value -> new WarehouseOption(value.warehouseId(), 0L, value.warehouseCode(),
value.warehouseName(), "OVERSEAS", value.status())).toList();
long pages = (all.size() + size - 1) / size;
long from = page > pages ? all.size() : (page - 1) * size;
long to = Math.min(from + size, all.size());
return ApiResponse.success(new PageResult<>(all.subList((int) from, (int) to), page, size, all.size(), pages));
}
public record WarehouseOption(long id, long customerId, String warehouseCode,
String warehouseName, String warehouseType, String status) { }
}