/**
 * Copyright
 * All right reserved.
 * 项目名称:
 * 创建日期:2022/5/23
 */
package org.springblade.etl;


import lombok.extern.slf4j.Slf4j;
import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
import org.springblade.etl.service.*;
import org.springblade.modules.baseinfo.stbase.service.IMvAttStBaseService;
import org.springblade.modules.business.project.base.service.IProjectBaseInfoService;
import org.springblade.modules.business.rtu.base.service.IRtuBaseInfoService;
import org.springblade.modules.business.rtu.data.service.IRtuDataGroundService;
import org.springblade.modules.business.rtu.data.service.IRtuDataRainService;
import org.springblade.modules.business.rtu.data.service.IRtuDataRiverService;
import org.springblade.modules.business.rtu.data.service.IRtuDataRsvrService;
import org.springblade.modules.business.rtumanage.service.IRtuManageService;
import org.springblade.modules.business.warning.service.IOriginalWarningService;
import org.springblade.modules.business.warning.service.IRtuWarningService;
import org.springblade.modules.system.service.IDictBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.*;

/***
 * Date:2022/5/22
 * Title: 环境辐射与气象监测系统(KRS) 模块
 * Description：MODBUS TCP 协议传输 ,任务管理
 * @author swp
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@Slf4j
@Component
@EnableScheduling
public class EtlTaskManager {

	/**
	 * 公共线程池
	 **/
	private static ThreadFactory publicThreadFactory = new ThreadFactoryBuilder().setNameFormat("public-thread-pool-%d").build();
	private static ExecutorService publicThreadPool = new ThreadPoolExecutor(1, 1,
		0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(1024), publicThreadFactory, new ThreadPoolExecutor.AbortPolicy());

	@Resource
	private IEtlWarningService etlWarningService;

	@Resource
	private IRtuWarningService rtuWarningService;

	@Resource
	private IRtuBaseInfoService rtuBaseInfoService;

	@Resource
	private IProjectBaseInfoService projectBaseInfoService;

	@Resource
	private IRtuDataRiverService dataRiverService;

	@Resource
	private IRtuDataRsvrService dataRsvrService;

	@Resource
	private IRtuDataRainService dataRainService;

	@Resource
	private IRtuDataGroundService dataGroundService;

	@Autowired
	private KafkaTemplate<String, String> kafkaTemplate;

	@Autowired
	private SimpMessagingTemplate messagingTemplate;

	@Autowired
	private RedisTemplate redisTemplate;

	@Resource
	private IDictBizService dictBizService;

	@Resource
	private IRtuManageService rtuManageService;

	@Resource
	private IOriginalWarningService originalWarningService;

	@Resource
	private IEtlRainDataService etlRainDataService;

	@Resource
	private IEtlRiverDataService etlRiverDataService;

	@Resource
	private IEtlRsvrDataService etlRsvrDataService;

	@Resource
	private IEtlGroundDataService etlGroundDataService;

	@Resource
	private IEtlMvAttStBaseService etlMvAttStBaseService;

	@Resource
	private IMvAttStBaseService mvAttStBaseService;


	@Scheduled(cron = "0 0/1 * * * * ")
	public void warnTask() {
		try {
//			EtlMvAttStBaseDataTask task = new EtlMvAttStBaseDataTask(etlMvAttStBaseService, mvAttStBaseService);
//			FutureTask<Integer> futureTask = new FutureTask<>(task);
//			publicThreadPool.execute(futureTask);


//			EtlRainDataTask task = new EtlRainDataTask(redisTemplate, etlRainDataService, dataRainService);
//			FutureTask<Integer> futureTask = new FutureTask<>(task);
//			publicThreadPool.execute(futureTask);


//			TestWarnTask task2 = new TestWarnTask(redisTemplate,kafkaTemplate,messagingTemplate,etlWarningService,rtuWarningService,rtuBaseInfoService,projectBaseInfoService,dataRainService,dataRiverService,dataRsvrService,dataGroundService,originalWarningService);
//			FutureTask<Integer> futureTask2 = new FutureTask<>(task2);
//			publicThreadPool.execute(futureTask2);


//			TestDataTask task = new TestDataTask(redisTemplate, kafkaTemplate, messagingTemplate, etlWarningService, rtuWarningService, rtuBaseInfoService, projectBaseInfoService, dataRainService, dataRiverService, dataRsvrService, dataGroundService, dictBizService, rtuManageService,etlRainDataService,etlRiverDataService,etlRsvrDataService,etlGroundDataService);
//			FutureTask<Integer> futureTask = new FutureTask<>(task);
//			publicThreadPool.execute(futureTask);


		} catch (Exception e) {
			log.error("{}", e.getMessage());
		}
	}

}
