StartInitTask.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package com.gzlh.device.plc.job;
  2. import cn.hutool.core.thread.ThreadUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import cn.hutool.extra.spring.SpringUtil;
  5. import com.gzlh.bus.ChannelCacheManager;
  6. import com.gzlh.bus.EventBus;
  7. import com.gzlh.bus.EventDataManager;
  8. import com.gzlh.bus.SysConfig;
  9. import com.gzlh.config.ModuleEnum;
  10. import com.gzlh.config.dto.SerialSetting;
  11. import com.gzlh.config.task.Task;
  12. import com.gzlh.device.plc.event.PLCEvent;
  13. import com.gzlh.device.weighbridge.event.WeighbridgeEvent;
  14. import com.gzlh.device.weighbridge.handler.impl.CommonWeighbridgeHandler;
  15. import com.gzlh.entity.ReqBO;
  16. import com.gzlh.utils.DeviceCache;
  17. import lombok.extern.slf4j.Slf4j;
  18. @Slf4j
  19. public class StartInitTask extends Task {
  20. public StartInitTask(String id, long delayInMilliseconds) {
  21. super(id, delayInMilliseconds);
  22. }
  23. @Override
  24. public void run() {
  25. EventBus eventBus = SpringUtil.getBean(EventBus.class);
  26. int count = 0;
  27. while (count < 20) {
  28. count++;
  29. if (!CommonWeighbridgeHandler.hsCar) {
  30. log.info("雷达断开,通道无车,触发初始化======");
  31. eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
  32. return;
  33. }
  34. ThreadUtil.sleep(1000);
  35. }
  36. SerialSetting.PlcDTO.StatusDTO pointInfo = SysConfig.serialSetting.getPlc().getStatus();
  37. String upPoint = pointInfo.getUpPoint();
  38. String plcStatus = DeviceCache.getPlcStatus();
  39. String upPointStatus = plcStatus.charAt(Integer.parseInt(upPoint)) + "";
  40. if (StrUtil.equals(upPointStatus, "1")) {
  41. eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.CAR_PASS);
  42. } else if (StrUtil.equals(upPointStatus, "0") && !CommonWeighbridgeHandler.hsCar) {
  43. eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.CAR_BACK);
  44. }
  45. }
  46. }