From d9448c181a8b15d1fc22a6b8148cfe2968e00b49 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Mon, 11 Mar 2019 19:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=20pay=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pay/pay-application/pom.xml | 151 ++++++++++++++++++ .../mall/pay/application/PayApplication.java | 13 ++ .../application/config/MVCConfiguration.java | 47 ++++++ .../config/SwaggerConfiguration.java | 36 +++++ .../application/controller/PayController.java | 15 ++ .../src/main/resources/application.yaml | 9 ++ pay/pay-service-api/pom.xml | 15 ++ .../cn/iocoder/mall/pay/api/PayService.java | 4 + .../iocoder/mall/pay/api/RefundService.java | 4 + .../pay/api/constant/PayErrorCodeEnum.java | 29 ++++ pay/pay-service-impl/pom.xml | 88 ++++++++++ .../pay/config/DatabaseConfiguration.java | 14 ++ .../config/ServiceExceptionConfiguration.java | 26 +++ .../cn/iocoder/mall/pay/package-info.java | 1 + .../mall/pay/service/PayServiceImpl.java | 9 ++ .../resources/config/application.properties | 1 + .../main/resources/config/application.yaml | 25 +++ .../src/main/resources/mybatis-config.xml | 19 +++ pay/pom.xml | 21 +++ pom.xml | 1 + .../{ => application}/ProductApplication.java | 2 +- 21 files changed, 529 insertions(+), 1 deletion(-) create mode 100644 pay/pay-application/pom.xml create mode 100644 pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/PayApplication.java create mode 100644 pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/config/MVCConfiguration.java create mode 100644 pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/config/SwaggerConfiguration.java create mode 100644 pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/PayController.java create mode 100644 pay/pay-application/src/main/resources/application.yaml create mode 100644 pay/pay-service-api/pom.xml create mode 100644 pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/PayService.java create mode 100644 pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/RefundService.java create mode 100644 pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayErrorCodeEnum.java create mode 100644 pay/pay-service-impl/pom.xml create mode 100644 pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/config/DatabaseConfiguration.java create mode 100644 pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/config/ServiceExceptionConfiguration.java create mode 100644 pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/package-info.java create mode 100644 pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayServiceImpl.java create mode 100644 pay/pay-service-impl/src/main/resources/config/application.properties create mode 100644 pay/pay-service-impl/src/main/resources/config/application.yaml create mode 100644 pay/pay-service-impl/src/main/resources/mybatis-config.xml create mode 100644 pay/pom.xml rename product/product-application/src/main/java/cn/iocoder/mall/product/{ => application}/ProductApplication.java (87%) diff --git a/pay/pay-application/pom.xml b/pay/pay-application/pom.xml new file mode 100644 index 000000000..850f1bc1a --- /dev/null +++ b/pay/pay-application/pom.xml @@ -0,0 +1,151 @@ + + + + pay + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + pay-application + + + 1.3.0.Final + + + + + + cn.iocoder.mall + common-framework + 1.0-SNAPSHOT + + + + cn.iocoder.mall + pay-service-impl + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.alibaba + dubbo + 2.6.5 + + + + com.alibaba.boot + dubbo-spring-boot-starter + 0.2.1.RELEASE + + + + org.apache.curator + curator-framework + 2.12.0 + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + io.springfox + springfox-swagger2 + 2.9.2 + + + io.springfox + springfox-swagger-ui + 2.9.2 + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + org.springframework.boot + spring-boot-devtools + true + + + + cn.iocoder.mall + admin-sdk + 1.0-SNAPSHOT + + + + + + + + + + + + + + + de.codecentric + spring-boot-admin-starter-client + 2.1.3 + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + + \ No newline at end of file diff --git a/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/PayApplication.java b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/PayApplication.java new file mode 100644 index 000000000..18b5ed807 --- /dev/null +++ b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/PayApplication.java @@ -0,0 +1,13 @@ +package cn.iocoder.mall.pay.application; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.pay"}) +public class PayApplication { + + public static void main(String[] args) { + SpringApplication.run(PayApplication.class, args); + } + +} \ No newline at end of file diff --git a/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/config/MVCConfiguration.java b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/config/MVCConfiguration.java new file mode 100644 index 000000000..d44bb4dcf --- /dev/null +++ b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/config/MVCConfiguration.java @@ -0,0 +1,47 @@ +package cn.iocoder.mall.pay.application.config; + +import cn.iocoder.common.framework.config.GlobalExceptionHandler; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@EnableWebMvc +@Configuration +@Import(value = {GlobalExceptionHandler.class, // 统一全局返回 +// AdminSecurityInterceptor.class +}) +public class MVCConfiguration implements WebMvcConfigurer { + +// @Autowired +// private UserSecurityInterceptor securityInterceptor; + +// @Autowired +// private AdminSecurityInterceptor adminSecurityInterceptor; +//// +// @Override +// public void addInterceptors(InterceptorRegistry registry) { +//// registry.addInterceptor(securityInterceptor).addPathPatterns("/user/**", "/admin/**"); // 只拦截我们定义的接口 +// registry.addInterceptor(adminSecurityInterceptor).addPathPatterns("/admins/**") +// .excludePathPatterns("/admins/passport/login"); // 排除登陆接口 +// } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + // 解决 swagger-ui.html 的访问,参考自 https://stackoverflow.com/questions/43545540/swagger-ui-no-mapping-found-for-http-request 解决 + registry.addResourceHandler("swagger-ui.html**").addResourceLocations("classpath:/META-INF/resources/swagger-ui.html"); + registry.addResourceHandler("webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); + } + + // TODO 芋艿,允许跨域 + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedHeaders("*") + .allowedMethods("*") + .allowedOrigins("*"); + } + +} \ No newline at end of file diff --git a/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/config/SwaggerConfiguration.java b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/config/SwaggerConfiguration.java new file mode 100644 index 000000000..c638d8efe --- /dev/null +++ b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/config/SwaggerConfiguration.java @@ -0,0 +1,36 @@ +package cn.iocoder.mall.pay.application.config; + +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.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 // TODO 生产环境时,禁用掉。 +public class SwaggerConfiguration { + + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("cn.iocoder.mall.pay.application.controller")) + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("支付子系统") + .description("支付子系统") + .termsOfServiceUrl("http://www.iocoder.cn") + .version("1.0.0") + .build(); + } + +} \ No newline at end of file diff --git a/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/PayController.java b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/PayController.java new file mode 100644 index 000000000..d8e45ca55 --- /dev/null +++ b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/PayController.java @@ -0,0 +1,15 @@ +package cn.iocoder.mall.pay.application.controller; + +import cn.iocoder.mall.pay.api.PayService; +import com.alibaba.dubbo.config.annotation.Reference; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/pay") +public class PayController { + + @Reference(validation = "true") + private PayService payService; + +} diff --git a/pay/pay-application/src/main/resources/application.yaml b/pay/pay-application/src/main/resources/application.yaml new file mode 100644 index 000000000..f939e8563 --- /dev/null +++ b/pay/pay-application/src/main/resources/application.yaml @@ -0,0 +1,9 @@ +spring: + application: + name: pay-application + +# server +server: + port: 18084 + servlet: + context-path: /pay-api/ \ No newline at end of file diff --git a/pay/pay-service-api/pom.xml b/pay/pay-service-api/pom.xml new file mode 100644 index 000000000..6e8532fa4 --- /dev/null +++ b/pay/pay-service-api/pom.xml @@ -0,0 +1,15 @@ + + + + pay + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + pay-service-api + + + \ No newline at end of file diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/PayService.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/PayService.java new file mode 100644 index 000000000..4556d0495 --- /dev/null +++ b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/PayService.java @@ -0,0 +1,4 @@ +package cn.iocoder.mall.pay.api; + +public interface PayService { +} diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/RefundService.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/RefundService.java new file mode 100644 index 000000000..7ef7405e7 --- /dev/null +++ b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/RefundService.java @@ -0,0 +1,4 @@ +package cn.iocoder.mall.pay.api; + +public interface RefundService { +} diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayErrorCodeEnum.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayErrorCodeEnum.java new file mode 100644 index 000000000..b51cd16f3 --- /dev/null +++ b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayErrorCodeEnum.java @@ -0,0 +1,29 @@ +package cn.iocoder.mall.pay.api.constant; + +/** + * 错误码枚举类 + * + * 管理员系统,使用 1-004-000-000 段 + */ +public enum PayErrorCodeEnum { + + // ========== PAY 模块 ========== + ; + + private final int code; + private final String message; + + PayErrorCodeEnum(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public String getMessage() { + return message; + } + +} \ No newline at end of file diff --git a/pay/pay-service-impl/pom.xml b/pay/pay-service-impl/pom.xml new file mode 100644 index 000000000..df25e7ea6 --- /dev/null +++ b/pay/pay-service-impl/pom.xml @@ -0,0 +1,88 @@ + + + + pay + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + pay-service-impl + + + 1.3.0.Final + + + + + com.alibaba + dubbo + compile + + + cn.iocoder.mall + admin-service-api + 1.0-SNAPSHOT + compile + + + cn.iocoder.mall + pay-service-api + 1.0-SNAPSHOT + compile + + + + mysql + mysql-connector-java + + + org.springframework.boot + spring-boot-starter-jdbc + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.0.0 + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + com.google.guava + guava + 27.0.1-jre + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + + + + \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/config/DatabaseConfiguration.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/config/DatabaseConfiguration.java new file mode 100644 index 000000000..7d7097cea --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/config/DatabaseConfiguration.java @@ -0,0 +1,14 @@ +package cn.iocoder.mall.pay.config; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@MapperScan("cn.iocoder.mall.pay.dao") // 扫描对应的 Mapper 接口 +@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600 +public class DatabaseConfiguration { + + // 数据源,使用 HikariCP + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/config/ServiceExceptionConfiguration.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/config/ServiceExceptionConfiguration.java new file mode 100644 index 000000000..28f5be277 --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/config/ServiceExceptionConfiguration.java @@ -0,0 +1,26 @@ +package cn.iocoder.mall.pay.config; + +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.event.EventListener; + +@Configuration +public class ServiceExceptionConfiguration { + + @EventListener(ApplicationReadyEvent.class) // 可参考 https://www.cnblogs.com/ssslinppp/p/7607509.html + public void initMessages() { +// 从 service_exception_message.properties 加载错误码的方案 +// Properties properties; +// try { +// properties = PropertiesLoaderUtils.loadAllProperties("classpath:service_exception_message.properties"); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } + for (AdminErrorCodeEnum item : AdminErrorCodeEnum.values()) { + ServiceExceptionUtil.put(item.getCode(), item.getMessage()); + } + } + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/package-info.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/package-info.java new file mode 100644 index 000000000..b8ddbcd3b --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.mall.pay; \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayServiceImpl.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayServiceImpl.java new file mode 100644 index 000000000..8d4a9c82f --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayServiceImpl.java @@ -0,0 +1,9 @@ +package cn.iocoder.mall.pay.service; + +import cn.iocoder.mall.pay.api.PayService; +import org.springframework.stereotype.Service; + +@Service +@com.alibaba.dubbo.config.annotation.Service(validation = "true") +public class PayServiceImpl implements PayService { +} diff --git a/pay/pay-service-impl/src/main/resources/config/application.properties b/pay/pay-service-impl/src/main/resources/config/application.properties new file mode 100644 index 000000000..125191e02 --- /dev/null +++ b/pay/pay-service-impl/src/main/resources/config/application.properties @@ -0,0 +1 @@ +##################### 业务模块 ##################### \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/resources/config/application.yaml b/pay/pay-service-impl/src/main/resources/config/application.yaml new file mode 100644 index 000000000..d52a8aa39 --- /dev/null +++ b/pay/pay-service-impl/src/main/resources/config/application.yaml @@ -0,0 +1,25 @@ +spring: + # datasource + datasource: + url: jdbc:mysql://180.167.213.26:13306/mall_pay?useSSL=false&useUnicode=true&characterEncoding=UTF-8 + driver-class-name: com.mysql.jdbc.Driver + username: root + password: ${MALL_MYSQL_PASSWORD} + +# mybatis +mybatis: + config-location: classpath:mybatis-config.xml + mapper-locations: classpath:mapper/*.xml + type-aliases-package: cn.iocoder.mall.pay.dataobject + +# dubbo +dubbo: + application: + name: pay-service + registry: + address: zookeeper://127.0.0.1:2181 + protocol: + port: -1 + name: dubbo + scan: + base-packages: cn.iocoder.mall.pay.service \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/resources/mybatis-config.xml b/pay/pay-service-impl/src/main/resources/mybatis-config.xml new file mode 100644 index 000000000..7f604cc7e --- /dev/null +++ b/pay/pay-service-impl/src/main/resources/mybatis-config.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pay/pom.xml b/pay/pom.xml new file mode 100644 index 000000000..78e402bcf --- /dev/null +++ b/pay/pom.xml @@ -0,0 +1,21 @@ + + + + mall-parent + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + pay + pom + + pay-application + pay-service-api + pay-service-impl + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 51f519a5e..b6880f12b 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ common admin ops + pay pom diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/ProductApplication.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/ProductApplication.java similarity index 87% rename from product/product-application/src/main/java/cn/iocoder/mall/product/ProductApplication.java rename to product/product-application/src/main/java/cn/iocoder/mall/product/application/ProductApplication.java index 8332826a2..19a1513e7 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/ProductApplication.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/ProductApplication.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.product; +package cn.iocoder.mall.product.application; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;