feat(profit-share): 实现分账消息发送功能

- 修改 ProfitShareKafkaProducer 的 sendRefundMessage 方法返回 CompletableFuture
- 在 WxMpPayAdapter 中增加 transactionId 和 refundTransactionId 字段解析
- 在 PayResponse 和 RefundResponse 中新增 transactionId 相关字段
- 在 WxPayServiceImpl 中注入 ProfitShareKafkaProducer 并发送分账消息
- 调整退款逻辑以异步方式发送分账退款消息后再执行退款操作
This commit is contained in:
2025-12-16 17:58:20 +08:00
parent a9555d612a
commit a9c33352f7
5 changed files with 48 additions and 19 deletions

View File

@@ -10,8 +10,11 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
import org.springframework.stereotype.Service;
import java.util.concurrent.CompletableFuture;
/**
* 分账Kafka消息生产者
*
@@ -58,7 +61,7 @@ public class ProfitShareKafkaProducer {
/**
* 发送退款消息(订单退款成功后调用)
*/
public void sendRefundMessage(RefundMessage message) {
public CompletableFuture<SendResult<String, String>> sendRefundMessage(RefundMessage message) {
validateRefund(message);
String topic = kafkaProps != null && StringUtils.isNotBlank(kafkaProps.getRefundTopic())
? kafkaProps.getRefundTopic()
@@ -69,7 +72,7 @@ public class ProfitShareKafkaProducer {
log.info("[REFUND] producing to topic={}, key={}, refundOrderId={}, originalOrderId={}, amount={}, type={}",
topic, key, message.getRefundOrderId(), message.getOriginalOrderId(), message.getRefundAmount(), message.getRefundType());
kafkaTemplate.send(topic, key, payload).whenComplete((metadata, ex) -> {
return kafkaTemplate.send(topic, key, payload).whenComplete((metadata, ex) -> {
if (ex != null) {
log.error("[REFUND] produce failed: refundOrderId={}, error={}", message.getRefundOrderId(), ex.getMessage(), ex);
} else if (metadata != null) {