LedHandlerFengLiYuan.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.gzlh.device.led.handler.impl;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.gzlh.bus.EventDataManager;
  4. import com.gzlh.config.SystemObject;
  5. import com.gzlh.device.led.action.LedAction;
  6. import com.gzlh.device.led.brand.LedBrandType;
  7. import com.gzlh.device.led.client.LedNettyConfig;
  8. import com.gzlh.device.led.handler.ILedHandler;
  9. import com.gzlh.device.led.utils.FengLiYuanPackUtils;
  10. import com.gzlh.device.led.utils.LedOptions;
  11. import com.gzlh.entity.ReqBO;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.util.StringUtils;
  15. import javax.annotation.Resource;
  16. @Service
  17. @Slf4j
  18. public class LedHandlerFengLiYuan implements ILedHandler {
  19. @Resource
  20. LedNettyConfig ledNettyConfig;
  21. @Override
  22. public LedBrandType brandType() {
  23. return LedBrandType.FENGLIYUAN;
  24. }
  25. @Override
  26. public void sendMsg(String content, LedOptions options) {
  27. log.info("丰利源发送led消息:{}", content);
  28. String msgHex = FengLiYuanPackUtils.build(content, options);
  29. log.info("数据包:{}", msgHex);
  30. ledNettyConfig.send(msgHex);
  31. }
  32. @Override
  33. public void handlerAction(String action) {
  34. if (StrUtil.contains(action, LedAction.LED_SHOW_CONTENT)) {
  35. LedOptions ledOptions = new LedOptions();
  36. // 默认显示到第一行
  37. ledOptions.setLine("01");
  38. action = action.substring(action.indexOf("(") + 1, action.indexOf(")"));
  39. if (StrUtil.contains(action, "|")) {
  40. String[] split = action.split("\\|");
  41. ledOptions.setLine(split[0]);
  42. action = split[1];
  43. }
  44. switch (ledOptions.getLine()) {
  45. case "02":
  46. ledOptions.setColor("05");
  47. break;
  48. case "03":
  49. ledOptions.setColor("04");
  50. break;
  51. case "04":
  52. ledOptions.setColor("01");
  53. break;
  54. default:
  55. ledOptions.setColor("06");
  56. break;
  57. }
  58. ReqBO reqBO = null;
  59. //展示内容
  60. if (StrUtil.contains(action, "platNo")) {
  61. String carNo = "";
  62. reqBO = EventDataManager.getCacheData();
  63. if (reqBO != null) {
  64. if (!StringUtils.isEmpty(reqBO.getCarNo())) {
  65. carNo = reqBO.getCarNo();
  66. }
  67. }
  68. ledOptions.setColor("05").setLine("02").setShowType("0B");
  69. sendMsg(carNo, ledOptions);
  70. } else if (StrUtil.contains(action, "weight")) {
  71. String weight = "";
  72. reqBO = EventDataManager.getCacheData();
  73. if (reqBO != null && reqBO.getWeight() != null) {
  74. weight = String.format("%.0f", EventDataManager.getCacheData().getWeight()).concat("kg");
  75. }
  76. ledOptions.setColor("04").setLine("03").setShowType("0B");
  77. sendMsg(weight, ledOptions);
  78. }else if (StrUtil.contains(action, "channel")) {
  79. ledOptions.setColor("06").setLine("01").setShowType("0B");
  80. sendMsg(SystemObject.applicationConfig.getChannelName(), ledOptions);
  81. } else {
  82. ledOptions.setShowType("00");
  83. sendMsg(action, ledOptions);
  84. }
  85. }
  86. }
  87. }