From 26c85f7de52e09a0d422a43dd814b6ae1de89a26 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=88=98=E6=B4=AA=E9=9D=92?= Date: Sun, 29 Sep 2019 18:19:27 +0800 Subject: [PATCH] =?utf8?q?feat:=20=E6=96=B0=E5=A2=9Ebiz-sa=E7=A4=BA?= =?utf8?q?=E4=BE=8B=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=B5=8B=E8=AF=95=E5=A4=9A?= =?utf8?q?=E5=90=8E=E7=AB=AF=E5=BE=AE=E6=9C=8D=E5=8A=A1=E7=9A=84=E9=A1=B9?= =?utf8?q?=E7=9B=AE=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sa/biz/.gitignore | 1 + sa/biz/Dockerfile | 18 ++ sa/biz/pom.xml | 204 ++++++++++++++++++ .../institute/backend/biz/sa/Application.java | 47 ++++ .../biz/sa/configuration/Swagger2Config.java | 110 ++++++++++ .../src/main/resources/application-docker.yml | 46 ++++ sa/biz/src/main/resources/application.yml | 48 +++++ sa/biz/src/main/resources/bootstrap.yml | 3 + sa/pom.xml | 1 + sql/biz.sql | 20 ++ 10 files changed, 498 insertions(+) create mode 100644 sa/biz/.gitignore create mode 100644 sa/biz/Dockerfile create mode 100644 sa/biz/pom.xml create mode 100644 sa/biz/src/main/java/com/supwisdom/institute/backend/biz/sa/Application.java create mode 100644 sa/biz/src/main/java/com/supwisdom/institute/backend/biz/sa/configuration/Swagger2Config.java create mode 100644 sa/biz/src/main/resources/application-docker.yml create mode 100644 sa/biz/src/main/resources/application.yml create mode 100644 sa/biz/src/main/resources/bootstrap.yml create mode 100644 sql/biz.sql diff --git a/sa/biz/.gitignore b/sa/biz/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/sa/biz/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/sa/biz/Dockerfile b/sa/biz/Dockerfile new file mode 100644 index 0000000..f7bf86e --- /dev/null +++ b/sa/biz/Dockerfile @@ -0,0 +1,18 @@ +FROM harbor.supwisdom.com/institute/openjdk:8-jre-alpine + +ENV ENABLE_JMX_SSL=false +ENV JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=docker +ENV SPRING_PROFILES_ACTIVE=docker + +ARG NAME +ARG VERSION +ARG JAR_FILE + +LABEL name=$NAME \ + version=$VERSION + +EXPOSE 8080 + +EXPOSE 8443 + +COPY --chown=java-app:java-app target/${JAR_FILE} /home/java-app/lib/app.jar diff --git a/sa/biz/pom.xml b/sa/biz/pom.xml new file mode 100644 index 0000000..aabc09e --- /dev/null +++ b/sa/biz/pom.xml @@ -0,0 +1,204 @@ + + 4.0.0 + + + com.supwisdom.institute + sw-backend-parent + 0.0.1-SNAPSHOT + ../../ + + + com.supwisdom.institute + sw-backend-biz-sa + 0.0.1-SNAPSHOT + jar + + Supwisdom Backend Framework Biz Super Admin + Supwisdom Backend Framework Biz Super Admin project + + + com.supwisdom.institute.backend.biz.sa.Application + + + + + + org.springframework.boot + spring-boot-starter + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.supwisdom.infras + infras-online-doc + + + + + + + + + + + + + + com.supwisdom.institute + sw-backend-biz-api + + + + + io.springfox + springfox-swagger2 + + + io.springfox + springfox-swagger-ui + + + + + mysql + mysql-connector-java + runtime + + + + + org.springframework.boot + spring-boot-devtools + runtime + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + ${project.artifactId} + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-failsafe-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-release-plugin + + + org.jacoco + jacoco-maven-plugin + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + com.spotify + dockerfile-maven-plugin + + false + + + + + + + + diff --git a/sa/biz/src/main/java/com/supwisdom/institute/backend/biz/sa/Application.java b/sa/biz/src/main/java/com/supwisdom/institute/backend/biz/sa/Application.java new file mode 100644 index 0000000..b2b44be --- /dev/null +++ b/sa/biz/src/main/java/com/supwisdom/institute/backend/biz/sa/Application.java @@ -0,0 +1,47 @@ +package com.supwisdom.institute.backend.biz.sa; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +import com.supwisdom.infras.online.doc.configuration.EnableInfrasOnlineDoc; +import com.supwisdom.institute.backend.common.core.transmit.annotation.EnableSimpleUserTransmit; +import com.supwisdom.institute.backend.common.framework.exception.EnableCustomExceptionHandler; + +@SpringBootApplication + +@EnableSimpleUserTransmit +@EnableCustomExceptionHandler + +@EnableInfrasOnlineDoc + +@EntityScan(basePackages = {"com.supwisdom.**.domain.entity"}) // 扫描子项目下的实体 +@EnableJpaRepositories(basePackages = {"com.supwisdom.**.domain.repo"}) // 扫描子项目下的持久类 +@ComponentScan(basePackages = {"com.supwisdom"}) +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Bean + public CorsFilter corsFilter() { + final CorsConfiguration config = new CorsConfiguration(); + // config.setAllowCredentials(true); + config.addAllowedOrigin("*"); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + + final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/v2/api-docs", config); + + return new CorsFilter(source); + } + +} diff --git a/sa/biz/src/main/java/com/supwisdom/institute/backend/biz/sa/configuration/Swagger2Config.java b/sa/biz/src/main/java/com/supwisdom/institute/backend/biz/sa/configuration/Swagger2Config.java new file mode 100644 index 0000000..f2ffe33 --- /dev/null +++ b/sa/biz/src/main/java/com/supwisdom/institute/backend/biz/sa/configuration/Swagger2Config.java @@ -0,0 +1,110 @@ +package com.supwisdom.institute.backend.biz.sa.configuration; + +import static com.google.common.collect.Lists.newArrayList; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.ApiKey; +import springfox.documentation.service.AuthorizationScope; +import springfox.documentation.service.Contact; +import springfox.documentation.service.SecurityReference; +import springfox.documentation.service.SecurityScheme; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger.web.UiConfiguration; +import springfox.documentation.swagger.web.UiConfigurationBuilder; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class Swagger2Config { + + @Value("${swagger2.apis.basePackage:com.supwisdom.institute}") + private String basePackage; + + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .securitySchemes(securitySchemes()) + .securityContexts(securityContexts()) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage(basePackage)) + .paths(PathSelectors.any()) + .build() + ; + } + + private ApiInfo apiInfo() { + Contact contact = new Contact("Backend Biz Super Admin", "https://sw-backend-biz-sa.supwisdom.com/swagger-ui.html", ""); // name, url, email + return new ApiInfoBuilder() + .title("Backend Biz Super Admin APIs") + .description("管理后台 - 服务接口

