Quellcode durchsuchen

添加swagger访问

lqc vor 4 Jahren
Ursprung
Commit
0b324b5b36

+ 10 - 0
pom.xml

@@ -188,6 +188,16 @@
             <artifactId>elasticsearch</artifactId>
             <version>6.4.3</version>
         </dependency>
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-boot-starter</artifactId>
+            <version>3.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.plugin</groupId>
+            <artifactId>spring-plugin-core</artifactId>
+            <version>2.0.0.RELEASE</version>
+        </dependency>
     </dependencies>
     <profiles>
         <!--        <profile>-->

+ 42 - 0
src/main/java/com/mokamrp/privates/config/SwaggerConfig.java

@@ -0,0 +1,42 @@
+package com.mokamrp.privates.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.oas.annotations.EnableOpenApi;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Contact;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+
+/**
+ * Swagger配置类
+ */
+@Configuration
+@EnableOpenApi
+public class SwaggerConfig {
+
+    @Bean
+    public Docket docket() {
+        return new Docket(DocumentationType.OAS_30)
+                .apiInfo(apiInfo()).enable(true)
+                .select()
+                //apis: 添加swagger接口提取范围
+                .apis(RequestHandlerSelectors.basePackage("com.mokamrp.privates"))
+                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
+                .paths(PathSelectors.any())
+                .build();
+    }
+
+    private ApiInfo apiInfo() {
+        return new ApiInfoBuilder()
+                .title("盘古项目接口文档")
+                .description("盘古项目")
+                .contact(new Contact("作者", "作者URL", "作者Email"))
+                .version("1.0")
+                .build();
+    }
+}

+ 2 - 0
src/main/java/com/mokamrp/privates/controller/pangu/FosterwxCashAccountScheduleController.java

@@ -12,6 +12,7 @@ import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashAccountSchedule;
 import com.mokamrp.privates.mapper.pojo.User;
 import com.mokamrp.privates.service.pangu.FosterwxCashAccountScheduleService;
 import com.mokamrp.privates.service.pangu.FosterwxCashScheduleTaskListService;
+import io.swagger.annotations.Api;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.BindingResult;
@@ -37,6 +38,7 @@ import java.util.*;
  */
 @RestController
 @RequestMapping("/fosterwxCashAccountSchedule")
+@Api(tags = "变现-账号排期")
 public class FosterwxCashAccountScheduleController extends BaseController<FosterwxCashAccountSchedule> {
 
     public static final String REGEX = ",";

+ 2 - 1
src/main/java/com/mokamrp/privates/mapper/pangu/FosterwxCashAccountScheduleMapper.java

@@ -1,5 +1,6 @@
 package com.mokamrp.privates.mapper.pangu;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashAccountSchedule;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -17,5 +18,5 @@ import java.util.List;
  */
 @Component
 public interface FosterwxCashAccountScheduleMapper extends BaseMapper<FosterwxCashAccountSchedule> {
-    public List<FosterwxCashAccountSchedule> getList(Page<FosterwxCashAccountSchedule> pageObj);
+    public List<FosterwxCashAccountSchedule> getList(@Param("ew") LambdaQueryWrapper<FosterwxCashAccountSchedule> pageObj);
 }

+ 13 - 4
src/main/java/com/mokamrp/privates/service/pangu/impl/FosterwxCashAccountScheduleServiceImpl.java

@@ -1,6 +1,6 @@
 package com.mokamrp.privates.service.pangu.impl;
 
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.mokamrp.privates.entity.ResHandle;
 import com.mokamrp.privates.entity.pangu.FosterwxCashAccountScheduleHandle;
@@ -36,11 +36,20 @@ public class FosterwxCashAccountScheduleServiceImpl extends ServiceImpl<Fosterwx
     public ResHandle<List<FosterwxCashAccountSchedule>> getList(FosterwxCashAccountScheduleHandle handle) {
         Integer pagesize = handle.getPageSize();
         Integer page = handle.getPage();
-        Page<FosterwxCashAccountSchedule> pageObj = new Page<FosterwxCashAccountSchedule>(page, pagesize);
-        List<FosterwxCashAccountSchedule> list = fosterwxCashAccountScheduleMapper.getList(pageObj);
+        LambdaQueryWrapper<FosterwxCashAccountSchedule> fosterwxCashAccountScheduleLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        // 任务模板
+        fosterwxCashAccountScheduleLambdaQueryWrapper.eq(FosterwxCashAccountSchedule::getTemplateId, handle.getTemplateId());
+        // 创建人
+        fosterwxCashAccountScheduleLambdaQueryWrapper.eq(FosterwxCashAccountSchedule::getCreateUid, handle.getCreateUid());
+        // 账号组别
+        fosterwxCashAccountScheduleLambdaQueryWrapper.eq(FosterwxCashAccountSchedule::getGroupId, handle.getGroupId());
+        // 获取总件数
+        Long maxCount = Long.valueOf(fosterwxCashAccountScheduleMapper.selectCount(fosterwxCashAccountScheduleLambdaQueryWrapper));
+
+        List<FosterwxCashAccountSchedule> list = fosterwxCashAccountScheduleMapper.getList(fosterwxCashAccountScheduleLambdaQueryWrapper);
         ResHandle<List<FosterwxCashAccountSchedule>> res = new ResHandle<>();
         res.setList(list);
-        res.setTotal(pageObj.getTotal());
+        res.setTotal(maxCount);
         return res;
     }
 

+ 2 - 0
src/main/resources/application-local.properties

@@ -86,3 +86,5 @@ typer.url=https://test.typer.mokamrp.com/api
 
 #定时任务全局开关,本地环境无需开启
 cronjob.power=true
+
+springfox.documentation.swagger-ui.enabled=true

+ 2 - 0
src/main/resources/application-prod.properties

@@ -80,3 +80,5 @@ typer.url=http://new-typer-combine-svc/api
 
 #定时任务全局开关,线上环境需要开启
 cronjob.power=true
+
+springfox.documentation.swagger-ui.enabled=false

+ 1 - 2
src/main/resources/application-test.properties

@@ -79,5 +79,4 @@ typer.url=http://new-typer-combine-svc/api
 #定时任务全局开关,线上环境需要开启
 cronjob.power=false
 
-
-
+springfox.documentation.swagger-ui.enabled=true