Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
|
9c14f9fe8c | |
|
25b9913eb1 |
|
@ -0,0 +1,6 @@
|
||||||
|
/**/logs
|
||||||
|
/**/*.iml
|
||||||
|
/**/.idea
|
||||||
|
/**/target
|
||||||
|
/**/.DS_Store
|
||||||
|
/**/.back*
|
|
@ -38,28 +38,28 @@ public class MqttConfig {
|
||||||
config = commonConfigDao.selectByName("mqtt_clientid");
|
config = commonConfigDao.selectByName("mqtt_clientid");
|
||||||
ConstUtil.MQTT_CLIENTID = config.getCnValue();
|
ConstUtil.MQTT_CLIENTID = config.getCnValue();
|
||||||
|
|
||||||
// config = commonConfigDao.selectByName("mqtt_device_broker");
|
config = commonConfigDao.selectByName("mqtt_device_broker");
|
||||||
// ConstUtil.MQTT_DEVICE_BROKER = config.getCnValue();
|
ConstUtil.MQTT_DEVICE_BROKER = config.getCnValue();
|
||||||
//
|
|
||||||
// config = commonConfigDao.selectByName("mqtt_device_topic_prefix");
|
config = commonConfigDao.selectByName("mqtt_device_topic_prefix");
|
||||||
// ConstUtil.MQTT_DEVICE_TOPIC = config.getCnValue();
|
ConstUtil.MQTT_DEVICE_TOPIC = config.getCnValue();
|
||||||
//
|
|
||||||
// config = commonConfigDao.selectByName("mqtt_device_user_name");
|
config = commonConfigDao.selectByName("mqtt_device_user_name");
|
||||||
// ConstUtil.MQTT_DEVICE_USER_NAME = config.getCnValue();
|
ConstUtil.MQTT_DEVICE_USER_NAME = config.getCnValue();
|
||||||
//
|
|
||||||
// config = commonConfigDao.selectByName("mqtt_device_password");
|
config = commonConfigDao.selectByName("mqtt_device_password");
|
||||||
// ConstUtil.MQTT_DEVICE_PASSWORD = config.getCnValue();
|
ConstUtil.MQTT_DEVICE_PASSWORD = config.getCnValue();
|
||||||
//
|
|
||||||
// config = commonConfigDao.selectByName("mqtt_device_clientid");
|
config = commonConfigDao.selectByName("mqtt_device_clientid");
|
||||||
// ConstUtil.MQTT_DEVICE_CLIENTID = config.getCnValue();
|
ConstUtil.MQTT_DEVICE_CLIENTID = config.getCnValue();
|
||||||
//
|
|
||||||
// config = commonConfigDao.selectByName("mqtt_device_type");
|
config = commonConfigDao.selectByName("mqtt_device_type");
|
||||||
// ConstUtil.MQTT_DEVICE_TYPE = config.getCnValue();
|
ConstUtil.MQTT_DEVICE_TYPE = config.getCnValue();
|
||||||
|
|
||||||
ThreadRecvCmdMqtt thread = new ThreadRecvCmdMqtt(hardService);
|
ThreadRecvCmdMqtt thread = new ThreadRecvCmdMqtt(hardService);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
||||||
// ThreadDeviceCmdMqtt devThread = new ThreadDeviceCmdMqtt(hardService);
|
ThreadDeviceCmdMqtt devThread = new ThreadDeviceCmdMqtt(hardService);
|
||||||
// devThread.start();
|
devThread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.jepsoninfo.req.*;
|
||||||
import com.jepsoninfo.service.HardService;
|
import com.jepsoninfo.service.HardService;
|
||||||
import com.jepsoninfo.util.ConstUtil;
|
import com.jepsoninfo.util.ConstUtil;
|
||||||
import com.jepsoninfo.util.ReturnCode;
|
import com.jepsoninfo.util.ReturnCode;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
public class HardController {
|
public class HardController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private HardService hardService;
|
private HardService hardService;
|
||||||
|
private final Logger logger = LoggerFactory.getLogger("HardController.class");// Logger.getLogger("HardService.class");
|
||||||
|
|
||||||
@PostMapping(value = "/plateRecognize")
|
@PostMapping(value = "/plateRecognize")
|
||||||
public ReturnCode plateRecognize(@RequestBody RecognizeAlarmInfoPlate req) {
|
public ReturnCode plateRecognize(@RequestBody RecognizeAlarmInfoPlate req) {
|
||||||
|
@ -23,7 +26,7 @@ public class HardController {
|
||||||
status.setCode(ConstUtil.CODE_SUCCESS[0]);
|
status.setCode(ConstUtil.CODE_SUCCESS[0]);
|
||||||
status.setMsg(ConstUtil.CODE_SUCCESS[1]);
|
status.setMsg(ConstUtil.CODE_SUCCESS[1]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.error("车牌识别处理失败", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,8 @@ import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class HardService {
|
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
|
@Autowired
|
||||||
private IntegratedMachineConfigDao integratedMachineConfigDao;
|
private IntegratedMachineConfigDao integratedMachineConfigDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -41,10 +43,10 @@ public class HardService {
|
||||||
private DisplayConfigDao displayConfigDao;
|
private DisplayConfigDao displayConfigDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageConfigDao messageConfigDao;
|
private MessageConfigDao messageConfigDao;
|
||||||
public MqttClient recvClient;
|
|
||||||
public MqttClient deviceClient;
|
|
||||||
|
|
||||||
public void plateRecognize(RecognizeAlarmInfoPlate req) {
|
public void plateRecognize(RecognizeAlarmInfoPlate req) {
|
||||||
|
logger.info("车牌识别结果:{}", JSONObject.toJSONString(req));
|
||||||
|
|
||||||
ReturnCode result;
|
ReturnCode result;
|
||||||
ReportCarPassRes ret;
|
ReportCarPassRes ret;
|
||||||
String strRet = "";
|
String strRet = "";
|
||||||
|
@ -53,8 +55,14 @@ public class HardService {
|
||||||
String carNo = req.getAlarmInfoPlate().getResult().getPlateResult().getLicense();
|
String carNo = req.getAlarmInfoPlate().getResult().getPlateResult().getLicense();
|
||||||
String devNo = req.getAlarmInfoPlate().getSerialno();
|
String devNo = req.getAlarmInfoPlate().getSerialno();
|
||||||
|
|
||||||
|
if (carNo == null || carNo.isEmpty() || carNo.contains("无")) {
|
||||||
|
logger.error("车牌识别失败, 车牌为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
printDate(carNo, devNo, laneName, optName, "收到车牌识别推送");
|
printDate(carNo, devNo, laneName, optName, "收到车牌识别推送");
|
||||||
|
|
||||||
|
|
||||||
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
||||||
integratedCond.setDevNo(devNo);
|
integratedCond.setDevNo(devNo);
|
||||||
// 获取一体机配置
|
// 获取一体机配置
|
||||||
|
@ -68,7 +76,8 @@ public class HardService {
|
||||||
String dirName = createLocalImgDir(carNo, devNo, laneName);
|
String dirName = createLocalImgDir(carNo, devNo, laneName);
|
||||||
String PhotoFrontFileName = RandomUtil.getRandomUuid() + ".jpg";
|
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);
|
||||||
|
logger.info("播放语音: {}", integratedCfg.getIpVoiceId());
|
||||||
|
try {
|
||||||
if (integratedCfg != null) {
|
if (integratedCfg != null) {
|
||||||
if (integratedCfg.getIsFront() == 1) {
|
if (integratedCfg.getIsFront() == 1) {
|
||||||
// 获取音柱配置
|
// 获取音柱配置
|
||||||
|
@ -87,9 +96,18 @@ public class HardService {
|
||||||
printDate(carNo, devNo, laneName, optName, "not find integrated");
|
printDate(carNo, devNo, laneName, optName, "not find integrated");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("播放语音失败", e);
|
||||||
|
}
|
||||||
|
|
||||||
String PhotoBodyUrl = UploadToAliUtil.uploadFile(dirName, new File(PhotoFrontFilePath), PhotoFrontFileName,
|
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);
|
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 reportUnifyReq = new ReportUnifyReq();
|
||||||
|
@ -422,6 +440,8 @@ public class HardService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int playVoice(PlayVoiceReq req) {
|
public int playVoice(PlayVoiceReq req) {
|
||||||
|
logger.info("播放语音请求:{}", JSONObject.toJSONString(req));
|
||||||
|
|
||||||
String carNo = req.getCarNo();
|
String carNo = req.getCarNo();
|
||||||
String devNo = req.getDeviceNo();
|
String devNo = req.getDeviceNo();
|
||||||
String laneName = "";
|
String laneName = "";
|
||||||
|
@ -464,7 +484,7 @@ public class HardService {
|
||||||
|
|
||||||
// printDate(carNo, devNo, laneName, optName, "播放语音结束");
|
// printDate(carNo, devNo, laneName, optName, "播放语音结束");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.info("语音播放异常", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printDate(carNo, devNo, laneName, optName, "device not fount");
|
printDate(carNo, devNo, laneName, optName, "device not fount");
|
||||||
|
@ -515,46 +535,87 @@ public class HardService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int mqttOpenDoor(DoorReq req) {
|
public int mqttOpenDoor(DoorReq req) {
|
||||||
String[] TOPIC_ARRAY = {
|
logger.info("开门请求: {}", JSONObject.toJSONString(req));
|
||||||
ConstUtil.MQTT_DEVICE_TOPIC + "user/get"};
|
|
||||||
|
// String[] TOPIC_ARRAY = {"/message/down/gpio_out"};
|
||||||
String carNo = req.getCarNo();
|
String carNo = req.getCarNo();
|
||||||
String devNo = req.getDeviceNo();
|
String deviceNo = req.getDeviceNo();
|
||||||
|
String devNo = deviceNo;
|
||||||
String laneName = "";
|
String laneName = "";
|
||||||
String optName = "开闸";
|
String optName = "开闸";
|
||||||
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
IntegratedMachineConfig integratedCond = new IntegratedMachineConfig();
|
||||||
|
|
||||||
integratedCond.setDevNo(req.getDeviceNo());
|
integratedCond.setDevNo(deviceNo);
|
||||||
// 获取一体机配置
|
// 获取一体机配置
|
||||||
IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond);
|
IntegratedMachineConfig integratedCfg = integratedMachineConfigDao.selectByCond(integratedCond);
|
||||||
|
int i = integratedCfg.getIoPort().intValue();
|
||||||
laneName = integratedCfg.getLaneName();
|
laneName = integratedCfg.getLaneName();
|
||||||
String msgId = System.currentTimeMillis() + RandomUtil.getRandomStr(7);
|
String msgId = System.currentTimeMillis() + RandomUtil.getRandomStr(7);
|
||||||
|
|
||||||
RecognizePlateResultAckQy ack = new RecognizePlateResultAckQy();
|
/* RecognizePlateResultAckQy ack = new RecognizePlateResultAckQy();
|
||||||
ack.setCmd("iooutput");
|
ack.setCmd("iooutput");
|
||||||
ack.setMsg_id(msgId);
|
ack.setMsg_id(msgId);
|
||||||
ack.setIonum(1);
|
ack.setIonum(1);
|
||||||
ack.setAction("on");
|
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();
|
MqttMessage ackMsg = new MqttMessage();
|
||||||
String strPayload = JSONObject.toJSONString(ack);
|
String strPayload = JSONObject.toJSONString(dorMsg);
|
||||||
|
|
||||||
ackMsg.setPayload(strPayload.getBytes(StandardCharsets.UTF_8));
|
ackMsg.setPayload(strPayload.getBytes(StandardCharsets.UTF_8));
|
||||||
try {
|
try {
|
||||||
String topic = ConstUtil.MQTT_DEVICE_TYPE + req.getDeviceNo() + TOPIC_ARRAY[0];
|
String topic = "device/" + deviceNo + "/message/down/gpio_out";
|
||||||
|
logger.info("主题: {},开门数据: {}", topic, strPayload);
|
||||||
printDate(carNo, devNo, laneName, optName, "开闸主题:" + topic);
|
printDate(carNo, devNo, laneName, optName, "开闸主题:" + topic);
|
||||||
printDate(carNo, devNo, laneName, optName, "开闸消息:" + strPayload);
|
printDate(carNo, devNo, laneName, optName, "开闸消息:" + strPayload);
|
||||||
deviceClient.publish(topic, ackMsg);
|
deviceClient.publish(topic, ackMsg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.error("开门失败", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
printDate(carNo, devNo, laneName, optName, "开闸结束");
|
printDate(carNo, devNo, laneName, optName, "开闸结束");
|
||||||
|
/* if (deviceNo.equals("e6141562-e3ca0602")) {
|
||||||
|
rollerDoor();
|
||||||
|
} */
|
||||||
return 1;
|
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) {
|
public int mqttCloseDoor(DoorReq req) {
|
||||||
String[] TOPIC_ARRAY = {
|
String[] TOPIC_ARRAY = {
|
||||||
ConstUtil.MQTT_DEVICE_TOPIC + "user/get"};
|
ConstUtil.MQTT_DEVICE_TOPIC + "user/get"};
|
||||||
|
@ -670,7 +731,8 @@ public class HardService {
|
||||||
}
|
}
|
||||||
clearCmd += " IA==";
|
clearCmd += " IA==";
|
||||||
clearCmd += " " + Base64.encodeBase64String(ConstUtil.DEFAULT_ADVERT_1.getBytes("UTF-8"));
|
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) {
|
if (displayCfg.getRs485Port().intValue() >= 0) {
|
||||||
cmd += " " + displayCfg.getRs485Port();
|
cmd += " " + displayCfg.getRs485Port();
|
||||||
clearCmd += " " + displayCfg.getRs485Port();
|
clearCmd += " " + displayCfg.getRs485Port();
|
||||||
|
@ -690,6 +752,7 @@ public class HardService {
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int mqttDisplayInfo(DisplayInfoReq req) {
|
public int mqttDisplayInfo(DisplayInfoReq req) {
|
||||||
String[] TOPIC_ARRAY = {
|
String[] TOPIC_ARRAY = {
|
||||||
ConstUtil.MQTT_DEVICE_TOPIC + "user/get"};
|
ConstUtil.MQTT_DEVICE_TOPIC + "user/get"};
|
||||||
|
|
|
@ -22,6 +22,9 @@ public class ThreadDeviceCmdMqtt extends Thread{
|
||||||
public void run() {
|
public void run() {
|
||||||
logger.info("ThreadDeviceCmdMqtt mqtt init");
|
logger.info("ThreadDeviceCmdMqtt mqtt init");
|
||||||
|
|
||||||
|
/* String[] TOPIC_ARRAY = {
|
||||||
|
ConstUtil.MQTT_DEVICE_TOPIC + "user/get",
|
||||||
|
ConstUtil.MQTT_DEVICE_TOPIC + "user/update"}; */
|
||||||
String[] TOPIC_ARRAY = {
|
String[] TOPIC_ARRAY = {
|
||||||
ConstUtil.MQTT_DEVICE_TOPIC + "user/get",
|
ConstUtil.MQTT_DEVICE_TOPIC + "user/get",
|
||||||
ConstUtil.MQTT_DEVICE_TOPIC + "user/update"};
|
ConstUtil.MQTT_DEVICE_TOPIC + "user/update"};
|
||||||
|
|
Loading…
Reference in New Issue