package shop.alien.job.store;

import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import shop.alien.entity.result.R;
import shop.alien.job.feign.AlienStoreFeign;

/**
 * 退款重试定时任务：查询支付状态为「退款中」的预订订单并重新发起退款（不发送短信和通知）
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class RefundRetryJob {

    private final AlienStoreFeign alienStoreFeign;

    @XxlJob("refundRetryJob")
    public void refundRetryJob() {
        log.info("【定时任务】退款重试：开始执行");
        try {
            R<Integer> result = alienStoreFeign.retryRefundFailed();
            int count = (result != null && result.getData() != null) ? result.getData() : 0;
            log.info("【定时任务】退款重试：执行完成，本次退款成功条数={}", count);
        } catch (Exception e) {
            log.error("【定时任务】退款重试：执行异常", e);
            throw e;
        }
    }
}
