提交 0705f230 authored 作者: liuhaiquan's avatar liuhaiquan

增加结算单支付锁

上级 cbff55b4
...@@ -6,4 +6,9 @@ public class RedissonConstants { ...@@ -6,4 +6,9 @@ public class RedissonConstants {
public static final String ORDER_CHILD_SAVE_USER_TRUCK_LOCK = "clx-performance:orderChild:save:userTruck:"; public static final String ORDER_CHILD_SAVE_USER_TRUCK_LOCK = "clx-performance:orderChild:save:userTruck:";
public static final String ORDER_CHILD_SAVE_ORDER_GOODS_NO_LOCK = "clx-performance:orderChild:save:orderGoodsNo:"; public static final String ORDER_CHILD_SAVE_ORDER_GOODS_NO_LOCK = "clx-performance:orderChild:save:orderGoodsNo:";
//货主结算单支付锁
public static final String SETTLEMENT_OWNER_BATCH_PAY_ID_LOCK = "clx-performance:settlementOwner:batchPay:id:";
//货主违约结算单支付锁
public static final String BREAK_CONTRACT_SETTLEMENT_OWNER_BATCH_PAY_ID_LOCK = "clx-performance:breakContractSettlementOwner:batchPay:id:";
} }
package com.clx.performance.service.impl.settle; package com.clx.performance.service.impl.settle;
import com.clx.performance.config.MslPaymentConfig; import com.clx.performance.config.MslPaymentConfig;
import com.clx.performance.constant.RedissonConstants;
import com.clx.performance.dao.OrderChildDao; import com.clx.performance.dao.OrderChildDao;
import com.clx.performance.dao.OrderGoodsDao; import com.clx.performance.dao.OrderGoodsDao;
import com.clx.performance.dao.settle.SettlementDriverDao; import com.clx.performance.dao.settle.SettlementDriverDao;
...@@ -31,11 +32,13 @@ import com.clx.performance.service.settle.SettlementLogService; ...@@ -31,11 +32,13 @@ import com.clx.performance.service.settle.SettlementLogService;
import com.clx.performance.service.settle.SettlementMqHandlerService; import com.clx.performance.service.settle.SettlementMqHandlerService;
import com.clx.performance.service.settle.SettlementService; import com.clx.performance.service.settle.SettlementService;
import com.clx.performance.utils.LocalDateTimeUtils; import com.clx.performance.utils.LocalDateTimeUtils;
import com.clx.performance.utils.RedisUtil;
import com.clx.performance.vo.mq.SettlementDetailAddMqParam; import com.clx.performance.vo.mq.SettlementDetailAddMqParam;
import com.clx.performance.vo.mq.SettlementDetailInvoiceTypeSyncMqParam; import com.clx.performance.vo.mq.SettlementDetailInvoiceTypeSyncMqParam;
import com.clx.user.vo.feign.DriverInfoFeignVo; import com.clx.user.vo.feign.DriverInfoFeignVo;
import com.clx.user.vo.feign.OwnerInfoFeignVO; import com.clx.user.vo.feign.OwnerInfoFeignVO;
import com.msl.common.enums.ResultCodeEnum; import com.msl.common.enums.ResultCodeEnum;
import com.msl.common.exception.ServiceSystemException;
import com.msl.common.result.Result; import com.msl.common.result.Result;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -46,6 +49,7 @@ import java.math.BigDecimal; ...@@ -46,6 +49,7 @@ import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.UUID;
@Slf4j @Slf4j
@Service @Service
...@@ -91,6 +95,9 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic ...@@ -91,6 +95,9 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic
@Autowired @Autowired
private OrderChildLogService orderChildLogService; private OrderChildLogService orderChildLogService;
@Autowired
RedisUtil redisUtil;
@Override @Override
...@@ -206,41 +213,54 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic ...@@ -206,41 +213,54 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic
* 车主结算单自动支付 * 车主结算单自动支付
*/ */
public String paySettlementDriver(SettlementDriverDetail detail){ public String paySettlementDriver(SettlementDriverDetail detail){
DriverInfoFeignVo driverInfoFeignVo = driverService.getDriverInfo(detail.getDriverUserNo()).orElseThrow(ResultCodeEnum.FAIL); String uuid = UUID.randomUUID().toString();
PayParam noCheckPwd = null ; String key = RedissonConstants.SETTLEMENT_OWNER_BATCH_PAY_ID_LOCK + detail.getId();
if(detail.getSettlementFreight().compareTo(BigDecimal.ZERO) > 0){
noCheckPwd = PayParam.builder().from(mslPaymentConfig.getTransportWalletCode())
.to(driverInfoFeignVo.getWalletCode())
.figure(detail.getSettlementFreight().intValue())
.tradeNo(detail.getChildNo())
.tradeId(detail.getChildNo())
.pwd("noCheckPwd")
.remark(PayRemarkEnum.toString(PayRemarkEnum.FREIGHT_TO_OWNER.getValue()))
.build();
}else{
BigDecimal freight = detail.getSettlementFreight().abs();
noCheckPwd = PayParam.builder().from(driverInfoFeignVo.getWalletCode())
.to(mslPaymentConfig.getTransportWalletCode())
.figure(freight.intValue())
.tradeNo(detail.getChildNo())
.tradeId(detail.getChildNo())
.pwd("noCheckPwd")
.remark(PayRemarkEnum.toString(PayRemarkEnum.FREIGHT_TO_OWNER.getValue()))
.build();
}
Result result = null;
String msg = null;
try{ try{
result = paymentService.paymentWallet(noCheckPwd); boolean flag = redisUtil.lock(key, uuid);
if(!flag){
return "获取支付锁失败,操作频繁,请稍后重试";
}
DriverInfoFeignVo driverInfoFeignVo = driverService.getDriverInfo(detail.getDriverUserNo()).orElseThrow(ResultCodeEnum.FAIL);
PayParam noCheckPwd = null ;
if(detail.getSettlementFreight().compareTo(BigDecimal.ZERO) > 0){
noCheckPwd = PayParam.builder().from(mslPaymentConfig.getTransportWalletCode())
.to(driverInfoFeignVo.getWalletCode())
.figure(detail.getSettlementFreight().intValue())
.tradeNo(detail.getChildNo())
.tradeId(detail.getChildNo())
.pwd("noCheckPwd")
.remark(PayRemarkEnum.toString(PayRemarkEnum.FREIGHT_TO_OWNER.getValue()))
.build();
}else{
BigDecimal freight = detail.getSettlementFreight().abs();
noCheckPwd = PayParam.builder().from(driverInfoFeignVo.getWalletCode())
.to(mslPaymentConfig.getTransportWalletCode())
.figure(freight.intValue())
.tradeNo(detail.getChildNo())
.tradeId(detail.getChildNo())
.pwd("noCheckPwd")
.remark(PayRemarkEnum.toString(PayRemarkEnum.FREIGHT_TO_OWNER.getValue()))
.build();
}
Result result = null;
String msg = null;
try{
result = paymentService.paymentWallet(noCheckPwd);
}catch (Exception e){
settlementDriverNotify(detail.getChildNo(),0,e.getMessage());
msg = e.getMessage();
}
if(Objects.nonNull(result)){
settlementDriverNotify(detail.getChildNo(),0,result.getMsg());
}
return msg;
}catch (Exception e){ }catch (Exception e){
settlementDriverNotify(detail.getChildNo(),0,e.getMessage()); //解锁
msg = e.getMessage(); redisUtil.unlock(key,uuid);
} throw new ServiceSystemException(PerformanceResultEnum.DATA_REPEAT);
if(Objects.nonNull(result)){
settlementDriverNotify(detail.getChildNo(),0,result.getMsg());
} }
return msg;
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论