package com.qs.mp.quartz.task;

import com.qs.mp.common.enums.MqTopicType;
import com.qs.mp.common.pulsar.PulsarClientService;
import com.qs.mp.common.utils.LogUtil;
import com.qs.mp.framework.service.IAsyncTaskService;
import com.qs.mp.pay.service.IWalletService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 后台人工操作入口
 *
 * @author zhongcp
 * @Date 2022/3/17
 */
@Component("operateToolTask")
public class OperateToolTask {

  protected final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());

  @Autowired
  private PulsarClientService pulsarClientService;

  @Autowired
  private IWalletService walletService;

  /**
   * 重新发送消息
   */
  public void resendTicketPayMsg(String orderId) {
    LogUtil.info(logger, "...重新发送盲票支付消息任务开始...");

    try {
      pulsarClientService.producer(MqTopicType.ticket_pay, orderId);
    } catch (Exception e) {
      LogUtil.error(logger, e, "重新发送盲票支付消息异常。orderId:{0}", orderId);
    }

    LogUtil.info(logger, "...重新发送盲票支付消息任务结束...");
  }


  /**
   * 退款
   * @param orderNo
   * @param refundAmount
   */
  public void refund(String orderNo, Integer refundAmount){
    LogUtil.info(logger, "...退款任务开始...");

    walletService.refund(orderNo, refundAmount, "后台人工操作");

    LogUtil.info(logger, "...退款任务结束...");

  }
}
