Quellcode durchsuchen

v1.0.0-feature: 增加swagger文档的支持

sckw-developer vor 2 Monaten
Ursprung
Commit
5be5846c0d

+ 0 - 10
sckw-common/sckw-common-core/pom.xml

@@ -178,16 +178,6 @@
             <groupId>org.apache.httpcomponents.client5</groupId>
             <artifactId>httpclient5</artifactId>
         </dependency>
-
-<!--        <dependency>-->
-<!--            <groupId>org.springdoc</groupId>-->
-<!--            <artifactId>springdoc-openapi-ui</artifactId>-->
-<!--        </dependency>-->
-        <dependency>
-            <groupId>org.springdoc</groupId>
-            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
-
-        </dependency>
         <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>easyexcel-core</artifactId>

+ 0 - 26
sckw-common/sckw-common-core/src/main/java/com/sckw/core/config/OpenApiConfig.java

@@ -1,26 +0,0 @@
-package com.sckw.core.config;
-
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.info.Contact;
-import io.swagger.v3.oas.models.OpenAPI;
-import io.swagger.v3.oas.models.info.Info;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author PC
- */
-@Configuration
-@OpenAPIDefinition
-public class OpenApiConfig {
-    @Bean
-    public OpenAPI customOpenAPI() {
-        return new OpenAPI()
-                .info(new Info()
-                        .title("API文档")
-                        .version("1.0")
-                        .description("<font color=\"#DC143C\">**以「高质量代码」为核心,「简洁、高效、安全」**</font>基于 SpringBoot + Sa-Token + Mybatis-Plus 和 Vue3 + Vite5 + Ant Design (同时支持JavaScript和TypeScript双版本) 的快速开发平台。" +
-                                "<br/><font color=\"#DC143C\">**国内首个满足《网络安全》、《数据安全》、三级等保**</font>, 支持登录限制、支持国产接口加解密等安全、支持数据加解密等一系列安全体系的开源项目。" +
-                                "<br/><font color=\"#DC143C\">**我们开源一套漂亮的代码和一套整洁的代码规范**</font>,让大家在这浮躁的代码世界里感受到一股把代码写好的清流!同时又让开发者节省大量的时间,减少加班,快乐工作,保持谦逊,保持学习,热爱代码,更热爱生活!"));
-    }
-}

+ 0 - 28
sckw-common/sckw-common-core/src/main/java/com/sckw/core/config/SwaggerConfig.java

@@ -1,28 +0,0 @@
-package com.sckw.core.config;
-
-import io.swagger.v3.oas.models.OpenAPI;
-import io.swagger.v3.oas.models.info.Info;
-import io.swagger.v3.oas.models.info.Contact;
-import io.swagger.v3.oas.models.info.License;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class SwaggerConfig {
-    
-    @Bean
-    public OpenAPI customOpenAPI() {
-        return new OpenAPI()
-                .info(new Info()
-                        .title("API 文档")
-                        .version("1.0")
-                        .description("Spring Boot REST API 文档")
-                        .contact(new Contact()
-                                .name("矿拉拉普适版")
-                                .email("dev@example.com")
-                                .url("https://example.com"))
-                        .license(new License()
-                                .name("Apache 2.0")
-                                .url("http://springdoc.org")));
-    }
-}

+ 8 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/filter/RequestCheckFilter.java

@@ -94,6 +94,14 @@ public class RequestCheckFilter implements Filter {
             filterChain.doFilter(servletRequest, servletResponse);
             return;
         }
+        
+        // 添加对Swagger相关路径的放行
+        if (requestUri.startsWith("/swagger-ui") || 
+            requestUri.startsWith("/v3/api-docs") ||
+            requestUri.startsWith("/webjars/")) {
+            filterChain.doFilter(servletRequest, servletResponse);
+            return;
+        }
 
         /*2、校验token**/
         /*2.1、校验token非空*/

+ 1 - 1
sckw-common/sckw-common-remote/src/main/java/com/sckw/remote/annotation/SckwRemoteApplication.java

@@ -11,6 +11,6 @@ import java.lang.annotation.*;
 @Inherited
 @EnableDubbo
 @EnableFeignClients({"com.sckw.*.api.feign"})
-@ComponentScan(basePackages = {"com.sckw.remote.filter", "com.sckw.*.service","com.sckw.*.repository", "com.sckw.*.dubbo", "com.sckw.*.model"})
+@ComponentScan(basePackages = {"com.sckw.payment.config","com.sckw.remote.filter","com.sckw.*.controller", "com.sckw.*.service","com.sckw.*.repository", "com.sckw.*.dubbo", "com.sckw.*.model"})
 public @interface SckwRemoteApplication {
 }

+ 10 - 0
sckw-modules/sckw-contract/pom.xml

@@ -104,6 +104,16 @@
             <artifactId>sckw-common-stream</artifactId>
             <version>${basic.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
 
     </dependencies>
     <build>

+ 10 - 0
sckw-modules/sckw-fleet/pom.xml

@@ -97,6 +97,16 @@
 <!--            <version>1.0.0</version>-->
             <version>${basic.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
 
     </dependencies>
 

+ 1 - 7
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/controller/KwfTruckAxleNumController.java

@@ -35,10 +35,4 @@ public class KwfTruckAxleNumController {
         return BaseResult.success(truckAxleNumVOS);
     }
 
-
-
-
-
-
-
-}
+}

