package org.gyk.modules.sssj.util;

import lombok.SneakyThrows;
import org.gyk.modules.lssj.jldls.mapper.JldlsMapper;
import org.gyk.modules.sssj.entity.YasuojiSj;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static org.gyk.modules.sssj.util.ConfigUtils.getsavetime;


/**
 * @Description: 多线程-实时数据5min存库
 * @Author: liao
 * @Date: 2021-04-05
 * @Version: V1.0
 */

//@Slf4j
public class saveYasuojiData extends Thread {//线程主体类
    private static int savetime;

    @Autowired(required = false)
    private JldlsMapper jldlsMapper;

    public saveYasuojiData() {
//        this.title = title;
//        savetime=this.yasuojisavetime;
    }

    private static Logger log = LoggerFactory.getLogger(saveYasuojiData.class);


    @SneakyThrows
    @Override
    public void run() {//线程的主体方法
        int savetime = getsavetime();
        Thread.sleep(5000);  //延迟5秒启动 待连接工业库成功
        while (true) {
            try {
               List<YasuojiSj> list = sssjTools.saveYasuojiSssj();

               if (list.size() > 0) {
 //***************************************     压缩机实时   发布时要去掉注释 *********************************************************************

                   jldlsMapper.YasuojiSssj(list);
                   log.info(sssjTools.getStrCurrentTime() + "-----保存压缩机数据" + list.size() + "条成功");

 //***************************************************************************************
               }
            } catch (Exception e) {
                log.error(e.toString());
            }
            Thread.sleep(savetime);
        }

    }
}




