package com.test.bijihoudaun.scheduler;

import com.test.bijihoudaun.service.ImageCleanupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 图片清理定时任务
 * 定期自动清理冗余图片
 */
@Component
@Slf4j
public class ImageCleanupScheduler {

    @Autowired
    private ImageCleanupService imageCleanupService;

    /**
     * 定时清理任务
     * 每天凌晨3点执行一次清理任务
     */
    @Scheduled(cron = "0 0 3 * * ?")
    public void scheduledCleanup() {
        int deletedCount = imageCleanupService.cleanupRedundantImages();
        // 优化：使用日志框架代替 System.out.println
        log.info("定时清理任务完成，清理了 {} 个冗余图片", deletedCount);
    }
}
