package com.zcxk.async;

import com.zcxk.service.AlarmDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description 在初始化完成后启动一个线程
 * @auto wangli
 * @data 2020-11-17 20:42
 */
@Service
@Slf4j
public class CheckDeviceStateAsync implements InitializingBean {

    @Autowired
    private AlarmDetailsService alarmDetailsService;

    @Override
    public void afterPropertiesSet() {
        new Thread(() -> {
            while (true) {
                try {
                    alarmDetailsService.checkStateAlarm();
                } catch (Exception e){
                    e.printStackTrace();
                    log.error("巡检设备状态异常：{}",e.getMessage());
                }
                try {
                    Thread.sleep(60000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    log.error(e.getMessage());
                }
            }
        }).start();
        //报警信息生产工单信息
        new Thread(() -> {
            while (true) {
                try {
                    alarmDetailsService.saveWorkOrderManageInfo();
                } catch (Exception e){
                    e.printStackTrace();
                    log.error("报警生成工单信息异常：{}",e.getMessage());
                }
                try {
                    Thread.sleep(60000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    log.error(e.getMessage());
                }
            }
        }).start();
    }
}
