package com.gxwebsoft.shop.task;

import com.gxwebsoft.shop.service.ShopSeckillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 秒杀状态自动更新定时任务
 * 每分钟检查一次，将过期活动标记为"已结束"，将到达开始时间的标记为"进行中"
 *
 * @author 科技小王子
 * @since 2026-06-25
 */
@Slf4j
@Component
public class SeckillStatusTask {

    @Resource
    private ShopSeckillService shopSeckillService;

    @Scheduled(fixedRate = 60000) // 每60秒执行一次
    public void updateSeckillStatus() {
        try {
            shopSeckillService.updateExpiredSeckillStatus();
        } catch (Exception e) {
            log.error("[秒杀] 定时更新状态异常", e);
        }
    }

}
