package com.aegis.resource.dashboard.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.aegis.resource.dashboard.service.IResourceDashboardService;

/**
 * 资源看板缓存刷新定时任务
 * 每5分钟自动刷新一次看板缓存
 * 
 * @author aegis
 */
@Component
public class ResourceDashboardRefreshTask {
    
    private static final Logger log = LoggerFactory.getLogger(ResourceDashboardRefreshTask.class);
    
    @Autowired
    private IResourceDashboardService dashboardService;
    
    /**
     * 定时刷新看板缓存
     * 每5分钟执行一次（cron表达式：0 *\/5 * * * ?）
     */
    @Scheduled(cron = "0 */5 * * * ?")
    public void refreshDashboardCache() {
        try {
            log.info("开始刷新资源看板缓存...");
            dashboardService.refreshDashboardCache();
            log.info("资源看板缓存刷新完成");
        } catch (Exception e) {
            log.error("刷新资源看板缓存失败", e);
        }
    }
}