| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /**
- * Copyright
- * All right reserved.
- * 项目名称:
- * 创建日期:2022/5/23
- */
- package org.springblade.modules.manage.task;
- import lombok.extern.slf4j.Slf4j;
- import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
- import org.springblade.modules.baseinfo.region.service.IBaseInfoRegionService;
- import org.springblade.modules.baseinfo.region.service.IOrgRegionInfoService;
- import org.springblade.modules.baseinfo.rtu.service.IRtuBaseInfoService;
- import org.springblade.modules.business.data.service.IRtuDataGroundService;
- import org.springblade.modules.business.data.service.IRtuDataRainService;
- import org.springblade.modules.business.data.service.IRtuDataRiverService;
- import org.springblade.modules.business.data.service.IRtuDataRsvrService;
- import org.springblade.modules.business.rtumanage.service.IRtuManageService;
- import org.springblade.modules.business.warning.service.IRtuWarningService;
- import org.springblade.modules.system.service.IDeptService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.kafka.core.KafkaTemplate;
- 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: 数据实时缓存
- * Description:从原始数据中生成实时数据
- * @author swp
- * @version 1.0
- * Remark:认为有必要的其他信息
- */
- @Slf4j
- @Component
- @EnableScheduling
- public class DataTaskManager {
- /**
- * 公共线程池
- **/
- private static ThreadFactory publicThreadFactory = new ThreadFactoryBuilder().setNameFormat("data-thread-pool-%d").build();
- private static ExecutorService publicThreadPool = new ThreadPoolExecutor(1, 1,
- 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(1024), publicThreadFactory, new ThreadPoolExecutor.AbortPolicy());
- @Autowired
- private RedisTemplate redisTemplate;
- @Autowired
- private KafkaTemplate<String, String> kafkaTemplate;
- @Resource
- private IRtuBaseInfoService iRtuBaseInfoService;
- @Resource
- private IDeptService iDeptService;
- @Resource
- private IOrgRegionInfoService iOrgRegionInfoService;
- @Resource
- private IBaseInfoRegionService iBaseInfoRegionService;
- @Resource
- private IRtuDataGroundService groundService;
- @Resource
- private IRtuDataRainService rainService;
- @Resource
- private IRtuDataRiverService riverService;
- @Resource
- private IRtuDataRsvrService rsvrService;
- @Resource
- private IRtuWarningService rtuWarningService;
- @Resource
- private IRtuManageService rtuManageService;
- @Value("${spring.task-config.warning-check-task}")
- boolean warningCheckTask;
- @Value("${spring.task-config.dept-update-task}")
- boolean deptUpdateTask;
- public void deptUpdateTask() {
- try {
- if (deptUpdateTask) {
- DeptCacheUpdateTask task = new DeptCacheUpdateTask(redisTemplate, iRtuBaseInfoService, iDeptService, iOrgRegionInfoService, iBaseInfoRegionService);
- FutureTask<Integer> futureTask = new FutureTask<>(task);
- publicThreadPool.execute(futureTask);
- }
- } catch (Exception e) {
- log.error("{}", e.getMessage());
- }
- }
- @Scheduled(cron = "0 0/5 * * * * ")
- public void warnTask() {
- try {
- if (warningCheckTask) {
- log.info("ETL-预警-定时任务开始执行*********************");
- WarningTask warningTask = new WarningTask(kafkaTemplate, redisTemplate, iRtuBaseInfoService, rtuWarningService, rtuManageService);
- FutureTask<Integer> futureTask = new FutureTask<>(warningTask);
- publicThreadPool.execute(futureTask);
- }
- } catch (Exception e) {
- log.error("{}", e.getMessage());
- }
- }
- }
|