Commit a0601766 authored by shiyu's avatar shiyu

藏家订单加锁避免重复创建订单

parent 9a04e972
......@@ -384,8 +384,11 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
@Override
@Transactional
public Result createCollectionOrder(DistributionOrderRequestDto dto) {
try {
Long itemId = dto.getItemId();
String itemIdKey = "COLLECTION:ORDER:CREATE:" + dto.getItemId();
RLock lock = redissonClient.getLock(itemIdKey);
try {
if (lock.tryLock(3, 3, TimeUnit.SECONDS)) {
String shareRecordId = dto.getShareRecordId();
if (StringUtils.hasLength(shareRecordId)) {
//查询分享记录详细信息
......@@ -494,8 +497,6 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
//平台佣金还要减去微信的服务手续费1%,实际上平台佣金就是订单金额* (平台佣金比例(默认0.15)- 微信手续费(0.01))
//暂时先不考虑
double channelServiceCost = distributionOrder.getAmount().doubleValue() * channelCostRebate;
double introduceCost = distributionOrder.getAmount().doubleValue() * rebate;
distributorProfit.setDistributionOrderId(distributionOrderId);
distributorProfit.setDistributorId(distributionOrder.getSellerId());
......@@ -513,9 +514,16 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
distributorProfit.setType(DistributionEnum.DistributionTypeEnum.COLLECT.getCode());
distributorProfitDao.insert(distributorProfit);
return Result.success(map);
} else {
return Result.failed("请勿重复提交");
}
} catch (Exception e) {
logger.error("创建藏品一口价订单失败 error : {}", e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
} finally {
if (lock != null && lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
return Result.failed("藏品一口价订单下单失败");
}
......
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