Ver código fonte

openApi接口

wujiefeng 1 ano atrás
pai
commit
1a0d4c5537

+ 1 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/config/OpenAPIConfig.java

@@ -1,6 +1,6 @@
 package com.zhongshu.card.server.core.config;
 
-import com.zhongshu.gateway.client.config.OpenApiGatewayClientConfiguration;
+import com.zhongshu.opengateway.client.config.OpenApiGatewayClientConfiguration;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
 

+ 89 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/openAPI/OpenApiConfigManagerController.java

@@ -0,0 +1,89 @@
+package com.zhongshu.card.server.core.controller.openAPI;
+
+import com.github.microservice.auth.client.constant.AuthConstant;
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.type.AuthType;
+import com.zhongshu.opengateway.client.model.OpenApiConfigModel;
+import com.zhongshu.opengateway.client.model.param.AddApiParam;
+import com.zhongshu.opengateway.client.model.param.LimitParam;
+import com.zhongshu.opengateway.client.model.ret.ResultContent;
+import com.zhongshu.opengateway.client.service.OpenApiConfigService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/openApi/apiConfig")
+@Tag(name = "OpenApi--接口管理")
+public class OpenApiConfigManagerController {
+
+    @Autowired
+    OpenApiConfigService openApiConfigService;
+
+    @Operation(summary = "添加应用", description = "添加应用")
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
+    @RequestMapping(value = "quoteOpenApi", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
+    public ResultContent quoteOpenApi(@RequestBody AddApiParam param){
+        return openApiConfigService.quoteOpenApi(param);
+    }
+
+
+    @Operation(summary = "分页查询App下openApi", description = "分页查询App下openApi")
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
+    @RequestMapping(value = "pageByApp", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
+    public ResultContent pageByApp(String appId, @PageableDefault(sort = "createTime", direction = Sort.Direction.DESC) Pageable pageable){
+
+        ResultContent<List<OpenApiConfigModel>> listRet = openApiConfigService.listByAppId(appId);
+        if (listRet.isFailed()){
+            return listRet;
+        }
+        List<OpenApiConfigModel> openApiConfigModelList = listRet.getContent();
+        Object[] openApiPathList = openApiConfigModelList.stream().map(it -> {
+            return it.getOpenApiModel().getPath();
+        }).toArray();
+
+       return openApiConfigService.pageByMql("{\"isDelete\": false, \"appId \" : \""+appId + "\", \"openApi.path\" : { $in: [\""+ StringUtils.join(openApiPathList, "\",\"") + "\"]}}", pageable);
+    }
+
+    @Operation(summary = "禁用/启用", description = "禁用/启用")
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
+    @RequestMapping(value = "disable", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
+    public ResultContent disable(String id){
+        return openApiConfigService.disable(id);
+    }
+
+    @Operation(summary = "删除", description = "删除")
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
+    @RequestMapping(value = "delete", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
+    public ResultContent delete(String id){
+        return openApiConfigService.delete(id);
+    }
+
+    @Operation(summary = " 获取openApi详情", description = " 获取openApi详情")
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
+    @RequestMapping(value = "get", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
+    public ResultContent get(String id){
+        return openApiConfigService.get(id);
+    }
+
+    @Operation(summary = "设置限流规则", description = "设置限流规则")
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
+    @RequestMapping(value = "setLimit", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
+    public ResultContent setLimit(@RequestBody LimitParam limitParam){
+        return openApiConfigService.setLimit(limitParam);
+    }
+}

+ 57 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/openAPI/OpenApiManagerController.java

@@ -0,0 +1,57 @@
+package com.zhongshu.card.server.core.controller.openAPI;
+
+import com.github.microservice.auth.client.constant.AuthConstant;
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.type.AuthType;
+import com.zhongshu.opengateway.client.model.OpenApiModel;
+import com.zhongshu.opengateway.client.model.SignModel;
+import com.zhongshu.opengateway.client.model.param.RefreshApiParam;
+import com.zhongshu.opengateway.client.model.ret.ResultContent;
+import com.zhongshu.opengateway.client.service.OpenApiService;
+import com.zhongshu.opengateway.client.service.SignService;
+import com.zhongshu.opengateway.client.type.ApiType;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/openApi/api")
+@Tag(name = "OpenApi--接口管理")
+public class OpenApiManagerController {
+
+    @Autowired
+    OpenApiService openApiService;
+
+    @Autowired
+    SignService signService;
+
+    /** 自定义条件分页查询openApi列表 */
+    @Operation(summary = "分页查询所有openApi列表", description = "添加应用")
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = AuthConstant.Admin, type = AuthType.Project, remark = "")
+    @RequestMapping(value = "page", method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE})
+    public ResultContent pageByMql(String appId,
+                                                @PageableDefault(sort = "createTime", direction = Sort.Direction.DESC) Pageable pageable){
+        ResultContent<SignModel> signModelResultContent = signService.get(appId);
+        if (signModelResultContent.isFailed()){
+            return signModelResultContent;
+        }
+        SignModel signModel = signModelResultContent.getContent();
+        Object[] array = signModel.getAppType().getApiType().stream().map(Enum::name).toArray();
+        String mql = "\"apiType\" : {$in :["+ StringUtils.join(array, "\",\"")+"], \"isDelete\" : false}";
+        return openApiService.pageByMql(mql, pageable);
+    }
+
+
+
+
+}

+ 72 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/openAPI/OpenAppManagerController.java

@@ -0,0 +1,72 @@
+package com.zhongshu.card.server.core.controller.openAPI;
+
+import com.github.microservice.auth.client.constant.AuthConstant;
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.type.AuthType;
+import com.zhongshu.card.server.core.service.openAPI.OpenAppManagerService;
+import com.zhongshu.opengateway.client.model.param.SignParam;
+import com.zhongshu.opengateway.client.service.OpenApiConfigService;
+import com.zhongshu.opengateway.client.type.AppState;
+import com.zhongshu.opengateway.client.type.AppType;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("/openApi/app")
+@Tag(name = "OpenApi--应用管理")
+public class OpenAppManagerController {
+
+    @Autowired
+    OpenAppManagerService openAppManagerService;
+
+    @Autowired
+    OpenApiConfigService openApiConfigService;
+
+    @Operation(summary = "添加应用", description = "添加应用")
+    @RequestMapping(value = "add", method = {RequestMethod.POST})
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = AuthConstant.Admin, type = AuthType.Project, remark = "")
+    public Object add(@RequestBody SignParam param){
+        return openAppManagerService.add(param);
+    }
+
+    /**
+     * 删除应用
+     */
+    @RequestMapping(value = "delete", method = {RequestMethod.POST})
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = AuthConstant.Admin, type = AuthType.Project, remark = "")
+    public Object delete(String appId){
+        return openAppManagerService.delete(appId);
+    }
+
+
+    /**
+     * 禁用/启用
+     */
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = AuthConstant.Admin, type = AuthType.Project, remark = "")
+    @RequestMapping(value = "disable", method = {RequestMethod.POST})
+    public Object disable(String appId, AppState appState){
+        return openAppManagerService.disable(appId, appState);
+    }
+
+    /**
+     * 分页获取该项目下的app列表
+     */
+    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+    @ResourceAuth(value = AuthConstant.Admin, type = AuthType.Project, remark = "")
+    @RequestMapping(value = "page", method = {RequestMethod.POST})
+    public Object page(@Parameter(description = "业务id", required = true) String businessId,
+                       @Parameter(description = "应用类型",required = false) AppType appType,
+                       @Parameter(description = "应用状态") AppState appState,
+                       @Parameter(description = "应用名称") String appName,
+                       @Parameter(hidden = true)@PageableDefault(page = 0, size = 10) Pageable pageable){
+        return openAppManagerService.page(businessId, appType, appState, appName, pageable);
+    }
+}

+ 1 - 4
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/openAPI/OpenAPIRegisterService.java

@@ -1,19 +1,16 @@
 package com.zhongshu.card.server.core.service.openAPI;
 
-import cn.hutool.json.JSONObject;
 import com.github.microservice.models.openAPI.OpenApiInfo;
 import com.github.microservice.models.openAPI.RefreshApiParam;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.utils.OpenAPIScan;
-import com.zhongshu.gateway.client.type.ApiType;
+import com.zhongshu.opengateway.client.type.ApiType;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /**

+ 65 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/openAPI/OpenAppManagerService.java

@@ -0,0 +1,65 @@
+package com.zhongshu.card.server.core.service.openAPI;
+
+import com.github.microservice.auth.security.helper.AuthHelper;
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.opengateway.client.model.param.SignParam;
+import com.zhongshu.opengateway.client.service.OpenApiService;
+import com.zhongshu.opengateway.client.service.SignService;
+import com.zhongshu.opengateway.client.type.AppState;
+import com.zhongshu.opengateway.client.type.AppType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.client.RestTemplate;
+
+import javax.annotation.Resource;
+import java.net.URI;
+
+@Service
+public class OpenAppManagerService {
+
+    @Autowired
+    RestTemplate restTemplate;
+
+    @Autowired
+    SignService signService;
+
+    @Autowired
+    OpenApiService openApiService;
+
+    @Autowired
+    AuthHelper authHelper;
+
+    /**
+     * 添加应用
+     */
+    public Object add(SignParam param){
+        return signService.add(param);
+    }
+
+    /**
+     * 删除应用
+     */
+    public Object delete(String appId){
+        return signService.delete(appId);
+    }
+
+    /**
+     * 禁用/启用
+     */
+    public Object disable(String appId, AppState appState){
+        return signService.disable(appId, appState);
+    }
+
+    /**
+     * 分页获取该项目下的app列表
+     */
+    public Object page(String businessId, AppType appType, AppState appState, String appName, Pageable pageable){
+        return signService.pageByBusinessId(businessId, appType, appState, appName, pageable);
+    }
+}