Compare commits

...

4 Commits
master ... tq

Author SHA1 Message Date
lzq baf68c9585 1 2025-06-10 12:14:07 +08:00
lzq 1d1a59e290 1 2025-06-04 14:57:01 +08:00
lzq 604631172b 1 2025-06-04 14:53:04 +08:00
lzq 25b9913eb1 修改道闸设备控制 2025-05-15 09:52:11 +08:00
7 changed files with 377 additions and 231 deletions

6
.gitignore vendored 100644
View File

@ -0,0 +1,6 @@
/**/logs
/**/*.iml
/**/.idea
/**/target
/**/.DS_Store
/**/.back*

BIN
mfcdirectlib.dll 100644

Binary file not shown.

View File

@ -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();
}
}

View File

@ -4,6 +4,8 @@ import com.jepsoninfo.req.*;
import com.jepsoninfo.service.HardService;
import com.jepsoninfo.util.ConstUtil;
import com.jepsoninfo.util.ReturnCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -14,6 +16,9 @@ public class HardController {
@Autowired
private HardService hardService;
private final Logger logger = LoggerFactory.getLogger("HardController.class");// Logger.getLogger("HardService.class");
@PostMapping(value = "/plateRecognize")
public ReturnCode plateRecognize(@RequestBody RecognizeAlarmInfoPlate req) {
ReturnCode status = new ReturnCode();
@ -23,9 +28,8 @@ public class HardController {
status.setCode(ConstUtil.CODE_SUCCESS[0]);
status.setMsg(ConstUtil.CODE_SUCCESS[1]);
} catch (Exception e) {
e.printStackTrace();
logger.error("处理失败", e);
}
return status;
}

View File

@ -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;
}
}
}

View File

@ -29,6 +29,8 @@ 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
@ -41,10 +43,10 @@ public class HardService {
private DisplayConfigDao displayConfigDao;
@Autowired
private MessageConfigDao messageConfigDao;
public MqttClient recvClient;
public MqttClient deviceClient;
public void plateRecognize(RecognizeAlarmInfoPlate req) {
logger.info("车牌识别结果:{}", JSONObject.toJSONString(req));
ReturnCode result;
ReportCarPassRes ret;
String strRet = "";
@ -53,8 +55,14 @@ public class HardService {
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);
// 获取一体机配置
@ -68,7 +76,8 @@ public class HardService {
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) {
// 获取音柱配置
@ -87,9 +96,18 @@ public class HardService {
printDate(carNo, devNo, laneName, optName, "not find integrated");
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);
} catch (Exception e) {
logger.error("图片上传失败", e);
throw new RuntimeException(e);
}
ReportUnifyReq reportUnifyReq = new ReportUnifyReq();
@ -422,6 +440,8 @@ public class HardService {
}
public int playVoice(PlayVoiceReq req) {
logger.info("播放语音请求:{}", JSONObject.toJSONString(req));
String carNo = req.getCarNo();
String devNo = req.getDeviceNo();
String laneName = "";
@ -464,7 +484,7 @@ public class HardService {
// printDate(carNo, devNo, laneName, optName, "播放语音结束");
} catch (Exception e) {
e.printStackTrace();
logger.info("语音播放异常", e);
}
} else {
printDate(carNo, devNo, laneName, optName, "device not fount");
@ -515,46 +535,87 @@ public class HardService {
}
public int mqttOpenDoor(DoorReq req) {
String[] TOPIC_ARRAY = {
ConstUtil.MQTT_DEVICE_TOPIC + "user/get"};
logger.info("开门请求: {}", JSONObject.toJSONString(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];
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) {
e.printStackTrace();
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"};
@ -670,7 +731,8 @@ public class HardService {
}
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();
@ -690,6 +752,7 @@ public class HardService {
return 1;
}
public int mqttDisplayInfo(DisplayInfoReq req) {
String[] TOPIC_ARRAY = {
ConstUtil.MQTT_DEVICE_TOPIC + "user/get"};

View File

@ -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"};