123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package com.gzlh.bus.task;
- import cn.hutool.cache.CacheUtil;
- import cn.hutool.cache.impl.TimedCache;
- import cn.hutool.core.util.RandomUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.extra.spring.SpringUtil;
- import com.gzlh.bus.ChannelCacheManager;
- import com.gzlh.bus.EventBus;
- import com.gzlh.bus.EventDataManager;
- import com.gzlh.bus.SysConfig;
- import com.gzlh.config.ModuleEnum;
- import com.gzlh.config.task.Task;
- import com.gzlh.config.task.TaskService;
- import com.gzlh.device.plc.event.PLCEvent;
- import com.gzlh.device.weighbridge.handler.impl.CommonWeighbridgeHandler;
- import com.gzlh.entity.ReqBO;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.cache.CacheManager;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- import java.util.Date;
- @Slf4j
- public class CheckInitTask extends Task {
- private int checkCount;
- public CheckInitTask(String id, long delayInMilliseconds, int checkCount) {
- super(id, delayInMilliseconds);
- this.checkCount = checkCount;
- }
- @Override
- public void run() {
- TaskService taskService=SpringUtil.getBean(TaskService.class);
- if (!ChannelCacheManager.stateEnable(SysConfig.channelSetting.getChannelCode())){
- taskService.addTask(new CheckInitTask(RandomUtil.randomNumbers(16),30000,0));
- return;
- }
- EventBus eventBus=SpringUtil.getBean(EventBus.class);
- ReqBO reqBO= EventDataManager.getCacheData();
- if (reqBO!=null&& StrUtil.isNotEmpty(reqBO.getCarNo())){
- if (new Date().getTime()/1000-reqBO.getGatherTime().getTime()/1000>90){
- log.info("----------触发初始化---------------");
- eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
- taskService.addTask(new CheckInitTask(RandomUtil.randomNumbers(16),15000,0));
- return;
- }
- taskService.addTask(new CheckInitTask(RandomUtil.randomNumbers(16),2000,0));
- return;
- }
- if (checkCount>=10){
- log.info("----------触发初始化---------------");
- eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
- taskService.addTask(new CheckInitTask(RandomUtil.randomNumbers(16),15000,0));
- return;
- }
- checkCount=checkCount+1;
- taskService.addTask(new CheckInitTask(RandomUtil.randomNumbers(16),2000,checkCount));
- }
- }
|