From e8c10e6807f10c1215e4b9c39e7c47a15d95b85d Mon Sep 17 00:00:00 2001 From: xc-yjs Date: Wed, 14 Aug 2024 17:48:23 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=20=E6=9B=B4=E6=96=B0=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nla-common/pom.xml | 36 ++++++++++ .../common/config/SwaggerConfiguration.java | 24 +++++++ .../java/cn/nla/common/config/WebConfig.java | 7 +- .../java/cn/nla/common/enums/ClientType.java | 22 ++++++ .../common/enums/ProductOrderPayTypeEnum.java | 20 ++++++ .../common/enums/ProductOrderStateEnum.java | 22 ++++++ .../common/enums/ProductOrderTypeEnum.java | 17 +++++ .../test/java/tools/MyBatisPlusGenerator.java | 8 +-- .../java/cn/nla/coupon/CouponApplication.java | 6 ++ .../src/main/resources/application.yml | 17 +++++ nla-order-service/pom.xml | 29 ++++++++ .../java/cn/nla/order/OrderApplication.java | 15 ++++ .../model/request/ConfirmOrderRequest.java | 57 +++++++++++++++ .../src/main/resources/application.yml | 26 +++++++ .../src/main/resources/logback.xml | 71 +++++++++++++++++++ .../java/cn/nla/user/UserApplication.java | 6 ++ .../nla/user/controller/UserController.java | 19 ++++- .../cn/nla/user/feign/CouponFeignService.java | 23 ++++++ .../model/request/NewUserCouponRequest.java | 20 ++++++ .../user/service/impl/UserServiceImpl.java | 24 ++++++- .../src/main/resources/application.yml | 19 +++++ pom.xml | 1 + 22 files changed, 478 insertions(+), 11 deletions(-) create mode 100644 nla-common/src/main/java/cn/nla/common/enums/ClientType.java create mode 100644 nla-common/src/main/java/cn/nla/common/enums/ProductOrderPayTypeEnum.java create mode 100644 nla-common/src/main/java/cn/nla/common/enums/ProductOrderStateEnum.java create mode 100644 nla-common/src/main/java/cn/nla/common/enums/ProductOrderTypeEnum.java create mode 100644 nla-order-service/pom.xml create mode 100644 nla-order-service/src/main/java/cn/nla/order/OrderApplication.java create mode 100644 nla-order-service/src/main/java/cn/nla/order/model/request/ConfirmOrderRequest.java create mode 100644 nla-order-service/src/main/resources/application.yml create mode 100644 nla-order-service/src/main/resources/logback.xml create mode 100644 nla-user-service/src/main/java/cn/nla/user/feign/CouponFeignService.java create mode 100644 nla-user-service/src/main/java/cn/nla/user/model/request/NewUserCouponRequest.java diff --git a/nla-common/pom.xml b/nla-common/pom.xml index c0c03cd..1ded6a1 100644 --- a/nla-common/pom.xml +++ b/nla-common/pom.xml @@ -94,6 +94,42 @@ fastjson 1.2.75 + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + org.springframework.boot + spring-boot-starter-amqp + diff --git a/nla-common/src/main/java/cn/nla/common/config/SwaggerConfiguration.java b/nla-common/src/main/java/cn/nla/common/config/SwaggerConfiguration.java index d5c3185..90f296b 100644 --- a/nla-common/src/main/java/cn/nla/common/config/SwaggerConfiguration.java +++ b/nla-common/src/main/java/cn/nla/common/config/SwaggerConfiguration.java @@ -89,6 +89,30 @@ public class SwaggerConfiguration { .globalResponses(HttpMethod.GET, getGlobalResponseMessage()) .globalResponses(HttpMethod.POST, getGlobalResponseMessage()); } + + /** + * 订单服务端的接口文档 + */ + @Bean + public Docket orderApiDoc() { + return new Docket(DocumentationType.OAS_30) // 版本3.0 + .groupName("订单端接口文档") + .pathMapping("/") + //定义是否开启Swagger,false是关闭,可以通过变量去控制,线上关闭 + .enable(true) + //配置文档的元信息 + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("cn.nla")) + //正则匹配请求路径,并分配到当前项目组 + .paths(PathSelectors.ant("/odr/**")) + .build() + // 新版SwaggerUI3.0 + .globalRequestParameters(globalRequestParameters()) + .globalResponses(HttpMethod.GET, getGlobalResponseMessage()) + .globalResponses(HttpMethod.POST, getGlobalResponseMessage()); + } + /** * 接口基本信息配置 */ diff --git a/nla-common/src/main/java/cn/nla/common/config/WebConfig.java b/nla-common/src/main/java/cn/nla/common/config/WebConfig.java index 88ff9c1..59cb1af 100644 --- a/nla-common/src/main/java/cn/nla/common/config/WebConfig.java +++ b/nla-common/src/main/java/cn/nla/common/config/WebConfig.java @@ -22,14 +22,15 @@ public class WebConfig implements WebMvcConfigurer { registry.addInterceptor(responseResultInterceptor); registry.addInterceptor(loginInterceptor) //拦截的路径 - .addPathPatterns("/user/*/**", "/address/*/**", "/cop/*/**", "/pdt/*/**") + .addPathPatterns("/user/*/**", "/address/*/**", "/cop/*/**", "/pdt/*/**", "/odr/*/**") //排查不拦截的路径 .excludePathPatterns( - "/user/**/send", "/user/**/captcha", + "/user/**/send_code", "/user/**/register", "/user/**/login", - "/user/**/uploadFile"); + "/user/**/uploadFile", + "/cop/coupon/v1/new_user_coupon"); } /** diff --git a/nla-common/src/main/java/cn/nla/common/enums/ClientType.java b/nla-common/src/main/java/cn/nla/common/enums/ClientType.java new file mode 100644 index 0000000..16e2364 --- /dev/null +++ b/nla-common/src/main/java/cn/nla/common/enums/ClientType.java @@ -0,0 +1,22 @@ +package cn.nla.common.enums; + +/** + * 客户端枚举类 + */ +public enum ClientType { + + /** + * 原生应用 + */ + APP, + + /** + * 电脑端 + */ + PC, + + /** + * 网页 + */ + H5 +} diff --git a/nla-common/src/main/java/cn/nla/common/enums/ProductOrderPayTypeEnum.java b/nla-common/src/main/java/cn/nla/common/enums/ProductOrderPayTypeEnum.java new file mode 100644 index 0000000..e56ac9e --- /dev/null +++ b/nla-common/src/main/java/cn/nla/common/enums/ProductOrderPayTypeEnum.java @@ -0,0 +1,20 @@ +package cn.nla.common.enums; + +public enum ProductOrderPayTypeEnum { + + /** + * 微信支付 + */ + WECHAT, + + /** + * 支付支付 + */ + ALIPAY, + + /** + * 银行卡支付 + */ + BANK; + +} diff --git a/nla-common/src/main/java/cn/nla/common/enums/ProductOrderStateEnum.java b/nla-common/src/main/java/cn/nla/common/enums/ProductOrderStateEnum.java new file mode 100644 index 0000000..424aa86 --- /dev/null +++ b/nla-common/src/main/java/cn/nla/common/enums/ProductOrderStateEnum.java @@ -0,0 +1,22 @@ +package cn.nla.common.enums; + +public enum ProductOrderStateEnum { + + /** + * 未支付订单 + */ + NEW, + + + /** + * 已经支付订单 + */ + PAY, + + /** + * 超时取消订单 + */ + CANCEL; + +} + diff --git a/nla-common/src/main/java/cn/nla/common/enums/ProductOrderTypeEnum.java b/nla-common/src/main/java/cn/nla/common/enums/ProductOrderTypeEnum.java new file mode 100644 index 0000000..5b816ee --- /dev/null +++ b/nla-common/src/main/java/cn/nla/common/enums/ProductOrderTypeEnum.java @@ -0,0 +1,17 @@ +package cn.nla.common.enums; + + +public enum ProductOrderTypeEnum { + + /** + * 普通订单 + */ + DAILY, + + + /** + * 促销订单 + */ + PROMOTION; + +} diff --git a/nla-common/src/test/java/tools/MyBatisPlusGenerator.java b/nla-common/src/test/java/tools/MyBatisPlusGenerator.java index 2674bc3..fcc90c8 100644 --- a/nla-common/src/test/java/tools/MyBatisPlusGenerator.java +++ b/nla-common/src/test/java/tools/MyBatisPlusGenerator.java @@ -22,7 +22,7 @@ public class MyBatisPlusGenerator { // 作者 .setAuthor("YJs") // ⽣成路径,最好使⽤绝对路径,window路径是不⼀样的 - .setOutputDir("D:\\workspace\\2024\\nla-shop\\nla-product-service\\src\\main\\java") + .setOutputDir("D:\\workspace\\2024\\nla-shop\\nla-coupon-service\\src\\main\\java") // ⽂件覆盖 .setFileOverride(true) // 主键策略 @@ -43,7 +43,7 @@ public class MyBatisPlusGenerator { // 设置数据库类型 dsConfig.setDbType(DbType.MYSQL) .setDriverName("com.mysql.cj.jdbc.Driver") - .setUrl("jdbc:mysql://117.72.43.105:3306/p_nla_product?useSSL=false") + .setUrl("jdbc:mysql://117.72.43.105:3306/p_nla_coupon?useSSL=false") .setUsername("root") .setPassword("Yuan625621105."); @@ -58,11 +58,11 @@ public class MyBatisPlusGenerator { //使⽤restcontroller注解 .setRestControllerStyle(true) // ⽣成的表, ⽀持多表⼀起⽣成,以数组形式填写 - .setInclude("product","banner"); + .setInclude("coupon_task"); //4. 包名策略配置 PackageConfig pkConfig = new PackageConfig(); - pkConfig.setParent("cn.nla.product") + pkConfig.setParent("cn.nla.coupon") .setMapper("mapper") .setService("service") .setController("controller") diff --git a/nla-coupon-service/src/main/java/cn/nla/coupon/CouponApplication.java b/nla-coupon-service/src/main/java/cn/nla/coupon/CouponApplication.java index b0fca53..a7b6d40 100644 --- a/nla-coupon-service/src/main/java/cn/nla/coupon/CouponApplication.java +++ b/nla-coupon-service/src/main/java/cn/nla/coupon/CouponApplication.java @@ -3,9 +3,15 @@ package cn.nla.coupon; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; +import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication +@EnableFeignClients +@EnableDiscoveryClient +@EnableTransactionManagement @MapperScan("cn.nla.*.mapper") @ComponentScan(basePackages = {"cn.nla.*"}) public class CouponApplication { diff --git a/nla-coupon-service/src/main/resources/application.yml b/nla-coupon-service/src/main/resources/application.yml index 72f25af..59e84b3 100644 --- a/nla-coupon-service/src/main/resources/application.yml +++ b/nla-coupon-service/src/main/resources/application.yml @@ -14,6 +14,14 @@ spring: url: jdbc:mysql://117.72.43.105:3306/p_nla_coupon?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai username: root password: Yuan625621105. + cloud: + #注册中心地址 + nacos: + discovery: + server-addr: 117.72.43.105:8848 +# username: nacos +# password: sW5U%pxecL#p +# namespace: yjs #配置plus打印sql⽇志 mybatis-plus: configuration: @@ -24,3 +32,12 @@ mybatis-plus: # level: # root: INFO + +#seata配置 +seata: + tx-service-group: ${spring.application.name}-group + service: + grouplist: + nla: 127.0.0.1:8091 + vgroup-mapping: + nla-coupon-service-group: nla diff --git a/nla-order-service/pom.xml b/nla-order-service/pom.xml new file mode 100644 index 0000000..39c7701 --- /dev/null +++ b/nla-order-service/pom.xml @@ -0,0 +1,29 @@ + + + + nla-shop + cn.nla + 1.0-SNAPSHOT + + 4.0.0 + nla-order-service + 订单服务模块 + + + 11 + 11 + + + + cn.nla + nla-common + 1.0-SNAPSHOT + + + org.projectlombok + lombok + + + diff --git a/nla-order-service/src/main/java/cn/nla/order/OrderApplication.java b/nla-order-service/src/main/java/cn/nla/order/OrderApplication.java new file mode 100644 index 0000000..fa9f45c --- /dev/null +++ b/nla-order-service/src/main/java/cn/nla/order/OrderApplication.java @@ -0,0 +1,15 @@ +package cn.nla.order; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@MapperScan("cn.nla.*.mapper") +@ComponentScan(basePackages = {"cn.nla.*"}) +public class OrderApplication { + public static void main(String[] args) { + SpringApplication.run(OrderApplication.class, args); + } +} diff --git a/nla-order-service/src/main/java/cn/nla/order/model/request/ConfirmOrderRequest.java b/nla-order-service/src/main/java/cn/nla/order/model/request/ConfirmOrderRequest.java new file mode 100644 index 0000000..584b188 --- /dev/null +++ b/nla-order-service/src/main/java/cn/nla/order/model/request/ConfirmOrderRequest.java @@ -0,0 +1,57 @@ +package cn.nla.order.model.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 订单请求参数 + */ +@ApiModel(value = "添加订单对象", description = "添加订单请求对象") +@Data +public class ConfirmOrderRequest { + @ApiModelProperty(value = "购物车使用的优惠券,集满减劵(如果传空或者小于0,则不用优惠券)", example = "1") + @JsonProperty("coupon_record_id") + private Long couponRecordId; + @ApiModelProperty(value = "最终购买的商品列表:传递id,购买数量从购物车中读取") + @JsonProperty("product_ids") + private List productIdList; + @ApiModelProperty(value = "支付方式", example = "WECHAT") + @JsonProperty("pay_type") + private String payType; + /** + * 端类型 + */ + @ApiModelProperty(value = "端类型", example = "APP") + @JsonProperty("client_type") + private String clientType; + /** + * 收货地址id + */ + @ApiModelProperty(value = "收货地址id", example = "中国") + @JsonProperty("address_id") + private long addressId; + /** + * 总价格,前端传递,后端需要验价 + */ + @ApiModelProperty(value = "总价格", example = "40.00") + @JsonProperty("total_amount") + private BigDecimal totalAmount; + /** + * 实际支付的价格, + * 如果用了优惠劵,则是减去优惠券后端价格,如果没的话,则是totalAmount一样 + */ + @ApiModelProperty(value = "实际支付的价格", example = "20.00") + @JsonProperty("real_pay_amount") + private BigDecimal realPayAmount; + /** + * 防重令牌 + */ + @ApiModelProperty(value = "防重令牌", example = "sdvdgwerqwerwrwerqweq") + @JsonProperty("token") + private String token; +} diff --git a/nla-order-service/src/main/resources/application.yml b/nla-order-service/src/main/resources/application.yml new file mode 100644 index 0000000..54ad622 --- /dev/null +++ b/nla-order-service/src/main/resources/application.yml @@ -0,0 +1,26 @@ +server: + port: 9004 +spring: + application: + name: nla-order-service + redis: + host: 127.0.0.1 + port: 6379 + database: 0 + password: yuan123456 + #数据库配置 + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://117.72.43.105:3306/p_nla_order?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: Yuan625621105. +#配置plus打印sql⽇志 +mybatis-plus: + configuration: + log-impl: + org.apache.ibatis.logging.stdout.StdOutImpl +#设置⽇志级别,ERROR/WARN/INFO/DEBUG,默认是INFO以上才显示 +#logging: +# level: +# root: INFO + diff --git a/nla-order-service/src/main/resources/logback.xml b/nla-order-service/src/main/resources/logback.xml new file mode 100644 index 0000000..fb410d8 --- /dev/null +++ b/nla-order-service/src/main/resources/logback.xml @@ -0,0 +1,71 @@ + + + + + + + + + + ${log.pattern} + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + + + + + + + + + + + + + diff --git a/nla-user-service/src/main/java/cn/nla/user/UserApplication.java b/nla-user-service/src/main/java/cn/nla/user/UserApplication.java index 7357dea..c82b96d 100644 --- a/nla-user-service/src/main/java/cn/nla/user/UserApplication.java +++ b/nla-user-service/src/main/java/cn/nla/user/UserApplication.java @@ -3,11 +3,17 @@ package cn.nla.user; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; +import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication +@EnableFeignClients +@EnableDiscoveryClient @MapperScan("cn.nla.*.mapper") @ComponentScan(basePackages = {"cn.nla.*"}) +@EnableTransactionManagement public class UserApplication { public static void main(String[] args) { SpringApplication.run(UserApplication.class, args); diff --git a/nla-user-service/src/main/java/cn/nla/user/controller/UserController.java b/nla-user-service/src/main/java/cn/nla/user/controller/UserController.java index 7738191..376d834 100644 --- a/nla-user-service/src/main/java/cn/nla/user/controller/UserController.java +++ b/nla-user-service/src/main/java/cn/nla/user/controller/UserController.java @@ -1,6 +1,7 @@ package cn.nla.user.controller; import cn.nla.common.util.JsonData; +import cn.nla.user.feign.CouponFeignService; import cn.nla.user.model.request.UserLoginRequest; import cn.nla.user.model.request.UserRegisterRequest; import cn.nla.user.service.UserService; @@ -10,6 +11,7 @@ import io.swagger.annotations.ApiParam; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.Map; /** *

@@ -24,6 +26,9 @@ public class UserController { @Resource private UserService userService; + @Resource + private CouponFeignService couponFeignService; + @ApiOperation("用户注册") @PostMapping("register") public JsonData register(@ApiParam("用户注册对象") @RequestBody UserRegisterRequest registerRequest) { @@ -32,7 +37,7 @@ public class UserController { @ApiOperation("用户登录") @PostMapping("login") - public JsonData login(@ApiParam("用户登录对象") @RequestBody UserLoginRequest userLoginRequest){ + public JsonData login(@ApiParam("用户登录对象") @RequestBody UserLoginRequest userLoginRequest) { return userService.login(userLoginRequest); } @@ -41,8 +46,18 @@ public class UserController { */ @ApiOperation("个人信息查询") @GetMapping("detail") - public JsonData detail(){ + public JsonData detail() { return JsonData.buildSuccess(userService.findUserDetail()); } + + + @ApiOperation("Feign调用分页查询优惠券") + @GetMapping("page_coupon") + public JsonData pageCouponList( + @ApiParam(value = "当前页") @RequestParam(value = "page", defaultValue = "1") int page, + @ApiParam(value = "每页显示多少条") @RequestParam(value = "size", defaultValue = "10") int size, + @RequestHeader Map header) { + return JsonData.buildSuccess(couponFeignService.pageCouponList(header, page, size)); + } } diff --git a/nla-user-service/src/main/java/cn/nla/user/feign/CouponFeignService.java b/nla-user-service/src/main/java/cn/nla/user/feign/CouponFeignService.java new file mode 100644 index 0000000..09ad1f4 --- /dev/null +++ b/nla-user-service/src/main/java/cn/nla/user/feign/CouponFeignService.java @@ -0,0 +1,23 @@ +package cn.nla.user.feign; + +import cn.nla.common.util.JsonData; +import cn.nla.user.model.request.NewUserCouponRequest; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * Feign调用优惠券服务接口 + */ +@FeignClient(name = "nla-coupon-service") +public interface CouponFeignService { + /** + * 分页查询优惠券 + */ + @GetMapping("/cop/coupon/v1/page_coupon") + JsonData pageCouponList(@RequestHeader Map header, @RequestParam("page") int page, @RequestParam("size") int size); + + @PostMapping("/cop/coupon/v1/new_user_coupon") + JsonData addNewUserCoupon(@RequestBody NewUserCouponRequest newUserCouponRequest); +} diff --git a/nla-user-service/src/main/java/cn/nla/user/model/request/NewUserCouponRequest.java b/nla-user-service/src/main/java/cn/nla/user/model/request/NewUserCouponRequest.java new file mode 100644 index 0000000..72bceba --- /dev/null +++ b/nla-user-service/src/main/java/cn/nla/user/model/request/NewUserCouponRequest.java @@ -0,0 +1,20 @@ +package cn.nla.user.model.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 新用户注册发放优惠卷 + */ +@ApiModel(value = "新用户注册发放优惠卷对象", description = "新用户注册发放优惠卷请求对象") +@Data +public class NewUserCouponRequest { + @ApiModelProperty(value = "用户Id", example = "19") + @JsonProperty("user_id") + private long userId; + @ApiModelProperty(value = "名称", example = "二当家") + @JsonProperty("name") + private String name; +} diff --git a/nla-user-service/src/main/java/cn/nla/user/service/impl/UserServiceImpl.java b/nla-user-service/src/main/java/cn/nla/user/service/impl/UserServiceImpl.java index 58d0816..7fcfb49 100644 --- a/nla-user-service/src/main/java/cn/nla/user/service/impl/UserServiceImpl.java +++ b/nla-user-service/src/main/java/cn/nla/user/service/impl/UserServiceImpl.java @@ -7,20 +7,25 @@ import cn.nla.common.model.LoginUser; import cn.nla.common.util.CommonUtil; import cn.nla.common.util.JWTUtil; import cn.nla.common.util.JsonData; +import cn.nla.user.feign.CouponFeignService; import cn.nla.user.model.VO.UserVO; import cn.nla.user.model.entity.UserEntity; import cn.nla.user.mapper.UserMapper; +import cn.nla.user.model.request.NewUserCouponRequest; import cn.nla.user.model.request.UserLoginRequest; import cn.nla.user.service.NotifyService; import cn.nla.user.service.UserService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import io.seata.spring.annotation.GlobalTransactional; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.Md5Crypt; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import cn.nla.user.model.request.UserRegisterRequest; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Date; @@ -41,6 +46,8 @@ public class UserServiceImpl extends ServiceImpl impleme private NotifyService notifyService; @Resource private UserMapper userMapper; + @Resource + private CouponFeignService couponFeignService; /** * 用户注册
@@ -50,7 +57,9 @@ public class UserServiceImpl extends ServiceImpl impleme * 插入数据库
* 新注册用户福利发放(TODO) */ +// @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) @Override + @GlobalTransactional public JsonData register(UserRegisterRequest registerRequest) { boolean checkCode = false; //校验验证码 @@ -73,8 +82,10 @@ public class UserServiceImpl extends ServiceImpl impleme if (checkUnique(userEntity.getMail())) { int rows = userMapper.insert(userEntity); log.info("rows:{},注册成功:{}", rows, userEntity); - //新用户注册成功,初始化信息,发放福利等 TODO + //新用户注册成功,初始化信息,发放福利等 userRegisterInitTask(userEntity); +// //模拟异常 +// int b = 1/0; return JsonData.buildSuccess(); } else { return JsonData.buildResult(BizCodeEnum.ACCOUNT_REPEAT); @@ -123,12 +134,21 @@ public class UserServiceImpl extends ServiceImpl impleme } /** - * 用户注册,初始化福利信息 TODO + * 用户注册,初始化福利信息 * * @param userEntity 用户对象信息 */ private void userRegisterInitTask(UserEntity userEntity) { log.info("初始化福利信息 TODO... {}", userEntity); + NewUserCouponRequest request = new NewUserCouponRequest(); + request.setName(userEntity.getName()); + request.setUserId(userEntity.getId()); + JsonData jsonData = couponFeignService.addNewUserCoupon(request); +// if(jsonData.getCode()!=0){ +// throw new RuntimeException("发放优惠券异常"); +// } + log.info("发放新用户注册优惠券:{},结果:{}",request.toString(),jsonData.toString()); + } } diff --git a/nla-user-service/src/main/resources/application.yml b/nla-user-service/src/main/resources/application.yml index dcdc1bc..16e975c 100644 --- a/nla-user-service/src/main/resources/application.yml +++ b/nla-user-service/src/main/resources/application.yml @@ -7,6 +7,7 @@ spring: host: 127.0.0.1 port: 6379 database: 0 + password: yuan123456 #数据库配置 datasource: driver-class-name: com.mysql.cj.jdbc.Driver @@ -22,6 +23,15 @@ spring: properties.mail.smtp.starttls.required: true properties.mail.smtp.ssl.enable: true default-encoding: utf-8 + cloud: + #注册中心地址 + nacos: + discovery: + server-addr: 117.72.43.105:8848 +# username: nacos +# password: sW5U%pxecL#p +# namespace: yjs + #配置plus打印sql⽇志 mybatis-plus: configuration: @@ -39,3 +49,12 @@ aliyun: access-key-id: LTAI5tGbV7aVMVKSnoDwmFUY access-key-secret: U4W5fsdxjAh5f3udizbYNFdUldD8pZ bucketname: yzdan + +#seata配置 +seata: + tx-service-group: ${spring.application.name}-group + service: + grouplist: + nla: 127.0.0.1:8091 + vgroup-mapping: + nla-user-service-group: nla diff --git a/pom.xml b/pom.xml index cfb0518..b0194db 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ nla-user-service nla-coupon-service nla-product-service + nla-order-service pom 拉新营销平台