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

import lombok.extern.slf4j.Slf4j;

import org.springblade.modules.baseinfo.org.service.IDeptRegionService;
import org.springblade.modules.baseinfo.rtu.service.IRtuBaseInfoService;
import org.springblade.modules.business.check.order.service.IRtuCheckOrderService;
import org.springblade.modules.business.equipment.inspection.plan.service.IEquipmentInspectionPlanService;
import org.springblade.modules.business.equipment.inspection.report.service.IEquipmentInspectionReportService;
import org.springblade.modules.business.notice.service.INoticeService;
import org.springblade.modules.business.notice.service.INoticeViewService;
import org.springblade.modules.business.warning.service.IRtuWarningService;
import org.springblade.modules.system.service.IDeptService;
import org.springblade.task.TaskManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
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;

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

	/**
	 * 公共线程池
	 **/
//	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 TaskManager taskManager;
	@Autowired
	private RedisTemplate redisTemplate;
	@Autowired
	private SimpMessagingTemplate messagingTemplate;
	@Resource
	private IRtuCheckOrderService checkOrderService;
	@Resource
	private IEquipmentInspectionPlanService planService;
	@Resource
	private IEquipmentInspectionReportService reportService;
	@Resource
	private INoticeService noticeService;
	@Resource
	private INoticeViewService noticeViewService;
	@Resource
	private IRtuBaseInfoService rtuBaseInfoService;
	@Resource
	private IRtuWarningService rtuWarningService;

	@Resource
	private IDeptService deptService;

	@Resource
	private IDeptRegionService deptRegionService;

	@Scheduled(cron = "0 0/5 * * * * ")
	public void countTask() {
		try {
			//HomeInfoCountTask task = new HomeInfoCountTask(redisTemplate,messagingTemplate,rtuBaseInfoService,rtuWarningService, checkOrderService,deptService,deptRegionService);
			//FutureTask<Integer> futureTask = new FutureTask<>(task);
			//taskManager.submitTask(futureTask);
			//publicThreadPool.execute(futureTask);
		} catch (Exception e) {
			log.error("{}",e.getMessage());
		}
	}

//	@PostConstruct
//	public void init(){
//		this.scheduleExecutor.scheduleWithFixedDelay(() -> {
//			try {
//				Calendar calendar = Calendar.getInstance();
//				int second =calendar.get(Calendar.SECOND);
//				int currTimePoint=second < TIME_SECOND_ROUND ? 0:(second/TIME_SECOND_ROUND);
//				if (timePoint != currTimePoint){
//					calendar.set(Calendar.SECOND,currTimePoint*TIME_SECOND_ROUND);
//					Date tm = calendar.getTime();
//					String timeText = DateUtil.format(tm, "yyyy年MM月dd日 HH时mm分ss秒");
//					log.info("KRS数据读取任务创建，时间：{}", timeText);
//					HomeInfoCountTask task = new HomeInfoCountTask(redisTemplate,rtuBaseInfoService,rtuWarningService,messagingTemplate);
//					FutureTask<Integer> futureTask = new FutureTask<>(task);
//					publicThreadPool.execute(futureTask);
//					//更新时间点
//					timePoint = currTimePoint;
//				}
//			}catch (Exception e){
//				log.error("KRS数据读取任务创建失败 {}",e.getMessage());
//			}
//		}, 0, 2, TimeUnit.SECONDS);
//	}
}
