package com.hzs.third.mqcall.controller;

import com.hzs.common.core.constant.MagicNumberConstants;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.domain.third.pay.TOnlinePayment;
import com.hzs.third.pay.dto.RefundDTO;
import com.hzs.third.pay.service.IRefundService;
import com.hzs.third.pay.service.ITOnlinePaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: MQ消息测试控制器
 * @Author: jiang chao
 * @Time: 2024/3/18 11:38
 * @Classname: MqTestController
 * @PackageName: com.hzs.third.mqcall.controller
 */
@Slf4j
@RestController
@RequestMapping("/mq-test")
public class MqTestController {

    @Autowired
    private IRefundService iRefundService;
    @Autowired
    private ITOnlinePaymentService itOnlinePaymentService;

    /**
     * 测试退款
     * @param paymentCode
     * @return
     */
    @GetMapping("/test-refund/{paymentCode}")
    public AjaxResult testRefund(@PathVariable("paymentCode") String paymentCode) {
        TOnlinePayment tOnlinePayment = itOnlinePaymentService.queryByPaymentCode(paymentCode, null);
        if (null == tOnlinePayment) {
            return AjaxResult.error("支付信息不存在");
        }

        RefundDTO refundDTO = RefundDTO.builder()
                .businessType(tOnlinePayment.getBusinessType())
                .businessCode(tOnlinePayment.getBusinessCode())
                .refundAmount(tOnlinePayment.getPayMoney())
                .userId(MagicNumberConstants.PK_ADMIN)
                .pkCountry(tOnlinePayment.getPkCountry())
                .build();

        String str = null;

        if (null == str) {
            return AjaxResult.success();
        }
        return AjaxResult.error(str);
    }

}
