| @@ -21,6 +21,7 @@ | |||||
| <module>suimangSchedule</module> | <module>suimangSchedule</module> | ||||
| <module>suimangMQConsumer</module> | <module>suimangMQConsumer</module> | ||||
| <module>open-api</module> | <module>open-api</module> | ||||
| <module>suimang-swagger</module> | |||||
| </modules> | </modules> | ||||
| <parent> | <parent> | ||||
| @@ -186,21 +187,21 @@ | |||||
| </dependency> | </dependency> | ||||
| <!-- Swagger --> | <!-- 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> | <dependency> | ||||
| <groupId>com.fasterxml.jackson.core</groupId> | <groupId>com.fasterxml.jackson.core</groupId> | ||||
| <artifactId>jackson-core</artifactId> | <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: 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: 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: 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-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-webmvc:5.2.4.RELEASE" level="project" /> | ||||
| <orderEntry type="library" name="Maven: org.springframework:spring-expression: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.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.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" 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: 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.objenesis:objenesis:2.6" level="project" /> | ||||
| <orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.5.0" 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: 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: 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: 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-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-databind:2.10.3" level="project" /> | ||||
| <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.2" 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.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: 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: 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: 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: 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" /> | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.2.5.RELEASE" level="project" /> | ||||
| @@ -1,5 +1,6 @@ | |||||
| package com.iformall; | package com.iformall; | ||||
| import com.iformall.annotation.BaseEnableSwagger; | |||||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | ||||
| import org.mybatis.spring.annotation.MapperScan; | import org.mybatis.spring.annotation.MapperScan; | ||||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | import org.rocketmq.starter.annotation.EnableRocketMQ; | ||||
| @@ -18,7 +19,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||||
| */ | */ | ||||
| @SpringBootApplication | @SpringBootApplication | ||||
| @MapperScan(basePackages = {"com.iformall.mapper"}) | @MapperScan(basePackages = {"com.iformall.mapper"}) | ||||
| @EnableSwagger2 | |||||
| @BaseEnableSwagger | |||||
| @EnableEncryptableProperties | @EnableEncryptableProperties | ||||
| @EnableAsync | @EnableAsync | ||||
| @EnableRocketMQ | @EnableRocketMQ | ||||
| @@ -139,6 +139,7 @@ public class ShiroConfig { | |||||
| // } | // } | ||||
| // swagger-ui | // swagger-ui | ||||
| filterChainDefinitionMap.put("/swagger-ui.html", "anon"); | filterChainDefinitionMap.put("/swagger-ui.html", "anon"); | ||||
| filterChainDefinitionMap.put("/doc.html", "anon"); | |||||
| filterChainDefinitionMap.put("/v2/**", "anon"); | filterChainDefinitionMap.put("/v2/**", "anon"); | ||||
| filterChainDefinitionMap.put("/swagger-resources/**", "anon"); | filterChainDefinitionMap.put("/swagger-resources/**", "anon"); | ||||
| filterChainDefinitionMap.put("/webjars/**", "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 | @Override | ||||
| public void addResourceHandlers(ResourceHandlerRegistry registry) { | 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/"); | .addResourceLocations("classpath:/META-INF/resources/"); | ||||
| registry.addResourceHandler("/webjars/**") | registry.addResourceHandler("/webjars/**") | ||||
| .addResourceLocations("classpath:/META-INF/resources/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; | 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.common.ResultData; | ||||
| import com.iformall.constant.SwaggerConstant; | |||||
| import com.iformall.domain.dto.sm.SaveApiGuideDTO; | import com.iformall.domain.dto.sm.SaveApiGuideDTO; | ||||
| import com.iformall.domain.dto.sm.UpdateApiGuideDTO; | import com.iformall.domain.dto.sm.UpdateApiGuideDTO; | ||||
| import com.iformall.domain.po.sm.ApiGuide; | import com.iformall.domain.po.sm.ApiGuide; | ||||
| @@ -18,23 +22,26 @@ public class ApiGuideController { | |||||
| @Autowired | @Autowired | ||||
| private ApiGuideService apiGuideService; | private ApiGuideService apiGuideService; | ||||
| @ApiOperation("分页查询api菜单") | |||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("分页查询api指南") | |||||
| @GetMapping("/page") | @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") | @PostMapping("/save") | ||||
| public ResultData saveApiGuide(@RequestBody SaveApiGuideDTO dto) { | |||||
| public R<Void> saveApiGuide(@RequestBody SaveApiGuideDTO dto) { | |||||
| apiGuideService.saveApiGuide(dto); | apiGuideService.saveApiGuide(dto); | ||||
| return new ResultData(); | |||||
| return R.ok(); | |||||
| } | } | ||||
| @ApiOperation("修改api菜单") | |||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("修改api指南") | |||||
| @PostMapping("/update") | @PostMapping("/update") | ||||
| public ResultData updateApiGuide(@RequestBody UpdateApiGuideDTO dto) { | |||||
| public R<Void> updateApiGuide(@RequestBody UpdateApiGuideDTO dto) { | |||||
| apiGuideService.updateApiGuide(dto); | apiGuideService.updateApiGuide(dto); | ||||
| return new ResultData(); | |||||
| return R.ok(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,10 +1,15 @@ | |||||
| package com.iformall.controller.sm; | package com.iformall.controller.sm; | ||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.annotation.ApiVersion; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.R; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.constant.SwaggerConstant; | |||||
| import com.iformall.domain.dto.sm.SaveApiMenuDTO; | import com.iformall.domain.dto.sm.SaveApiMenuDTO; | ||||
| import com.iformall.domain.dto.sm.UpdateApiMenuDTO; | import com.iformall.domain.dto.sm.UpdateApiMenuDTO; | ||||
| import com.iformall.domain.po.sm.ApiMenu; | import com.iformall.domain.po.sm.ApiMenu; | ||||
| import com.iformall.domain.vo.sm.ApiMenuVO; | |||||
| import com.iformall.exception.BizException; | import com.iformall.exception.BizException; | ||||
| import com.iformall.service.sm.ApiMenuService; | import com.iformall.service.sm.ApiMenuService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| @@ -12,6 +17,8 @@ import io.swagger.annotations.ApiOperation; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.util.List; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("/apiMenu") | @RequestMapping("/apiMenu") | ||||
| @Api(tags = "api菜单接口") | @Api(tags = "api菜单接口") | ||||
| @@ -20,38 +27,43 @@ public class ApiMenuController { | |||||
| @Autowired | @Autowired | ||||
| private ApiMenuService apiMenuService; | private ApiMenuService apiMenuService; | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("分页查询api菜单") | @ApiOperation("分页查询api菜单") | ||||
| @GetMapping("/page") | @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菜单") | @ApiOperation("单个查询api菜单") | ||||
| @GetMapping("/get") | @GetMapping("/get") | ||||
| public ResultData getApiMenu(Long id) { | |||||
| public R<ApiMenuVO> getApiMenu(Long id) { | |||||
| if (id == null) { | if (id == null) { | ||||
| throw new BizException(ErrorCode.SYS_PARAMETER_NOT_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菜单") | @ApiOperation("新增api菜单") | ||||
| @PostMapping("/save") | @PostMapping("/save") | ||||
| public ResultData saveApiMenu(@RequestBody SaveApiMenuDTO dto) { | |||||
| public R<Void> saveApiMenu(@RequestBody SaveApiMenuDTO dto) { | |||||
| apiMenuService.saveApiMenu(dto); | apiMenuService.saveApiMenu(dto); | ||||
| return new ResultData(); | |||||
| return R.ok(); | |||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("修改api菜单") | @ApiOperation("修改api菜单") | ||||
| @PostMapping("/update") | @PostMapping("/update") | ||||
| public ResultData updateApiMenu(@RequestBody UpdateApiMenuDTO dto) { | |||||
| public R<Void> updateApiMenu(@RequestBody UpdateApiMenuDTO dto) { | |||||
| apiMenuService.updateApiMenu(dto); | apiMenuService.updateApiMenu(dto); | ||||
| return new ResultData(); | |||||
| return R.ok(); | |||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("全查询父级api菜单") | @ApiOperation("全查询父级api菜单") | ||||
| @GetMapping("/listParentMenu") | @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; | 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.common.ResultData; | ||||
| import com.iformall.constant.SwaggerConstant; | |||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.dto.sm.SaveServiceInfoDTO; | import com.iformall.domain.dto.sm.SaveServiceInfoDTO; | ||||
| import com.iformall.domain.dto.sm.UpdateServiceInfoDTO; | import com.iformall.domain.dto.sm.UpdateServiceInfoDTO; | ||||
| @@ -20,30 +24,34 @@ public class ServiceInfoController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private ServiceInfoService serviceInfoService; | private ServiceInfoService serviceInfoService; | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("分页查询合作商") | @ApiOperation("分页查询合作商") | ||||
| @GetMapping("/page") | @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("新增合作商") | @ApiOperation("新增合作商") | ||||
| @PostMapping("/save") | @PostMapping("/save") | ||||
| public ResultData saveServiceInfo(@RequestBody SaveServiceInfoDTO dto) { | |||||
| public R<Void> saveServiceInfo(@RequestBody SaveServiceInfoDTO dto) { | |||||
| serviceInfoService.saveServiceInfo(dto); | serviceInfoService.saveServiceInfo(dto); | ||||
| return new ResultData(); | |||||
| return R.ok(); | |||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("修改合作商") | @ApiOperation("修改合作商") | ||||
| @PostMapping("/update") | @PostMapping("/update") | ||||
| public ResultData updateServiceInfo(@RequestBody UpdateServiceInfoDTO dto) { | |||||
| public R<Void> updateServiceInfo(@RequestBody UpdateServiceInfoDTO dto) { | |||||
| serviceInfoService.updateServiceInfo(dto); | serviceInfoService.updateServiceInfo(dto); | ||||
| return new ResultData(); | |||||
| return R.ok(); | |||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("修改合作商状态") | @ApiOperation("修改合作商状态") | ||||
| @PostMapping("/updateStatus") | @PostMapping("/updateStatus") | ||||
| public ResultData updateServiceInfoStatus(@RequestBody UpdateServiceInfoStatusDTO dto) { | |||||
| public R<Void> updateServiceInfoStatus(@RequestBody UpdateServiceInfoStatusDTO dto) { | |||||
| serviceInfoService.updateServiceInfoStatus(dto); | serviceInfoService.updateServiceInfoStatus(dto); | ||||
| return new ResultData(); | |||||
| return R.ok(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,7 +1,11 @@ | |||||
| package com.iformall.controller.sm; | package com.iformall.controller.sm; | ||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.annotation.ApiVersion; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.R; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.constant.SwaggerConstant; | |||||
| import com.iformall.domain.dto.sm.UpdateThirdPartyApiStatusDTO; | import com.iformall.domain.dto.sm.UpdateThirdPartyApiStatusDTO; | ||||
| import com.iformall.domain.po.WxThirdPartyApi; | import com.iformall.domain.po.WxThirdPartyApi; | ||||
| import com.iformall.exception.BizException; | import com.iformall.exception.BizException; | ||||
| @@ -19,25 +23,28 @@ public class ThirdPartyApiController { | |||||
| @Autowired | @Autowired | ||||
| private WxThirdPartyApiService thirdPartyApiService; | private WxThirdPartyApiService thirdPartyApiService; | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("分页查询秘钥") | @ApiOperation("分页查询秘钥") | ||||
| @GetMapping("/page") | @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("单个查询秘钥") | @ApiOperation("单个查询秘钥") | ||||
| @GetMapping("/get") | @GetMapping("/get") | ||||
| public ResultData getThirdPartyApi(Long id) { | |||||
| public R<WxThirdPartyApi> getThirdPartyApi(Long id) { | |||||
| if (id == null) { | if (id == null) { | ||||
| throw new BizException(ErrorCode.SYS_PARAMETER_NOT_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("修改秘钥状态") | @ApiOperation("修改秘钥状态") | ||||
| @PostMapping("/updateStatus") | @PostMapping("/updateStatus") | ||||
| public ResultData updateThirdPartyApiStatus(@RequestBody UpdateThirdPartyApiStatusDTO dto) { | |||||
| public R<Void> updateThirdPartyApiStatus(@RequestBody UpdateThirdPartyApiStatusDTO dto) { | |||||
| thirdPartyApiService.updateThirdPartyApiStatus(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.Constants; | ||||
| import com.google.code.kaptcha.Producer; | import com.google.code.kaptcha.Producer; | ||||
| import com.iformall.annotation.ApiVersion; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.constant.SwaggerConstant; | |||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
| @@ -75,6 +77,7 @@ public class HomeController extends BaseController { | |||||
| @Qualifier("objectCommonRedisTemplate") | @Qualifier("objectCommonRedisTemplate") | ||||
| RedisTemplate<String, Object> redisTemplate; | RedisTemplate<String, Object> redisTemplate; | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("验证码") | @ApiOperation("验证码") | ||||
| @GetMapping("/captcha.jpg") | @GetMapping("/captcha.jpg") | ||||
| public void captcha(HttpServletResponse response)throws ServletException, IOException { | public void captcha(HttpServletResponse response)throws ServletException, IOException { | ||||
| @@ -97,6 +100,7 @@ public class HomeController extends BaseController { | |||||
| IOUtils.closeQuietly(out); | IOUtils.closeQuietly(out); | ||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("登录") | @ApiOperation("登录") | ||||
| @PostMapping("/doLogin") | @PostMapping("/doLogin") | ||||
| public ResultData login(@RequestBody MallUserInfo user, HttpServletResponse response) { | public ResultData login(@RequestBody MallUserInfo user, HttpServletResponse response) { | ||||
| @@ -1,10 +1,12 @@ | |||||
| package com.iformall.controller.sys; | package com.iformall.controller.sys; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.annotation.ApiVersion; | |||||
| import com.iformall.annotation.SystemControllerLog; | import com.iformall.annotation.SystemControllerLog; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.constant.SwaggerConstant; | |||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.po.base.BaseEntity; | import com.iformall.domain.po.base.BaseEntity; | ||||
| @@ -43,6 +45,7 @@ public class MallRoleController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private MallUserRoleService mallUserRoleService; | private MallUserRoleService mallUserRoleService; | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("角色列表") | @ApiOperation("角色列表") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @@ -95,7 +98,7 @@ public class MallRoleController extends BaseController { | |||||
| return new ResultData(role); | return new ResultData(role); | ||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("角色保存") | @ApiOperation("角色保存") | ||||
| @PostMapping("saveOrUpdate") | @PostMapping("saveOrUpdate") | ||||
| //@RequiresPermissions("sys:role:save") | //@RequiresPermissions("sys:role:save") | ||||
| @@ -126,6 +129,7 @@ public class MallRoleController extends BaseController { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("角色删除") | @ApiOperation("角色删除") | ||||
| @PostMapping("/del") | @PostMapping("/del") | ||||
| //@RequiresPermissions("sys:role:del") | //@RequiresPermissions("sys:role:del") | ||||
| @@ -1,10 +1,12 @@ | |||||
| package com.iformall.controller.sys; | package com.iformall.controller.sys; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.annotation.ApiVersion; | |||||
| import com.iformall.annotation.SystemControllerLog; | import com.iformall.annotation.SystemControllerLog; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.constant.SwaggerConstant; | |||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.po.base.BaseEntity; | import com.iformall.domain.po.base.BaseEntity; | ||||
| @@ -60,6 +62,7 @@ public class MallUserInfoController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| WxMsgValidationcodeService wxMsgValidationcodeService; | WxMsgValidationcodeService wxMsgValidationcodeService; | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation(value = "用户分页接口", response = String.class) | @ApiOperation(value = "用户分页接口", response = String.class) | ||||
| @GetMapping("lists") | @GetMapping("lists") | ||||
| //@RequiresPermissions("sys:user:list") | //@RequiresPermissions("sys:user:list") | ||||
| @@ -110,6 +113,7 @@ public class MallUserInfoController extends BaseController { | |||||
| return new ResultData(user); | return new ResultData(user); | ||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation(value = "创建用户接口", response = String.class) | @ApiOperation(value = "创建用户接口", response = String.class) | ||||
| @PostMapping("add") | @PostMapping("add") | ||||
| //@RequiresPermissions("sys:user:add") | //@RequiresPermissions("sys:user:add") | ||||
| @@ -147,6 +151,7 @@ public class MallUserInfoController extends BaseController { | |||||
| return new ResultData(userInfo); | return new ResultData(userInfo); | ||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation(value = "修改用户接口", response = String.class) | @ApiOperation(value = "修改用户接口", response = String.class) | ||||
| @PostMapping("update") | @PostMapping("update") | ||||
| //@RequiresPermissions("sys:user:update") | //@RequiresPermissions("sys:user:update") | ||||
| @@ -225,6 +230,7 @@ public class MallUserInfoController extends BaseController { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation(value = "删除用户接口", response = String.class) | @ApiOperation(value = "删除用户接口", response = String.class) | ||||
| @PostMapping("/del") | @PostMapping("/del") | ||||
| //@RequiresPermissions("sys:user:del") | //@RequiresPermissions("sys:user:del") | ||||
| @@ -320,6 +326,7 @@ public class MallUserInfoController extends BaseController { | |||||
| return new ResultData(menu); | return new ResultData(menu); | ||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation(value = "用户密码发送验证码") | @ApiOperation(value = "用户密码发送验证码") | ||||
| @GetMapping("sendvalidationcode") | @GetMapping("sendvalidationcode") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @@ -353,6 +360,7 @@ public class MallUserInfoController extends BaseController { | |||||
| return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | ||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation(value = "修改密码", notes = "{\"userName\",\"string\",\"code\",\"string\",\"pwd\",\"string\"}") | @ApiOperation(value = "修改密码", notes = "{\"userName\",\"string\",\"code\",\"string\",\"pwd\",\"string\"}") | ||||
| @PostMapping("/updatepwd") | @PostMapping("/updatepwd") | ||||
| @SystemControllerLog(description = "用户管理-修改密码") | @SystemControllerLog(description = "用户管理-修改密码") | ||||
| @@ -1,9 +1,11 @@ | |||||
| package com.iformall.controller.sys; | package com.iformall.controller.sys; | ||||
| import com.iformall.annotation.ApiVersion; | |||||
| import com.iformall.annotation.SystemControllerLog; | import com.iformall.annotation.SystemControllerLog; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.constant.SwaggerConstant; | |||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.MallPermission; | import com.iformall.domain.po.MallPermission; | ||||
| import com.iformall.domain.po.MallRole; | import com.iformall.domain.po.MallRole; | ||||
| @@ -65,6 +67,7 @@ public class SysMenuController extends BaseController { | |||||
| return new ResultData(map); | return new ResultData(map); | ||||
| } | } | ||||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||||
| @ApiOperation("所有菜单列表") | @ApiOperation("所有菜单列表") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| //@RequiresPermissions("sys:menu:list") | //@RequiresPermissions("sys:menu:list") | ||||
| @@ -209,4 +209,18 @@ suimang: | |||||
| photo_speak_hy: xxx | photo_speak_hy: xxx | ||||
| digital_avatar: xxx | digital_avatar: xxx | ||||
| digital_avatar_hy: 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; | package com.iformall; | ||||
| import com.iformall.annotation.BaseEnableSwagger; | |||||
| import org.mybatis.spring.annotation.MapperScan; | import org.mybatis.spring.annotation.MapperScan; | ||||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | import org.rocketmq.starter.annotation.EnableRocketMQ; | ||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
| @@ -15,6 +16,7 @@ import org.springframework.scheduling.annotation.EnableAsync; | |||||
| * @author chenkx | * @author chenkx | ||||
| * @date 2017-12-26 | * @date 2017-12-26 | ||||
| */ | */ | ||||
| @BaseEnableSwagger | |||||
| @SpringBootApplication | @SpringBootApplication | ||||
| @MapperScan(basePackages = {"com.iformall.mapper"}) | @MapperScan(basePackages = {"com.iformall.mapper"}) | ||||
| @EnableEncryptableProperties | @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 | @Override | ||||
| public void addResourceHandlers(ResourceHandlerRegistry registry) { | 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/"); | .addResourceLocations("classpath:/META-INF/resources/"); | ||||
| registry.addResourceHandler("/webjars/**") | registry.addResourceHandler("/webjars/**") | ||||
| .addResourceLocations("classpath:/META-INF/resources/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 | @Override | ||||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||||
| AuthIgnore annotation; | AuthIgnore annotation; | ||||
| if(handler instanceof HandlerMethod) { | if(handler instanceof HandlerMethod) { | ||||
| annotation = ((HandlerMethod) handler).getMethodAnnotation(AuthIgnore.class); | annotation = ((HandlerMethod) handler).getMethodAnnotation(AuthIgnore.class); | ||||
| @@ -196,3 +196,17 @@ suimang: | |||||
| digital_avatar: http://nas.pucao.cn:2005 | digital_avatar: http://nas.pucao.cn:2005 | ||||
| digital_avatar_hy: http://nas.pucao.cn:2003 | digital_avatar_hy: http://nas.pucao.cn:2003 | ||||
| callbackUrl: https://mtest.metavatar.cc/C | 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> | <scope>compile</scope> | ||||
| </dependency> | </dependency> | ||||
| --> | --> | ||||
| <dependency> | |||||
| <groupId>com.iformall</groupId> | |||||
| <artifactId>suimang-swagger</artifactId> | |||||
| <version>1.0</version> | |||||
| </dependency> | |||||
| <dependency> | <dependency> | ||||
| <groupId>com.iformall</groupId> | <groupId>com.iformall</groupId> | ||||
| <artifactId>suimangVideo</artifactId> | <artifactId>suimangVideo</artifactId> | ||||
| @@ -1,6 +1,12 @@ | |||||
| package com.iformall.common; | package com.iformall.common; | ||||
| public interface CommonConstants { | public interface CommonConstants { | ||||
| /** | |||||
| * 接口响应码:200:成功 500:失败 | |||||
| */ | |||||
| Integer SUCCESS = 200; | |||||
| Integer FAILED = 500; | |||||
| /** | /** | ||||
| * 状态(0:正常,1:锁定) | * 状态(0:正常,1:锁定) | ||||
| */ | */ | ||||
| @@ -681,6 +681,9 @@ public enum ErrorCode{ | |||||
| SECRET_NOT_EXISTS(71001, "该秘钥不存在"), | SECRET_NOT_EXISTS(71001, "该秘钥不存在"), | ||||
| SERVICE_LOCKED(71002, "合作商被锁定,无法修改"), | SERVICE_LOCKED(71002, "合作商被锁定,无法修改"), | ||||
| NAME_REPEAT(81000, "名称重复"), | |||||
| EXIST_AVAILABLE_GUIDE(81001, "存在可用指南"), | |||||
| ; | ; | ||||
| private int code; | 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.iformall.domain.po.sm.ApiMenu; | ||||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||
| import com.iformall.domain.vo.sm.ApiMenuVO; | import com.iformall.domain.vo.sm.ApiMenuVO; | ||||
| import com.iformall.domain.vo.sm.ListApiSubmenuVO; | |||||
| import java.util.List; | import java.util.List; | ||||
| @@ -16,6 +17,8 @@ public interface ApiMenuMapper extends BaseMapper<ApiMenu> { | |||||
| List<ApiMenu> listParentMenu(); | List<ApiMenu> listParentMenu(); | ||||
| List<ApiMenuVO> listApiMenuAndDetail(ApiMenu apiMenu); | 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 saveApiGuide(SaveApiGuideDTO dto); | ||||
| void updateApiGuide(UpdateApiGuideDTO 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.iformall.domain.po.sm.ApiMenu; | ||||
| import com.baomidou.mybatisplus.extension.service.IService; | import com.baomidou.mybatisplus.extension.service.IService; | ||||
| import com.iformall.domain.vo.sm.ApiMenuVO; | import com.iformall.domain.vo.sm.ApiMenuVO; | ||||
| import com.iformall.domain.vo.sm.ListApiSubmenuVO; | |||||
| import java.util.List; | import java.util.List; | ||||
| @@ -23,4 +24,8 @@ public interface ApiMenuService extends IService<ApiMenu> { | |||||
| List<ApiMenu> listParentMenu(); | List<ApiMenu> listParentMenu(); | ||||
| ApiMenuVO getApiMenu(Long id); | ApiMenuVO getApiMenu(Long id); | ||||
| List<ApiMenu> listMenu(); | |||||
| List<ListApiSubmenuVO> listApiSubmenu(Long id); | |||||
| } | } | ||||
| @@ -1,16 +1,23 @@ | |||||
| package com.iformall.service.sm.impl; | package com.iformall.service.sm.impl; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | 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.SaveApiGuideDTO; | ||||
| import com.iformall.domain.dto.sm.UpdateApiGuideDTO; | import com.iformall.domain.dto.sm.UpdateApiGuideDTO; | ||||
| import com.iformall.domain.po.sm.ApiGuide; | import com.iformall.domain.po.sm.ApiGuide; | ||||
| import com.iformall.exception.BizException; | |||||
| import com.iformall.service.sm.ApiGuideService; | import com.iformall.service.sm.ApiGuideService; | ||||
| import com.iformall.mapper.ApiGuideMapper; | import com.iformall.mapper.ApiGuideMapper; | ||||
| import org.apache.commons.collections.CollectionUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.util.List; | |||||
| /** | /** | ||||
| * | * | ||||
| */ | */ | ||||
| @@ -27,15 +34,52 @@ public class ApiGuideServiceImpl extends ServiceImpl<ApiGuideMapper, ApiGuide> i | |||||
| @Override | @Override | ||||
| public void saveApiGuide(SaveApiGuideDTO dto) { | 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); | ApiGuide apiGuide = SaveApiGuideDTO.mapping(dto); | ||||
| apiGuideMapper.insert(apiGuide); | apiGuideMapper.insert(apiGuide); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public void updateApiGuide(UpdateApiGuideDTO dto) { | 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); | ApiGuide apiGuide = UpdateApiGuideDTO.mapping(dto); | ||||
| apiGuideMapper.updateById(apiGuide); | 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.ApiDetail; | ||||
| import com.iformall.domain.po.sm.ApiMenu; | import com.iformall.domain.po.sm.ApiMenu; | ||||
| import com.iformall.domain.vo.sm.ApiMenuVO; | import com.iformall.domain.vo.sm.ApiMenuVO; | ||||
| import com.iformall.domain.vo.sm.ListApiSubmenuVO; | |||||
| import com.iformall.mapper.ApiDetailMapper; | import com.iformall.mapper.ApiDetailMapper; | ||||
| import com.iformall.service.sm.ApiMenuService; | import com.iformall.service.sm.ApiMenuService; | ||||
| import com.iformall.mapper.ApiMenuMapper; | import com.iformall.mapper.ApiMenuMapper; | ||||
| @@ -76,6 +77,16 @@ public class ApiMenuServiceImpl extends ServiceImpl<ApiMenuMapper, ApiMenu> impl | |||||
| public List<ApiMenu> listParentMenu() { | public List<ApiMenu> listParentMenu() { | ||||
| return apiMenuMapper.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} | and `name` = #{name} | ||||
| </if> | </if> | ||||
| <if test=" null != status "> | <if test=" null != status "> | ||||
| and `status = #{status} | |||||
| and `status` = #{status} | |||||
| </if> | </if> | ||||
| </sql> | </sql> | ||||
| @@ -79,4 +79,13 @@ | |||||
| LEFT JOIN api_detail d ON m.id = d.menu_id | LEFT JOIN api_detail d ON m.id = d.menu_id | ||||
| <include refid="dynamicWhereConditions"/> | <include refid="dynamicWhereConditions"/> | ||||
| </select> | </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> | </mapper> | ||||