package com.gyee.wisdom.dataadapter.websocket.backwork;

import com.gyee.wisdom.dataadapter.domain.timeseries.TsPointService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @descrition:风机信息更新线程
 * @author:Wanghs
 * @date:2019-09-23
 */
@Component
public class BackWorkStart implements ApplicationRunner {
    @Value("${websocket_start:false}")
    private String websocketIsStart;

    @Value("${isLoadAllTag:false}")
    private String isLoadAllWindturbineTag;

    @Autowired
    private WindturbineInfoCache windturbineInfoCache;

    @Autowired
    private TsPointService tsPointService;

    @Override
    public void run(ApplicationArguments args) throws Exception {

        //一次性加载所有测点至缓存
        if(Boolean.valueOf(isLoadAllWindturbineTag)){
            tsPointService.getAllTsPointToCache();
        }

        if (Boolean.valueOf(websocketIsStart)) {
            boolean initSuccess = windturbineInfoCache.init();
            if (initSuccess) {
                //数据更新线程启动
                windturbineInfoCache.start();
            }
        }

    }


}