+ 10 - 0
sckw-modules/sckw-manage/pom.xml

@@ -103,6 +103,16 @@
 <!--            <version>1.0.0</version>-->
             <version>${basic.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

+ 10 - 0
sckw-modules/sckw-message/pom.xml

@@ -83,6 +83,16 @@
 <!--            <version>1.0.0</version>-->
             <version>${basic.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
 
     </dependencies>
 

+ 10 - 0
sckw-modules/sckw-operation/pom.xml

@@ -78,6 +78,16 @@
 <!--            <version>1.0.0</version>-->
             <version>${basic.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
 
     </dependencies>
 	<build>

+ 10 - 0
sckw-modules/sckw-order/pom.xml

@@ -118,6 +118,16 @@
 <!--            <version>1.0.0</version>-->
             <version>${basic.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
 
     </dependencies>
 

+ 11 - 0
sckw-modules/sckw-payment/pom.xml

@@ -100,6 +100,17 @@
             <artifactId>sckw-manage-api</artifactId>
             <version>${basic.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
+
 
     </dependencies>
     <build>

+ 52 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/config/OpenApiConfig.java

@@ -0,0 +1,52 @@
+package com.sckw.payment.config;
+
+import io.swagger.v3.oas.models.OpenAPI;
+import io.swagger.v3.oas.models.info.Contact;
+import io.swagger.v3.oas.models.info.Info;
+import io.swagger.v3.oas.models.info.License;
+import io.swagger.v3.oas.models.servers.Server;
+import org.springdoc.core.models.GroupedOpenApi;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.List;
+
+@Configuration
+public class OpenApiConfig {
+
+    @Value("${spring.application.name:Application}")
+    private String applicationName;
+
+    @Bean
+    public OpenAPI customOpenAPI() {
+        return new OpenAPI()
+                .info(new Info()
+                        .title(applicationName + " API")
+                        .version("1.0.0")
+                        .description("钱包以及支付DOC文档 - 提供钱包管理以及支付等API接口")
+                        .contact(new Contact()
+                                .name("开物钱包开发团队")
+                                .email("iot-dev@example.com")
+                                .url("https://iot-platform.com"))
+                        .license(new License()
+                                .name("Apache 2.0")
+                                .url("https://www.apache.org/licenses/LICENSE-2.0")))
+                .servers(List.of(
+                        new Server()
+                                .url("http://localhost:10120")
+                                .description("开发环境"),
+                        new Server()
+                                .url("https://api.payment.example.com")
+                                .description("生产环境")
+                ));
+    }
+    
+    @Bean
+    public GroupedOpenApi paymentApi() {
+        return GroupedOpenApi.builder()
+                .group("payment")
+                .packagesToScan("com.sckw.payment.controller")
+                .build();
+    }
+}

+ 2 - 6
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/KwpBizWalletController.java

@@ -1,7 +1,7 @@
 package com.sckw.payment.controller;
 
 
-import com.sckw.core.ExcelUtils;
+import com.sckw.excel.utils.ExcelUtil;
 import com.sckw.core.web.response.BaseResult;
 import com.sckw.core.web.response.result.PageDataResult;
 import com.sckw.payment.repose.KwpBizWalletPageResponse;
@@ -109,11 +109,7 @@ public class KwpBizWalletController {
         //查询导出数据
         List<KwpBizWalletPrepayExcelVO> excelVOList = kwpBizWalletService.queryExportWalletPrepay(request);
         //导出
-        try {
-            ExcelUtils.exportTemplate(response, "冻账明细表", KwpBizWalletPrepayExcelVO.class, excelVOList);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
+        ExcelUtil.downData(response, KwpBizWalletPrepayExcelVO.class, excelVOList);
         return BaseResult.success();
     }
 

+ 14 - 1
sckw-modules/sckw-payment/src/main/resources/bootstrap.yml

@@ -13,7 +13,20 @@ spring:
 mybatis-plus:
   configuration:
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+
 logging:
   level:
     root: info
-    com.sckw.payment: debug
+    com.sckw.payment: debug
+
+# SpringDoc OpenAPI 配置
+springdoc:
+  swagger-ui:
+    path: /swagger-ui.html
+    tags-sorter: alpha
+    operations-sorter: alpha
+  api-docs:
+    path: /v3/api-docs
+  show-actuator: true
+  cache:
+    disabled: true

+ 10 - 0
sckw-modules/sckw-product/pom.xml

@@ -94,6 +94,16 @@
 <!--            <version>1.0.0</version>-->
             <version>${basic.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
 
     </dependencies>
 

+ 10 - 0
sckw-modules/sckw-report/pom.xml

@@ -147,6 +147,16 @@
 <!--            <version>1.0.0</version>-->
             <version>${basic.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

+ 10 - 0
sckw-modules/sckw-system/pom.xml

@@ -87,6 +87,16 @@
             <artifactId>sckw-common-excel</artifactId>
             <version>${basic.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
 
     </dependencies>
     <build>

+ 10 - 0
sckw-modules/sckw-transport/pom.xml

@@ -138,6 +138,16 @@
             <artifactId>sckw-common-log</artifactId>
             <version>1.0.0</version>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+            <version>2.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
+            <version>4.5.0</version>
+        </dependency>
 
     </dependencies>