| @@ -21,6 +21,7 @@ | |||
| <module>suimangSchedule</module> | |||
| <module>suimangMQConsumer</module> | |||
| <module>open-api</module> | |||
| <module>suimang-swagger</module> | |||
| </modules> | |||
| <parent> | |||
| @@ -186,21 +187,21 @@ | |||
| </dependency> | |||
| <!-- Swagger --> | |||
| <dependency> | |||
| <groupId>io.springfox</groupId> | |||
| <artifactId>springfox-swagger2</artifactId> | |||
| <version>2.8.0</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>io.springfox</groupId> | |||
| <artifactId>springfox-swagger-ui</artifactId> | |||
| <version>2.8.0</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>io.springfox</groupId> | |||
| <artifactId>springfox-spring-web</artifactId> | |||
| <version>2.8.0</version> | |||
| </dependency> | |||
| <!-- <dependency>--> | |||
| <!-- <groupId>io.springfox</groupId>--> | |||
| <!-- <artifactId>springfox-swagger2</artifactId>--> | |||
| <!-- <version>2.8.0</version>--> | |||
| <!-- </dependency>--> | |||
| <!-- <dependency>--> | |||
| <!-- <groupId>io.springfox</groupId>--> | |||
| <!-- <artifactId>springfox-swagger-ui</artifactId>--> | |||
| <!-- <version>2.8.0</version>--> | |||
| <!-- </dependency>--> | |||
| <!-- <dependency>--> | |||
| <!-- <groupId>io.springfox</groupId>--> | |||
| <!-- <artifactId>springfox-spring-web</artifactId>--> | |||
| <!-- <version>2.8.0</version>--> | |||
| <!-- </dependency>--> | |||
| <dependency> | |||
| <groupId>com.fasterxml.jackson.core</groupId> | |||
| <artifactId>jackson-core</artifactId> | |||
| @@ -0,0 +1,28 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | |||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
| <parent> | |||
| <artifactId>suimang</artifactId> | |||
| <groupId>com.iformall</groupId> | |||
| <version>1.0</version> | |||
| </parent> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <artifactId>suimang-swagger</artifactId> | |||
| <dependencies> | |||
| <!--swagger 相关依赖--> | |||
| <dependency> | |||
| <groupId>io.springfox</groupId> | |||
| <artifactId>springfox-swagger2</artifactId> | |||
| <version>2.9.2</version> | |||
| </dependency> | |||
| <!--doc.html模式--> | |||
| <dependency> | |||
| <groupId>com.github.xiaoymin</groupId> | |||
| <artifactId>swagger-bootstrap-ui</artifactId> | |||
| <version>1.9.3</version> | |||
| </dependency> | |||
| </dependencies> | |||
| </project> | |||
| @@ -0,0 +1,19 @@ | |||
| package com.iformall.annotation; | |||
| import java.lang.annotation.ElementType; | |||
| import java.lang.annotation.Retention; | |||
| import java.lang.annotation.RetentionPolicy; | |||
| import java.lang.annotation.Target; | |||
| @Target(ElementType.METHOD) | |||
| @Retention(RetentionPolicy.RUNTIME) | |||
| public @interface ApiVersion { | |||
| /** | |||
| * 接口版本号(对应swagger中的group) | |||
| * | |||
| * @return String[] | |||
| */ | |||
| String[] group(); | |||
| } | |||
| @@ -0,0 +1,14 @@ | |||
| package com.iformall.annotation; | |||
| import com.iformall.config.SwaggerConfiguration; | |||
| import org.springframework.context.annotation.Import; | |||
| import java.lang.annotation.*; | |||
| @Target({ElementType.TYPE}) | |||
| @Retention(RetentionPolicy.RUNTIME) | |||
| @Documented | |||
| @Inherited | |||
| @Import({SwaggerConfiguration.class}) | |||
| public @interface BaseEnableSwagger { | |||
| } | |||
| @@ -0,0 +1,94 @@ | |||
| package com.iformall.config; | |||
| import com.google.common.base.Predicate; | |||
| import com.google.common.base.Predicates; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | |||
| 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.service.ApiInfo; | |||
| import springfox.documentation.service.Contact; | |||
| import springfox.documentation.spi.DocumentationType; | |||
| import springfox.documentation.spring.web.plugins.Docket; | |||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| import javax.servlet.ServletContext; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| import java.util.List; | |||
| @Configuration | |||
| @EnableSwagger2 | |||
| @EnableAutoConfiguration | |||
| @EnableConfigurationProperties(SwaggerProperties.class) | |||
| @ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true) | |||
| public class SwaggerConfiguration { | |||
| private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error"); | |||
| private static final String BASE_PATH = "/**"; | |||
| @Autowired | |||
| private SwaggerProperties swaggerProperties; | |||
| /** | |||
| * 1、分组 | |||
| * 2、切换分组,修改访问/v2/api-docs/ 接口的路径 | |||
| * https://admintest.malls.iformall.com/v2/api-docs/ | |||
| * https://admintest.malls.iformall.com/B/v2/api-docs/ | |||
| * | |||
| * @param servletContext | |||
| * @return {@link Docket} | |||
| */ | |||
| @Bean | |||
| public Docket api(ServletContext servletContext) { | |||
| // base-path处理 | |||
| if (swaggerProperties.getBasePath().isEmpty()) { | |||
| swaggerProperties.getBasePath().add(BASE_PATH); | |||
| } | |||
| List<Predicate<String>> basePath = new ArrayList<>(swaggerProperties.getBasePath().size()); | |||
| swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path))); | |||
| // exclude-path处理 | |||
| if (swaggerProperties.getExcludePath().isEmpty()) { | |||
| swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH); | |||
| } | |||
| List<Predicate<String>> excludePath = new ArrayList<>(); | |||
| swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path))); | |||
| return new Docket(DocumentationType.SWAGGER_2) | |||
| .host(swaggerProperties.getHost()) | |||
| .apiInfo(apiInfo(swaggerProperties)).select() | |||
| .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage())) | |||
| .apis(input -> { | |||
| ApiVersion apiVersion = input.getHandlerMethod().getMethodAnnotation(ApiVersion.class); | |||
| return apiVersion != null && Arrays.asList(apiVersion.group()).contains(SwaggerConstant.V_1_0_0); | |||
| }) | |||
| .paths( | |||
| Predicates.and( | |||
| Predicates.not(Predicates.or(excludePath)), | |||
| Predicates.or(basePath) | |||
| ) | |||
| ) | |||
| .build(); | |||
| } | |||
| private ApiInfo apiInfo(SwaggerProperties swaggerProperties) { | |||
| return new ApiInfoBuilder() | |||
| .title(swaggerProperties.getTitle()) | |||
| .description(swaggerProperties.getDescription()) | |||
| .license(swaggerProperties.getLicense()) | |||
| .licenseUrl(swaggerProperties.getLicenseUrl()) | |||
| .termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl()) | |||
| .contact(new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail())) | |||
| .version(swaggerProperties.getVersion()) | |||
| .build(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,123 @@ | |||
| package com.iformall.config; | |||
| import lombok.Data; | |||
| import lombok.NoArgsConstructor; | |||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @Data | |||
| @ConfigurationProperties("swagger") | |||
| public class SwaggerProperties { | |||
| private Map<String, String> services; | |||
| private String prePath; | |||
| /** | |||
| * 是否开启swagger | |||
| */ | |||
| private Boolean enabled; | |||
| /** | |||
| * swagger会解析的包路径 | |||
| **/ | |||
| private String basePackage = ""; | |||
| /** | |||
| * swagger会解析的url规则 | |||
| **/ | |||
| private List<String> basePath = new ArrayList<>(); | |||
| /** | |||
| * 在basePath基础上需要排除的url规则 | |||
| **/ | |||
| private List<String> excludePath = new ArrayList<>(); | |||
| /** | |||
| * 标题 | |||
| **/ | |||
| private String title = ""; | |||
| /** | |||
| * 描述 | |||
| **/ | |||
| private String description = ""; | |||
| /** | |||
| * 版本 | |||
| **/ | |||
| private String version = ""; | |||
| /** | |||
| * 许可证 | |||
| **/ | |||
| private String license = ""; | |||
| /** | |||
| * 许可证URL | |||
| **/ | |||
| private String licenseUrl = ""; | |||
| /** | |||
| * 服务条款URL | |||
| **/ | |||
| private String termsOfServiceUrl = ""; | |||
| /** | |||
| * host信息 | |||
| **/ | |||
| private String host = ""; | |||
| /** | |||
| * 联系人信息 | |||
| */ | |||
| private Contact contact = new Contact(); | |||
| /** | |||
| * 全局统一鉴权配置 | |||
| **/ | |||
| private Authorization authorization = new Authorization(); | |||
| @Data | |||
| public static class Contact { | |||
| /** | |||
| * 联系人 | |||
| **/ | |||
| private String name = ""; | |||
| /** | |||
| * 联系人url | |||
| **/ | |||
| private String url = ""; | |||
| /** | |||
| * 联系人email | |||
| **/ | |||
| private String email = ""; | |||
| } | |||
| @Data | |||
| @NoArgsConstructor | |||
| public static class Authorization { | |||
| /** | |||
| * 鉴权策略ID,需要和SecurityReferences ID保持一致 | |||
| */ | |||
| private String name = ""; | |||
| /** | |||
| * 需要开启鉴权URL的正则 | |||
| */ | |||
| private String authRegex = "^.*$"; | |||
| /** | |||
| * 鉴权作用域列表 | |||
| */ | |||
| private List<AuthorizationScope> authorizationScopeList = new ArrayList<>(); | |||
| private List<String> tokenUrlList = new ArrayList<>(); | |||
| } | |||
| @Data | |||
| @NoArgsConstructor | |||
| public static class AuthorizationScope { | |||
| /** | |||
| * 作用域名称 | |||
| */ | |||
| private String scope = ""; | |||
| /** | |||
| * 作用域描述 | |||
| */ | |||
| private String description = ""; | |||
| } | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| package com.iformall.constant; | |||
| public interface SwaggerConstant { | |||
| /** | |||
| * | |||
| */ | |||
| String V_1_0_0 = "v1.0.0"; | |||
| } | |||
| @@ -25,6 +25,7 @@ | |||
| <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-validation:2.2.5.RELEASE" level="project" /> | |||
| <orderEntry type="library" name="Maven: jakarta.validation:jakarta.validation-api:2.0.2" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.18.Final" level="project" /> | |||
| <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.5.1" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.springframework:spring-web:5.2.4.RELEASE" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.2.4.RELEASE" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.2.4.RELEASE" level="project" /> | |||
| @@ -161,7 +162,7 @@ | |||
| <orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:3.13.2" level="project" /> | |||
| <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest:2.1" level="project" /> | |||
| <orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:3.1.0" level="project" /> | |||
| <orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.10.8" level="project" /> | |||
| <orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.10.8" level="project" /> | |||
| <orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.10.8" level="project" /> | |||
| <orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" /> | |||
| <orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.5.0" level="project" /> | |||
| @@ -184,21 +185,6 @@ | |||
| <orderEntry type="library" name="Maven: org.quartz-scheduler:quartz:2.3.0" level="project" /> | |||
| <orderEntry type="library" name="Maven: com.mchange:mchange-commons-java:0.2.11" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" /> | |||
| <orderEntry type="library" name="Maven: io.springfox:springfox-swagger2:2.8.0" level="project" /> | |||
| <orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.5.14" level="project" /> | |||
| <orderEntry type="library" name="Maven: io.swagger:swagger-models:1.5.14" level="project" /> | |||
| <orderEntry type="library" name="Maven: io.springfox:springfox-spi:2.8.0" level="project" /> | |||
| <orderEntry type="library" name="Maven: io.springfox:springfox-core:2.8.0" level="project" /> | |||
| <orderEntry type="library" name="Maven: io.springfox:springfox-schema:2.8.0" level="project" /> | |||
| <orderEntry type="library" name="Maven: io.springfox:springfox-swagger-common:2.8.0" level="project" /> | |||
| <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.5.1" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.mapstruct:mapstruct:1.2.0.Final" level="project" /> | |||
| <orderEntry type="library" name="Maven: io.springfox:springfox-swagger-ui:2.8.0" level="project" /> | |||
| <orderEntry type="library" name="Maven: io.springfox:springfox-spring-web:2.8.0" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.reflections:reflections:0.9.11" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" /> | |||
| <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.10.3" level="project" /> | |||
| <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.10.3" level="project" /> | |||
| <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.2" level="project" /> | |||
| @@ -239,6 +225,7 @@ | |||
| <orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:4.1.1" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:3.1.0" level="project" /> | |||
| <orderEntry type="library" name="Maven: ognl:ognl:3.2.6" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" /> | |||
| <orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.1.Final" level="project" /> | |||
| <orderEntry type="library" name="Maven: cn.afterturn:easypoi-annotation:4.1.3.A" level="project" /> | |||
| <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.2.5.RELEASE" level="project" /> | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall; | |||
| import com.iformall.annotation.BaseEnableSwagger; | |||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | |||
| import org.mybatis.spring.annotation.MapperScan; | |||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | |||
| @@ -18,7 +19,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| */ | |||
| @SpringBootApplication | |||
| @MapperScan(basePackages = {"com.iformall.mapper"}) | |||
| @EnableSwagger2 | |||
| @BaseEnableSwagger | |||
| @EnableEncryptableProperties | |||
| @EnableAsync | |||
| @EnableRocketMQ | |||
| @@ -139,6 +139,7 @@ public class ShiroConfig { | |||
| // } | |||
| // swagger-ui | |||
| filterChainDefinitionMap.put("/swagger-ui.html", "anon"); | |||
| filterChainDefinitionMap.put("/doc.html", "anon"); | |||
| filterChainDefinitionMap.put("/v2/**", "anon"); | |||
| filterChainDefinitionMap.put("/swagger-resources/**", "anon"); | |||
| filterChainDefinitionMap.put("/webjars/**", "anon"); | |||
| @@ -1,61 +1,61 @@ | |||
| package com.iformall.config; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import springfox.documentation.builders.ApiInfoBuilder; | |||
| import springfox.documentation.builders.ParameterBuilder; | |||
| import springfox.documentation.builders.PathSelectors; | |||
| import springfox.documentation.builders.RequestHandlerSelectors; | |||
| import springfox.documentation.schema.ModelRef; | |||
| import springfox.documentation.service.ApiInfo; | |||
| import springfox.documentation.service.Parameter; | |||
| import springfox.documentation.spi.DocumentationType; | |||
| import springfox.documentation.spring.web.paths.RelativePathProvider; | |||
| import springfox.documentation.spring.web.plugins.Docket; | |||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| import javax.servlet.ServletContext; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| //参考:http://blog.csdn.net/catoop/article/details/50668896 | |||
| @Configuration | |||
| @EnableSwagger2 | |||
| public class Swagger2Config { | |||
| @Autowired | |||
| private ServletContext servletContext; | |||
| @Bean | |||
| public Docket createRestApi() { | |||
| ParameterBuilder tokenPar = new ParameterBuilder(); | |||
| List<Parameter> pars = new ArrayList<Parameter>(); | |||
| //增加一个request的header参数 | |||
| tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||
| pars.add(tokenPar.build()); | |||
| return new Docket(DocumentationType.SWAGGER_2) | |||
| .apiInfo(apiInfo()) | |||
| .select() | |||
| .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||
| .paths(PathSelectors.any()) | |||
| .build() | |||
| .globalOperationParameters(pars) | |||
| .pathProvider(new RelativePathProvider(servletContext) { | |||
| @Override | |||
| public String getApplicationBasePath() { | |||
| return "/api"; | |||
| } | |||
| }); | |||
| } | |||
| private ApiInfo apiInfo() { | |||
| return new ApiInfoBuilder() | |||
| .title("a端 api") | |||
| .description("a api") | |||
| .termsOfServiceUrl("http://localhost:7000") | |||
| .version("2.0") | |||
| .build(); | |||
| } | |||
| } | |||
| //package com.iformall.config; | |||
| // | |||
| //import org.springframework.beans.factory.annotation.Autowired; | |||
| //import org.springframework.context.annotation.Bean; | |||
| //import org.springframework.context.annotation.Configuration; | |||
| //import springfox.documentation.builders.ApiInfoBuilder; | |||
| //import springfox.documentation.builders.ParameterBuilder; | |||
| //import springfox.documentation.builders.PathSelectors; | |||
| //import springfox.documentation.builders.RequestHandlerSelectors; | |||
| //import springfox.documentation.schema.ModelRef; | |||
| //import springfox.documentation.service.ApiInfo; | |||
| //import springfox.documentation.service.Parameter; | |||
| //import springfox.documentation.spi.DocumentationType; | |||
| //import springfox.documentation.spring.web.paths.RelativePathProvider; | |||
| //import springfox.documentation.spring.web.plugins.Docket; | |||
| //import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| // | |||
| //import javax.servlet.ServletContext; | |||
| //import java.util.ArrayList; | |||
| //import java.util.List; | |||
| // | |||
| ////参考:http://blog.csdn.net/catoop/article/details/50668896 | |||
| //@Configuration | |||
| //@EnableSwagger2 | |||
| //public class Swagger2Config { | |||
| // | |||
| // @Autowired | |||
| // private ServletContext servletContext; | |||
| // | |||
| // @Bean | |||
| // public Docket createRestApi() { | |||
| // ParameterBuilder tokenPar = new ParameterBuilder(); | |||
| // List<Parameter> pars = new ArrayList<Parameter>(); | |||
| // //增加一个request的header参数 | |||
| // tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||
| // pars.add(tokenPar.build()); | |||
| // return new Docket(DocumentationType.SWAGGER_2) | |||
| // .apiInfo(apiInfo()) | |||
| // .select() | |||
| // .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||
| // .paths(PathSelectors.any()) | |||
| // .build() | |||
| // .globalOperationParameters(pars) | |||
| // .pathProvider(new RelativePathProvider(servletContext) { | |||
| // @Override | |||
| // public String getApplicationBasePath() { | |||
| // return "/api"; | |||
| // } | |||
| // }); | |||
| // } | |||
| // | |||
| // private ApiInfo apiInfo() { | |||
| // return new ApiInfoBuilder() | |||
| // .title("a端 api") | |||
| // .description("a api") | |||
| // .termsOfServiceUrl("http://localhost:7000") | |||
| // .version("2.0") | |||
| // .build(); | |||
| // } | |||
| // | |||
| //} | |||
| @@ -100,7 +100,9 @@ public class WebConfig implements WebMvcConfigurer { | |||
| @Override | |||
| public void addResourceHandlers(ResourceHandlerRegistry registry) { | |||
| registry.addResourceHandler("swagger-ui.html") | |||
| // registry.addResourceHandler("swagger-ui.html") | |||
| // .addResourceLocations("classpath:/META-INF/resources/"); | |||
| registry.addResourceHandler("doc.html") | |||
| .addResourceLocations("classpath:/META-INF/resources/"); | |||
| registry.addResourceHandler("/webjars/**") | |||
| .addResourceLocations("classpath:/META-INF/resources/webjars/"); | |||
| @@ -1,26 +0,0 @@ | |||
| package com.iformall.controller.sm; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.sm.SaveApiMenuDTO; | |||
| import com.iformall.domain.po.sm.ApiDetail; | |||
| import com.iformall.service.sm.ApiDetailService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| @RestController | |||
| @RequestMapping("/apiDetail") | |||
| @Api(tags = "api菜单详情接口") | |||
| public class ApiDetailController { | |||
| @Autowired | |||
| private ApiDetailService apiDetailService; | |||
| @ApiOperation("查询单个api菜单详情") | |||
| @GetMapping("/get") | |||
| public ResultData getApiDetail(Long id) { | |||
| ApiDetail apiDetail = apiDetailService.getApiDetail(id); | |||
| return new ResultData(apiDetail); | |||
| } | |||
| } | |||
| @@ -1,6 +1,10 @@ | |||
| package com.iformall.controller.sm; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.common.R; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.domain.dto.sm.SaveApiGuideDTO; | |||
| import com.iformall.domain.dto.sm.UpdateApiGuideDTO; | |||
| import com.iformall.domain.po.sm.ApiGuide; | |||
| @@ -18,23 +22,26 @@ public class ApiGuideController { | |||
| @Autowired | |||
| private ApiGuideService apiGuideService; | |||
| @ApiOperation("分页查询api菜单") | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("分页查询api指南") | |||
| @GetMapping("/page") | |||
| public ResultData pageApiGuide(ApiGuide apiGuide, Integer pageNum, Integer pageSize) { | |||
| return new ResultData(apiGuideService.pageApiGuide(apiGuide, pageNum, pageSize)); | |||
| public R<PageInfo<ApiGuide>> pageApiGuide(ApiGuide apiGuide, Integer pageNum, Integer pageSize) { | |||
| return R.ok(apiGuideService.pageApiGuide(apiGuide, pageNum, pageSize)); | |||
| } | |||
| @ApiOperation("新增api菜单") | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("新增api指南") | |||
| @PostMapping("/save") | |||
| public ResultData saveApiGuide(@RequestBody SaveApiGuideDTO dto) { | |||
| public R<Void> saveApiGuide(@RequestBody SaveApiGuideDTO dto) { | |||
| apiGuideService.saveApiGuide(dto); | |||
| return new ResultData(); | |||
| return R.ok(); | |||
| } | |||
| @ApiOperation("修改api菜单") | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("修改api指南") | |||
| @PostMapping("/update") | |||
| public ResultData updateApiGuide(@RequestBody UpdateApiGuideDTO dto) { | |||
| public R<Void> updateApiGuide(@RequestBody UpdateApiGuideDTO dto) { | |||
| apiGuideService.updateApiGuide(dto); | |||
| return new ResultData(); | |||
| return R.ok(); | |||
| } | |||
| } | |||
| @@ -1,10 +1,15 @@ | |||
| package com.iformall.controller.sm; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.R; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.domain.dto.sm.SaveApiMenuDTO; | |||
| import com.iformall.domain.dto.sm.UpdateApiMenuDTO; | |||
| import com.iformall.domain.po.sm.ApiMenu; | |||
| import com.iformall.domain.vo.sm.ApiMenuVO; | |||
| import com.iformall.exception.BizException; | |||
| import com.iformall.service.sm.ApiMenuService; | |||
| import io.swagger.annotations.Api; | |||
| @@ -12,6 +17,8 @@ import io.swagger.annotations.ApiOperation; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.List; | |||
| @RestController | |||
| @RequestMapping("/apiMenu") | |||
| @Api(tags = "api菜单接口") | |||
| @@ -20,38 +27,43 @@ public class ApiMenuController { | |||
| @Autowired | |||
| private ApiMenuService apiMenuService; | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("分页查询api菜单") | |||
| @GetMapping("/page") | |||
| public ResultData pageApiMenu(ApiMenu ApiMenu, Integer pageNum, Integer pageSize) { | |||
| return new ResultData(apiMenuService.pageApiMenu(ApiMenu, pageNum, pageSize)); | |||
| public R<PageInfo<ApiMenuVO>> pageApiMenu(ApiMenu ApiMenu, Integer pageNum, Integer pageSize) { | |||
| return R.ok(apiMenuService.pageApiMenu(ApiMenu, pageNum, pageSize)); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("单个查询api菜单") | |||
| @GetMapping("/get") | |||
| public ResultData getApiMenu(Long id) { | |||
| public R<ApiMenuVO> getApiMenu(Long id) { | |||
| if (id == null) { | |||
| throw new BizException(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| return new ResultData(apiMenuService.getApiMenu(id)); | |||
| return R.ok(apiMenuService.getApiMenu(id)); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("新增api菜单") | |||
| @PostMapping("/save") | |||
| public ResultData saveApiMenu(@RequestBody SaveApiMenuDTO dto) { | |||
| public R<Void> saveApiMenu(@RequestBody SaveApiMenuDTO dto) { | |||
| apiMenuService.saveApiMenu(dto); | |||
| return new ResultData(); | |||
| return R.ok(); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("修改api菜单") | |||
| @PostMapping("/update") | |||
| public ResultData updateApiMenu(@RequestBody UpdateApiMenuDTO dto) { | |||
| public R<Void> updateApiMenu(@RequestBody UpdateApiMenuDTO dto) { | |||
| apiMenuService.updateApiMenu(dto); | |||
| return new ResultData(); | |||
| return R.ok(); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("全查询父级api菜单") | |||
| @GetMapping("/listParentMenu") | |||
| public ResultData listParentMenu() { | |||
| return new ResultData(apiMenuService.listParentMenu()); | |||
| public R<List<ApiMenu>> listParentMenu() { | |||
| return R.ok(apiMenuService.listParentMenu()); | |||
| } | |||
| } | |||
| @@ -1,6 +1,10 @@ | |||
| package com.iformall.controller.sm; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.common.R; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.dto.sm.SaveServiceInfoDTO; | |||
| import com.iformall.domain.dto.sm.UpdateServiceInfoDTO; | |||
| @@ -20,30 +24,34 @@ public class ServiceInfoController extends BaseController { | |||
| @Autowired | |||
| private ServiceInfoService serviceInfoService; | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("分页查询合作商") | |||
| @GetMapping("/page") | |||
| public ResultData pageServiceInfo(ServiceInfo serviceInfo, Integer pageNum, Integer pageSize) { | |||
| return new ResultData(serviceInfoService.pageServiceInfo(serviceInfo, pageNum, pageSize)); | |||
| public R<PageInfo<ServiceInfo>> pageServiceInfo(ServiceInfo serviceInfo, Integer pageNum, Integer pageSize) { | |||
| return R.ok(serviceInfoService.pageServiceInfo(serviceInfo, pageNum, pageSize)); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("新增合作商") | |||
| @PostMapping("/save") | |||
| public ResultData saveServiceInfo(@RequestBody SaveServiceInfoDTO dto) { | |||
| public R<Void> saveServiceInfo(@RequestBody SaveServiceInfoDTO dto) { | |||
| serviceInfoService.saveServiceInfo(dto); | |||
| return new ResultData(); | |||
| return R.ok(); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("修改合作商") | |||
| @PostMapping("/update") | |||
| public ResultData updateServiceInfo(@RequestBody UpdateServiceInfoDTO dto) { | |||
| public R<Void> updateServiceInfo(@RequestBody UpdateServiceInfoDTO dto) { | |||
| serviceInfoService.updateServiceInfo(dto); | |||
| return new ResultData(); | |||
| return R.ok(); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("修改合作商状态") | |||
| @PostMapping("/updateStatus") | |||
| public ResultData updateServiceInfoStatus(@RequestBody UpdateServiceInfoStatusDTO dto) { | |||
| public R<Void> updateServiceInfoStatus(@RequestBody UpdateServiceInfoStatusDTO dto) { | |||
| serviceInfoService.updateServiceInfoStatus(dto); | |||
| return new ResultData(); | |||
| return R.ok(); | |||
| } | |||
| } | |||
| @@ -1,7 +1,11 @@ | |||
| package com.iformall.controller.sm; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.R; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.domain.dto.sm.UpdateThirdPartyApiStatusDTO; | |||
| import com.iformall.domain.po.WxThirdPartyApi; | |||
| import com.iformall.exception.BizException; | |||
| @@ -19,25 +23,28 @@ public class ThirdPartyApiController { | |||
| @Autowired | |||
| private WxThirdPartyApiService thirdPartyApiService; | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("分页查询秘钥") | |||
| @GetMapping("/page") | |||
| public ResultData pageThirdPartyApi(WxThirdPartyApi thirdPartyApi, Integer pageNum, Integer pageSize) { | |||
| return new ResultData(thirdPartyApiService.pageThirdPartyApi(thirdPartyApi, pageNum, pageSize)); | |||
| public R<PageInfo<WxThirdPartyApi>> pageThirdPartyApi(WxThirdPartyApi thirdPartyApi, Integer pageNum, Integer pageSize) { | |||
| return R.ok(thirdPartyApiService.pageThirdPartyApi(thirdPartyApi, pageNum, pageSize)); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("单个查询秘钥") | |||
| @GetMapping("/get") | |||
| public ResultData getThirdPartyApi(Long id) { | |||
| public R<WxThirdPartyApi> getThirdPartyApi(Long id) { | |||
| if (id == null) { | |||
| throw new BizException(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| return new ResultData(thirdPartyApiService.getThirdPartyApi(id)); | |||
| return R.ok(thirdPartyApiService.getThirdPartyApi(id)); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("修改秘钥状态") | |||
| @PostMapping("/updateStatus") | |||
| public ResultData updateThirdPartyApiStatus(@RequestBody UpdateThirdPartyApiStatusDTO dto) { | |||
| public R<Void> updateThirdPartyApiStatus(@RequestBody UpdateThirdPartyApiStatusDTO dto) { | |||
| thirdPartyApiService.updateThirdPartyApiStatus(dto); | |||
| return new ResultData(); | |||
| return R.ok(); | |||
| } | |||
| } | |||
| @@ -2,9 +2,11 @@ package com.iformall.controller.sys; | |||
| import com.google.code.kaptcha.Constants; | |||
| import com.google.code.kaptcha.Producer; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| @@ -75,6 +77,7 @@ public class HomeController extends BaseController { | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| RedisTemplate<String, Object> redisTemplate; | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("验证码") | |||
| @GetMapping("/captcha.jpg") | |||
| public void captcha(HttpServletResponse response)throws ServletException, IOException { | |||
| @@ -97,6 +100,7 @@ public class HomeController extends BaseController { | |||
| IOUtils.closeQuietly(out); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("登录") | |||
| @PostMapping("/doLogin") | |||
| public ResultData login(@RequestBody MallUserInfo user, HttpServletResponse response) { | |||
| @@ -1,10 +1,12 @@ | |||
| package com.iformall.controller.sys; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| @@ -43,6 +45,7 @@ public class MallRoleController extends BaseController { | |||
| @Autowired | |||
| private MallUserRoleService mallUserRoleService; | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("角色列表") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -95,7 +98,7 @@ public class MallRoleController extends BaseController { | |||
| return new ResultData(role); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("角色保存") | |||
| @PostMapping("saveOrUpdate") | |||
| //@RequiresPermissions("sys:role:save") | |||
| @@ -126,6 +129,7 @@ public class MallRoleController extends BaseController { | |||
| return new ResultData(); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("角色删除") | |||
| @PostMapping("/del") | |||
| //@RequiresPermissions("sys:role:del") | |||
| @@ -1,10 +1,12 @@ | |||
| package com.iformall.controller.sys; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| @@ -60,6 +62,7 @@ public class MallUserInfoController extends BaseController { | |||
| @Autowired | |||
| WxMsgValidationcodeService wxMsgValidationcodeService; | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation(value = "用户分页接口", response = String.class) | |||
| @GetMapping("lists") | |||
| //@RequiresPermissions("sys:user:list") | |||
| @@ -110,6 +113,7 @@ public class MallUserInfoController extends BaseController { | |||
| return new ResultData(user); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation(value = "创建用户接口", response = String.class) | |||
| @PostMapping("add") | |||
| //@RequiresPermissions("sys:user:add") | |||
| @@ -147,6 +151,7 @@ public class MallUserInfoController extends BaseController { | |||
| return new ResultData(userInfo); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation(value = "修改用户接口", response = String.class) | |||
| @PostMapping("update") | |||
| //@RequiresPermissions("sys:user:update") | |||
| @@ -225,6 +230,7 @@ public class MallUserInfoController extends BaseController { | |||
| return new ResultData(); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation(value = "删除用户接口", response = String.class) | |||
| @PostMapping("/del") | |||
| //@RequiresPermissions("sys:user:del") | |||
| @@ -320,6 +326,7 @@ public class MallUserInfoController extends BaseController { | |||
| return new ResultData(menu); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation(value = "用户密码发送验证码") | |||
| @GetMapping("sendvalidationcode") | |||
| @ApiImplicitParams({ | |||
| @@ -353,6 +360,7 @@ public class MallUserInfoController extends BaseController { | |||
| return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation(value = "修改密码", notes = "{\"userName\",\"string\",\"code\",\"string\",\"pwd\",\"string\"}") | |||
| @PostMapping("/updatepwd") | |||
| @SystemControllerLog(description = "用户管理-修改密码") | |||
| @@ -1,9 +1,11 @@ | |||
| package com.iformall.controller.sys; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.MallPermission; | |||
| import com.iformall.domain.po.MallRole; | |||
| @@ -65,6 +67,7 @@ public class SysMenuController extends BaseController { | |||
| return new ResultData(map); | |||
| } | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("所有菜单列表") | |||
| @GetMapping("list") | |||
| //@RequiresPermissions("sys:menu:list") | |||
| @@ -209,4 +209,18 @@ suimang: | |||
| photo_speak_hy: xxx | |||
| digital_avatar: xxx | |||
| digital_avatar_hy: xxx | |||
| callbackUrl: xxx | |||
| callbackUrl: xxx | |||
| swagger: | |||
| base-package: com.iformall.controller | |||
| title: 遂芒_metavatar_接口文档 | |||
| description: 前后端联调 | |||
| version: 1.0 | |||
| license: Apache | |||
| license-url: https://mtest.metavatar.cc/ | |||
| terms-of-service-url: https://mtest.metavatar.cc/ | |||
| host: localhost:8888 | |||
| contact: | |||
| name: 张三 | |||
| url: https://mtest.metavatar.cc/ | |||
| email: zhangsan@163.com | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall; | |||
| import com.iformall.annotation.BaseEnableSwagger; | |||
| import org.mybatis.spring.annotation.MapperScan; | |||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| @@ -15,6 +16,7 @@ import org.springframework.scheduling.annotation.EnableAsync; | |||
| * @author chenkx | |||
| * @date 2017-12-26 | |||
| */ | |||
| @BaseEnableSwagger | |||
| @SpringBootApplication | |||
| @MapperScan(basePackages = {"com.iformall.mapper"}) | |||
| @EnableEncryptableProperties | |||
| @@ -1,61 +1,61 @@ | |||
| package com.iformall.config; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import springfox.documentation.builders.ApiInfoBuilder; | |||
| import springfox.documentation.builders.ParameterBuilder; | |||
| import springfox.documentation.builders.PathSelectors; | |||
| import springfox.documentation.builders.RequestHandlerSelectors; | |||
| import springfox.documentation.schema.ModelRef; | |||
| import springfox.documentation.service.ApiInfo; | |||
| import springfox.documentation.service.Parameter; | |||
| import springfox.documentation.spi.DocumentationType; | |||
| import springfox.documentation.spring.web.paths.RelativePathProvider; | |||
| import springfox.documentation.spring.web.plugins.Docket; | |||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| import javax.servlet.ServletContext; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| //参考:http://blog.csdn.net/catoop/article/details/50668896 | |||
| @Configuration | |||
| @EnableSwagger2 | |||
| public class Swagger2Config { | |||
| @Autowired | |||
| private ServletContext servletContext; | |||
| @Bean | |||
| public Docket createRestApi() { | |||
| ParameterBuilder tokenPar = new ParameterBuilder(); | |||
| List<Parameter> pars = new ArrayList<Parameter>(); | |||
| //增加一个request的header参数 | |||
| tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||
| pars.add(tokenPar.build()); | |||
| return new Docket(DocumentationType.SWAGGER_2) | |||
| .apiInfo(apiInfo()) | |||
| .select() | |||
| .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||
| .paths(PathSelectors.any()) | |||
| .build() | |||
| .globalOperationParameters(pars) | |||
| .pathProvider(new RelativePathProvider(servletContext) { | |||
| @Override | |||
| public String getApplicationBasePath() { | |||
| return "/api"; | |||
| } | |||
| }); | |||
| } | |||
| private ApiInfo apiInfo() { | |||
| return new ApiInfoBuilder() | |||
| .title("c端 api") | |||
| .description("c api") | |||
| .termsOfServiceUrl("http://localhost:7000") | |||
| .version("2.0") | |||
| .build(); | |||
| } | |||
| } | |||
| //package com.iformall.config; | |||
| // | |||
| //import org.springframework.beans.factory.annotation.Autowired; | |||
| //import org.springframework.context.annotation.Bean; | |||
| //import org.springframework.context.annotation.Configuration; | |||
| //import springfox.documentation.builders.ApiInfoBuilder; | |||
| //import springfox.documentation.builders.ParameterBuilder; | |||
| //import springfox.documentation.builders.PathSelectors; | |||
| //import springfox.documentation.builders.RequestHandlerSelectors; | |||
| //import springfox.documentation.schema.ModelRef; | |||
| //import springfox.documentation.service.ApiInfo; | |||
| //import springfox.documentation.service.Parameter; | |||
| //import springfox.documentation.spi.DocumentationType; | |||
| //import springfox.documentation.spring.web.paths.RelativePathProvider; | |||
| //import springfox.documentation.spring.web.plugins.Docket; | |||
| //import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| // | |||
| //import javax.servlet.ServletContext; | |||
| //import java.util.ArrayList; | |||
| //import java.util.List; | |||
| // | |||
| ////参考:http://blog.csdn.net/catoop/article/details/50668896 | |||
| //@Configuration | |||
| //@EnableSwagger2 | |||
| //public class Swagger2Config { | |||
| // | |||
| // @Autowired | |||
| // private ServletContext servletContext; | |||
| // | |||
| // @Bean | |||
| // public Docket createRestApi() { | |||
| // ParameterBuilder tokenPar = new ParameterBuilder(); | |||
| // List<Parameter> pars = new ArrayList<Parameter>(); | |||
| // //增加一个request的header参数 | |||
| // tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||
| // pars.add(tokenPar.build()); | |||
| // return new Docket(DocumentationType.SWAGGER_2) | |||
| // .apiInfo(apiInfo()) | |||
| // .select() | |||
| // .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||
| // .paths(PathSelectors.any()) | |||
| // .build() | |||
| // .globalOperationParameters(pars) | |||
| // .pathProvider(new RelativePathProvider(servletContext) { | |||
| // @Override | |||
| // public String getApplicationBasePath() { | |||
| // return "/api"; | |||
| // } | |||
| // }); | |||
| // } | |||
| // | |||
| // private ApiInfo apiInfo() { | |||
| // return new ApiInfoBuilder() | |||
| // .title("c端 api") | |||
| // .description("c api") | |||
| // .termsOfServiceUrl("http://localhost:7000") | |||
| // .version("2.0") | |||
| // .build(); | |||
| // } | |||
| // | |||
| //} | |||
| @@ -54,7 +54,9 @@ public class WebMvcConfig implements WebMvcConfigurer { | |||
| @Override | |||
| public void addResourceHandlers(ResourceHandlerRegistry registry) { | |||
| registry.addResourceHandler("swagger-ui.html") | |||
| // registry.addResourceHandler("swagger-ui.html") | |||
| // .addResourceLocations("classpath:/META-INF/resources/"); | |||
| registry.addResourceHandler("doc.html") | |||
| .addResourceLocations("classpath:/META-INF/resources/"); | |||
| registry.addResourceHandler("/webjars/**") | |||
| .addResourceLocations("classpath:/META-INF/resources/webjars/"); | |||
| @@ -0,0 +1,32 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.annotation.AuthIgnore; | |||
| import com.iformall.common.R; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.domain.po.sm.ApiGuide; | |||
| import com.iformall.service.sm.ApiGuideService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| @RestController | |||
| @RequestMapping("/api/apiGuide") | |||
| @Api(tags = "api指南接口") | |||
| public class ApiGuideController { | |||
| @Autowired | |||
| private ApiGuideService apiGuideService; | |||
| @AuthIgnore | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("单个查询api指南") | |||
| @GetMapping("/getAvailableApiGuide") | |||
| public R<ApiGuide> getAvailableApiGuide() { | |||
| return R.ok(apiGuideService.getAvailableApiGuide()); | |||
| } | |||
| } | |||
| @@ -0,0 +1,58 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.annotation.AuthIgnore; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.R; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.domain.po.sm.ApiMenu; | |||
| import com.iformall.domain.vo.sm.ApiMenuVO; | |||
| import com.iformall.domain.vo.sm.ListApiSubmenuVO; | |||
| import com.iformall.exception.BizException; | |||
| import com.iformall.service.sm.ApiMenuService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.List; | |||
| @RestController | |||
| @RequestMapping("/api/apiMenu") | |||
| @Api(tags = "api菜单接口") | |||
| public class ApiMenuController { | |||
| @Autowired | |||
| private ApiMenuService apiMenuService; | |||
| @AuthIgnore | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("全查询api菜单") | |||
| @GetMapping("/list") | |||
| public R<List<ApiMenu>> listApiMenu() { | |||
| return R.ok(apiMenuService.listMenu()); | |||
| } | |||
| @AuthIgnore | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("查询某个api菜单所有子菜单") | |||
| @GetMapping("/listSubmenu") | |||
| public R<List<ListApiSubmenuVO>> listApiSubmenu(Long id) { | |||
| if (id == null) { | |||
| throw new BizException(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| return R.ok(apiMenuService.listApiSubmenu(id)); | |||
| } | |||
| @AuthIgnore | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("单个查询菜单详情") | |||
| @GetMapping("/get") | |||
| public R<ApiMenuVO> getApiMenu(Long id) { | |||
| if (id == null) { | |||
| throw new BizException(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| return R.ok(apiMenuService.getApiMenu(id)); | |||
| } | |||
| } | |||
| @@ -44,7 +44,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||
| @Override | |||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |||
| AuthIgnore annotation; | |||
| if(handler instanceof HandlerMethod) { | |||
| annotation = ((HandlerMethod) handler).getMethodAnnotation(AuthIgnore.class); | |||
| @@ -196,3 +196,17 @@ suimang: | |||
| digital_avatar: http://nas.pucao.cn:2005 | |||
| digital_avatar_hy: http://nas.pucao.cn:2003 | |||
| callbackUrl: https://mtest.metavatar.cc/C | |||
| swagger: | |||
| base-package: com.iformall.controller | |||
| title: 遂芒_metavatar_接口文档 | |||
| description: 前后端联调 | |||
| version: 1.0 | |||
| license: Apache | |||
| license-url: https://mtest.metavatar.cc/ | |||
| terms-of-service-url: https://mtest.metavatar.cc/ | |||
| host: localhost:8888 | |||
| contact: | |||
| name: 张三 | |||
| url: https://mtest.metavatar.cc/ | |||
| email: zhangsan@163.com | |||
| @@ -20,6 +20,11 @@ | |||
| <scope>compile</scope> | |||
| </dependency> | |||
| --> | |||
| <dependency> | |||
| <groupId>com.iformall</groupId> | |||
| <artifactId>suimang-swagger</artifactId> | |||
| <version>1.0</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.iformall</groupId> | |||
| <artifactId>suimangVideo</artifactId> | |||
| @@ -1,6 +1,12 @@ | |||
| package com.iformall.common; | |||
| public interface CommonConstants { | |||
| /** | |||
| * 接口响应码:200:成功 500:失败 | |||
| */ | |||
| Integer SUCCESS = 200; | |||
| Integer FAILED = 500; | |||
| /** | |||
| * 状态(0:正常,1:锁定) | |||
| */ | |||
| @@ -681,6 +681,9 @@ public enum ErrorCode{ | |||
| SECRET_NOT_EXISTS(71001, "该秘钥不存在"), | |||
| SERVICE_LOCKED(71002, "合作商被锁定,无法修改"), | |||
| NAME_REPEAT(81000, "名称重复"), | |||
| EXIST_AVAILABLE_GUIDE(81001, "存在可用指南"), | |||
| ; | |||
| private int code; | |||
| @@ -0,0 +1,76 @@ | |||
| package com.iformall.common; | |||
| import io.swagger.annotations.ApiModel; | |||
| import io.swagger.annotations.ApiModelProperty; | |||
| import lombok.Data; | |||
| import java.io.Serializable; | |||
| /** | |||
| * 响应信息主体 | |||
| * | |||
| * @author xmzhao71 | |||
| * @date 2023-10-26 | |||
| */ | |||
| @ApiModel(description = "响应信息主体") | |||
| @Data | |||
| public class R<T> implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @ApiModelProperty(value = "返回标记:成功=0,失败=1") | |||
| private int code; | |||
| @ApiModelProperty(value = "返回信息") | |||
| private String message; | |||
| @ApiModelProperty(value = "数据") | |||
| private T data; | |||
| public Boolean isOk() { | |||
| return code == 200; | |||
| } | |||
| public static <T> R<T> ok() { | |||
| return restResult(null, CommonConstants.SUCCESS, null); | |||
| } | |||
| public static <T> R<T> ok(T data) { | |||
| return restResult(data, CommonConstants.SUCCESS, null); | |||
| } | |||
| public static <T> R<T> ok(T data, String msg) { | |||
| return restResult(data, CommonConstants.SUCCESS, msg); | |||
| } | |||
| public static <T> R<T> failed() { | |||
| return restResult(null, CommonConstants.FAILED, null); | |||
| } | |||
| public static <T> R<T> failed(String msg) { | |||
| return restResult(null, CommonConstants.FAILED, msg); | |||
| } | |||
| public static <T> R<T> failed(T data) { | |||
| return restResult(data, CommonConstants.FAILED, null); | |||
| } | |||
| public static <T> R<T> failed(T data, String msg) { | |||
| return restResult(data, CommonConstants.FAILED, msg); | |||
| } | |||
| public static <T> R<T> failed(T data, int code, String msg) { | |||
| return restResult(data, code, msg); | |||
| } | |||
| public static <T> R<T> failed(int code, String msg) { | |||
| return restResult(null, code, msg); | |||
| } | |||
| private static <T> R<T> restResult(T data, int code, String msg) { | |||
| R<T> apiResult = new R<>(); | |||
| apiResult.setCode(code); | |||
| apiResult.setData(data); | |||
| apiResult.setMessage(msg); | |||
| return apiResult; | |||
| } | |||
| } | |||
| @@ -0,0 +1,27 @@ | |||
| package com.iformall.domain.vo.sm; | |||
| import com.iformall.domain.po.sm.ApiDetail; | |||
| import com.iformall.domain.po.sm.ApiMenu; | |||
| import io.swagger.annotations.ApiModel; | |||
| import io.swagger.annotations.ApiModelProperty; | |||
| import lombok.Data; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @ApiModel(value = "查询某个api菜单所有子菜单相应数据") | |||
| @Data | |||
| public class ListApiSubmenuVO { | |||
| @ApiModelProperty("菜单id") | |||
| private Long id; | |||
| @ApiModelProperty("修改时间") | |||
| private Date updateTime; | |||
| @ApiModelProperty("菜单名称") | |||
| private String name; | |||
| @ApiModelProperty("状态(0:正常,1:锁定)") | |||
| private Integer status; | |||
| @ApiModelProperty("详情id") | |||
| private Long detailId; | |||
| @ApiModelProperty("接口描述") | |||
| private String description; | |||
| } | |||
| @@ -3,6 +3,7 @@ package com.iformall.mapper; | |||
| import com.iformall.domain.po.sm.ApiMenu; | |||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
| import com.iformall.domain.vo.sm.ApiMenuVO; | |||
| import com.iformall.domain.vo.sm.ListApiSubmenuVO; | |||
| import java.util.List; | |||
| @@ -16,6 +17,8 @@ public interface ApiMenuMapper extends BaseMapper<ApiMenu> { | |||
| List<ApiMenu> listParentMenu(); | |||
| List<ApiMenuVO> listApiMenuAndDetail(ApiMenu apiMenu); | |||
| List<ListApiSubmenuVO> listSubmenu(Long id); | |||
| } | |||
| @@ -16,4 +16,6 @@ public interface ApiGuideService extends IService<ApiGuide> { | |||
| void saveApiGuide(SaveApiGuideDTO dto); | |||
| void updateApiGuide(UpdateApiGuideDTO dto); | |||
| ApiGuide getAvailableApiGuide(); | |||
| } | |||
| @@ -6,6 +6,7 @@ import com.iformall.domain.dto.sm.UpdateApiMenuDTO; | |||
| import com.iformall.domain.po.sm.ApiMenu; | |||
| import com.baomidou.mybatisplus.extension.service.IService; | |||
| import com.iformall.domain.vo.sm.ApiMenuVO; | |||
| import com.iformall.domain.vo.sm.ListApiSubmenuVO; | |||
| import java.util.List; | |||
| @@ -23,4 +24,8 @@ public interface ApiMenuService extends IService<ApiMenu> { | |||
| List<ApiMenu> listParentMenu(); | |||
| ApiMenuVO getApiMenu(Long id); | |||
| List<ApiMenu> listMenu(); | |||
| List<ListApiSubmenuVO> listApiSubmenu(Long id); | |||
| } | |||
| @@ -1,16 +1,23 @@ | |||
| package com.iformall.service.sm.impl; | |||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.CommonConstants; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.dto.sm.SaveApiGuideDTO; | |||
| import com.iformall.domain.dto.sm.UpdateApiGuideDTO; | |||
| import com.iformall.domain.po.sm.ApiGuide; | |||
| import com.iformall.exception.BizException; | |||
| import com.iformall.service.sm.ApiGuideService; | |||
| import com.iformall.mapper.ApiGuideMapper; | |||
| import org.apache.commons.collections.CollectionUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.List; | |||
| /** | |||
| * | |||
| */ | |||
| @@ -27,15 +34,52 @@ public class ApiGuideServiceImpl extends ServiceImpl<ApiGuideMapper, ApiGuide> i | |||
| @Override | |||
| public void saveApiGuide(SaveApiGuideDTO dto) { | |||
| ApiGuide dbApiGuide = apiGuideMapper.selectOne(new LambdaQueryWrapper<ApiGuide>().eq(ApiGuide::getName, dto.getName())); | |||
| if (dbApiGuide != null) { | |||
| throw new BizException(ErrorCode.NAME_REPEAT); | |||
| } | |||
| // 暂时处理,存在正常的指南,则不可新增新的正常指南 | |||
| List<ApiGuide> apiGuides = apiGuideMapper.selectList(new LambdaQueryWrapper<ApiGuide>() | |||
| .eq(ApiGuide::getStatus, CommonConstants.STATUS_NORMAL) | |||
| .eq(ApiGuide::getDeleteFlag, CommonConstants.FLAG_FALSE)); | |||
| if (CommonConstants.STATUS_NORMAL.equals(dto.getStatus()) && !CollectionUtils.isEmpty(apiGuides)) { | |||
| throw new BizException(ErrorCode.EXIST_AVAILABLE_GUIDE); | |||
| } | |||
| ApiGuide apiGuide = SaveApiGuideDTO.mapping(dto); | |||
| apiGuideMapper.insert(apiGuide); | |||
| } | |||
| @Override | |||
| public void updateApiGuide(UpdateApiGuideDTO dto) { | |||
| ApiGuide dbApiGuide = apiGuideMapper.selectOne(new LambdaQueryWrapper<ApiGuide>() | |||
| .eq(ApiGuide::getName, dto.getName()) | |||
| .ne(ApiGuide::getId, dto.getId())); | |||
| if (dbApiGuide != null) { | |||
| throw new BizException(ErrorCode.NAME_REPEAT); | |||
| } | |||
| // 暂时处理,存在正常的指南,则不可修改新的正常指南 | |||
| List<ApiGuide> apiGuides = apiGuideMapper.selectList(new LambdaQueryWrapper<ApiGuide>() | |||
| .eq(ApiGuide::getStatus, CommonConstants.STATUS_NORMAL) | |||
| .eq(ApiGuide::getDeleteFlag, CommonConstants.FLAG_FALSE) | |||
| .ne(ApiGuide::getId, dto.getId())); | |||
| if (CommonConstants.STATUS_NORMAL.equals(dto.getStatus()) && !CollectionUtils.isEmpty(apiGuides)) { | |||
| throw new BizException(ErrorCode.EXIST_AVAILABLE_GUIDE); | |||
| } | |||
| ApiGuide apiGuide = UpdateApiGuideDTO.mapping(dto); | |||
| apiGuideMapper.updateById(apiGuide); | |||
| } | |||
| @Override | |||
| public ApiGuide getAvailableApiGuide() { | |||
| ApiGuide apiGuide = new ApiGuide(); | |||
| apiGuide.setStatus(CommonConstants.STATUS_NORMAL); | |||
| List<ApiGuide> apiGuides = apiGuideMapper.listApiGuide(apiGuide); | |||
| return !CollectionUtils.isEmpty(apiGuides) ? apiGuides.get(0) : null; | |||
| } | |||
| } | |||
| @@ -10,6 +10,7 @@ import com.iformall.domain.dto.sm.UpdateApiMenuDTO; | |||
| import com.iformall.domain.po.sm.ApiDetail; | |||
| import com.iformall.domain.po.sm.ApiMenu; | |||
| import com.iformall.domain.vo.sm.ApiMenuVO; | |||
| import com.iformall.domain.vo.sm.ListApiSubmenuVO; | |||
| import com.iformall.mapper.ApiDetailMapper; | |||
| import com.iformall.service.sm.ApiMenuService; | |||
| import com.iformall.mapper.ApiMenuMapper; | |||
| @@ -76,6 +77,16 @@ public class ApiMenuServiceImpl extends ServiceImpl<ApiMenuMapper, ApiMenu> impl | |||
| public List<ApiMenu> listParentMenu() { | |||
| return apiMenuMapper.listParentMenu(); | |||
| } | |||
| @Override | |||
| public List<ApiMenu> listMenu() { | |||
| return apiMenuMapper.listApiMenu(null); | |||
| } | |||
| @Override | |||
| public List<ListApiSubmenuVO> listApiSubmenu(Long id) { | |||
| return apiMenuMapper.listSubmenu(id); | |||
| } | |||
| } | |||
| @@ -30,7 +30,7 @@ | |||
| and `name` = #{name} | |||
| </if> | |||
| <if test=" null != status "> | |||
| and `status = #{status} | |||
| and `status` = #{status} | |||
| </if> | |||
| </sql> | |||
| @@ -79,4 +79,13 @@ | |||
| LEFT JOIN api_detail d ON m.id = d.menu_id | |||
| <include refid="dynamicWhereConditions"/> | |||
| </select> | |||
| <select id="listSubmenu" resultType="com.iformall.domain.vo.sm.ListApiSubmenuVO"> | |||
| SELECT | |||
| m.id AS id, m.update_time AS updateTime, m.name AS name, m.status AS status, d.id AS detailId, d.description AS description | |||
| FROM | |||
| api_menu m | |||
| LEFT JOIN api_detail d ON m.id = d.menu_id | |||
| WHERE | |||
| m.delete_flag = 0 AND m.`status` = 0 AND m.parent_id = #{id} | |||
| </select> | |||
| </mapper> | |||