package com.sunyard.chsm.task;

import com.sunyard.chsm.service.DeviceService;
import com.sunyard.chsm.service.TmkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.Duration;

/**
 * @author liulu
 * @since 2024/11/4
 */
@Slf4j
@Component
public class DeviceTask implements InitializingBean {

    @Resource
    private TmkService tmkService;
    @Resource
    private DeviceService deviceService;
    @Resource
    private ThreadPoolTaskScheduler threadPoolTaskScheduler;

    @Override
    public void afterPropertiesSet() throws Exception {
        threadPoolTaskScheduler.scheduleWithFixedDelay(deviceService::checkDeviceStatus, Duration.ofMinutes(5L));
        threadPoolTaskScheduler.scheduleWithFixedDelay(tmkService::checkSoftDeviceTmk, Duration.ofMinutes(5L));
//        if (Platform.isLinux() || Platform.isWindows()) {
//            threadPoolTaskScheduler.scheduleWithFixedDelay(deviceService::checkDeviceStatus, Duration.ofMinutes(5L));
//            threadPoolTaskScheduler.scheduleWithFixedDelay(tmkService::checkSoftDeviceTmk, Duration.ofMinutes(5L));
//        } else {
//            log.warn("操作系统: {} 不支持启动检查设备状态定时任务", System.getProperty("os.name"));
//        }

    }
}
