From 783272d17be7fce92808bd9fb99f9d64f450bfc9 Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 周四, 11 7月 2024 14:24:11 +0800
Subject: [PATCH] 添加三一车辆透传订阅提交
---
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplSerialPort.java | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++++
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java | 5 +
2 files changed, 266 insertions(+), 0 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
index d7644e2..00c1e59 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
@@ -13,6 +13,7 @@
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.sy.gps31.PushClientImplSerialPort;
import com.ruoyi.sy.param.ArdSyCarParam;
import com.ruoyi.sy.service.IArdTankAbnormalParkAlarmService;
import com.ruoyi.sy.vo.ArdSyCarVo;
@@ -131,6 +132,10 @@
Thread pushClientImplAlarmThread = new Thread(pushClientImplAlarm);
pushClientImplAlarmThread.start();
+ PushClientImplSerialPort pushClientImplSerialPort = new PushClientImplSerialPort(ip,userId,password);
+ Thread pushClientImplSerialPortThread = new Thread(pushClientImplSerialPort);
+ pushClientImplSerialPortThread.start();
+
//删除结束时间为null的记录
int result = ardTankAbnormalParkAlarmService.deleteArdTankAbnormalParkAlarmByEndTime();
}
diff --git a/ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplSerialPort.java b/ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplSerialPort.java
new file mode 100644
index 0000000..4cb0a4d
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplSerialPort.java
@@ -0,0 +1,261 @@
+/**
+ * <p>Description: </p>
+ * <p>Copyright: Copyright (c) 2020</p>
+ * <p>Company: www.31gps.net</p>
+ * @author chencq
+ * @version 1.0
+ */
+package com.ruoyi.sy.gps31;
+
+import com.alibaba.fastjson2.JSON;
+import com.gps31.push.netty.PushClient;
+import com.gps31.push.netty.PushMsg;
+import com.gps31.push.netty.client.TcpClient;
+import com.gps31.push.util.MapUtil;
+import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.sy.domain.ArdSyCarLock;
+import com.ruoyi.sy.domain.ArdSyCarRtu;
+import com.ruoyi.sy.service.ArdSyCarLockService;
+import com.ruoyi.sy.service.ArdSyCarRtuService;
+import com.ruoyi.sy.service.impl.ArdSyCarDayServiceImpl;
+import com.ruoyi.sy.service.impl.ArdSyCarServiceImpl;
+import com.ruoyi.sy.service.impl.ArdTankAbnormalParkAlarmServiceImpl;
+import com.ruoyi.utils.qymqtt.newM.EmqClient;
+import com.ruoyi.utils.qymqtt.newM.QosEnum;
+import lombok.extern.slf4j.Slf4j;
+import org.eclipse.paho.client.mqttv3.MqttException;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * <p>Description: </p>
+ * <p>Copyright: Copyright (c) 2020</p>
+ * <p>Company: www.31gps.net</p>
+ * @author chencq
+ * @version 1.0
+ */
+@Slf4j(topic = "mqttCar")
+public class PushClientImplSerialPort extends PushClient implements Runnable {
+
+// private static final Log log = LogFactory.getLog(PushClientImplPosition.class);
+
+ private String ip;
+
+ private String userId;
+
+ private String password;
+
+ public PushClientImplSerialPort(String ip, String userId, String password) {
+ this.ip = ip;
+ this.userId = userId;
+ this.password = password;
+ }
+
+ public PushClientImplSerialPort() {
+
+ }
+
+ @Override
+ public void messageReceived(TcpClient tcpClient, PushMsg pushMsg)
+ throws Exception {
+ if("8001".equals(pushMsg.getCmd())) {//登录应答
+ String rspResult = MapUtil.getStrVal(pushMsg.getJsonMap(),"rspResult","1");
+ if("0".equals(rspResult)) {//登录成功,定阅动态消息
+ Map<String,Object> map = new HashMap<String,Object>();
+ map.put("seq", "1");
+ map.put("action", "add");
+ map.put("msgIds", JSON.toJSONString(getSubCmdSet()));
+ PushMsg subMsg = getInstance("0003",map);
+ sendMsg(subMsg);
+ }
+ }else if("8002".equals(pushMsg.getCmd())){//心跳应答
+
+ }else if("8003".equals(pushMsg.getCmd())){//订阅动态消息应答
+ String rspResult = MapUtil.getStrVal(pushMsg.getJsonMap(),"rspResult","1");
+ //log.error(String.format(" 订阅应答:%s", "0".equals(rspResult)?"成功":"失败"));
+ }else if("0200".equals(pushMsg.getCmd())) {//定位信息
+ Map<String,Object> gpsMap = pushMsg.getJsonMap();
+ log.debug(String.format(" ---->----收到定位数据如下:%s",JSON.toJSONString(gpsMap)));
+ /**
+ *
+ * 请加入三方集成方的业务逻辑
+ *
+ */
+ }else if("0300".equals(pushMsg.getCmd())) {//报警消息
+ Map<String,Object> alarmMap = pushMsg.getJsonMap();
+ String carName = MapUtil.getStrVal(alarmMap, "carName","");//获取车牌号
+ //log.error(String.format(" ---->收到报警数据:%s",JSON.toJSONString(alarmMap)));
+ /**
+ *
+ * 请加入三方集成方的业务逻辑
+ *
+ */
+ }else if("0401".equals(pushMsg.getCmd())) {//透传消息
+ Map<String,Object> dataMap = pushMsg.getJsonMap();
+ String carName = MapUtil.getStrVal(dataMap, "carName","");//获取车牌号
+ //log.error(String.format(" ---->收到透传数据:%s",JSON.toJSONString(dataMap)));
+ /**
+ *
+ * 请加入三方集成方的业务逻辑
+ *
+ */
+ }
+ }
+
+ public void sendMassage() {
+ try {
+ PushClientImplSerialPort client = new PushClientImplSerialPort();
+ client.setLog(false);//是否打印明文
+ client.setHost(this.ip);//服务器IP
+ client.setPort(10100);//服务器端口
+ client.setUserName(this.userId);//系统用户名
+ client.setPwd(this.password);//系统用户密码
+ client.setSubMsgIds("0401");//订阅的动态消息,多个动态消息使用|辟分,当前示例是订阅 定位消息(0x0200)和报警消息(0x0300)
+ client.setDesc("测试客户端");//客户端的描述,
+ client.start();
+ while(true) {
+ Thread.sleep(1000);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void run() {
+ sendMassage();
+ }
+
+ private void feng(String carId,String type,ArdSyCarRtuService carRtuService,ArdSyCarLockService lockService) throws MqttException {
+ //查询装油点既定Rtu状态
+ ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId);
+ if(ardSyCarRtu!=null){
+ //查询锁信息
+ List<ArdSyCarLock> ardSyCarLocks = lockService.carLock(ardSyCarRtu.getId());
+ if(ardSyCarLocks.size()>0){
+ Integer fengType = null;
+ if("装油点".equals(type)){
+ fengType = ardSyCarRtu.getInstallType();
+ }else if("卸油点".equals(type)){
+ fengType = ardSyCarRtu.getUnloadType();
+ }else if("施封".equals(type)){
+ fengType = 0;
+ }
+ //1解封
+ if(fengType==1){
+ //如果不是解封封状态,则发送施封命令
+ if(ardSyCarLocks.get(0).getRelayInfo()==0 || ardSyCarLocks.get(0).getRelayInfo()==null){
+// Map<String,Object> map = new HashMap<>();
+// map.put("A01", 110000);//导通第一路继电器
+// map.put("A02", 110000);//导通第二路继电器
+// map.put("res", String.valueOf(System.currentTimeMillis()));
+// String mapString = com.alibaba.fastjson.JSON.toJSONString(map);
+ String mapString = "{\"A01\":110000,\"A02\":110000,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}";
+ log.debug("自动解封:"+mapString);
+ EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+ emqClient.connect();
+ emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
+ log.debug("车辆"+carId+"解封命令发送成功!");
+ // mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"解封");
+ }
+ }
+
+ //0施封
+ if(fengType==0){
+ if(ardSyCarLocks.get(0).getRelayInfo()==1 || ardSyCarLocks.get(0).getRelayInfo()==null){
+ //锁开关状态
+ int lockCloseNum = 0;
+ String mapString1 = "{\"A01\":100000,\"A02\":100000,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}";
+ System.out.println("自动施封:"+mapString1);
+ EmqClient emqClient1 = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+ emqClient1.connect();
+ emqClient1.publish(ardSyCarRtu.getTopicPublish(),mapString1, QosEnum.QoS2,false);
+ //如果不是施封状态,则发送施封命令
+ if(ardSyCarLocks.get(0).getRelayInfo()!=null){
+ if(ardSyCarLocks.get(0).getRelayInfo()==1){
+ for (int j = 0; j < ardSyCarLocks.size(); j++) {
+ ArdSyCarLock ardSyCarLock = ardSyCarLocks.get(j);
+ String currents = ardSyCarLock.getCurrents();
+ Double currentInfo = ardSyCarLock.getCurrentInfo();
+ //电流值为4.0是关锁状态
+ if(currentInfo.equals(4.00) || currentInfo.equals(4)){
+ lockCloseNum += 1;
+ }else {
+ String key = "";
+ if(currents.equals("C01")){
+ key = "D03";
+ }else if(currents.equals("C02")){
+ key = "D04";
+ }
+// Map<String,Object> map = new HashMap();
+// map.put(key, 0.01);
+// map.put("res", String.valueOf(System.currentTimeMillis()));
+// String mapString = com.alibaba.fastjson.JSON.toJSONString(map);
+ String mapString = "{\""+key+"\":0.01,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}";
+ log.debug("自动关锁:"+mapString);
+ EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+ emqClient.connect();
+ emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
+ // mqttOnce.publishCar("carId",ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"开锁:"+currents);
+ while(true){
+ ArdSyCarLock ardSyCarLock1 = lockService.getCurrentInfo(ardSyCarRtu.getId(),currents);
+ Double currentInfo1 = ardSyCarLock1.getCurrentInfo();
+ if(currentInfo1.equals(4.00) || currentInfo1.equals(4)){
+ lockCloseNum +=1;
+ break;
+ }
+ }
+ }
+ }
+ if(lockCloseNum == 2){
+// Map<String,Object> map = new HashMap<>();
+// map.put("A01", 100000);//断开第一路继电器
+// map.put("A02", 100000);//断开第二路继电器
+// map.put("res", String.valueOf(System.currentTimeMillis()));
+// String mapString = com.alibaba.fastjson.JSON.toJSONString(map);
+ log.debug("车辆"+carId+"施封命令发送成功!");
+ // mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"施封");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public Double[] azimuth_offset(double origin_lon, double origin_lat, Integer direction,double distance){
+ Double[] lonlat = new Double[2];
+ if(direction != null && distance > 0){
+ lonlat[0] = origin_lon + distance * Math.sin(direction* Math.PI / 180) * 180 / ( Math.PI * 6371229 * Math.cos(origin_lat * Math.PI / 180));
+ lonlat[1] = origin_lat + distance * Math.cos(direction* Math.PI / 180) / ( Math.PI * 6371229 / 180);
+ }else{
+ lonlat[0] = origin_lon;
+ lonlat[1] = origin_lat;
+ }
+ return lonlat;
+ }
+
+ public Double getDistance(Double velocity ,Double acceleration ,String time){
+ Double distance = velocity*Double.parseDouble(time) + 0.5*acceleration*Double.parseDouble(time)*Double.parseDouble(time);
+ return distance;
+ }
+
+ /*public Double getVelocity(Double velocity ,Double acceleration ,String time){
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Long t = (long) 0;
+ try {
+ t = (new Date().getTime() - simpleDateFormat.parse(time).getTime())/1000;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Double velocityt = velocity + acceleration*t;
+ return velocityt;
+ }*/
+
+}
--
Gitblit v1.9.3