995 lines
41 KiB
Java
995 lines
41 KiB
Java
package com.jepsoninfo.service;
|
||
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.jepsoninfo.dao.*;
|
||
import com.jepsoninfo.entity.*;
|
||
import com.jepsoninfo.entity.ex.HkCameraConfigEx;
|
||
import com.jepsoninfo.entity.ex.IntegratedMachineConfigEx;
|
||
import com.jepsoninfo.entity.ex.IpVoiceboxConfigEx;
|
||
import com.jepsoninfo.req.*;
|
||
import com.jepsoninfo.resp.DoorStatus;
|
||
import com.jepsoninfo.resp.ReportCarPassRes;
|
||
import com.jepsoninfo.util.*;
|
||
import org.apache.commons.codec.binary.Base64;
|
||
import org.apache.commons.lang.StringUtils;
|
||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
|
||
import java.io.File;
|
||
import java.nio.charset.StandardCharsets;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.ArrayList;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
|
||
@Service
|
||
public class HardService {
|
||
private final Logger logger = LoggerFactory.getLogger("HardService.class");// Logger.getLogger("HardService.class");
|
||
public MqttClient recvClient;
|
||
public MqttClient deviceClient;
|
||
@Autowired
|
||
private IntegratedMachineConfigDao integratedMachineConfigDao;
|
||
@Autowired
|
||
private WagonBalanceConfigDao wagonBalanceConfigDao;
|
||
@Autowired
|
||
private HkCameraConfigDao hkCameraConfigDao;
|
||
@Autowired
|
||
private IpVoiceboxConfigDao ipVoiceboxConfigDao;
|
||
@Autowired
|
||
private DisplayConfigDao displayConfigDao;
|
||
@Autowired
|
||
private MessageConfigDao messageConfigDao;
|
||
|
||
public void plateRecognize(RecognizeAlarmInfoPlate req) {
|
||
logger.info("车牌识别结果:{}", JSONObject.toJSONString(req));
|
||
|
||
ReturnCode result;
|
||
ReportCarPassRes ret;
|
||
String strRet = "";
|
||
String laneName = "";
|
||
String optName = "车牌识别";
|
||
String carNo = req.getAlarmInfoPlate().getResult().getPlateResult().getLicense();
|
||
String devNo = req.getAlarmInfoPlate().getSerialno();
|
||
|
||
if (carNo == null || carNo.isEmpty() || carNo.contains("无")) {
|
||
logger.error("车牌识别失败, 车牌为空");
|
||
return;
|
||
}
|
||
|
||
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, "车牌识别详细信息");
|
||
|
||
// 保持车头照
|
||
String dirName = createLocalImgDir(carNo, devNo, laneName);
|
||
String PhotoFrontFileName = RandomUtil.getRandomUuid() + ".jpg";
|
||
String PhotoFrontFilePath = saveFrontImage(req.getAlarmInfoPlate().getResult().getPlateResult().getImageFile(), carNo, dirName, devNo, laneName, PhotoFrontFileName);
|
||
logger.info("播放语音: {}", integratedCfg.getIpVoiceId());
|
||
try {
|
||
if (integratedCfg != null) {
|
||
if (integratedCfg.getIsFront() == 1) {
|
||
// 获取音柱配置
|
||
IpVoiceboxConfigEx ipVoiceboxConfig = ipVoiceboxConfigDao.selectByPrimaryKey(integratedCfg.getIpVoiceId());
|
||
if (ipVoiceboxConfig != null) {
|
||
MessageConfig messageConfig = messageConfigDao.selectByPrimaryKey(3L);
|
||
|
||
PlayVoiceReq playVoice = new PlayVoiceReq();
|
||
playVoice.setCarNo(carNo);
|
||
playVoice.setDeviceNo(ipVoiceboxConfig.getDevNo());
|
||
playVoice.setText(messageConfig.getContent());
|
||
playVoice(playVoice);
|
||
}
|
||
}
|
||
} else {
|
||
printDate(carNo, devNo, laneName, optName, "not find integrated");
|
||
return;
|
||
}
|
||
} catch (Exception e) {
|
||
logger.error("播放语音失败", e);
|
||
}
|
||
|
||
String PhotoBodyUrl = null;
|
||
try {
|
||
PhotoBodyUrl = UploadToAliUtil.uploadFile(dirName, new File(PhotoFrontFilePath), PhotoFrontFileName,
|
||
ConstUtil.OSS_ENDPOINT, ConstUtil.OSS_BUCKET, ConstUtil.OSS_SECRET_ID, ConstUtil.OSS_SECRET_KEY);
|
||
} catch (Exception e) {
|
||
logger.error("图片上传失败", e);
|
||
throw new RuntimeException(e);
|
||
}
|
||
|
||
|
||
ReportUnifyReq reportUnifyReq = new ReportUnifyReq();
|
||
|
||
reportUnifyReq.setCarNumber(carNo);
|
||
reportUnifyReq.setCarDiscernCode(devNo);
|
||
reportUnifyReq.setPhotoFront(PhotoBodyUrl);
|
||
|
||
printDate(carNo, devNo, laneName, optName + "上报", reportUnifyReq);
|
||
String jsonObj;
|
||
jsonObj = JSONObject.toJSONString(reportUnifyReq);
|
||
strRet = HttpClientUtil.postJson(ConstUtil.REPORT_SERVER + ConstUtil.REPORT_PASS_SERVER_URL, jsonObj);
|
||
// strRet = "{" +
|
||
// " \"data\":{" +
|
||
// " \"carNumber\":\"测试A12345\"," +
|
||
// " \"type\":\"1\"," +
|
||
// " \"orderNo\":\"12345\"," +
|
||
// " \"errMsg\":\"\"," +
|
||
// " \"scene\":\"CPR\"" +
|
||
// " }\n" +
|
||
// "}";
|
||
printDate(carNo, devNo, laneName, optName, "上报返回:" + strRet);
|
||
result = JSONObject.parseObject(strRet, ReturnCode.class);
|
||
|
||
// printDate(carNo,devNo,laneName,optName,"上报解析:" + result);
|
||
|
||
ConstUtil.DOOR_STATUS.put(devNo, 0);
|
||
|
||
if (result != null && result.getData() != null) {
|
||
ret = JSONObject.parseObject(result.getData(), ReportCarPassRes.class);
|
||
|
||
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 + "");
|
||
if (nLane == 0) {
|
||
// 出场
|
||
} else {
|
||
if (integratedCfg.getIsDoorStatus() == 1) {
|
||
if (checkDoorStatus(devNo, carNo, laneName) == false) {
|
||
return;
|
||
}
|
||
}
|
||
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 + "");
|
||
if (nLane == 0) {
|
||
// 出场
|
||
if (integratedCfg.getIsDoorStatus() == 1) {
|
||
if (checkDoorStatus(devNo, carNo, laneName) == false) {
|
||
return;
|
||
}
|
||
}
|
||
|
||
closeDoor(0, carNo, devNo, laneName);
|
||
collectAndUploadData(req, ret.getOrderNo(), dirName, PhotoFrontFilePath);
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
printDate(carNo, devNo, laneName, optName, "服务器无法访问或返回错误");
|
||
}
|
||
}
|
||
|
||
public void collectAndUploadData(RecognizeAlarmInfoPlate req, String orderNo, String dirName, String PhotoFrontFilePath) {
|
||
ReturnCode ret;
|
||
boolean bRet;
|
||
String PhotoBodyUrl = "";
|
||
String strRet = "";
|
||
String jsonObj = "";
|
||
String carNo = req.getAlarmInfoPlate().getResult().getPlateResult().getLicense();
|
||
String devNo = req.getAlarmInfoPlate().getSerialno();
|
||
String laneName = "";
|
||
String optName = "数据采集";
|
||
ReportUnifyReq reportUnifyReq = new ReportUnifyReq();
|
||
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
||
MessageConfig messageConfig;
|
||
|
||
integratedCond.setDevNo(devNo);
|
||
// 获取一体机配置
|
||
IntegratedMachineConfigEx integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond);
|
||
// 获取地磅配置
|
||
WagonBalanceConfig wagonCfg = wagonBalanceConfigDao.selectByPrimaryKey(integratedCfg.getWagonBalanceId());
|
||
// 获取网络摄像头1配置
|
||
HkCameraConfigEx hkCameraConfig = hkCameraConfigDao.selectByPrimaryKey(integratedCfg.getHkCameraId());
|
||
// 获取网络音柱配置
|
||
IpVoiceboxConfig ipVoiceboxConfig = ipVoiceboxConfigDao.selectByPrimaryKey(integratedCfg.getIpVoiceId());
|
||
|
||
laneName = integratedCfg.getLaneName();
|
||
printDate(carNo, devNo, laneName, optName, "collectAndUploadData");
|
||
|
||
// 显示车牌
|
||
DisplayInfoReq displayInfoReq = new DisplayInfoReq();
|
||
|
||
displayInfoReq.setCarPlate(carNo);
|
||
displayInfoReq.setAmount("");
|
||
displayInfoReq.setWeight("");
|
||
displayInfoReq.setDeviceNo(devNo);
|
||
displayInfo(displayInfoReq);
|
||
|
||
double weight = 0.0;
|
||
int weightLoop = 3;
|
||
if (wagonCfg != null) {
|
||
while (weightLoop > 0) {
|
||
// 播放等待语音
|
||
if (ipVoiceboxConfig != null) {
|
||
messageConfig = messageConfigDao.selectByPrimaryKey(2L);
|
||
PlayVoiceReq playVoice = new PlayVoiceReq();
|
||
|
||
playVoice.setCarNo(carNo);
|
||
playVoice.setDeviceNo(ipVoiceboxConfig.getDevNo());
|
||
playVoice.setText(messageConfig.getContent());
|
||
playVoice(playVoice);
|
||
}
|
||
|
||
// 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,"称重","读地磅结束");
|
||
if (nWeight <= 200) {
|
||
// 播放重新称重提示
|
||
if (ipVoiceboxConfig != null) {
|
||
messageConfig = messageConfigDao.selectByPrimaryKey(4L);
|
||
PlayVoiceReq playVoice = new PlayVoiceReq();
|
||
|
||
playVoice.setCarNo(carNo);
|
||
playVoice.setDeviceNo(ipVoiceboxConfig.getDevNo());
|
||
playVoice.setText(messageConfig.getContent());
|
||
playVoice(playVoice);
|
||
}
|
||
weightLoop--;
|
||
} 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 PhotoFrontUrl = "";
|
||
|
||
if (hkCameraConfig != null) {
|
||
printDate(carNo, devNo, laneName, "高位", "获取高位摄像头开始");
|
||
bRet = captureImage(hkCameraConfig, ConstUtil.LOCAL_PATH + PhotoBodyFilePath, carNo, devNo, laneName);
|
||
if (bRet == true) {
|
||
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, "高位", "上传车头照");
|
||
// 上传车头照
|
||
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);
|
||
// 上传数据
|
||
// printDate(carNo,devNo,laneName,optName,"上传数据开始");
|
||
// //获取另一台识别设备的设备号
|
||
// IntegratedMachineConfig listCond = new IntegratedMachineConfig();
|
||
//
|
||
// listCond.setLaneNo(integratedCfg.getLaneNo());
|
||
// List<IntegratedMachineConfigEx> listIntegrated = integratedMachineConfigDao.selectListByCond(listCond);
|
||
//
|
||
// for(int i = 0;i < listIntegrated.size();i++){
|
||
// IntegratedMachineConfigEx item = listIntegrated.get(i);
|
||
// String curDevNo = item.getDevNo();
|
||
// printDate("当前编号:" + curDevNo);
|
||
// printDate("设备编号:" + devNo);
|
||
//
|
||
// if(curDevNo.equals(devNo) == false) {
|
||
// printDate("编号不同");
|
||
// devNo = item.getDevNo();
|
||
// break;
|
||
// }
|
||
// }
|
||
|
||
reportUnifyReq.setCarNumber(carNo);
|
||
reportUnifyReq.setCarDiscernCode(devNo);
|
||
reportUnifyReq.setWeight(weight + "");
|
||
reportUnifyReq.setPhotoFront(PhotoFrontUrl);
|
||
reportUnifyReq.setPhotoBody(PhotoBodyUrl);
|
||
reportUnifyReq.setTelephone(req.getAlarmInfoPlate().getResult().getPlateResult().getTelephone());
|
||
reportUnifyReq.setOnlyCar(0);
|
||
reportUnifyReq.setOrderNo(orderNo);
|
||
|
||
jsonObj = JSONObject.toJSONString(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);
|
||
|
||
req.getAlarmInfoPlate().getResult().getPlateResult().setImageFile("");
|
||
jsonObj = JSONObject.toJSONString(req);
|
||
printDate(carNo, devNo, laneName, "车牌识别", "车牌识别数据:" + req);
|
||
|
||
printDate(carNo, devNo, laneName, optName, "上传数据结束");
|
||
}
|
||
|
||
public int getDoorStatus(String devNo, String carNo) {
|
||
String laneName = "";
|
||
String optName = "获取道闸状态";
|
||
printDate(carNo, devNo, laneName, optName, "获取道闸状态开始");
|
||
String strStatus = "";
|
||
DoorStatus doorStatus;
|
||
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);
|
||
CmdUtil cmdUtil = new CmdUtil();
|
||
List<String> listRet = cmdUtil.exec(cmd);
|
||
String line;
|
||
for (int i = 0; i < listRet.size(); i++) {
|
||
line = listRet.get(i);
|
||
int pos = line.indexOf("getDoorStatus_success:");
|
||
if (pos >= 0) {
|
||
strStatus = line.substring(22);
|
||
printDate(carNo, devNo, laneName, optName, strStatus);
|
||
doorStatus = JSONObject.parseObject(strStatus, DoorStatus.class);
|
||
// 信号为0的时候说明闸是关着的;信号是1的时候,说明闸开了
|
||
if (doorStatus.getValue().compareTo("0") == 0) {
|
||
nRet = 1;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
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) {
|
||
String weight = "0.0";
|
||
double dWeight = 0.0;
|
||
String optName = "称重";
|
||
|
||
try {
|
||
String cmd = ConstUtil.CMD_PATH + " readWeight " + pPort + " " + BaudRate + " " + ByteSize + " " + Parity + " " + StopBits + "";
|
||
CmdUtil cmdUtil = new CmdUtil();
|
||
List<String> listRet = cmdUtil.exec(cmd);
|
||
String line;
|
||
for (int i = 0; i < listRet.size(); i++) {
|
||
line = listRet.get(i);
|
||
printDate(carNo, devNo, laneName, optName, line);
|
||
int pos = line.indexOf("weight:");
|
||
if (pos >= 0) {
|
||
weight = line.substring(7, line.length() - 1);
|
||
break;
|
||
}
|
||
}
|
||
dWeight = Double.parseDouble(weight);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
return dWeight;
|
||
}
|
||
|
||
public boolean captureImage(HkCameraConfigEx config, String fileName, String carNo, String devNo, String laneName) {
|
||
boolean bRet = false;
|
||
String optName = "高位";
|
||
|
||
try {
|
||
String cmd = ConstUtil.CMD_PATH + " captureImage" + config.getVerNo() + " " + config.getIpAddr() + " " + fileName + " " + config.getPort() + " " + config.getUserName() + " " + config.getPassword();
|
||
|
||
CmdUtil cmdUtil = new CmdUtil();
|
||
List<String> listRet = cmdUtil.exec(cmd);
|
||
String line;
|
||
for (int i = 0; i < listRet.size(); i++) {
|
||
line = listRet.get(i);
|
||
printDate(carNo, devNo, laneName, optName, line);
|
||
int pos = line.indexOf("captureImage:success");
|
||
if (pos >= 0) {
|
||
bRet = true;
|
||
break;
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
return bRet;
|
||
}
|
||
|
||
public int playVoice(PlayVoiceReq req) {
|
||
logger.info("播放语音请求:{}", JSONObject.toJSONString(req));
|
||
|
||
String carNo = req.getCarNo();
|
||
String devNo = req.getDeviceNo();
|
||
String laneName = "";
|
||
String optName = "语音";
|
||
String jsonReq = JSONObject.toJSONString(req);
|
||
IpVoiceboxConfig cond = new IpVoiceboxConfig();
|
||
|
||
cond.setDevNo(req.getDeviceNo());
|
||
IpVoiceboxConfigEx cfg = ipVoiceboxConfigDao.selectByCond(cond);
|
||
if (cfg != null) {
|
||
try {
|
||
laneName = cfg.getLaneName();
|
||
// 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"));
|
||
String cmd = ConstUtil.CMD_PATH + " playVoice" + cfg.getVerNo() + " " + cfg.getIpAddr() + " " + baseStr;
|
||
if (cfg.getTcpPort().intValue() >= 0) {
|
||
cmd += " " + cfg.getTcpPort();
|
||
}
|
||
if (cfg.getHttpPort().intValue() >= 0) {
|
||
cmd += " " + cfg.getHttpPort();
|
||
}
|
||
if (StringUtils.isNotBlank(cfg.getUserName()) == true) {
|
||
cmd += " " + cfg.getUserName();
|
||
}
|
||
if (StringUtils.isNotBlank(cfg.getPasswd()) == true) {
|
||
cmd += " " + cfg.getPasswd();
|
||
}
|
||
if (cfg.getRs485Port().intValue() >= 0) {
|
||
cmd += " " + cfg.getRs485Port();
|
||
}
|
||
if (cfg.getMaxVol().intValue() >= 0) {
|
||
cmd += " " + cfg.getMaxVol();
|
||
}
|
||
|
||
String prefix = "voice dev return ";
|
||
ThreadPlayVoice thread = new ThreadPlayVoice(this, cmd, prefix, jsonReq, optName, carNo, devNo, laneName);
|
||
thread.start();
|
||
|
||
// printDate(carNo, devNo, laneName, optName, "播放语音结束");
|
||
} catch (Exception e) {
|
||
logger.info("语音播放异常", e);
|
||
}
|
||
} else {
|
||
printDate(carNo, devNo, laneName, optName, "device not fount");
|
||
}
|
||
|
||
return 1;
|
||
}
|
||
|
||
public int openDoor(DoorReq req) {
|
||
String jsonReq = JSONObject.toJSONString(req);
|
||
String carNo = req.getCarNo();
|
||
String devNo = req.getDeviceNo();
|
||
String laneName = "";
|
||
String optName = "开闸";
|
||
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
||
|
||
integratedCond.setDevNo(req.getDeviceNo());
|
||
// 获取一体机配置
|
||
IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond);
|
||
|
||
laneName = integratedCfg.getLaneName();
|
||
printDate(carNo, devNo, laneName, optName, "开闸开始");
|
||
if (integratedCfg != null) {
|
||
String cmd = ConstUtil.CMD_PATH + " openDoor" + integratedCfg.getVerNo() + " " + integratedCfg.getIpAddr();
|
||
if (integratedCfg.getTcpPort().intValue() >= 0) {
|
||
cmd += " " + integratedCfg.getTcpPort();
|
||
}
|
||
if (integratedCfg.getHttpPort().intValue() >= 0) {
|
||
cmd += " " + integratedCfg.getHttpPort();
|
||
}
|
||
if (integratedCfg.getIoPort().intValue() >= 0) {
|
||
cmd += " " + integratedCfg.getIoPort();
|
||
}
|
||
printDate(carNo, devNo, laneName, optName, cmd);
|
||
String prefix = "dev return ";
|
||
|
||
try {
|
||
ThreadOpenDoor thread = new ThreadOpenDoor(this, cmd, prefix, jsonReq, optName, carNo, devNo, laneName);
|
||
thread.start();
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
printDate(carNo, devNo, laneName, optName, "开闸结束");
|
||
}
|
||
|
||
return 1;
|
||
}
|
||
|
||
public int mqttOpenDoor(DoorReq req) {
|
||
logger.info("开门请求: {}", JSONObject.toJSONString(req));
|
||
|
||
// String[] TOPIC_ARRAY = {"/message/down/gpio_out"};
|
||
String carNo = req.getCarNo();
|
||
String deviceNo = req.getDeviceNo();
|
||
String devNo = deviceNo;
|
||
String laneName = "";
|
||
String optName = "开闸";
|
||
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
||
|
||
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();
|
||
ack.setCmd("iooutput");
|
||
ack.setMsg_id(msgId);
|
||
ack.setIonum(1);
|
||
ack.setAction("on");
|
||
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(dorMsg);
|
||
|
||
ackMsg.setPayload(strPayload.getBytes(StandardCharsets.UTF_8));
|
||
try {
|
||
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, "开闸结束");
|
||
/* if (deviceNo.equals("e6141562-e3ca0602")) {
|
||
rollerDoor();
|
||
} */
|
||
return 1;
|
||
}
|
||
|
||
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();
|
||
String devNo = req.getDeviceNo();
|
||
String laneName = "";
|
||
String optName = "开闸";
|
||
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
||
|
||
integratedCond.setDevNo(req.getDeviceNo());
|
||
// 获取一体机配置
|
||
IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond);
|
||
|
||
laneName = integratedCfg.getLaneName();
|
||
String msgId = System.currentTimeMillis() + RandomUtil.getRandomStr(7);
|
||
|
||
RecognizePlateResultAckQy ack = new RecognizePlateResultAckQy();
|
||
ack.setCmd("iooutput");
|
||
ack.setMsg_id(msgId);
|
||
ack.setIonum(1);
|
||
ack.setAction("off");
|
||
ack.setUtc_ts(1);
|
||
|
||
MqttMessage ackMsg = new MqttMessage();
|
||
String strPayload = JSONObject.toJSONString(ack);
|
||
|
||
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();
|
||
}
|
||
|
||
printDate(carNo, devNo, laneName, optName, "开闸结束");
|
||
|
||
return 1;
|
||
}
|
||
|
||
public int manualTrigger(DoorReq req) {
|
||
String carNo = req.getCarNo();
|
||
String devNo = req.getDeviceNo();
|
||
String laneName = "";
|
||
String optName = "手动触发";
|
||
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
||
|
||
integratedCond.setDevNo(req.getDeviceNo());
|
||
// 获取一体机配置
|
||
IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond);
|
||
|
||
laneName = integratedCfg.getLaneName();
|
||
|
||
if (integratedCfg != null) {
|
||
String cmd = ConstUtil.CMD_PATH + " manualTrigger " + integratedCfg.getIpAddr() + " " + integratedCfg.getTcpPort();
|
||
CmdUtil cmdUtil = new CmdUtil();
|
||
List<String> listRet = cmdUtil.exec(cmd);
|
||
String line;
|
||
for (int i = 0; i < listRet.size(); i++) {
|
||
line = listRet.get(i);
|
||
int pos = line.indexOf("dev return ");
|
||
if (pos >= 0) {
|
||
String devRet = line.substring(11);
|
||
printDate(carNo, devNo, laneName, optName, devRet);
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
return 1;
|
||
}
|
||
|
||
public int displayInfo(DisplayInfoReq req) {
|
||
String jsonReq = JSONObject.toJSONString(req);
|
||
String carNo = req.getCarPlate();
|
||
String devNo = req.getDeviceNo();
|
||
String laneName = "";
|
||
String optName = "显示";
|
||
|
||
DisplayConfig displayCond = new DisplayConfig();
|
||
|
||
displayCond.setDevNo(devNo);
|
||
// 获取一体机配置
|
||
DisplayConfig displayCfg = displayConfigDao.selectByCond(displayCond);
|
||
|
||
if (displayCfg != null) {
|
||
try {
|
||
laneName = displayCfg.getLaneName();
|
||
printDate(carNo, devNo, laneName, optName, req);
|
||
// 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) {
|
||
cmd += " " + displayCfg.getTcpPort();
|
||
clearCmd += " " + displayCfg.getTcpPort();
|
||
}
|
||
if (StringUtils.isBlank(req.getCarPlate()) == true) {
|
||
cmd += " " + "IA==";
|
||
} else {
|
||
cmd += " " + Base64.encodeBase64String(req.getCarPlate().getBytes("UTF-8"));
|
||
}
|
||
if (StringUtils.isBlank(req.getWeight()) == true) {
|
||
cmd += " " + "IA==";
|
||
} else {
|
||
cmd += " " + Base64.encodeBase64String(req.getWeight().getBytes("UTF-8"));
|
||
}
|
||
if (StringUtils.isBlank(req.getAmount()) == true) {
|
||
cmd += " " + "IA==";
|
||
} 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"));
|
||
;
|
||
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);
|
||
thread.start();
|
||
ThreadClearDisplay clearThread = new ThreadClearDisplay(this, clearCmd, carNo, devNo, laneName);
|
||
clearThread.start();
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
} 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"};
|
||
String carNo = "";
|
||
String devNo = req.getDeviceNo();
|
||
String laneName = "";
|
||
String optName = "开闸";
|
||
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
||
|
||
integratedCond.setDevNo(req.getDeviceNo());
|
||
// 获取一体机配置
|
||
IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond);
|
||
|
||
laneName = integratedCfg.getLaneName();
|
||
String msgId = System.currentTimeMillis() + RandomUtil.getRandomStr(7);
|
||
|
||
RecognizePlateResultAckQy ack = new RecognizePlateResultAckQy();
|
||
ShowDataInfoQy showData = new ShowDataInfoQy();
|
||
List<ShowLineInfoQy> lineInfo = new ArrayList<ShowLineInfoQy>();
|
||
ShowLineInfoQy line1 = new ShowLineInfoQy();
|
||
line1.setLine(1);
|
||
line1.setLcdcontent(req.getCarPlate());
|
||
lineInfo.add(line1);
|
||
|
||
ShowLineInfoQy line2 = new ShowLineInfoQy();
|
||
line2.setLine(1);
|
||
line2.setLcdcontent(req.getWeight());
|
||
lineInfo.add(line2);
|
||
|
||
ShowLineInfoQy line3 = new ShowLineInfoQy();
|
||
line3.setLine(1);
|
||
line3.setLcdcontent(req.getAmount());
|
||
lineInfo.add(line3);
|
||
|
||
showData.setLineInfo(lineInfo);
|
||
showData.setScond(10);
|
||
|
||
ack.setCmd("LCDCurrentShowInfo");
|
||
ack.setMsg_id(msgId);
|
||
ack.setShowDataInfo(showData);
|
||
|
||
MqttMessage ackMsg = new MqttMessage();
|
||
String strPayload = JSONObject.toJSONString(ack);
|
||
|
||
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();
|
||
}
|
||
|
||
printDate(carNo, devNo, laneName, optName, "开闸结束");
|
||
|
||
return 1;
|
||
}
|
||
|
||
public void clearDisplay() {
|
||
|
||
}
|
||
|
||
public int manualPlateRecognize(RecognizeAlarmInfoPlate req, String orderNo) {
|
||
String jsonObj = JSONObject.toJSONString(req);
|
||
String devNo = req.getAlarmInfoPlate().getSerialno();
|
||
String carNo = req.getAlarmInfoPlate().getResult().getPlateResult().getLicense();
|
||
String laneName = "";
|
||
String optName = "手动车牌识别";
|
||
|
||
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
||
|
||
integratedCond.setDevNo(devNo);
|
||
// 获取一体机配置
|
||
IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond);
|
||
|
||
laneName = integratedCfg.getLaneName();
|
||
|
||
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);
|
||
|
||
if (integratedCfg != null) {
|
||
boolean bRet = false;
|
||
|
||
try {
|
||
String cmd = ConstUtil.CMD_PATH + " manualPlateRecognize " + integratedCfg.getIpAddr() + " " + integratedCfg.getTcpPort() + " " + PhotoFrontFilePath;
|
||
printDate(carNo, devNo, laneName, optName, cmd);
|
||
CmdUtil cmdUtil = new CmdUtil();
|
||
List<String> listRet = cmdUtil.exec(cmd);
|
||
String line;
|
||
for (int i = 0; i < listRet.size(); i++) {
|
||
line = listRet.get(i);
|
||
int pos = line.indexOf("captureImage:success");
|
||
if (pos >= 0) {
|
||
bRet = true;
|
||
break;
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
if (bRet == false) {
|
||
PhotoFrontFilePath = "";
|
||
}
|
||
// req.getAlarmInfoPlate().getResult().getPlateResult().setImageFile(imageData);
|
||
ThreadManualPlateRecognize thread = new ThreadManualPlateRecognize(this, req, orderNo, dirName, PhotoFrontFilePath);
|
||
thread.start();
|
||
}
|
||
|
||
return 1;
|
||
}
|
||
|
||
public void resetDevTime(TimeReq req) {
|
||
String carNo = req.getCarNo();
|
||
String devNo = req.getDeviceNo();
|
||
String laneName = "";
|
||
String optName = "设置时间";
|
||
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
||
|
||
integratedCond.setDevNo(req.getDeviceNo());
|
||
// 获取一体机配置
|
||
List<IntegratedMachineConfigEx> list = integratedMachineConfigDao.selectListByCond(integratedCond);
|
||
|
||
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);
|
||
CmdUtil cmdUtil = new CmdUtil();
|
||
List<String> listRet = cmdUtil.exec(cmd);
|
||
String line;
|
||
for (int j = 0; j < listRet.size(); j++) {
|
||
line = listRet.get(j);
|
||
printDate(carNo, devNo, laneName, optName, line);
|
||
}
|
||
}
|
||
}
|
||
|
||
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);
|
||
|
||
// 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);
|
||
} catch (InterruptedException e) {
|
||
e.printStackTrace();
|
||
}
|
||
i++;
|
||
}
|
||
|
||
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次道闸状态,确认道闸是否为落闸
|
||
while (nTotalTime < 100) {
|
||
try {
|
||
int doorStatus = getDoorStatus(devNo, carNo);
|
||
if (doorStatus == ConstUtil.DOOR_STATUS_CLOSEED) {
|
||
return true;
|
||
}
|
||
Thread.sleep(500);
|
||
nTotalTime++;
|
||
} catch (Exception e1) {
|
||
e1.printStackTrace();
|
||
}
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
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) {
|
||
String optName = "创建图片目录";
|
||
Date date = new Date();
|
||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||
String dirName = dateFormat.format(date);
|
||
printDate(carNo, devNo, laneName, optName, dirName);
|
||
|
||
File file = new File(ConstUtil.LOCAL_PATH + dirName);
|
||
|
||
if (!file.exists()) {
|
||
printDate(carNo, devNo, laneName, optName, "目录不存在");
|
||
// 创建上级目录
|
||
file.mkdirs();
|
||
}
|
||
return dirName;
|
||
}
|
||
|
||
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);
|
||
if (bRet == false) {
|
||
PhotoFrontFilePath = "";
|
||
printDate(carNo, devNo, laneName, optName, "一体机拍摄失败:" + carNo);
|
||
}
|
||
|
||
return PhotoFrontFilePath;
|
||
}
|
||
|
||
public void printDate(String carNo, String devNo, String laneName, String optName, Object content) {
|
||
logger.info(optName + ":" + carNo + ":" + devNo + ":" + laneName + ":" + content);
|
||
|
||
LogEntity logEntity = new LogEntity();
|
||
|
||
logEntity.logTime = System.currentTimeMillis();
|
||
logEntity.content = content;
|
||
logEntity.carNo = carNo;
|
||
logEntity.devNo = devNo;
|
||
logEntity.laneName = laneName;
|
||
logEntity.optName = optName;
|
||
logEntity.companyNo = ConstUtil.COMPANY_NO;
|
||
logEntity.companyName = ConstUtil.COMPANY_NAME;
|
||
|
||
ConstUtil.deque.offer(logEntity);
|
||
}
|
||
}
|