分布式事务测试成功

This commit is contained in:
jieyuu 2024-08-24 18:47:03 +08:00
parent 915dd648f3
commit e65a801a62
4 changed files with 38 additions and 31 deletions
xdclass-common/src/main/java/net/jieyuu/exception
xdclass-coupon-service/src/main/java/net/jieyuu/config
xdclass-user-service/src/main/java/net/jieyuu

View File

@ -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("全局异常,未知错误");
}
}
}
//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("全局异常,未知错误");
// }
//
// }
//}

View File

@ -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);
}

View File

@ -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 {

View File

@ -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<UserMapper, UserDO> 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<UserMapper, UserDO> 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<UserMapper, UserDO> implements
}
/**
* 用户注册初始化福利信息 todo
* 用户注册初始化福利信息
*
* @param userDO
*/