package com.haha.admin.task;

import com.haha.service.UserCouponService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class CouponExpireTask {

    private final UserCouponService userCouponService;

    @Scheduled(cron = "0 0 * * * ?")
    public void expireCoupons() {
        log.info("开始执行优惠券过期处理任务");
        try {
            userCouponService.expireCoupons();
            log.info("优惠券过期处理任务执行完成");
        } catch (Exception e) {
            log.error("优惠券过期处理任务执行失败", e);
        }
    }
}