" + + "X-FORWARD-USER(测试用):

" + + "明文:{\"attributes\":{\"accountId\":\"1\"},\"roles\":[\"ROLE_ADMIN\",\"administrator\",\"user\"],\"username\":\"swadmin\"}

" + + "Base64:eyJhdHRyaWJ1dGVzIjp7ImFjY291bnRJZCI6IjEifSwicm9sZXMiOlsiUk9MRV9BRE1JTiIsImFkbWluaXN0cmF0b3IiLCJ1c2VyIl0sInVzZXJuYW1lIjoic3dhZG1pbiJ9

" + + "使用 Base64字符串 进行 Authorize,然后进行接口测试

" + + "若需要其他帐号,请自行拼接明文,再进行 Base64 编码

" + + "" + ) + .termsOfServiceUrl("http://www.supwisdom.com/") + .contact(contact) + .version("1.0") + .build(); + } + + private List securitySchemes() { + //return newArrayList(new BasicAuth("sample")); + return newArrayList( + //new BasicAuth("Basic"), + //new ApiKey("JWTToken", "Authorization", "header"), + new ApiKey("SimpleUserTransmit", "X-FORWARD-USER", "header")); + } + + private List securityContexts() { + + List globalSecurityReference = newArrayList( + new SecurityReference("SimpleUserTransmit", new AuthorizationScope[]{new AuthorizationScope("global", "accessEverything")})); + +// AuthorizationScope[] authScopes = new AuthorizationScope[1]; +// authScopes[0] = new AuthorizationScopeBuilder() +// .scope("read") +// .description("read access") +// .build(); +// SecurityReference securityReference = SecurityReference.builder() +// .reference("sample") +// .scopes(authScopes) +// .build(); + + return newArrayList( + SecurityContext.builder() + .securityReferences(newArrayList(globalSecurityReference)) + .build()); + } + + @Bean + UiConfiguration uiConfig() { + + return UiConfigurationBuilder.builder().build(); + +// return new UiConfiguration(null, // url +// "none", // docExpansion => none | list +// "alpha", // apiSorter => alpha +// "schema", // defaultModelRendering => schema +// UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS, +// false, // enableJsonEditor => true || false +// true, // showRequestHeaders => true | false +// 60000L); // requestTimeout => in milliseconds, defaults to null +// // (uses jquery xh timeout) + } + +} diff --git a/sa/biz/src/main/resources/application-docker.yml b/sa/biz/src/main/resources/application-docker.yml new file mode 100644 index 0000000..cbf3924 --- /dev/null +++ b/sa/biz/src/main/resources/application-docker.yml @@ -0,0 +1,46 @@ +server: + port: ${SERVER_PORT:8443} + ssl: + enabled: ${SSL_ENABLED:true} + clientAuth: NEED + key-store: ${SSL_KEYSTORE_FILE:file:/certs/server/server.keystore} + key-store-password: ${SSL_KEYSTORE_PASSWORD:} + trust-store: ${SSL_TRUSTSTORE_FILE:file:/certs/server/server.truststore} + trust-store-password: ${SSL_TRUSTSTORE_PASSWORD:} + tomcat: + accesslog: + enabled: ${TOMCAT_ACCESSLOG_ENABLED:false} + buffered: ${TOMCAT_ACCESSLOG_BUFFERED:true} + directory: ${TOMCAT_ACCESSLOG_DIR:log} + prefix: ${TOMCAT_ACCESSLOG_PREFIX:sa-api-accesslog} + suffix: ${TOMCAT_ACCESSLOG_SUFFIX:.log} + file-date-format: ${TOMCAT_ACCESSLOG_FILE_DATE_FORMAT:.yyyy-MM-dd} + rotate: ${TOMCAT_ACCESSLOG_ROTATE:true} + + +## +# logging +# +logging: + level: + root: INFO + com.supwisdom: INFO + + +spring: + jackson: + time-zone: ${JACKSON_TIME_ZONE:Asia/Shanghai} + + datasource: + driver-class-name: ${JDBC_DRIVER_CLASS_NAME:com.mysql.cj.jdbc.Driver} + url: ${JDBC_URL:jdbc:mysql://mysql-server:3306/sw-biz} + username: ${JDBC_USERNAME:sw-biz} + password: ${JDBC_PASSWORD:} + + +## +# online-doc +# +infras.online-doc.enabled: ${INFRAS_ONLINE_DOC_ENABLED:false} +infras.online-doc.md-docs.staitc.path: ${INFRAS_ONLINE_DOC_MD_DOCS_STATIC_PATH:/doc/} +infras.online-doc.api-docs.staitc.path: ${INFRAS_ONLINE_DOC_API_DOCS_STATIC_PATH:/api-docs/} diff --git a/sa/biz/src/main/resources/application.yml b/sa/biz/src/main/resources/application.yml new file mode 100644 index 0000000..531f8bd --- /dev/null +++ b/sa/biz/src/main/resources/application.yml @@ -0,0 +1,48 @@ +server: + port: 8083 + ssl: + enabled: false + + +## +# logging +# +logging: + level: + root: INFO + com.supwisdom: DEBUG +# org.springframework.web: INFO +# org.springframework.cloud.openfeign: INFO + + +swagger2.apis.basePackage: com.supwisdom.institute + + +spring: + jackson: + time-zone: Asia/Shanghai + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/sw-biz + username: root + password: root + hikari: + data-source-properties: + useSSL: false + characterEncoding: utf8 + characterSetResults: utf8 + jpa: + hibernate: + ddl-auto: none + naming: + physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl + database-platform: org.hibernate.dialect.MySQL5InnoDBDialect + show-sql: false + + +## +# infras.online-doc +# +infras.online-doc.enabled: true +infras.online-doc.md-docs.staitc.path: /Users/loie/c/work/git/institute/sw-backend/doc/ +infras.online-doc.api-docs.staitc.path: /Users/loie/c/work/git/institute/sw-backend/api-docs/ diff --git a/sa/biz/src/main/resources/bootstrap.yml b/sa/biz/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..8c1026a --- /dev/null +++ b/sa/biz/src/main/resources/bootstrap.yml @@ -0,0 +1,3 @@ +spring: + application: + name: sw-backend-biz-sa diff --git a/sa/pom.xml b/sa/pom.xml index 6aafbda..40724ff 100644 --- a/sa/pom.xml +++ b/sa/pom.xml @@ -19,6 +19,7 @@ admin + biz diff --git a/sql/biz.sql b/sql/biz.sql new file mode 100644 index 0000000..7e8b585 --- /dev/null +++ b/sql/biz.sql @@ -0,0 +1,20 @@ + +CREATE TABLE `TB_BIZ` ( + `ID` VARCHAR(100) NOT NULL COMMENT '', + `COMPANY_ID` VARCHAR(100) COMMENT 'CompanyID', + `DELETED` INT(1) COMMENT '是否删除', + `ADD_ACCOUNT` VARCHAR(100) COMMENT '创建人', + `ADD_TIME` DATETIME COMMENT '创建时间', + `EDIT_ACCOUNT` VARCHAR(100) COMMENT '修改人', + `EDIT_TIME` DATETIME COMMENT '修改时间', + `DELETE_ACCOUNT` VARCHAR(100) COMMENT '删除人', + `DELETE_TIME` DATETIME COMMENT '删除时间', + + `NAME` VARCHAR(200) NOT NULL COMMENT '名称', + `BOOL` INT(1) NOT NULL COMMENT '布尔', + `DATE` DATETIME COMMENT '时间', + `NUM` INT(11) NOT NULL COMMENT '数字', + + PRIMARY KEY (`ID`) +) +COMMENT = '测试表'; -- 2.17.1