Commit 67bb91be by zhoulm Committed by 周立明

fix: 为商品上架审批相关方法添加分布式锁并优化异常处理

1. 新增BeanConfig配置类注册Redis分布式锁组件
2. 为reject、review、submitReview、updateConfirmStep方法添加GlsxDistributeLock分布式锁
3. 优化异常捕获逻辑,先单独处理RpcServiceException再捕获全局Exception
4. 将SERVICE_ERROR枚举修正为SERVER_ERROR
1 parent f6b92f9e
package cn.com.glsx.dj.goods.listing.config;
import org.oreframework.boot.autoconfigure.distributelock.redis.RedisDistributeLockProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.integration.redis.util.RedisLockRegistry;
import org.springframework.integration.support.locks.LockRegistry;
import lombok.extern.slf4j.Slf4j;
/**
* @Title: BeanConfig.java
* @Description:
* @author Alvin
* @date 2019年3月9日 下午4:22:04
* @version V1.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2018
*/
@Slf4j
@Configuration
public class BeanConfig {
@Autowired
private RedisConnectionFactory redisConnectionFactory;
@Autowired
private RedisDistributeLockProperties redisDistributeLockProperties;
@Bean
public LockRegistry lockRegistry() {
return new RedisLockRegistry(this.redisConnectionFactory, this.redisDistributeLockProperties.getRegistryKey(), 1800000);
}
}
......@@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
......@@ -257,6 +258,7 @@ public class GoodsListingApprovalService {
}
//驳回
@GlsxDistributeLockable(name="'GoodsListingApprovalService_' + #record.businessCode", time = 60,timeoutException=RpcServiceException.class)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public Boolean reject(GoodsListingApproval record) {
RpcAssert.assertNotNull(record, DefaultErrorEnum.DATA_NULL, "record not be null");
......@@ -281,12 +283,15 @@ public class GoodsListingApprovalService {
.updatedBy(record.getUpdatedBy()).updatedDate(now)
.build());
return true;
}catch (RpcServiceException e) {
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, e.getMessage());
}
}
@GlsxDistributeLockable(name="'GoodsListingApprovalService_' + #record.businessCode", time = 1800,timeoutException=RpcServiceException.class)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public Boolean review(GoodsListingApproval record) {
RpcAssert.assertNotNull(record, DefaultErrorEnum.DATA_NULL, "record not be null");
......@@ -313,12 +318,15 @@ public class GoodsListingApprovalService {
thiz.publishApprovedListingData(record.getBusinessCode(), record.getUpdatedBy());
log.info("商品上架审核end,businessCode:{} consuming:{} ms",record.getBusinessCode(),System.currentTimeMillis() - l);
return true;
} catch (Exception e) {
}catch (RpcServiceException e) {
throw e;
}catch (Exception e) {
log.error(e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage());
}
}
@GlsxDistributeLockable(name="'GoodsListingApprovalService_' + #record.businessCode", time = 1800,timeoutException=RpcServiceException.class)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public Boolean submitReview(GoodsListingApproval record) {
RpcAssert.assertNotNull(record, DefaultErrorEnum.DATA_NULL, "record not be null");
......@@ -1884,6 +1892,7 @@ public class GoodsListingApprovalService {
}
}
@GlsxDistributeLockable(name="'GoodsListingApprovalService_' + #dto.businessCode", time = 1800,timeoutException=RpcServiceException.class)
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public Boolean updateConfirmStep(GoodsListingApprovalDTO dto) {
RpcAssert.assertNotNull(dto, DefaultErrorEnum.DATA_NULL,"dto is null");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!