update rabbit消息结算订单

This commit is contained in:
Guoqs
2024-11-06 15:18:37 +08:00
parent ac33d967f8
commit 60154da1bf
3 changed files with 17 additions and 23 deletions

View File

@@ -1,11 +1,14 @@
package com.jsowell.mq;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.jsowell.common.constant.RabbitConstants;
import com.jsowell.pile.dto.AfterSettleOrderDTO;
import com.jsowell.pile.service.OrderBasicInfoService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
@@ -16,6 +19,8 @@ import java.io.IOException;
@Slf4j
@Service
public class OrderRabbitListener {
@Autowired
private OrderBasicInfoService orderBasicInfoService;
/**
* 多线程消费请求消息
@@ -24,6 +29,13 @@ public class OrderRabbitListener {
@RabbitListener(queues = RabbitConstants.QUEUE_CHARGE_ORDER_DATA)
public void receiveChargeOrderData(AfterSettleOrderDTO afterSettleOrderDTO, Channel channel, Message message) throws IOException {
log.info("接收到订单结算数据:{}", afterSettleOrderDTO);
try {
orderBasicInfoService.realTimeOrderSplit(afterSettleOrderDTO);
} catch (BaseAdaPayException e) {
throw new RuntimeException(e);
}
//由于配置设置了手动应答所以这里要进行一个手动应答。注意如果设置了自动应答这里又进行手动应答会出现double ack那么程序会报错。
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
}

View File

@@ -203,6 +203,8 @@ public interface OrderBasicInfoService{
OrderSplitResult doBalancePaymentWithDelay(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount, String wechatAppId) throws BaseAdaPayException;
OrderSplitResult realTimeOrderSplit(AfterSettleOrderDTO afterSettleOrderDTO) throws BaseAdaPayException;
/**
* 批量查询订单
* @param orderCodeList

View File

@@ -1455,6 +1455,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
* @param orderBasicInfo 订单
* @param adapayMemberAccount 结算账户
*/
@Override
public OrderSplitResult doPaymentConfirmWithDelay(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount, String wechatAppId) throws BaseAdaPayException {
// 订单编号
String orderCode = orderBasicInfo.getOrderCode();
@@ -1505,30 +1506,9 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
* 订单实时分账方法
* 2024年9月24日16点17分 新的分账方法
*/
public OrderSplitResult realTimeOrderSplit(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount, String wechatAppId) throws BaseAdaPayException {
// 订单编号
String orderCode = orderBasicInfo.getOrderCode();
// 订单结算金额
BigDecimal settleAmount = orderBasicInfo.getSettleAmount();
// 查询订单支付记录
List<OrderPayRecord> orderPayRecordList = orderPayRecordService.getOrderPayRecordList(orderCode);
// 需要分账信息
List<PaymentInfo> paymentInfos = Lists.newArrayList();
for (OrderPayRecord orderPayRecord : orderPayRecordList) {
BigDecimal payAmount = orderPayRecord.getPayAmount();
BigDecimal refundAmount = orderPayRecord.getRefundAmount() == null ? BigDecimal.ZERO : orderPayRecord.getRefundAmount();
// 如果相减等于0说明这笔支付单退完了就不用分账了
BigDecimal subtract = payAmount.subtract(refundAmount);
if (subtract.compareTo(BigDecimal.ZERO) > 0) {
paymentInfos.addAll(orderPayRecordService.parseDeductionRecord(orderPayRecord.getDeductionRecord()));
}
}
@Override
public OrderSplitResult realTimeOrderSplit(AfterSettleOrderDTO afterSettleOrderDTO) throws BaseAdaPayException {
// 根据站点id查询该站点配置的分账信息, 如果为空表示本运营商分100%
List<ShareMemberVO> shareMemberList = stationSplitConfigService.queryShareMembersByStationId(orderBasicInfo.getStationId());
// 计算每个账户 订单分账金额
List<DivMember> divMemberList = splitAmount(shareMemberList, settleAmount, paymentInfos);
return null;
}