mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:19:19 +08:00
refactor: 调整开放模块
This commit is contained in:
+2
-2
@@ -8,8 +8,8 @@ import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequireOpenScope;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.context.OpenApiContextHolder;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.security.OpenApiPrincipal;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.common.context.OpenApiContextHolder;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.common.security.OpenApiPrincipal;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ import org.springframework.security.web.access.AccessDeniedHandler;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
import top.xyquan.ecomdmbbackend.common.filter.JwtAuthenticationFilter;
|
||||
import top.xyquan.ecomdmbbackend.modules.agent.mcp.security.AgentMcpAuthenticationFilter;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.filter.ApiKeyAuthenticationFilter;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.common.filter.ApiKeyAuthenticationFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
+6
-7
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.controller;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.channel.pdd.adfee.importtask.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -16,33 +16,32 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.adfee.importtask.model.dto.
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.adfee.importtask.model.vo.PddGoodsAdFeeImportTaskVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.adfee.importtask.service.PddGoodsAdFeeImportService;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.adfee.model.dto.BatchImportPddGoodsAdFeeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.constants.OpenApiScopeConstants;
|
||||
|
||||
/**
|
||||
* OpenAPI:浏览器扩展只创建导入任务并查询进度。
|
||||
* OpenAPI:拼多多商品广告费导入任务(浏览器扩展)。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/open/v1/channel/pdd/goods/adfee")
|
||||
@RequiredArgsConstructor
|
||||
public class OpenPddGoodsAdFeeController {
|
||||
public class OpenPddGoodsAdFeeImportController {
|
||||
|
||||
private final PddGoodsAdFeeImportService importService;
|
||||
|
||||
@PostMapping("/batch-import")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.PDD_GOODS_AD_FEE_IMPORT, description = "创建拼多多商品广告费导入任务")
|
||||
@RequireOpenScope(value = "open:product:adfee", description = "创建拼多多商品广告费导入任务")
|
||||
public ApiResponse<PddGoodsAdFeeImportTaskVO> batchImport(
|
||||
@Valid @RequestBody BatchImportPddGoodsAdFeeDTO dto) {
|
||||
return ApiResponse.success("已创建导入任务", importService.createAndEnqueue(dto));
|
||||
}
|
||||
|
||||
@GetMapping("/import-task/{id}")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.PDD_GOODS_AD_FEE_IMPORT, description = "查询拼多多商品广告费导入任务")
|
||||
@RequireOpenScope(value = "open:product:adfee", description = "查询拼多多商品广告费导入任务")
|
||||
public ApiResponse<PddGoodsAdFeeImportTaskVO> importTaskDetail(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取成功", importService.getDetail(id));
|
||||
}
|
||||
|
||||
@PostMapping("/import-task/list")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.PDD_GOODS_AD_FEE_IMPORT, description = "查询拼多多商品广告费导入任务列表")
|
||||
@RequireOpenScope(value = "open:product:adfee", description = "查询拼多多商品广告费导入任务列表")
|
||||
public ApiResponse<PageResultVO<PddGoodsAdFeeImportTaskVO>> importTaskList(
|
||||
@Valid @RequestBody PageQueryDTO<PddGoodsAdFeeImportTaskFilterDTO> pageQueryDTO) {
|
||||
return ApiResponse.success("获取成功", importService.getPage(pageQueryDTO));
|
||||
+5
-3
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.controller;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.channel.pdd.shop.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -13,8 +13,10 @@ import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.dto.PddShopFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.vo.PddShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.service.PddShopService;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.constants.OpenApiScopeConstants;
|
||||
|
||||
/**
|
||||
* OpenAPI:拼多多渠道店铺。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/open/v1/channel/pdd/shop")
|
||||
@RequiredArgsConstructor
|
||||
@@ -23,7 +25,7 @@ public class OpenPddShopController {
|
||||
private final PddShopService pddShopService;
|
||||
|
||||
@PostMapping("/list")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.PDD_SHOP_READ, description = "查询拼多多渠道店铺列表")
|
||||
@RequireOpenScope(value = "open:shop:pdd:read", description = "查询拼多多渠道店铺列表")
|
||||
public ApiResponse<PageResultVO<PddShopVO>> getPddShopPage(
|
||||
@Valid @RequestBody PageQueryDTO<PddShopFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<PddShopVO> result = pddShopService.getPddShopPage(pageQueryDTO);
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.constants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 开放接口权限码常量(对应 sys_permission.code,前缀 open:scope:)
|
||||
*/
|
||||
public final class OpenApiScopeConstants {
|
||||
|
||||
public static final String PREFIX = "open:scope:";
|
||||
|
||||
public static final String ORDER_IMPORT = "open:scope:order:import";
|
||||
public static final String ORDER_READ = "open:scope:order:read";
|
||||
public static final String IMPORT_TASK_READ = "open:scope:import_task:read";
|
||||
public static final String META_READ = "open:scope:meta:read";
|
||||
public static final String PDD_GOODS_AD_FEE_IMPORT = "open:scope:pdd_goods_ad_fee:import";
|
||||
public static final String PDD_SHOP_READ = "open:scope:pdd_shop:read";
|
||||
public static final String EXTENSION_FEATURE_READ = "open:scope:extension_feature:read";
|
||||
|
||||
public static final List<String> ALL = List.of(
|
||||
ORDER_IMPORT,
|
||||
ORDER_READ,
|
||||
IMPORT_TASK_READ,
|
||||
META_READ,
|
||||
PDD_GOODS_AD_FEE_IMPORT,
|
||||
PDD_SHOP_READ,
|
||||
EXTENSION_FEATURE_READ
|
||||
);
|
||||
|
||||
private OpenApiScopeConstants() {
|
||||
}
|
||||
|
||||
public static boolean isOpenScopeCode(String code) {
|
||||
return code != null && code.startsWith(PREFIX);
|
||||
}
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequireOpenScope;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.status.model.vo.OrderStatusMetaVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.status.support.OrderStatusMetaSupport;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo.ShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.constants.OpenApiScopeConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/open/v1/ec")
|
||||
@RequiredArgsConstructor
|
||||
public class OpenMetaController {
|
||||
|
||||
private final ShopService shopService;
|
||||
|
||||
@PostMapping("/shop/list")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.META_READ, description = "查询店铺列表")
|
||||
public ApiResponse<PageResultVO<ShopVO>> getShopPage(
|
||||
@Valid @RequestBody PageQueryDTO<ShopFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<ShopVO> result = shopService.getShopPage(pageQueryDTO);
|
||||
return ApiResponse.success("获取店铺列表成功", result);
|
||||
}
|
||||
|
||||
@GetMapping("/order-status/list")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.META_READ, description = "查询订单状态列表")
|
||||
public ApiResponse<List<OrderStatusMetaVO>> getAllOrderStatuses() {
|
||||
return ApiResponse.success("获取订单状态列表成功", OrderStatusMetaSupport.allMeta());
|
||||
}
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequireOpenScope;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.dto.BatchImportOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.vo.BatchImportResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.vo.OrderFieldConstants;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.vo.OrderFieldVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.service.OrderService;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.constants.OpenApiScopeConstants;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.license.LicenseRequired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/open/v1/ec/order")
|
||||
@RequiredArgsConstructor
|
||||
public class OpenOrderController {
|
||||
|
||||
private final OrderService orderService;
|
||||
|
||||
@GetMapping("/fields")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.ORDER_READ, description = "查询订单字段")
|
||||
public ApiResponse<List<OrderFieldVO>> getOrderFieldDefs() {
|
||||
return ApiResponse.success("获取订单字段成功", OrderFieldConstants.FIELDS);
|
||||
}
|
||||
|
||||
@PostMapping("/batch-import")
|
||||
@LicenseRequired
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.ORDER_IMPORT, description = "批量导入订单")
|
||||
public ApiResponse<BatchImportResultVO> batchImportOrders(@Valid @RequestBody BatchImportOrderDTO dto) {
|
||||
BatchImportResultVO result = orderService.batchImportOrders(dto);
|
||||
return ApiResponse.success("批量导入订单成功", result);
|
||||
}
|
||||
}
|
||||
+7
-9
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.controller;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.extension.features.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -7,14 +7,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequireOpenScope;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.constants.OpenApiScopeConstants;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.model.vo.ExtensionFeatureManifestVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.model.vo.ExtensionFeatureScriptVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.service.ExtensionFeatureService;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.extension.features.model.vo.ExtensionFeatureManifestVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.extension.features.model.vo.ExtensionFeatureScriptVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.extension.features.service.ExtensionFeatureService;
|
||||
|
||||
/**
|
||||
* 浏览器扩展功能清单 / 脚本。
|
||||
* 数据来自 classpath:static/extension-features/(与构建产物 dist-features 对齐)。
|
||||
* OpenAPI:浏览器扩展功能清单 / 脚本。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/open/v1/extension/features")
|
||||
@@ -24,13 +22,13 @@ public class OpenExtensionFeatureController {
|
||||
private final ExtensionFeatureService extensionFeatureService;
|
||||
|
||||
@GetMapping
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.EXTENSION_FEATURE_READ, description = "查询浏览器扩展功能清单")
|
||||
@RequireOpenScope(value = "open:extension:feature:read", description = "查询浏览器扩展功能清单")
|
||||
public ApiResponse<ExtensionFeatureManifestVO> listFeatures() {
|
||||
return ApiResponse.success("获取扩展功能清单成功", extensionFeatureService.getManifest());
|
||||
}
|
||||
|
||||
@GetMapping("/{featureId}/script")
|
||||
@RequireOpenScope(value = OpenApiScopeConstants.EXTENSION_FEATURE_READ, description = "下载浏览器扩展功能脚本")
|
||||
@RequireOpenScope(value = "open:extension:feature:read", description = "下载浏览器扩展功能脚本")
|
||||
public ApiResponse<ExtensionFeatureScriptVO> getScript(@PathVariable String featureId) {
|
||||
return ApiResponse.success("获取扩展功能脚本成功", extensionFeatureService.getScript(featureId));
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.extension.features.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.extension.features.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.extension.features.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.extension.features.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.extension.features.model.vo.ExtensionFeatureManifestVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.extension.features.model.vo.ExtensionFeatureScriptVO;
|
||||
|
||||
/**
|
||||
* 浏览器扩展功能清单与脚本读取。
|
||||
*/
|
||||
public interface ExtensionFeatureService {
|
||||
|
||||
ExtensionFeatureManifestVO getManifest();
|
||||
|
||||
ExtensionFeatureScriptVO getScript(String featureId);
|
||||
}
|
||||
+8
-5
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.service.impl;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.extension.features.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -8,10 +8,10 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.model.vo.ExtensionFeatureItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.model.vo.ExtensionFeatureManifestVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.model.vo.ExtensionFeatureScriptVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.service.ExtensionFeatureService;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.extension.features.model.vo.ExtensionFeatureItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.extension.features.model.vo.ExtensionFeatureManifestVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.extension.features.model.vo.ExtensionFeatureScriptVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.extension.features.service.ExtensionFeatureService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -19,6 +19,9 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* 从 classpath:static/extension-features/ 读取扩展功能清单与脚本。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ExtensionFeatureServiceImpl implements ExtensionFeatureService {
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.model.vo.ExtensionFeatureManifestVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.model.vo.ExtensionFeatureScriptVO;
|
||||
|
||||
public interface ExtensionFeatureService {
|
||||
|
||||
ExtensionFeatureManifestVO getManifest();
|
||||
|
||||
ExtensionFeatureScriptVO getScript(String featureId);
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.context;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.common.context;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.security.OpenApiPrincipal;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.common.security.OpenApiPrincipal;
|
||||
|
||||
/**
|
||||
* 开放 API 请求上下文(ThreadLocal)
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.filter;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.common.filter;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.FilterChain;
|
||||
@@ -13,9 +13,9 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.context.OpenApiContextHolder;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.security.OpenApiAuthentication;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.security.OpenApiPrincipal;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.common.context.OpenApiContextHolder;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.common.security.OpenApiAuthentication;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.common.security.OpenApiPrincipal;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.key.model.po.OpenApiKeyPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.key.service.OpenApiKeyService;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.security;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.common.security;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.security.core.Authentication;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.open.api.security;
|
||||
package top.xyquan.ecomdmbbackend.modules.open.common.security;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
+11
-3
@@ -10,7 +10,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.constants.OpenApiScopeConstants;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.key.mapper.OpenApiKeyMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.key.mapper.OpenApiKeyPermissionMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.key.model.dto.CreateOpenApiKeyDTO;
|
||||
@@ -174,7 +173,7 @@ public class OpenApiKeyServiceImpl implements OpenApiKeyService {
|
||||
public List<OpenApiAvailablePermissionVO> getAvailablePermissions() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
return companyPermissionMapper.selectPermissionsByCompanyId(companyId).stream()
|
||||
.filter(p -> OpenApiScopeConstants.isOpenScopeCode(p.getCode()))
|
||||
.filter(p -> isBindableOpenApiPermission(p.getCode(), p.getType()))
|
||||
.map(p -> {
|
||||
CompanyPermissionPO cp = getCompanyPermission(companyId, p.getId());
|
||||
OpenApiAvailablePermissionVO vo = new OpenApiAvailablePermissionVO();
|
||||
@@ -200,7 +199,8 @@ public class OpenApiKeyServiceImpl implements OpenApiKeyService {
|
||||
throw new BusinessException("存在无效的公司权限: " + id);
|
||||
}
|
||||
PermissionPO permission = permissionMapper.selectById(cp.getPermissionId());
|
||||
if (permission == null || !OpenApiScopeConstants.isOpenScopeCode(permission.getCode())) {
|
||||
if (permission == null
|
||||
|| !isBindableOpenApiPermission(permission.getCode(), permission.getType())) {
|
||||
throw new BusinessException("仅可绑定开放接口权限");
|
||||
}
|
||||
return cp;
|
||||
@@ -270,4 +270,12 @@ public class OpenApiKeyServiceImpl implements OpenApiKeyService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 可绑到 API Key 的开放叶子权限:open: 前缀、api 类型,排除控制台 api-key 管理 */
|
||||
private static boolean isBindableOpenApiPermission(String code, String type) {
|
||||
if (!"api".equals(type) || code == null) {
|
||||
return false;
|
||||
}
|
||||
return code.startsWith("open:") && !"open:api-key:manage".equals(code);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,9 +6,9 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.agent.mcp.security.AgentMcpAuthentication;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.context.OpenApiContextHolder;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.security.OpenApiAuthentication;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.api.security.OpenApiPrincipal;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.common.context.OpenApiContextHolder;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.common.security.OpenApiAuthentication;
|
||||
import top.xyquan.ecomdmbbackend.modules.open.common.security.OpenApiPrincipal;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.company.member.model.po.CompanyMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.company.member.service.CompanyMemberService;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user