wlzboy
2 天以前 8cb5d3440208a3be3e772e65f1bd0ec63031ba62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.ruoyi.system.event;
 
import com.ruoyi.payment.domain.event.PaymentSuccessEvent;
import com.ruoyi.payment.domain.model.PaymentOrder;
import com.ruoyi.payment.domain.model.PaymentTransaction;
import com.ruoyi.system.service.ISysTaskPaymentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
 
/**
 * 支付成功事件监听器
 * 将支付模块的事件回调转换为业务表更新
 */
@Component
public class PaymentSuccessEventListener {
 
    private static final Logger log = LoggerFactory.getLogger(PaymentSuccessEventListener.class);
 
    @Autowired
    private ISysTaskPaymentService taskPaymentService;
 
    /**
     * 监听 dryad-payment 的支付成功事件
     */
    @EventListener
    public void handlePaymentSuccess(PaymentSuccessEvent event) {
        PaymentOrder order = event.getOrder();
        PaymentTransaction transaction = event.getTransaction();
 
        String outTradeNo = order.getBizOrderId();
        String tradeNo = order.getChannelTradeNo();
        String channel = order.getChannel();
        String provider = "WECHAT";
        if ("ALIPAY".equalsIgnoreCase(channel)) {
            provider = "ALIPAY";
        }
 
        try {
            boolean success = taskPaymentService.handlePaymentCallback(outTradeNo, tradeNo, provider);
            if (success) {
                log.info("[事件监听] 业务支付更新成功: bizOrderId={}, tradeNo={}, provider={}", outTradeNo, tradeNo, provider);
            } else {
                log.warn("[事件监听] 业务支付更新失败: bizOrderId={}, tradeNo={}, provider={}", outTradeNo, tradeNo, provider);
            }
        } catch (Exception e) {
            log.error("[事件监听] 处理支付成功事件异常", e);
        }
    }
}