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;

/**
 * 到店提醒定时任务
 * 订单状态为待使用且当前时间距离预定开始时间（user_reservation.reservation_date + start_time）≤30分钟时，发送到店提醒短信
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ReservationArrivalReminderJob {

    private final AlienStoreFeign alienStoreFeign;

    @XxlJob("reservationArrivalReminderJob")
    public void reservationArrivalReminderJob() {
        log.info("【定时任务】到店提醒：开始执行");
        try {
            R<Integer> result = alienStoreFeign.sendArrivalReminder();
            int count = (result != null && result.getData() != null) ? result.getData() : 0;
            log.info("【定时任务】到店提醒：执行完成，本次发送短信条数={}", count);
        } catch (Exception e) {
            log.error("【定时任务】到店提醒：执行异常", e);
            throw e;
        }
    }
}
