From 25b9913eb127d18f34b72d12d7b1c0ca7e573c9c Mon Sep 17 00:00:00 2001 From: lzq Date: Thu, 15 May 2025 09:52:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=81=93=E9=97=B8=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 + .../com/jepsoninfo/config/MqttConfig.java | 38 +- src/main/java/com/jepsoninfo/req/DorMsg.java | 70 +++ .../com/jepsoninfo/service/HardService.java | 435 ++++++++++-------- .../service/ThreadDeviceCmdMqtt.java | 3 + 5 files changed, 337 insertions(+), 215 deletions(-) create mode 100644 .gitignore create mode 100644 src/main/java/com/jepsoninfo/req/DorMsg.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..595a079 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/**/logs +/**/*.iml +/**/.idea +/**/target +/**/.DS_Store +/**/.back* diff --git a/src/main/java/com/jepsoninfo/config/MqttConfig.java b/src/main/java/com/jepsoninfo/config/MqttConfig.java index a1e7231..657e232 100644 --- a/src/main/java/com/jepsoninfo/config/MqttConfig.java +++ b/src/main/java/com/jepsoninfo/config/MqttConfig.java @@ -38,28 +38,28 @@ public class MqttConfig { config = commonConfigDao.selectByName("mqtt_clientid"); ConstUtil.MQTT_CLIENTID = config.getCnValue(); -// config = commonConfigDao.selectByName("mqtt_device_broker"); -// ConstUtil.MQTT_DEVICE_BROKER = config.getCnValue(); -// -// config = commonConfigDao.selectByName("mqtt_device_topic_prefix"); -// ConstUtil.MQTT_DEVICE_TOPIC = config.getCnValue(); -// -// config = commonConfigDao.selectByName("mqtt_device_user_name"); -// ConstUtil.MQTT_DEVICE_USER_NAME = config.getCnValue(); -// -// config = commonConfigDao.selectByName("mqtt_device_password"); -// ConstUtil.MQTT_DEVICE_PASSWORD = config.getCnValue(); -// -// config = commonConfigDao.selectByName("mqtt_device_clientid"); -// ConstUtil.MQTT_DEVICE_CLIENTID = config.getCnValue(); -// -// config = commonConfigDao.selectByName("mqtt_device_type"); -// ConstUtil.MQTT_DEVICE_TYPE = config.getCnValue(); + config = commonConfigDao.selectByName("mqtt_device_broker"); + ConstUtil.MQTT_DEVICE_BROKER = config.getCnValue(); + + config = commonConfigDao.selectByName("mqtt_device_topic_prefix"); + ConstUtil.MQTT_DEVICE_TOPIC = config.getCnValue(); + + config = commonConfigDao.selectByName("mqtt_device_user_name"); + ConstUtil.MQTT_DEVICE_USER_NAME = config.getCnValue(); + + config = commonConfigDao.selectByName("mqtt_device_password"); + ConstUtil.MQTT_DEVICE_PASSWORD = config.getCnValue(); + + config = commonConfigDao.selectByName("mqtt_device_clientid"); + ConstUtil.MQTT_DEVICE_CLIENTID = config.getCnValue(); + + config = commonConfigDao.selectByName("mqtt_device_type"); + ConstUtil.MQTT_DEVICE_TYPE = config.getCnValue(); ThreadRecvCmdMqtt thread = new ThreadRecvCmdMqtt(hardService); thread.start(); -// ThreadDeviceCmdMqtt devThread = new ThreadDeviceCmdMqtt(hardService); -// devThread.start(); + ThreadDeviceCmdMqtt devThread = new ThreadDeviceCmdMqtt(hardService); + devThread.start(); } } diff --git a/src/main/java/com/jepsoninfo/req/DorMsg.java b/src/main/java/com/jepsoninfo/req/DorMsg.java new file mode 100644 index 0000000..e04fa64 --- /dev/null +++ b/src/main/java/com/jepsoninfo/req/DorMsg.java @@ -0,0 +1,70 @@ +package com.jepsoninfo.req; + +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +public class DorMsg { + + /** + * id + */ + private String id; + /** + * sn + */ + private String sn; + /** + * name + */ + private String name = "gpio_out"; + /** + * version + */ + private String version = "1.0"; + /** + * timestamp + */ + private Long timestamp; + /** + * payload + */ + private Payload payload; + + /** + * Payload + */ + @Data + @Accessors(chain = true) + public static class Payload { + /** + * type + */ + private String type = "gpio_out"; + /** + * body + */ + private Body body; + + /** + * Body + */ + @Data + @Accessors(chain = true) + public static class Body { + /** + * delay + */ + private Integer delay = 500; + /** + * io + */ + private Integer io; + /** + * value + */ + private Integer value = 2; + } + } +} diff --git a/src/main/java/com/jepsoninfo/service/HardService.java b/src/main/java/com/jepsoninfo/service/HardService.java index d0b1afb..20d38ff 100644 --- a/src/main/java/com/jepsoninfo/service/HardService.java +++ b/src/main/java/com/jepsoninfo/service/HardService.java @@ -28,7 +28,9 @@ import java.util.List; @Service public class HardService { - private final Logger logger = LoggerFactory.getLogger("HardService.class");//Logger.getLogger("HardService.class"); + private final Logger logger = LoggerFactory.getLogger("HardService.class");// Logger.getLogger("HardService.class"); + public MqttClient recvClient; + public MqttClient deviceClient; @Autowired private IntegratedMachineConfigDao integratedMachineConfigDao; @Autowired @@ -41,8 +43,6 @@ public class HardService { private DisplayConfigDao displayConfigDao; @Autowired private MessageConfigDao messageConfigDao; - public MqttClient recvClient; - public MqttClient deviceClient; public void plateRecognize(RecognizeAlarmInfoPlate req) { ReturnCode result; @@ -53,25 +53,25 @@ public class HardService { String carNo = req.getAlarmInfoPlate().getResult().getPlateResult().getLicense(); String devNo = req.getAlarmInfoPlate().getSerialno(); - printDate(carNo,devNo,laneName,optName,"收到车牌识别推送"); + printDate(carNo, devNo, laneName, optName, "收到车牌识别推送"); IntegratedMachineConfig integratedCond = new IntegratedMachineConfig(); integratedCond.setDevNo(devNo); - //获取一体机配置 + // 获取一体机配置 IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond); laneName = integratedCfg.getLaneName(); - printDate(carNo,devNo,laneName,optName,"车牌识别详细信息"); + printDate(carNo, devNo, laneName, optName, "车牌识别详细信息"); - //保持车头照 - String dirName = createLocalImgDir(carNo,devNo,laneName); + // 保持车头照 + String dirName = createLocalImgDir(carNo, devNo, laneName); String PhotoFrontFileName = RandomUtil.getRandomUuid() + ".jpg"; - String PhotoFrontFilePath = saveFrontImage(req.getAlarmInfoPlate().getResult().getPlateResult().getImageFile(),carNo,dirName,devNo,laneName,PhotoFrontFileName); + String PhotoFrontFilePath = saveFrontImage(req.getAlarmInfoPlate().getResult().getPlateResult().getImageFile(), carNo, dirName, devNo, laneName, PhotoFrontFileName); - if(integratedCfg != null) { + if (integratedCfg != null) { if (integratedCfg.getIsFront() == 1) { - //获取音柱配置 + // 获取音柱配置 IpVoiceboxConfigEx ipVoiceboxConfig = ipVoiceboxConfigDao.selectByPrimaryKey(integratedCfg.getIpVoiceId()); if (ipVoiceboxConfig != null) { MessageConfig messageConfig = messageConfigDao.selectByPrimaryKey(3L); @@ -83,8 +83,8 @@ public class HardService { playVoice(playVoice); } } - }else{ - printDate(carNo,devNo,laneName,optName,"not find integrated"); + } else { + printDate(carNo, devNo, laneName, optName, "not find integrated"); return; } @@ -98,7 +98,7 @@ public class HardService { reportUnifyReq.setCarDiscernCode(devNo); reportUnifyReq.setPhotoFront(PhotoBodyUrl); - printDate(carNo,devNo,laneName,optName + "上报",reportUnifyReq); + printDate(carNo, devNo, laneName, optName + "上报", reportUnifyReq); String jsonObj; jsonObj = JSONObject.toJSONString(reportUnifyReq); strRet = HttpClientUtil.postJson(ConstUtil.REPORT_SERVER + ConstUtil.REPORT_PASS_SERVER_URL, jsonObj); @@ -111,61 +111,61 @@ public class HardService { // " \"scene\":\"CPR\"" + // " }\n" + // "}"; - printDate(carNo,devNo,laneName,optName,"上报返回:" + strRet); - result = JSONObject.parseObject(strRet,ReturnCode.class); + printDate(carNo, devNo, laneName, optName, "上报返回:" + strRet); + result = JSONObject.parseObject(strRet, ReturnCode.class); - //printDate(carNo,devNo,laneName,optName,"上报解析:" + result); + // printDate(carNo,devNo,laneName,optName,"上报解析:" + result); - ConstUtil.DOOR_STATUS.put(devNo,0); + ConstUtil.DOOR_STATUS.put(devNo, 0); - if(result != null && result.getData() != null) { + if (result != null && result.getData() != null) { ret = JSONObject.parseObject(result.getData(), ReportCarPassRes.class); - printDate(carNo,devNo,laneName,optName,"type:" + ret.getType().intValue() + ""); + printDate(carNo, devNo, laneName, optName, "type:" + ret.getType().intValue() + ""); if (ret.getScene().compareTo("OPEN") == 0) { System.out.println("open enter door"); } else { if (ret.getType().intValue() == 0) { - //无效数据 + // 无效数据 } else if (ret.getType().intValue() == 1) { - //进场,需要获取进场磅重 + // 进场,需要获取进场磅重 int nLane = integratedCfg.getNType(); - printDate(carNo,devNo,laneName,optName,"车道编号:" + nLane + ""); + printDate(carNo, devNo, laneName, optName, "车道编号:" + nLane + ""); if (nLane == 0) { - //出场 + // 出场 } else { - if(integratedCfg.getIsDoorStatus() == 1) { - if (checkDoorStatus(devNo,carNo,laneName) == false) { + if (integratedCfg.getIsDoorStatus() == 1) { + if (checkDoorStatus(devNo, carNo, laneName) == false) { return; } } - collectAndUploadData(req, ret.getOrderNo(),dirName,PhotoFrontFilePath); - //closeDoor(30000,carNo,devNo,laneName); + collectAndUploadData(req, ret.getOrderNo(), dirName, PhotoFrontFilePath); + // closeDoor(30000,carNo,devNo,laneName); } } else if (ret.getType().intValue() == 2) { - //出场,需要获取出场磅重 + // 出场,需要获取出场磅重 int nLane = integratedCfg.getNType(); - printDate(carNo,devNo,laneName,optName,"车道编号:" + nLane + ""); + printDate(carNo, devNo, laneName, optName, "车道编号:" + nLane + ""); if (nLane == 0) { - //出场 - if(integratedCfg.getIsDoorStatus() == 1) { - if (checkDoorStatus(devNo,carNo,laneName) == false) { + // 出场 + if (integratedCfg.getIsDoorStatus() == 1) { + if (checkDoorStatus(devNo, carNo, laneName) == false) { return; } } - closeDoor(0,carNo,devNo,laneName); - collectAndUploadData(req, ret.getOrderNo(),dirName,PhotoFrontFilePath); + closeDoor(0, carNo, devNo, laneName); + collectAndUploadData(req, ret.getOrderNo(), dirName, PhotoFrontFilePath); } } } - }else{ - printDate(carNo,devNo,laneName,optName,"服务器无法访问或返回错误"); + } else { + printDate(carNo, devNo, laneName, optName, "服务器无法访问或返回错误"); } } - public void collectAndUploadData(RecognizeAlarmInfoPlate req,String orderNo,String dirName,String PhotoFrontFilePath){ + public void collectAndUploadData(RecognizeAlarmInfoPlate req, String orderNo, String dirName, String PhotoFrontFilePath) { ReturnCode ret; boolean bRet; String PhotoBodyUrl = ""; @@ -180,19 +180,19 @@ public class HardService { MessageConfig messageConfig; integratedCond.setDevNo(devNo); - //获取一体机配置 + // 获取一体机配置 IntegratedMachineConfigEx integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond); - //获取地磅配置 + // 获取地磅配置 WagonBalanceConfig wagonCfg = wagonBalanceConfigDao.selectByPrimaryKey(integratedCfg.getWagonBalanceId()); - //获取网络摄像头1配置 + // 获取网络摄像头1配置 HkCameraConfigEx hkCameraConfig = hkCameraConfigDao.selectByPrimaryKey(integratedCfg.getHkCameraId()); - //获取网络音柱配置 + // 获取网络音柱配置 IpVoiceboxConfig ipVoiceboxConfig = ipVoiceboxConfigDao.selectByPrimaryKey(integratedCfg.getIpVoiceId()); laneName = integratedCfg.getLaneName(); - printDate(carNo,devNo,laneName,optName,"collectAndUploadData"); + printDate(carNo, devNo, laneName, optName, "collectAndUploadData"); - //显示车牌 + // 显示车牌 DisplayInfoReq displayInfoReq = new DisplayInfoReq(); displayInfoReq.setCarPlate(carNo); @@ -205,7 +205,7 @@ public class HardService { int weightLoop = 3; if (wagonCfg != null) { while (weightLoop > 0) { - //播放等待语音 + // 播放等待语音 if (ipVoiceboxConfig != null) { messageConfig = messageConfigDao.selectByPrimaryKey(2L); PlayVoiceReq playVoice = new PlayVoiceReq(); @@ -216,19 +216,19 @@ public class HardService { playVoice(playVoice); } - //printDate(carNo,devNo,laneName,"称重","读地磅开始"); + // printDate(carNo,devNo,laneName,"称重","读地磅开始"); - //读取地磅数据 + // 读取地磅数据 weight = getWeightInfo(wagonCfg.getPortName(), wagonCfg.getBaudRate(), wagonCfg.getDataBits().byteValue() , wagonCfg.getParity().byteValue(), wagonCfg.getStopBits().byteValue() , carNo, devNo, "称重"); int nWeight = (int) weight; printDate(carNo, devNo, laneName, "称重", "磅重数据:" + weight); - //nWeight = 10000; - //printDate(carNo,devNo,laneName,"称重","读地磅结束"); + // nWeight = 10000; + // printDate(carNo,devNo,laneName,"称重","读地磅结束"); if (nWeight <= 200) { - //播放重新称重提示 + // 播放重新称重提示 if (ipVoiceboxConfig != null) { messageConfig = messageConfigDao.selectByPrimaryKey(4L); PlayVoiceReq playVoice = new PlayVoiceReq(); @@ -239,47 +239,47 @@ public class HardService { playVoice(playVoice); } weightLoop--; - }else{ + } else { break; } } } - //显示磅重 + // 显示磅重 displayInfoReq.setCarPlate(carNo); displayInfoReq.setWeight("磅重:" + (weight / 1000)); displayInfoReq.setAmount(""); displayInfoReq.setDeviceNo(devNo); displayInfo(displayInfoReq); - //抓拍车斗图片并上传 + // 抓拍车斗图片并上传 String PhotoBodyFileName = RandomUtil.getRandomUuid() + ".jpg"; - String PhotoBodyFilePath = "/" +dirName + "/" + PhotoBodyFileName; + String PhotoBodyFilePath = "/" + dirName + "/" + PhotoBodyFileName; String PhotoFrontUrl = ""; - if(hkCameraConfig != null) { - printDate(carNo,devNo,laneName,"高位","获取高位摄像头开始"); - bRet = captureImage(hkCameraConfig, ConstUtil.LOCAL_PATH + PhotoBodyFilePath,carNo,devNo,laneName); + if (hkCameraConfig != null) { + printDate(carNo, devNo, laneName, "高位", "获取高位摄像头开始"); + bRet = captureImage(hkCameraConfig, ConstUtil.LOCAL_PATH + PhotoBodyFilePath, carNo, devNo, laneName); if (bRet == true) { - printDate(carNo,devNo,laneName,"高位","上传车斗照"); + printDate(carNo, devNo, laneName, "高位", "上传车斗照"); PhotoBodyUrl = "/file" + PhotoBodyFilePath; PhotoBodyUrl = UploadToAliUtil.uploadFile(dirName, new File(ConstUtil.LOCAL_PATH + PhotoBodyFilePath), PhotoBodyFileName, ConstUtil.OSS_ENDPOINT, ConstUtil.OSS_BUCKET, ConstUtil.OSS_SECRET_ID, ConstUtil.OSS_SECRET_KEY); } else { PhotoBodyFilePath = ""; - printDate(carNo,devNo,laneName,"高位","高位摄像头拍摄失败"); + printDate(carNo, devNo, laneName, "高位", "高位摄像头拍摄失败"); } - printDate(carNo,devNo,laneName,"高位","获取高位摄像头结束"); + printDate(carNo, devNo, laneName, "高位", "获取高位摄像头结束"); } - printDate(carNo,devNo,laneName,"高位","上传车头照"); - //上传车头照 + printDate(carNo, devNo, laneName, "高位", "上传车头照"); + // 上传车头照 File file = new File(PhotoFrontFilePath); String PhotoFrontFileName = file.getName(); PhotoFrontUrl = UploadToAliUtil.uploadFile(dirName, new File(PhotoFrontFilePath), PhotoFrontFileName, ConstUtil.OSS_ENDPOINT, ConstUtil.OSS_BUCKET, ConstUtil.OSS_SECRET_ID, ConstUtil.OSS_SECRET_KEY); - //ConstUtil.DOOR_STATUS.put(devNo,0); - //上传数据 + // ConstUtil.DOOR_STATUS.put(devNo,0); + // 上传数据 // printDate(carNo,devNo,laneName,optName,"上传数据开始"); // //获取另一台识别设备的设备号 // IntegratedMachineConfig listCond = new IntegratedMachineConfig(); @@ -311,50 +311,50 @@ public class HardService { jsonObj = JSONObject.toJSONString(reportUnifyReq); - printDate(carNo,devNo,laneName,optName,"上传数据开始:" + reportUnifyReq); + printDate(carNo, devNo, laneName, optName, "上传数据开始:" + reportUnifyReq); strRet = HttpClientUtil.postJson(ConstUtil.REPORT_SERVER + ConstUtil.REPORT_SERVER_URL, jsonObj); - printDate(carNo,devNo,laneName,optName,"上传数据返回:" + strRet); - //ret = JSONObject.parseObject(strRet, ReturnCode.class); + printDate(carNo, devNo, laneName, optName, "上传数据返回:" + strRet); + // ret = JSONObject.parseObject(strRet, ReturnCode.class); req.getAlarmInfoPlate().getResult().getPlateResult().setImageFile(""); jsonObj = JSONObject.toJSONString(req); - printDate(carNo,devNo,laneName,"车牌识别","车牌识别数据:" + req); + printDate(carNo, devNo, laneName, "车牌识别", "车牌识别数据:" + req); - printDate(carNo,devNo,laneName,optName,"上传数据结束"); + printDate(carNo, devNo, laneName, optName, "上传数据结束"); } - public int getDoorStatus(String devNo,String carNo){ + public int getDoorStatus(String devNo, String carNo) { String laneName = ""; String optName = "获取道闸状态"; - printDate(carNo,devNo,laneName,optName,"获取道闸状态开始"); + printDate(carNo, devNo, laneName, optName, "获取道闸状态开始"); String strStatus = ""; DoorStatus doorStatus; - int nRet = 0; + int nRet = 0; IntegratedMachineConfig integratedCond = new IntegratedMachineConfig(); integratedCond.setDevNo(devNo); - //获取一体机配置 + // 获取一体机配置 IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond); laneName = integratedCfg.getLaneName(); try { - String cmd = ConstUtil.CMD_PATH + " getDoorStatus" + integratedCfg.getVerNo() + " " + integratedCfg.getIpAddr() +" " + integratedCfg.getTcpPort() +" " + integratedCfg.getRs485Port(); - printDate(carNo,devNo,laneName,optName,cmd); + String cmd = ConstUtil.CMD_PATH + " getDoorStatus" + integratedCfg.getVerNo() + " " + integratedCfg.getIpAddr() + " " + integratedCfg.getTcpPort() + " " + integratedCfg.getRs485Port(); + printDate(carNo, devNo, laneName, optName, cmd); CmdUtil cmdUtil = new CmdUtil(); List listRet = cmdUtil.exec(cmd); String line; - for (int i = 0;i < listRet.size();i++){ + for (int i = 0; i < listRet.size(); i++) { line = listRet.get(i); int pos = line.indexOf("getDoorStatus_success:"); - if(pos >= 0){ + if (pos >= 0) { strStatus = line.substring(22); - printDate(carNo,devNo,laneName,optName,strStatus); + printDate(carNo, devNo, laneName, optName, strStatus); doorStatus = JSONObject.parseObject(strStatus, DoorStatus.class); - //信号为0的时候说明闸是关着的;信号是1的时候,说明闸开了 - if(doorStatus.getValue().compareTo("0") == 0){ + // 信号为0的时候说明闸是关着的;信号是1的时候,说明闸开了 + if (doorStatus.getValue().compareTo("0") == 0) { nRet = 1; } break; @@ -363,12 +363,12 @@ public class HardService { } catch (Exception e) { e.printStackTrace(); } - printDate(carNo,devNo,laneName,optName,"status is " + nRet); - printDate(carNo,devNo,laneName,optName,"获取道闸状态结束"); + printDate(carNo, devNo, laneName, optName, "status is " + nRet); + printDate(carNo, devNo, laneName, optName, "获取道闸状态结束"); return nRet; } - public double getWeightInfo(String pPort,int BaudRate,byte ByteSize,byte Parity,byte StopBits,String carNo,String devNo,String laneName){ + public double getWeightInfo(String pPort, int BaudRate, byte ByteSize, byte Parity, byte StopBits, String carNo, String devNo, String laneName) { String weight = "0.0"; double dWeight = 0.0; String optName = "称重"; @@ -378,12 +378,12 @@ public class HardService { CmdUtil cmdUtil = new CmdUtil(); List listRet = cmdUtil.exec(cmd); String line; - for (int i = 0;i < listRet.size();i++) { + for (int i = 0; i < listRet.size(); i++) { line = listRet.get(i); - printDate(carNo,devNo,laneName,optName,line); + printDate(carNo, devNo, laneName, optName, line); int pos = line.indexOf("weight:"); - if(pos >= 0){ - weight = line.substring(7,line.length() - 1); + if (pos >= 0) { + weight = line.substring(7, line.length() - 1); break; } } @@ -395,7 +395,7 @@ public class HardService { return dWeight; } - public boolean captureImage(HkCameraConfigEx config,String fileName,String carNo,String devNo,String laneName){ + public boolean captureImage(HkCameraConfigEx config, String fileName, String carNo, String devNo, String laneName) { boolean bRet = false; String optName = "高位"; @@ -405,9 +405,9 @@ public class HardService { CmdUtil cmdUtil = new CmdUtil(); List listRet = cmdUtil.exec(cmd); String line; - for (int i = 0;i < listRet.size();i++) { + for (int i = 0; i < listRet.size(); i++) { line = listRet.get(i); - printDate(carNo,devNo,laneName,optName,line); + printDate(carNo, devNo, laneName, optName, line); int pos = line.indexOf("captureImage:success"); if (pos >= 0) { bRet = true; @@ -431,10 +431,10 @@ public class HardService { cond.setDevNo(req.getDeviceNo()); IpVoiceboxConfigEx cfg = ipVoiceboxConfigDao.selectByCond(cond); - if(cfg != null) { + if (cfg != null) { try { laneName = cfg.getLaneName(); - //printDate(carNo, devNo, laneName, optName, "播放语音开始"); + // printDate(carNo, devNo, laneName, optName, "播放语音开始"); printDate(carNo, devNo, laneName, optName, req); String strChinese = StringToChineseUtil.convert(req.getText()); String baseStr = Base64.encodeBase64String(strChinese.getBytes("UTF-8")); @@ -459,15 +459,15 @@ public class HardService { } String prefix = "voice dev return "; - ThreadPlayVoice thread = new ThreadPlayVoice(this,cmd, prefix, jsonReq, optName, carNo, devNo, laneName); + ThreadPlayVoice thread = new ThreadPlayVoice(this, cmd, prefix, jsonReq, optName, carNo, devNo, laneName); thread.start(); - //printDate(carNo, devNo, laneName, optName, "播放语音结束"); - }catch (Exception e){ + // printDate(carNo, devNo, laneName, optName, "播放语音结束"); + } catch (Exception e) { e.printStackTrace(); } - }else{ - printDate(carNo,devNo,laneName,optName,"device not fount"); + } else { + printDate(carNo, devNo, laneName, optName, "device not fount"); } return 1; @@ -482,80 +482,121 @@ public class HardService { IntegratedMachineConfig integratedCond = new IntegratedMachineConfig(); integratedCond.setDevNo(req.getDeviceNo()); - //获取一体机配置 + // 获取一体机配置 IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond); laneName = integratedCfg.getLaneName(); - printDate(carNo,devNo,laneName,optName,"开闸开始"); - if(integratedCfg != null) { + printDate(carNo, devNo, laneName, optName, "开闸开始"); + if (integratedCfg != null) { String cmd = ConstUtil.CMD_PATH + " openDoor" + integratedCfg.getVerNo() + " " + integratedCfg.getIpAddr(); - if(integratedCfg.getTcpPort().intValue() >= 0){ + if (integratedCfg.getTcpPort().intValue() >= 0) { cmd += " " + integratedCfg.getTcpPort(); } - if(integratedCfg.getHttpPort().intValue() >= 0){ + if (integratedCfg.getHttpPort().intValue() >= 0) { cmd += " " + integratedCfg.getHttpPort(); } - if(integratedCfg.getIoPort().intValue() >= 0){ + if (integratedCfg.getIoPort().intValue() >= 0) { cmd += " " + integratedCfg.getIoPort(); } - printDate(carNo,devNo,laneName,optName,cmd); + printDate(carNo, devNo, laneName, optName, cmd); String prefix = "dev return "; try { - ThreadOpenDoor thread = new ThreadOpenDoor(this,cmd, prefix, jsonReq, optName, carNo, devNo, laneName); + ThreadOpenDoor thread = new ThreadOpenDoor(this, cmd, prefix, jsonReq, optName, carNo, devNo, laneName); thread.start(); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } - printDate(carNo,devNo,laneName,optName,"开闸结束"); + printDate(carNo, devNo, laneName, optName, "开闸结束"); } return 1; } - public int mqttOpenDoor(DoorReq req){ - String[] TOPIC_ARRAY = { - ConstUtil.MQTT_DEVICE_TOPIC + "user/get"}; + public int mqttOpenDoor(DoorReq req) { + logger.info("开门请求: {}", req); + + // String[] TOPIC_ARRAY = {"/message/down/gpio_out"}; String carNo = req.getCarNo(); - String devNo = req.getDeviceNo(); + String deviceNo = req.getDeviceNo(); + String devNo = deviceNo; String laneName = ""; String optName = "开闸"; IntegratedMachineConfig integratedCond = new IntegratedMachineConfig(); - integratedCond.setDevNo(req.getDeviceNo()); - //获取一体机配置 + integratedCond.setDevNo(deviceNo); + // 获取一体机配置 IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond); - + int i = integratedCfg.getIoPort().intValue(); laneName = integratedCfg.getLaneName(); String msgId = System.currentTimeMillis() + RandomUtil.getRandomStr(7); - RecognizePlateResultAckQy ack = new RecognizePlateResultAckQy(); + /* RecognizePlateResultAckQy ack = new RecognizePlateResultAckQy(); ack.setCmd("iooutput"); ack.setMsg_id(msgId); ack.setIonum(1); ack.setAction("on"); - ack.setUtc_ts(1); + ack.setUtc_ts(1); */ + + long time = new Date().getTime(); + DorMsg dorMsg = new DorMsg() + .setId("open" + time) + .setSn(deviceNo) + .setTimestamp(time) + .setPayload(new DorMsg.Payload() + .setBody(new DorMsg.Payload.Body() + .setIo(i) + )); MqttMessage ackMsg = new MqttMessage(); - String strPayload = JSONObject.toJSONString(ack); + String strPayload = JSONObject.toJSONString(dorMsg); ackMsg.setPayload(strPayload.getBytes(StandardCharsets.UTF_8)); try { - String topic = ConstUtil.MQTT_DEVICE_TYPE + req.getDeviceNo() + TOPIC_ARRAY[0]; - printDate(carNo,devNo,laneName,optName,"开闸主题:" + topic); - printDate(carNo,devNo,laneName,optName,"开闸消息:" + strPayload); - deviceClient.publish( topic, ackMsg); - }catch (Exception e){ - e.printStackTrace(); + String topic = "device/" + deviceNo + "/message/down/gpio_out"; + logger.info("主题: {},开门数据: {}", topic, strPayload); + printDate(carNo, devNo, laneName, optName, "开闸主题:" + topic); + printDate(carNo, devNo, laneName, optName, "开闸消息:" + strPayload); + deviceClient.publish(topic, ackMsg); + } catch (Exception e) { + logger.error("开门失败", e); } - printDate(carNo,devNo,laneName,optName,"开闸结束"); - + printDate(carNo, devNo, laneName, optName, "开闸结束"); + if (deviceNo.equals("e6141562-e3ca0602")) { + rollerDoor(); + } return 1; } - public int mqttCloseDoor(DoorReq req){ + void rollerDoor() { + logger.info("开卷闸门"); + long time = new Date().getTime(); + String sn = "5417bd21-ca9f6a6b"; + DorMsg dorMsg = new DorMsg() + .setId("open" + time) + .setSn(sn) + .setTimestamp(time) + .setPayload(new DorMsg.Payload() + .setBody(new DorMsg.Payload.Body() + .setIo(1) + )); + + MqttMessage ackMsg = new MqttMessage(); + String strPayload = JSONObject.toJSONString(dorMsg); + + ackMsg.setPayload(strPayload.getBytes(StandardCharsets.UTF_8)); + try { + String topic = "device/" + sn + "/message/down/gpio_out"; + logger.info("主题: {},开门数据: {}", topic, strPayload); + deviceClient.publish(topic, ackMsg); + } catch (Exception e) { + logger.error("开门失败", e); + } + } + + public int mqttCloseDoor(DoorReq req) { String[] TOPIC_ARRAY = { ConstUtil.MQTT_DEVICE_TOPIC + "user/get"}; String carNo = req.getCarNo(); @@ -565,7 +606,7 @@ public class HardService { IntegratedMachineConfig integratedCond = new IntegratedMachineConfig(); integratedCond.setDevNo(req.getDeviceNo()); - //获取一体机配置 + // 获取一体机配置 IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond); laneName = integratedCfg.getLaneName(); @@ -583,15 +624,15 @@ public class HardService { ackMsg.setPayload(strPayload.getBytes(StandardCharsets.UTF_8)); try { - String topic = ConstUtil.MQTT_DEVICE_TYPE + req.getDeviceNo() + TOPIC_ARRAY[0]; - printDate(carNo,devNo,laneName,optName,"开闸主题:" + topic); - printDate(carNo,devNo,laneName,optName,"开闸消息:" + strPayload); - deviceClient.publish( topic, ackMsg); - }catch (Exception e){ + String topic = ConstUtil.MQTT_DEVICE_TYPE + req.getDeviceNo() + TOPIC_ARRAY[0]; + printDate(carNo, devNo, laneName, optName, "开闸主题:" + topic); + printDate(carNo, devNo, laneName, optName, "开闸消息:" + strPayload); + deviceClient.publish(topic, ackMsg); + } catch (Exception e) { e.printStackTrace(); } - printDate(carNo,devNo,laneName,optName,"开闸结束"); + printDate(carNo, devNo, laneName, optName, "开闸结束"); return 1; } @@ -604,22 +645,22 @@ public class HardService { IntegratedMachineConfig integratedCond = new IntegratedMachineConfig(); integratedCond.setDevNo(req.getDeviceNo()); - //获取一体机配置 + // 获取一体机配置 IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond); laneName = integratedCfg.getLaneName(); - if(integratedCfg != null) { + if (integratedCfg != null) { String cmd = ConstUtil.CMD_PATH + " manualTrigger " + integratedCfg.getIpAddr() + " " + integratedCfg.getTcpPort(); CmdUtil cmdUtil = new CmdUtil(); List listRet = cmdUtil.exec(cmd); String line; - for (int i = 0;i < listRet.size();i++) { + for (int i = 0; i < listRet.size(); i++) { line = listRet.get(i); int pos = line.indexOf("dev return "); - if(pos >= 0){ + if (pos >= 0) { String devRet = line.substring(11); - printDate(carNo,devNo,laneName,optName,devRet); + printDate(carNo, devNo, laneName, optName, devRet); break; } @@ -639,14 +680,14 @@ public class HardService { DisplayConfig displayCond = new DisplayConfig(); displayCond.setDevNo(devNo); - //获取一体机配置 + // 获取一体机配置 DisplayConfig displayCfg = displayConfigDao.selectByCond(displayCond); - if(displayCfg != null) { + if (displayCfg != null) { try { laneName = displayCfg.getLaneName(); printDate(carNo, devNo, laneName, optName, req); - //printDate(carNo, devNo, laneName, optName, "显示文字开始"); + // printDate(carNo, devNo, laneName, optName, "显示文字开始"); String cmd = ConstUtil.CMD_PATH + " displayInfo" + displayCfg.getVerNo() + " " + displayCfg.getIpAddr(); String clearCmd = ConstUtil.CMD_PATH + " displayInfo" + displayCfg.getVerNo() + " " + displayCfg.getIpAddr(); if (displayCfg.getTcpPort().intValue() >= 0) { @@ -655,41 +696,43 @@ public class HardService { } if (StringUtils.isBlank(req.getCarPlate()) == true) { cmd += " " + "IA=="; - }else{ + } else { cmd += " " + Base64.encodeBase64String(req.getCarPlate().getBytes("UTF-8")); } if (StringUtils.isBlank(req.getWeight()) == true) { cmd += " " + "IA=="; - }else { + } else { cmd += " " + Base64.encodeBase64String(req.getWeight().getBytes("UTF-8")); } if (StringUtils.isBlank(req.getAmount()) == true) { cmd += " " + "IA=="; - }else { + } else { cmd += " " + Base64.encodeBase64String(req.getAmount().getBytes("UTF-8")); } clearCmd += " IA=="; clearCmd += " " + Base64.encodeBase64String(ConstUtil.DEFAULT_ADVERT_1.getBytes("UTF-8")); - clearCmd += " " + Base64.encodeBase64String(ConstUtil.DEFAULT_ADVERT_2.getBytes("UTF-8"));; + clearCmd += " " + Base64.encodeBase64String(ConstUtil.DEFAULT_ADVERT_2.getBytes("UTF-8")); + ; if (displayCfg.getRs485Port().intValue() >= 0) { cmd += " " + displayCfg.getRs485Port(); clearCmd += " " + displayCfg.getRs485Port(); } String prefix = "display dev return "; - ThreadDisplayInfo thread = new ThreadDisplayInfo(this,cmd, prefix, jsonReq, "显示", carNo, devNo, laneName); + ThreadDisplayInfo thread = new ThreadDisplayInfo(this, cmd, prefix, jsonReq, "显示", carNo, devNo, laneName); thread.start(); - ThreadClearDisplay clearThread = new ThreadClearDisplay(this,clearCmd, carNo, devNo, laneName); + ThreadClearDisplay clearThread = new ThreadClearDisplay(this, clearCmd, carNo, devNo, laneName); clearThread.start(); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } - }else{ - printDate(carNo,devNo,laneName,optName,"device not find"); + } else { + printDate(carNo, devNo, laneName, optName, "device not find"); } return 1; } + public int mqttDisplayInfo(DisplayInfoReq req) { String[] TOPIC_ARRAY = { ConstUtil.MQTT_DEVICE_TOPIC + "user/get"}; @@ -700,7 +743,7 @@ public class HardService { IntegratedMachineConfig integratedCond = new IntegratedMachineConfig(); integratedCond.setDevNo(req.getDeviceNo()); - //获取一体机配置 + // 获取一体机配置 IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond); laneName = integratedCfg.getLaneName(); @@ -736,24 +779,24 @@ public class HardService { ackMsg.setPayload(strPayload.getBytes(StandardCharsets.UTF_8)); try { - String topic = ConstUtil.MQTT_DEVICE_TYPE + req.getDeviceNo() + TOPIC_ARRAY[0]; - printDate(carNo,devNo,laneName,optName,"开闸主题:" + topic); - printDate(carNo,devNo,laneName,optName,"开闸消息:" + strPayload); + String topic = ConstUtil.MQTT_DEVICE_TYPE + req.getDeviceNo() + TOPIC_ARRAY[0]; + printDate(carNo, devNo, laneName, optName, "开闸主题:" + topic); + printDate(carNo, devNo, laneName, optName, "开闸消息:" + strPayload); deviceClient.publish(topic, ackMsg); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } - printDate(carNo,devNo,laneName,optName,"开闸结束"); + printDate(carNo, devNo, laneName, optName, "开闸结束"); return 1; } - public void clearDisplay(){ + public void clearDisplay() { } - public int manualPlateRecognize(RecognizeAlarmInfoPlate req,String orderNo) { + public int manualPlateRecognize(RecognizeAlarmInfoPlate req, String orderNo) { String jsonObj = JSONObject.toJSONString(req); String devNo = req.getAlarmInfoPlate().getSerialno(); String carNo = req.getAlarmInfoPlate().getResult().getPlateResult().getLicense(); @@ -763,28 +806,28 @@ public class HardService { IntegratedMachineConfig integratedCond = new IntegratedMachineConfig(); integratedCond.setDevNo(devNo); - //获取一体机配置 + // 获取一体机配置 IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond); laneName = integratedCfg.getLaneName(); - String dirName = createLocalImgDir(carNo,carNo,laneName); + String dirName = createLocalImgDir(carNo, carNo, laneName); String PhotoFrontFileName = RandomUtil.getRandomUuid() + ".jpg"; String PhotoFrontFilePath = ConstUtil.LOCAL_PATH + "/" + dirName + "/" + PhotoFrontFileName; - printDate(carNo,devNo,laneName,optName,"手动获取数据"); - printDate(carNo,devNo,laneName,optName,req); + printDate(carNo, devNo, laneName, optName, "手动获取数据"); + printDate(carNo, devNo, laneName, optName, req); - if(integratedCfg != null) { + if (integratedCfg != null) { boolean bRet = false; try { String cmd = ConstUtil.CMD_PATH + " manualPlateRecognize " + integratedCfg.getIpAddr() + " " + integratedCfg.getTcpPort() + " " + PhotoFrontFilePath; - printDate(carNo,devNo,laneName,optName,cmd); + printDate(carNo, devNo, laneName, optName, cmd); CmdUtil cmdUtil = new CmdUtil(); List listRet = cmdUtil.exec(cmd); String line; - for (int i = 0;i < listRet.size();i++) { + for (int i = 0; i < listRet.size(); i++) { line = listRet.get(i); int pos = line.indexOf("captureImage:success"); if (pos >= 0) { @@ -796,11 +839,11 @@ public class HardService { e.printStackTrace(); } - if(bRet == false){ + if (bRet == false) { PhotoFrontFilePath = ""; } - //req.getAlarmInfoPlate().getResult().getPlateResult().setImageFile(imageData); - ThreadManualPlateRecognize thread = new ThreadManualPlateRecognize(this, req, orderNo,dirName,PhotoFrontFilePath); + // req.getAlarmInfoPlate().getResult().getPlateResult().setImageFile(imageData); + ThreadManualPlateRecognize thread = new ThreadManualPlateRecognize(this, req, orderNo, dirName, PhotoFrontFilePath); thread.start(); } @@ -815,33 +858,33 @@ public class HardService { IntegratedMachineConfig integratedCond = new IntegratedMachineConfig(); integratedCond.setDevNo(req.getDeviceNo()); - //获取一体机配置 + // 获取一体机配置 List list = integratedMachineConfigDao.selectListByCond(integratedCond); - for (int i = 0;i < list.size();i++){ + for (int i = 0; i < list.size(); i++) { IntegratedMachineConfigEx integratedCfg = list.get(i); String cmd = ConstUtil.CMD_PATH + " resetDevTime" + integratedCfg.getVerNo() + " " + integratedCfg.getIpAddr() + " " + integratedCfg.getTcpPort() + " " + integratedCfg.getRs485Port(); - printDate(carNo,devNo,laneName,optName,cmd); + printDate(carNo, devNo, laneName, optName, cmd); CmdUtil cmdUtil = new CmdUtil(); List listRet = cmdUtil.exec(cmd); String line; - for (int j = 0;j < listRet.size();j++) { + for (int j = 0; j < listRet.size(); j++) { line = listRet.get(j); - printDate(carNo,devNo,laneName,optName,line); + printDate(carNo, devNo, laneName, optName, line); } } } - public boolean checkDoorStatus(String devNo,String carNo,String laneName){ + public boolean checkDoorStatus(String devNo, String carNo, String laneName) { String optName = "获取道闸状态"; Integer status = ConstUtil.DOOR_STATUS.get(devNo); int i = 0; - printDate(carNo,devNo,laneName,optName,"checkDoorStatus:" + status); + printDate(carNo, devNo, laneName, optName, "checkDoorStatus:" + status); - //20秒内是否已下发开闸指令,如果已下发,状态为IS_SEND_OPEN_DOOR,否则20秒内检测40次 - while (status.compareTo(ConstUtil.IS_NOT_SEND_OPEN_DOOR) == 0 && i < 40){ + // 20秒内是否已下发开闸指令,如果已下发,状态为IS_SEND_OPEN_DOOR,否则20秒内检测40次 + while (status.compareTo(ConstUtil.IS_NOT_SEND_OPEN_DOOR) == 0 && i < 40) { try { Thread.sleep(500); status = ConstUtil.DOOR_STATUS.get(devNo); @@ -851,15 +894,15 @@ public class HardService { i++; } - printDate(carNo,devNo,laneName,optName,"status:" + status); - //已下发开闸指令,开始获取落闸信号 - if(status.compareTo(ConstUtil.IS_SEND_OPEN_DOOR) == 0) { + printDate(carNo, devNo, laneName, optName, "status:" + status); + // 已下发开闸指令,开始获取落闸信号 + if (status.compareTo(ConstUtil.IS_SEND_OPEN_DOOR) == 0) { int nTotalTime = 0; - printDate(carNo,devNo,laneName,optName,"已开闸"); - //50秒内取100次道闸状态,确认道闸是否为落闸 + printDate(carNo, devNo, laneName, optName, "已开闸"); + // 50秒内取100次道闸状态,确认道闸是否为落闸 while (nTotalTime < 100) { try { - int doorStatus = getDoorStatus(devNo,carNo); + int doorStatus = getDoorStatus(devNo, carNo); if (doorStatus == ConstUtil.DOOR_STATUS_CLOSEED) { return true; } @@ -874,45 +917,45 @@ public class HardService { return false; } - public void closeDoor(int times,String carNo,String devNo,String laneName){ - //关卷帘门,苏州弘盛发专用 - ThreadCloseDoor thread = new ThreadCloseDoor(this,carNo,devNo,laneName,times); + public void closeDoor(int times, String carNo, String devNo, String laneName) { + // 关卷帘门,苏州弘盛发专用 + ThreadCloseDoor thread = new ThreadCloseDoor(this, carNo, devNo, laneName, times); thread.start(); } - public String createLocalImgDir(String carNo,String devNo,String laneName){ + public String createLocalImgDir(String carNo, String devNo, String laneName) { String optName = "创建图片目录"; Date date = new Date(); - SimpleDateFormat dateFormat= new SimpleDateFormat("yyyyMMdd"); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); String dirName = dateFormat.format(date); - printDate(carNo,devNo,laneName,optName,dirName); + printDate(carNo, devNo, laneName, optName, dirName); File file = new File(ConstUtil.LOCAL_PATH + dirName); if (!file.exists()) { - printDate(carNo,devNo,laneName,optName,"目录不存在"); - //创建上级目录 + printDate(carNo, devNo, laneName, optName, "目录不存在"); + // 创建上级目录 file.mkdirs(); } return dirName; } - public String saveFrontImage(String imageData,String carNo,String dirName,String devNo,String laneName,String PhotoFrontFileName){ + public String saveFrontImage(String imageData, String carNo, String dirName, String devNo, String laneName, String PhotoFrontFileName) { String optName = "保存图片"; String PhotoFrontFilePath = ConstUtil.LOCAL_PATH + "/" + dirName + "/" + PhotoFrontFileName; - //保存车牌图片并上传 + // 保存车牌图片并上传 boolean bRet = ImageUtil.generateImage(imageData, PhotoFrontFilePath); - printDate(carNo,devNo,laneName,optName,"保存车牌图片完成:" + PhotoFrontFilePath); + printDate(carNo, devNo, laneName, optName, "保存车牌图片完成:" + PhotoFrontFilePath); if (bRet == false) { PhotoFrontFilePath = ""; - printDate(carNo,devNo,laneName,optName,"一体机拍摄失败:" + carNo); + printDate(carNo, devNo, laneName, optName, "一体机拍摄失败:" + carNo); } return PhotoFrontFilePath; } - public void printDate(String carNo,String devNo,String laneName,String optName,Object content){ + public void printDate(String carNo, String devNo, String laneName, String optName, Object content) { logger.info(optName + ":" + carNo + ":" + devNo + ":" + laneName + ":" + content); LogEntity logEntity = new LogEntity(); diff --git a/src/main/java/com/jepsoninfo/service/ThreadDeviceCmdMqtt.java b/src/main/java/com/jepsoninfo/service/ThreadDeviceCmdMqtt.java index 5694b95..96d2ae0 100644 --- a/src/main/java/com/jepsoninfo/service/ThreadDeviceCmdMqtt.java +++ b/src/main/java/com/jepsoninfo/service/ThreadDeviceCmdMqtt.java @@ -22,6 +22,9 @@ public class ThreadDeviceCmdMqtt extends Thread{ public void run() { logger.info("ThreadDeviceCmdMqtt mqtt init"); + /* String[] TOPIC_ARRAY = { + ConstUtil.MQTT_DEVICE_TOPIC + "user/get", + ConstUtil.MQTT_DEVICE_TOPIC + "user/update"}; */ String[] TOPIC_ARRAY = { ConstUtil.MQTT_DEVICE_TOPIC + "user/get", ConstUtil.MQTT_DEVICE_TOPIC + "user/update"};