package org.gyk.modules.sssj.util;

import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Description: 计量点异步实时推送
 * @Author: liao
 * @Date: 2021-04-05
 * @Version: V1.0
 */
@Component
public class AsyncTask {
    public static int num_visitor = 0;
    @Value("${HeartBeat}")
    private int HeartBeat;

    @Async
    @Scheduled(initialDelay = 3000, fixedRate = Long.MAX_VALUE)
    public void testAsync() throws InterruptedException, TException {

        KDBClient.KHServerTime = 0L;
        KDBClient.KDBServerConnect();
        //从工业实时服务器上获取所有的计量点参数名字并存储在AllName中
        KDBClient.KDBTagGetAllNames();
        //获取每个计量点所属的单位、站场和计量点名称
        KDBClient.KDBTagGetZhanc(KDBClient.AllName);

        while (true) {
            try {
                if (!KDBClient.ServerIsConnected()) {
                    KDBClient.KDBServerConnect();
                }
                KDBClient.KDBDataGetCurrentValue(KDBClient.AllName);
            } catch (Exception e) {
                KDBClient.KDBServerDisconnect();
            }
            Thread.sleep(HeartBeat);
        }
    }
}

