package com.bohuikeji.delivery.backstage.listener.pay;

import com.bohuikeji.frame.module.admin.base.MqListener;
import com.bohuikeji.frame.module.admin.entity.vo.AliReturnPayVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * 支付宝支付回调（功能：订单扫码支付、派送员代付、派送员入驻缴费、客户钱包充值）
 *
 * @author sjh
 * @date 2022/2/22 16:45
 **/
@Service
@Slf4j
@RequiredArgsConstructor
public class AliPayListener extends MqListener<AliReturnPayVo> {

    final PayCallBackService payCallBackService;

    @Override
    public boolean onReceive(AliReturnPayVo req) throws Exception {
        String orderNum = req.getOut_trade_no();
        log.info("支付宝监听测试队列 [{}] ", req.getOut_trade_no());
        if (!"TRADE_SUCCESS".equals(req.getTrade_status())) {
            log.error("非支付回调，请求丢弃，参数：[{}]", req);
            return false;
        }
        payCallBackService.getAllPay(null, req);
        return false;
    }

    @Override
    public void onError(AliReturnPayVo msg, Exception e) {

    }
}
