分布式事务测试成功
This commit is contained in:
parent
915dd648f3
commit
e65a801a62
@ -1,28 +1,28 @@
|
|||||||
package net.jieyuu.exception;
|
package net.jieyuu.exception;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import net.jieyuu.utils.JsonData;
|
//import net.jieyuu.utils.JsonData;
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
//import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
//import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
//import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
//
|
||||||
@ControllerAdvice
|
//@ControllerAdvice
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
public class CustomExceptionHandle {
|
//public class CustomExceptionHandle {
|
||||||
|
//
|
||||||
@ExceptionHandler(value = Exception.class)
|
// @ExceptionHandler(value = Exception.class)
|
||||||
@ResponseBody
|
// @ResponseBody
|
||||||
public JsonData Handle(Exception e) {
|
// public JsonData Handle(Exception e) {
|
||||||
|
//
|
||||||
if (e instanceof BizException) {
|
// if (e instanceof BizException) {
|
||||||
BizException bizException = (BizException) e;
|
// BizException bizException = (BizException) e;
|
||||||
log.info("[业务异常]{}", e);
|
// log.info("[业务异常]{}", e);
|
||||||
return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg());
|
// return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg());
|
||||||
|
//
|
||||||
} else {
|
// } else {
|
||||||
log.info("[系统异常]{}", e);
|
// log.info("[系统异常]{}", e);
|
||||||
return JsonData.buildError("全局异常,未知错误");
|
// return JsonData.buildError("全局异常,未知错误");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -18,7 +18,7 @@ public class InterceptorConfig implements WebMvcConfigurer {
|
|||||||
//拦截的路径
|
//拦截的路径
|
||||||
.addPathPatterns("/api/coupon/*/**","/api/coupon_record/v1/*/**")
|
.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);
|
WebMvcConfigurer.super.addInterceptors(registry);
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,12 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
@EnableFeignClients
|
@EnableFeignClients
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableTransactionManagement
|
||||||
@MapperScan("net.jieyuu.mapper")
|
@MapperScan("net.jieyuu.mapper")
|
||||||
public class UserServiceApplication {
|
public class UserServiceApplication {
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.jieyuu.service.impl;
|
package net.jieyuu.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import io.seata.spring.annotation.GlobalTransactional;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -27,6 +28,8 @@ import org.springframework.beans.BeanUtils;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -66,7 +69,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@GlobalTransactional
|
||||||
public JsonData register(UserRegisterRequest registerRequest) {
|
public JsonData register(UserRegisterRequest registerRequest) {
|
||||||
|
|
||||||
boolean checkCode = false;
|
boolean checkCode = false;
|
||||||
//校验验证码
|
//校验验证码
|
||||||
if (StringUtils.isNotBlank(registerRequest.getMail())) {
|
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());
|
String cryptPwd = Md5Crypt.md5Crypt(userDO.getPwd().getBytes(), userDO.getSecret());
|
||||||
userDO.setPwd(cryptPwd);
|
userDO.setPwd(cryptPwd);
|
||||||
|
|
||||||
//账号唯一性检查 todo
|
//账号唯一性检查
|
||||||
if (checkUnique(userDO.getMail())) {
|
if (checkUnique(userDO.getMail())) {
|
||||||
//插入数据库
|
//插入数据库
|
||||||
int rows = userMapper.insert(userDO);
|
int rows = userMapper.insert(userDO);
|
||||||
log.info("rows:{},注册成功{}", rows, userDO.toString());
|
log.info("rows:{},注册成功{}", rows, userDO.toString());
|
||||||
|
|
||||||
//新用户创建成功,初始化,发福利 todo
|
//新用户创建成功,初始化,发福利
|
||||||
userRegisterInitTask(userDO);
|
userRegisterInitTask(userDO);
|
||||||
return JsonData.buildSuccess();
|
return JsonData.buildSuccess();
|
||||||
|
|
||||||
@ -126,7 +131,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户注册,初始化福利信息 todo
|
* 用户注册,初始化福利信息
|
||||||
*
|
*
|
||||||
* @param userDO
|
* @param userDO
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user