package com.kym.admin.jobs;

import com.kym.service.FaultNotificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 故障通知定时兜底任务
 * 每5分钟扫描一次，补发遗漏的故障通知
 *
 * @author skyline
 */
@Component
@Slf4j
public class FaultNotificationJob {

    private final FaultNotificationService faultNotificationService;

    public FaultNotificationJob(FaultNotificationService faultNotificationService) {
        this.faultNotificationService = faultNotificationService;
    }

    @Async("AsyncExecutor")
    @Scheduled(cron = "0 */5 * * * ?")
    public void reconcileFaultNotifications() {
        log.debug("故障通知兜底扫描开始...");
        try {
            faultNotificationService.reconcileUnnotifiedFaults();
        } catch (Exception e) {
            log.error("故障通知兜底扫描异常", e);
        }
        log.debug("故障通知兜底扫描结束");
    }
}
