SubmitFaceToLimitServerThread.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package com.gzlh.device.face.task;
  2. import cn.hutool.core.thread.ThreadUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import cn.hutool.extra.spring.SpringUtil;
  5. import cn.hutool.http.HttpUtil;
  6. import cn.hutool.json.JSONObject;
  7. import cn.hutool.json.JSONUtil;
  8. import com.gzlh.bus.EventBus;
  9. import com.gzlh.bus.EventDataManager;
  10. import com.gzlh.bus.SysConfig;
  11. import com.gzlh.cache.CacheManager;
  12. import com.gzlh.cache.PassCacheManager;
  13. import com.gzlh.config.ModuleEnum;
  14. import com.gzlh.config.SystemObject;
  15. import com.gzlh.config.dto.ChannelSetting;
  16. import com.gzlh.config.properties.ExternalProperties;
  17. import com.gzlh.device.led.utils.LedOptions;
  18. import com.gzlh.device.plc.event.PLCEvent;
  19. import com.gzlh.entity.ReqBO;
  20. import com.gzlh.utils.DeviceCache;
  21. import lombok.extern.slf4j.Slf4j;
  22. @Slf4j
  23. public class SubmitFaceToLimitServerThread implements Runnable {
  24. @Override
  25. public void run() {
  26. ReqBO reqBO = EventDataManager.getCacheData();
  27. int channelType = SysConfig.channelSetting.getChannelType();
  28. //非人行通道,需要有车牌
  29. if (channelType != 3) {
  30. if (reqBO == null || StrUtil.isEmpty(reqBO.getCarNo())) {
  31. return;
  32. }
  33. }
  34. ExternalProperties externalProperties = SpringUtil.getBean(ExternalProperties.class);
  35. String uploadFaceGateUrl = externalProperties.getFaceOpenGatePath();
  36. JSONObject params = new JSONObject();
  37. ReqBO.Face face = reqBO.getFace();
  38. boolean pass = face.isPass();
  39. params.set("employeeNo", face.getEmployeeNo())
  40. .set("ip", face.getIp())
  41. .set("time", face.getTime())
  42. .set("carNo", reqBO.getCarNo())
  43. .set("pass", pass)
  44. .set("channelCode", reqBO.getChannelCode());
  45. String resp = HttpUtil.createPost(uploadFaceGateUrl).body(params.toJSONString(0)).execute().body();
  46. log.info("上报开门事件:{},{},{}", uploadFaceGateUrl, params.toJSONString(0), resp);
  47. //非行人通道
  48. if (channelType != 3) {
  49. LedOptions options = new LedOptions().setLine("03").setShowType("00");
  50. if (pass) {
  51. //行政通道---直接抬杆
  52. if (channelType == 1) {
  53. SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
  54. .sendMsg("请通行", options);
  55. EventBus eventBus = SpringUtil.getBean(EventBus.class);
  56. eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.RAILING_RISE);
  57. PassCacheManager.carPass = null;
  58. PassCacheManager.customerPass = null;
  59. PassCacheManager.facePass = null;
  60. return;
  61. }
  62. SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
  63. .sendMsg("请等待核验", options);
  64. EventBus eventBus = SpringUtil.getBean(EventBus.class);
  65. int count = 0;
  66. String serverUrl = SysConfig.channelSetting.getTwinService();
  67. while (count < 15) {
  68. String response = HttpUtil.get(serverUrl);
  69. JSONObject result = JSONUtil.parseObj(response);
  70. Boolean re = result.getBool("data");
  71. if (re == null) {
  72. count++;
  73. ThreadUtil.sleep(1000);
  74. continue;
  75. }
  76. if (re) {
  77. PassCacheManager.carPass = null;
  78. PassCacheManager.customerPass = null;
  79. PassCacheManager.facePass = null;
  80. //抬杆
  81. eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.RAILING_RISE);
  82. } else {
  83. SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
  84. .sendMsg("核验失败,请退出通道", options);
  85. DeviceCache.setInterrupt(true);
  86. break;
  87. }
  88. }
  89. } else {
  90. SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
  91. .sendMsg("核验失败,请退出通道", options);
  92. DeviceCache.setInterrupt(true);
  93. }
  94. }
  95. }
  96. }