DataTaskManager.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * Copyright
  3. * All right reserved.
  4. * 项目名称:
  5. * 创建日期:2022/5/23
  6. */
  7. package org.springblade.modules.manage.task;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
  10. import org.springblade.modules.baseinfo.region.service.IBaseInfoRegionService;
  11. import org.springblade.modules.baseinfo.region.service.IOrgRegionInfoService;
  12. import org.springblade.modules.baseinfo.rtu.service.IRtuBaseInfoService;
  13. import org.springblade.modules.business.data.service.IRtuDataGroundService;
  14. import org.springblade.modules.business.data.service.IRtuDataRainService;
  15. import org.springblade.modules.business.data.service.IRtuDataRiverService;
  16. import org.springblade.modules.business.data.service.IRtuDataRsvrService;
  17. import org.springblade.modules.business.rtumanage.service.IRtuManageService;
  18. import org.springblade.modules.business.warning.service.IRtuWarningService;
  19. import org.springblade.modules.system.service.IDeptService;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.data.redis.core.RedisTemplate;
  23. import org.springframework.kafka.core.KafkaTemplate;
  24. import org.springframework.scheduling.annotation.EnableScheduling;
  25. import org.springframework.scheduling.annotation.Scheduled;
  26. import org.springframework.stereotype.Component;
  27. import javax.annotation.Resource;
  28. import java.util.concurrent.*;
  29. /***
  30. * Date:2022/5/22
  31. * Title: 数据实时缓存
  32. * Description:从原始数据中生成实时数据
  33. * @author swp
  34. * @version 1.0
  35. * Remark:认为有必要的其他信息
  36. */
  37. @Slf4j
  38. @Component
  39. @EnableScheduling
  40. public class DataTaskManager {
  41. /**
  42. * 公共线程池
  43. **/
  44. private static ThreadFactory publicThreadFactory = new ThreadFactoryBuilder().setNameFormat("data-thread-pool-%d").build();
  45. private static ExecutorService publicThreadPool = new ThreadPoolExecutor(1, 1,
  46. 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(1024), publicThreadFactory, new ThreadPoolExecutor.AbortPolicy());
  47. @Autowired
  48. private RedisTemplate redisTemplate;
  49. @Autowired
  50. private KafkaTemplate<String, String> kafkaTemplate;
  51. @Resource
  52. private IRtuBaseInfoService iRtuBaseInfoService;
  53. @Resource
  54. private IDeptService iDeptService;
  55. @Resource
  56. private IOrgRegionInfoService iOrgRegionInfoService;
  57. @Resource
  58. private IBaseInfoRegionService iBaseInfoRegionService;
  59. @Resource
  60. private IRtuDataGroundService groundService;
  61. @Resource
  62. private IRtuDataRainService rainService;
  63. @Resource
  64. private IRtuDataRiverService riverService;
  65. @Resource
  66. private IRtuDataRsvrService rsvrService;
  67. @Resource
  68. private IRtuWarningService rtuWarningService;
  69. @Resource
  70. private IRtuManageService rtuManageService;
  71. @Value("${spring.task-config.warning-check-task}")
  72. boolean warningCheckTask;
  73. @Value("${spring.task-config.dept-update-task}")
  74. boolean deptUpdateTask;
  75. public void deptUpdateTask() {
  76. try {
  77. if (deptUpdateTask) {
  78. DeptCacheUpdateTask task = new DeptCacheUpdateTask(redisTemplate, iRtuBaseInfoService, iDeptService, iOrgRegionInfoService, iBaseInfoRegionService);
  79. FutureTask<Integer> futureTask = new FutureTask<>(task);
  80. publicThreadPool.execute(futureTask);
  81. }
  82. } catch (Exception e) {
  83. log.error("{}", e.getMessage());
  84. }
  85. }
  86. @Scheduled(cron = "0 0/5 * * * * ")
  87. public void warnTask() {
  88. try {
  89. if (warningCheckTask) {
  90. log.info("ETL-预警-定时任务开始执行*********************");
  91. WarningTask warningTask = new WarningTask(kafkaTemplate, redisTemplate, iRtuBaseInfoService, rtuWarningService, rtuManageService);
  92. FutureTask<Integer> futureTask = new FutureTask<>(warningTask);
  93. publicThreadPool.execute(futureTask);
  94. }
  95. } catch (Exception e) {
  96. log.error("{}", e.getMessage());
  97. }
  98. }
  99. }