From a34eee65acd6cae4540b60cd839af3002d4372c5 Mon Sep 17 00:00:00 2001
From: YunaiV <>
Date: Mon, 8 Apr 2019 23:41:48 +0800
Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=EF=BC=9A=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=20cart=20=E7=B3=BB=E7=BB=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
cart/cart-application/pom.xml | 70 +++++++++++++++++++
.../cart/application/CartApplication.java | 13 ++++
.../application/config/MVCConfiguration.java | 42 +++++++++++
.../config/SwaggerConfiguration.java | 36 ++++++++++
.../src/main/resources/application.yaml | 9 +++
cart/cart-service-api/pom.xml | 40 +++++++++++
.../cn/iocoder/mall/cart/api/CartService.java | 4 ++
.../cart/api/constant/CartErrorCodeEnum.java | 28 ++++++++
cart/cart-service-impl/pom.xml | 66 +++++++++++++++++
.../biz/config/DatabaseConfiguration.java | 14 ++++
.../config/ServiceExceptionConfiguration.java | 19 +++++
.../iocoder/mall/cart/biz/package-info.java | 1 +
.../resources/config/application.properties | 1 +
.../main/resources/config/application.yaml | 44 ++++++++++++
.../src/main/resources/mybatis-config.xml | 19 +++++
cart/pom.xml | 21 ++++++
.../constant/ModuleErrorCodeInterval.java | 4 +-
pay/pay-application/pom.xml | 5 --
pay/pay-service-api/pom.xml | 1 +
pay/pay-service-impl/pom.xml | 4 --
pom.xml | 1 +
.../application/config/MVCConfiguration.java | 18 ++---
22 files changed, 441 insertions(+), 19 deletions(-)
create mode 100644 cart/cart-application/pom.xml
create mode 100644 cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/CartApplication.java
create mode 100644 cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/config/MVCConfiguration.java
create mode 100644 cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/config/SwaggerConfiguration.java
create mode 100644 cart/cart-application/src/main/resources/application.yaml
create mode 100644 cart/cart-service-api/pom.xml
create mode 100644 cart/cart-service-api/src/main/java/cn/iocoder/mall/cart/api/CartService.java
create mode 100644 cart/cart-service-api/src/main/java/cn/iocoder/mall/cart/api/constant/CartErrorCodeEnum.java
create mode 100644 cart/cart-service-impl/pom.xml
create mode 100644 cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/config/DatabaseConfiguration.java
create mode 100644 cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/config/ServiceExceptionConfiguration.java
create mode 100644 cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/package-info.java
create mode 100644 cart/cart-service-impl/src/main/resources/config/application.properties
create mode 100644 cart/cart-service-impl/src/main/resources/config/application.yaml
create mode 100644 cart/cart-service-impl/src/main/resources/mybatis-config.xml
create mode 100644 cart/pom.xml
diff --git a/cart/cart-application/pom.xml b/cart/cart-application/pom.xml
new file mode 100644
index 000000000..4043c93b7
--- /dev/null
+++ b/cart/cart-application/pom.xml
@@ -0,0 +1,70 @@
+
+
+
+ cart
+ cn.iocoder.mall
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ cart-application
+
+
+
+
+ cn.iocoder.mall
+ common-framework
+ 1.0-SNAPSHOT
+
+
+
+ cn.iocoder.mall
+ user-sdk
+ 1.0-SNAPSHOT
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ com.alibaba
+ dubbo
+
+
+ com.alibaba.boot
+ dubbo-spring-boot-starter
+
+
+
+ org.apache.curator
+ curator-framework
+
+
+
+ io.springfox
+ springfox-swagger2
+
+
+ io.springfox
+ springfox-swagger-ui
+
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ true
+
+
+
+
+
diff --git a/cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/CartApplication.java b/cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/CartApplication.java
new file mode 100644
index 000000000..c65c010b8
--- /dev/null
+++ b/cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/CartApplication.java
@@ -0,0 +1,13 @@
+package cn.iocoder.mall.cart.application;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.cart"})
+public class CartApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(CartApplication.class, args);
+ }
+
+}
diff --git a/cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/config/MVCConfiguration.java b/cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/config/MVCConfiguration.java
new file mode 100644
index 000000000..c1c5c7bcc
--- /dev/null
+++ b/cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/config/MVCConfiguration.java
@@ -0,0 +1,42 @@
+package cn.iocoder.mall.cart.application.config;
+
+import cn.iocoder.common.framework.config.GlobalExceptionHandler;
+import cn.iocoder.common.framework.servlet.CorsFilter;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.web.servlet.config.annotation.*;
+
+@EnableWebMvc
+@Configuration
+@Import(value = {GlobalExceptionHandler.class}) // 统一全局返回
+public class MVCConfiguration implements WebMvcConfigurer {
+
+// @Autowired
+// private SecurityInterceptor securityInterceptor;
+
+// @Reference
+// private OAuth2Service oauth2Service;
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+// registry.addInterceptor(securityInterceptor);
+ }
+
+ @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/");
+ }
+
+ @Bean
+ public FilterRegistrationBean corsFilter() {
+ FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
+ registrationBean.setFilter(new CorsFilter());
+ registrationBean.addUrlPatterns("/*");
+ return registrationBean;
+ }
+
+}
diff --git a/cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/config/SwaggerConfiguration.java b/cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/config/SwaggerConfiguration.java
new file mode 100644
index 000000000..d52f167cf
--- /dev/null
+++ b/cart/cart-application/src/main/java/cn/iocoder/mall/cart/application/config/SwaggerConfiguration.java
@@ -0,0 +1,36 @@
+package cn.iocoder.mall.cart.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
+public class SwaggerConfiguration {
+
+ @Bean
+ public Docket createRestApi() {
+ return new Docket(DocumentationType.SWAGGER_2)
+ .apiInfo(apiInfo())
+ .select()
+ .apis(RequestHandlerSelectors.basePackage("cn.iocoder.mall.biz.application.controller"))
+ .paths(PathSelectors.any())
+ .build();
+ }
+
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder()
+ .title("购物车子系统")
+ .description("购物车子系统")
+ .termsOfServiceUrl("http://www.iocoder.cn")
+ .version("1.0.0")
+ .build();
+ }
+
+}
diff --git a/cart/cart-application/src/main/resources/application.yaml b/cart/cart-application/src/main/resources/application.yaml
new file mode 100644
index 000000000..c925f363d
--- /dev/null
+++ b/cart/cart-application/src/main/resources/application.yaml
@@ -0,0 +1,9 @@
+spring:
+ application:
+ name: cart-application
+
+# server
+server:
+ port: 18086
+ servlet:
+ context-path: /cart-api/
diff --git a/cart/cart-service-api/pom.xml b/cart/cart-service-api/pom.xml
new file mode 100644
index 000000000..d301868b7
--- /dev/null
+++ b/cart/cart-service-api/pom.xml
@@ -0,0 +1,40 @@
+
+
+
+ cart
+ cn.iocoder.mall
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ cart-service-api
+
+
+
+ cn.iocoder.mall
+ common-framework
+ 1.0-SNAPSHOT
+
+
+
+ javax.validation
+ validation-api
+
+
+
+ org.mapstruct
+ mapstruct
+
+
+ org.mapstruct
+ mapstruct-jdk8
+
+
+ org.projectlombok
+ lombok
+
+
+
+
diff --git a/cart/cart-service-api/src/main/java/cn/iocoder/mall/cart/api/CartService.java b/cart/cart-service-api/src/main/java/cn/iocoder/mall/cart/api/CartService.java
new file mode 100644
index 000000000..47a6a8311
--- /dev/null
+++ b/cart/cart-service-api/src/main/java/cn/iocoder/mall/cart/api/CartService.java
@@ -0,0 +1,4 @@
+package cn.iocoder.mall.cart.api;
+
+public interface CartService {
+}
diff --git a/cart/cart-service-api/src/main/java/cn/iocoder/mall/cart/api/constant/CartErrorCodeEnum.java b/cart/cart-service-api/src/main/java/cn/iocoder/mall/cart/api/constant/CartErrorCodeEnum.java
new file mode 100644
index 000000000..0dae7880b
--- /dev/null
+++ b/cart/cart-service-api/src/main/java/cn/iocoder/mall/cart/api/constant/CartErrorCodeEnum.java
@@ -0,0 +1,28 @@
+package cn.iocoder.mall.cart.api.constant;
+
+/**
+ * 错误码枚举类
+ *
+ * 购物车系统,使用 1-005-000-000 段
+ */
+public enum CartErrorCodeEnum {
+
+ ;
+
+ private final int code;
+ private final String message;
+
+ CartErrorCodeEnum(int code, String message) {
+ this.code = code;
+ this.message = message;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+}
diff --git a/cart/cart-service-impl/pom.xml b/cart/cart-service-impl/pom.xml
new file mode 100644
index 000000000..96e609cee
--- /dev/null
+++ b/cart/cart-service-impl/pom.xml
@@ -0,0 +1,66 @@
+
+
+
+ cart
+ cn.iocoder.mall
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ cart-service-impl
+
+
+
+ com.alibaba
+ dubbo
+
+
+ cn.iocoder.mall
+ cart-service-api
+ 1.0-SNAPSHOT
+
+
+
+ mysql
+ mysql-connector-java
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+
+
+
+ com.google.guava
+ guava
+
+
+
+ com.xuxueli
+ xxl-job-core
+
+
+
+ org.apache.rocketmq
+ rocketmq-spring-boot-starter
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+
+
+
diff --git a/cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/config/DatabaseConfiguration.java b/cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/config/DatabaseConfiguration.java
new file mode 100644
index 000000000..375a47b3e
--- /dev/null
+++ b/cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/config/DatabaseConfiguration.java
@@ -0,0 +1,14 @@
+package cn.iocoder.mall.cart.biz.config;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+@Configuration
+@MapperScan("cn.iocoder.mall.cart.biz.dao") // 扫描对应的 Mapper 接口
+@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600
+public class DatabaseConfiguration {
+
+ // 数据源,使用 HikariCP
+
+}
diff --git a/cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/config/ServiceExceptionConfiguration.java b/cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/config/ServiceExceptionConfiguration.java
new file mode 100644
index 000000000..40263e309
--- /dev/null
+++ b/cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/config/ServiceExceptionConfiguration.java
@@ -0,0 +1,19 @@
+package cn.iocoder.mall.cart.biz.config;
+
+import cn.iocoder.common.framework.util.ServiceExceptionUtil;
+import cn.iocoder.mall.cart.api.constant.CartErrorCodeEnum;
+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() {
+ for (CartErrorCodeEnum item : CartErrorCodeEnum.values()) {
+ ServiceExceptionUtil.put(item.getCode(), item.getMessage());
+ }
+ }
+
+}
diff --git a/cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/package-info.java b/cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/package-info.java
new file mode 100644
index 000000000..5fcec432d
--- /dev/null
+++ b/cart/cart-service-impl/src/main/java/cn/iocoder/mall/cart/biz/package-info.java
@@ -0,0 +1 @@
+package cn.iocoder.mall.cart.biz;
diff --git a/cart/cart-service-impl/src/main/resources/config/application.properties b/cart/cart-service-impl/src/main/resources/config/application.properties
new file mode 100644
index 000000000..125191e02
--- /dev/null
+++ b/cart/cart-service-impl/src/main/resources/config/application.properties
@@ -0,0 +1 @@
+##################### 业务模块 #####################
\ No newline at end of file
diff --git a/cart/cart-service-impl/src/main/resources/config/application.yaml b/cart/cart-service-impl/src/main/resources/config/application.yaml
new file mode 100644
index 000000000..fc176627c
--- /dev/null
+++ b/cart/cart-service-impl/src/main/resources/config/application.yaml
@@ -0,0 +1,44 @@
+spring:
+ # datasource
+ datasource:
+ url: jdbc:mysql://180.167.213.26:13306/mall_cart?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.cart.biz.dataobject
+
+# dubbo
+dubbo:
+ application:
+ name: cart-service
+ registry:
+ address: zookeeper://127.0.0.1:2181
+ protocol:
+ port: -1
+ name: dubbo
+ scan:
+ base-packages: cn.iocoder.mall.cart.biz.service
+
+# xxl-job
+#xxl:
+# job:
+# admin:
+# addresses: http://127.0.0.1:8080/xxl-job-admin
+# executor:
+# appname: cart-job-executor
+# ip:
+# port: 0
+# logpath: /Users/yunai/logs/xxl-job/
+# logretentiondays: 1
+# accessToken:
+
+# rocketmq
+#rocketmq:
+# name-server: 127.0.0.1:9876
+# producer:
+# group: cart-producer-group
diff --git a/cart/cart-service-impl/src/main/resources/mybatis-config.xml b/cart/cart-service-impl/src/main/resources/mybatis-config.xml
new file mode 100644
index 000000000..7f604cc7e
--- /dev/null
+++ b/cart/cart-service-impl/src/main/resources/mybatis-config.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cart/pom.xml b/cart/pom.xml
new file mode 100644
index 000000000..dc05e2d77
--- /dev/null
+++ b/cart/pom.xml
@@ -0,0 +1,21 @@
+
+
+
+ mall-parent
+ cn.iocoder.mall
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ cart
+ pom
+
+ cart-application
+ cart-service-api
+ cart-service-impl
+
+
+
+
diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/ModuleErrorCodeInterval.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/ModuleErrorCodeInterval.java
index cebcac185..d4649b533 100644
--- a/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/ModuleErrorCodeInterval.java
+++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/ModuleErrorCodeInterval.java
@@ -27,9 +27,9 @@ public class ModuleErrorCodeInterval {
// pay 错误码区间 [1-004-000-000 ~ 1-005-000-000)
-
+ // cart 错误码区间 [1-005-000-000 ~ 1-006-000-000)
// promotion 错误码区间 [1-006-000-000 ~ 1-007-000-000)
-}
\ No newline at end of file
+}
diff --git a/pay/pay-application/pom.xml b/pay/pay-application/pom.xml
index 8f7bf977b..2a8a646a7 100644
--- a/pay/pay-application/pom.xml
+++ b/pay/pay-application/pom.xml
@@ -11,12 +11,7 @@
pay-application
-
- 1.3.0.Final
-
-
-
cn.iocoder.mall
common-framework
diff --git a/pay/pay-service-api/pom.xml b/pay/pay-service-api/pom.xml
index 2bf007bbc..fc8bf89c3 100644
--- a/pay/pay-service-api/pom.xml
+++ b/pay/pay-service-api/pom.xml
@@ -10,6 +10,7 @@
4.0.0
pay-service-api
+
cn.iocoder.mall
diff --git a/pay/pay-service-impl/pom.xml b/pay/pay-service-impl/pom.xml
index 967fb2afc..1125e7e5f 100644
--- a/pay/pay-service-impl/pom.xml
+++ b/pay/pay-service-impl/pom.xml
@@ -11,10 +11,6 @@
pay-service-impl
-
- 1.3.0.Final
-
-
com.alibaba
diff --git a/pom.xml b/pom.xml
index 5c5481e3c..b0189b4e6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,6 +22,7 @@
ops
pay
promotion
+ cart
pom
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/config/MVCConfiguration.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/config/MVCConfiguration.java
index 6bb15b388..bfba70c60 100644
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/config/MVCConfiguration.java
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/config/MVCConfiguration.java
@@ -1,6 +1,9 @@
package cn.iocoder.mall.product.application.config;
import cn.iocoder.common.framework.config.GlobalExceptionHandler;
+import cn.iocoder.common.framework.servlet.CorsFilter;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.*;
@@ -28,13 +31,12 @@ public class MVCConfiguration implements WebMvcConfigurer {
registry.addResourceHandler("webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
- // TODO 芋艿,允许跨域
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- registry.addMapping("/**")
- .allowedHeaders("*")
- .allowedMethods("*")
- .allowedOrigins("*");
+ @Bean
+ public FilterRegistrationBean corsFilter() {
+ FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
+ registrationBean.setFilter(new CorsFilter());
+ registrationBean.addUrlPatterns("/*");
+ return registrationBean;
}
-}
\ No newline at end of file
+}