Commit e4e73cce authored by 杨锐's avatar 杨锐

redis分布式锁,处理/user/center/save/userExtInfo并发问题,导致MySQLIntegrityConstraintViolationException

parent 8d88ed7c
......@@ -2,6 +2,7 @@ package cn.quantgroup.xyqb.aspect.lock;
import cn.quantgroup.xyqb.exception.ResubmissionException;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
......@@ -9,8 +10,6 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
......@@ -24,12 +23,11 @@ import java.lang.reflect.Method;
/**
* Redis Lock Aspect
*/
@Slf4j
@Aspect
@Component
public class RedisLockAspect {
private final static Logger LOGGER = LoggerFactory.getLogger(RedisLockAspect.class);
@Autowired
@Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate;
......@@ -70,7 +68,7 @@ public class RedisLockAspect {
lockKey = prefix.concat(":").concat(keySPEL);
}
} catch (ExpressionException e) {
LOGGER.error("key表达式“" + keySPEL + "”错误:{}", e);
log.error("key表达式“" + keySPEL + "”错误:{}", e);
throw e;
}
} else {
......@@ -85,11 +83,11 @@ public class RedisLockAspect {
if (lock.lock()) {
return pjp.proceed();
} else {
LOGGER.warn("调用方法失败,已有业务数据在处理中 lockKey:{}", lock.getLockKey());
log.warn("调用方法失败,已有业务数据在处理中 lockKey:{}", lock.getLockKey());
throw new ResubmissionException();
}
} catch (InterruptedException e) {
LOGGER.warn("获取锁失败:lockKey:{},exception:{}", lock.getLockKey(), e.getMessage());
log.warn("获取锁失败:lockKey:{},exception:{}", lock.getLockKey(), e.getMessage());
throw new ResubmissionException();
} finally {
lock.unlock();
......
......@@ -171,6 +171,6 @@ public class ExceptionHandlingController implements IBaseController {
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public JsonResult resubmissionException(ResubmissionException re) {
return new JsonResult(re.getMessage(), 0L, null, re.getBusinessCode());
return JsonResult.buildErrorStateResult(re.getMessage(), null);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment