LedCommonHandler.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.gzlh.device.led.handler.impl;
  2. import cn.hutool.core.util.NumberUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.gzlh.bus.EventDataManager;
  5. import com.gzlh.bus.SysConfig;
  6. import com.gzlh.config.SystemObject;
  7. import com.gzlh.device.led.action.LedAction;
  8. import com.gzlh.device.led.utils.LedOptions;
  9. import com.gzlh.entity.ReqBO;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.util.StringUtils;
  12. @Slf4j
  13. public class LedCommonHandler {
  14. public static void handlerAction(String action) {
  15. //log.info("led handler action:{}", action);
  16. if (StrUtil.contains(action, LedAction.LED_SHOW_CONTENT)) {
  17. LedOptions ledOptions = new LedOptions();
  18. // 默认显示到第一行---红色字体
  19. String line = "01";
  20. ledOptions.setColor("01").setShowType("0B");
  21. action = action.substring(action.indexOf("(") + 1, action.indexOf(")"));
  22. if (StrUtil.contains(action, "|")) {
  23. String[] split = action.split("\\|");
  24. line = NumberUtil.isNumber(split[0]) ? split[0] : line;
  25. ledOptions.setLine(line);
  26. action = split[1];
  27. if (split.length == 3) {
  28. ledOptions.setColor(split[2]);
  29. }
  30. }
  31. ReqBO reqBO;
  32. String msg = "";
  33. //展示内容
  34. if (StrUtil.contains(action, "platNo")) {
  35. String carNo = "";
  36. reqBO = EventDataManager.getCacheData();
  37. if (!StringUtils.isEmpty(reqBO.getCarNo())) {
  38. carNo = reqBO.getCarNo();
  39. }
  40. ledOptions.setLine(line).setShowType("0B");
  41. SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand()).sendMsg(carNo, ledOptions);
  42. // sendMsg(carNo, ledOptions);
  43. } else if (StrUtil.contains(action, "weight")) {
  44. String weight = "";
  45. weight = String.format("%.0f", EventDataManager.getCacheData().getWeight()).concat("kg");
  46. ledOptions.setLine(line).setShowType("0B");
  47. if (StrUtil.equals("0kg", weight)) {
  48. weight = "";
  49. }
  50. SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand()).sendMsg(weight, ledOptions);
  51. //sendMsg(weight, ledOptions);
  52. } else if (StrUtil.contains(action, "channel")) {
  53. ledOptions.setLine(line).setShowType("0B").setTime("00").setType("01");
  54. String channelName = SysConfig.channelSetting.getChannelName();
  55. SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand()).sendMsg(channelName, ledOptions);
  56. } else {
  57. ledOptions.setShowType("00");
  58. SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand()).sendMsg(action, ledOptions);
  59. }
  60. } else if (StrUtil.equalsIgnoreCase(action, LedAction.INIT)) {
  61. SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand()).init();
  62. }
  63. }
  64. }