From e65a801a62cb082d603a32bd0ee23d1971cd72fb Mon Sep 17 00:00:00 2001 From: jieyuu <645634619@qq.com> Date: Sat, 24 Aug 2024 18:47:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E5=B8=83=E5=BC=8F=E4=BA=8B=E5=8A=A1?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/CustomExceptionHandle.java | 52 +++++++++---------- .../net/jieyuu/config/InterceptorConfig.java | 2 +- .../net/jieyuu/UserServiceApplication.java | 4 +- .../jieyuu/service/impl/UserServiceImpl.java | 11 ++-- 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/xdclass-common/src/main/java/net/jieyuu/exception/CustomExceptionHandle.java b/xdclass-common/src/main/java/net/jieyuu/exception/CustomExceptionHandle.java index c4a055a..bf15c7a 100644 --- a/xdclass-common/src/main/java/net/jieyuu/exception/CustomExceptionHandle.java +++ b/xdclass-common/src/main/java/net/jieyuu/exception/CustomExceptionHandle.java @@ -1,28 +1,28 @@ package net.jieyuu.exception; -import lombok.extern.slf4j.Slf4j; -import net.jieyuu.utils.JsonData; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; - -@ControllerAdvice -@Slf4j -public class CustomExceptionHandle { - - @ExceptionHandler(value = Exception.class) - @ResponseBody - public JsonData Handle(Exception e) { - - if (e instanceof BizException) { - BizException bizException = (BizException) e; - log.info("[业务异常]{}", e); - return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg()); - - } else { - log.info("[系统异常]{}", e); - return JsonData.buildError("全局异常,未知错误"); - } - - } -} \ No newline at end of file +//import lombok.extern.slf4j.Slf4j; +//import net.jieyuu.utils.JsonData; +//import org.springframework.web.bind.annotation.ControllerAdvice; +//import org.springframework.web.bind.annotation.ExceptionHandler; +//import org.springframework.web.bind.annotation.ResponseBody; +// +//@ControllerAdvice +//@Slf4j +//public class CustomExceptionHandle { +// +// @ExceptionHandler(value = Exception.class) +// @ResponseBody +// public JsonData Handle(Exception e) { +// +// if (e instanceof BizException) { +// BizException bizException = (BizException) e; +// log.info("[业务异常]{}", e); +// return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg()); +// +// } else { +// log.info("[系统异常]{}", e); +// return JsonData.buildError("全局异常,未知错误"); +// } +// +// } +//} \ No newline at end of file diff --git a/xdclass-coupon-service/src/main/java/net/jieyuu/config/InterceptorConfig.java b/xdclass-coupon-service/src/main/java/net/jieyuu/config/InterceptorConfig.java index 87a45a6..e963528 100644 --- a/xdclass-coupon-service/src/main/java/net/jieyuu/config/InterceptorConfig.java +++ b/xdclass-coupon-service/src/main/java/net/jieyuu/config/InterceptorConfig.java @@ -18,7 +18,7 @@ public class InterceptorConfig implements WebMvcConfigurer { //拦截的路径 .addPathPatterns("/api/coupon/*/**","/api/coupon_record/v1/*/**") //放行的路径 - .excludePathPatterns("/api/coupon/*/page_coupon","/api/coupon/*/initNewUserCoupon"); + .excludePathPatterns("/api/coupon/*/page_coupon","/api/coupon/*/new_user_coupon"); WebMvcConfigurer.super.addInterceptors(registry); } diff --git a/xdclass-user-service/src/main/java/net/jieyuu/UserServiceApplication.java b/xdclass-user-service/src/main/java/net/jieyuu/UserServiceApplication.java index 82c472f..500aee9 100644 --- a/xdclass-user-service/src/main/java/net/jieyuu/UserServiceApplication.java +++ b/xdclass-user-service/src/main/java/net/jieyuu/UserServiceApplication.java @@ -5,10 +5,12 @@ 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.transaction.annotation.EnableTransactionManagement; -@EnableFeignClients +@EnableFeignClients @EnableDiscoveryClient @SpringBootApplication +@EnableTransactionManagement @MapperScan("net.jieyuu.mapper") public class UserServiceApplication { diff --git a/xdclass-user-service/src/main/java/net/jieyuu/service/impl/UserServiceImpl.java b/xdclass-user-service/src/main/java/net/jieyuu/service/impl/UserServiceImpl.java index 1107e82..2c70839 100644 --- a/xdclass-user-service/src/main/java/net/jieyuu/service/impl/UserServiceImpl.java +++ b/xdclass-user-service/src/main/java/net/jieyuu/service/impl/UserServiceImpl.java @@ -1,6 +1,7 @@ package net.jieyuu.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import io.seata.spring.annotation.GlobalTransactional; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; @@ -27,6 +28,8 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; @@ -66,7 +69,9 @@ public class UserServiceImpl extends ServiceImpl implements * @return */ @Override + @GlobalTransactional public JsonData register(UserRegisterRequest registerRequest) { + boolean checkCode = false; //校验验证码 if (StringUtils.isNotBlank(registerRequest.getMail())) { @@ -93,13 +98,13 @@ public class UserServiceImpl extends ServiceImpl implements String cryptPwd = Md5Crypt.md5Crypt(userDO.getPwd().getBytes(), userDO.getSecret()); userDO.setPwd(cryptPwd); - //账号唯一性检查 todo + //账号唯一性检查 if (checkUnique(userDO.getMail())) { //插入数据库 int rows = userMapper.insert(userDO); log.info("rows:{},注册成功{}", rows, userDO.toString()); - //新用户创建成功,初始化,发福利 todo + //新用户创建成功,初始化,发福利 userRegisterInitTask(userDO); return JsonData.buildSuccess(); @@ -126,7 +131,7 @@ public class UserServiceImpl extends ServiceImpl implements } /** - * 用户注册,初始化福利信息 todo + * 用户注册,初始化福利信息 * * @param userDO */