CheckInitTask.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package com.gzlh.bus.task;
  2. import cn.hutool.cache.CacheUtil;
  3. import cn.hutool.cache.impl.TimedCache;
  4. import cn.hutool.core.util.RandomUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import cn.hutool.extra.spring.SpringUtil;
  7. import com.gzlh.bus.ChannelCacheManager;
  8. import com.gzlh.bus.EventBus;
  9. import com.gzlh.bus.EventDataManager;
  10. import com.gzlh.bus.SysConfig;
  11. import com.gzlh.config.ModuleEnum;
  12. import com.gzlh.config.task.Task;
  13. import com.gzlh.config.task.TaskService;
  14. import com.gzlh.device.plc.event.PLCEvent;
  15. import com.gzlh.device.weighbridge.handler.impl.CommonWeighbridgeHandler;
  16. import com.gzlh.entity.ReqBO;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.springframework.cache.CacheManager;
  19. import org.springframework.scheduling.annotation.Scheduled;
  20. import org.springframework.stereotype.Component;
  21. import java.util.Date;
  22. @Slf4j
  23. public class CheckInitTask extends Task {
  24. private int checkCount;
  25. public CheckInitTask(String id, long delayInMilliseconds, int checkCount) {
  26. super(id, delayInMilliseconds);
  27. this.checkCount = checkCount;
  28. }
  29. @Override
  30. public void run() {
  31. TaskService taskService=SpringUtil.getBean(TaskService.class);
  32. if (!ChannelCacheManager.stateEnable(SysConfig.channelSetting.getChannelCode())){
  33. taskService.addTask(new CheckInitTask(RandomUtil.randomNumbers(16),30000,0));
  34. return;
  35. }
  36. EventBus eventBus=SpringUtil.getBean(EventBus.class);
  37. ReqBO reqBO= EventDataManager.getCacheData();
  38. if (reqBO!=null&& StrUtil.isNotEmpty(reqBO.getCarNo())){
  39. if (new Date().getTime()/1000-reqBO.getGatherTime().getTime()/1000>90){
  40. log.info("----------触发初始化---------------");
  41. eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
  42. taskService.addTask(new CheckInitTask(RandomUtil.randomNumbers(16),15000,0));
  43. return;
  44. }
  45. taskService.addTask(new CheckInitTask(RandomUtil.randomNumbers(16),2000,0));
  46. return;
  47. }
  48. if (checkCount>=10){
  49. log.info("----------触发初始化---------------");
  50. eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
  51. taskService.addTask(new CheckInitTask(RandomUtil.randomNumbers(16),15000,0));
  52. return;
  53. }
  54. checkCount=checkCount+1;
  55. taskService.addTask(new CheckInitTask(RandomUtil.randomNumbers(16),2000,checkCount));
  56. }
  57. }