From c2e9f82dfe87e9bd967d8445bd4b5b632f3f0d1a Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期五, 24 十一月 2023 11:19:43 +0800
Subject: [PATCH] 清淤锁重新封装
---
ard-work/src/main/java/com/ruoyi/utils/qymqtt/oldM/PushCallback.java | 2
ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/MessageCallback.java | 104 ++++++++++++++
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarLockServiceImpl.java | 87 ++---------
ard-work/src/main/java/com/ruoyi/utils/qymqtt/AutoMqtt.java | 14 +
ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/QosEnum.java | 15 ++
ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/EmqClient.java | 115 ++++++++++++++++
ard-work/src/main/java/com/ruoyi/utils/qymqtt/oldM/MqttCustomerClient.java | 3
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java | 22 +-
8 files changed, 278 insertions(+), 84 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java b/ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java
index 8517bb0..e34debc 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java
@@ -17,7 +17,9 @@
import com.ruoyi.sy.service.*;
import com.ruoyi.sy.service.impl.*;
import com.ruoyi.utils.gps.GeoTools;
-import com.ruoyi.utils.qymqtt.MqttCustomerClient;
+import com.ruoyi.utils.qymqtt.newM.EmqClient;
+import com.ruoyi.utils.qymqtt.newM.QosEnum;
+import com.ruoyi.utils.qymqtt.oldM.MqttCustomerClient;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.paho.client.mqttv3.MqttException;
@@ -453,9 +455,9 @@
map.put("A02", 110000);//瀵奸�氱浜岃矾缁х數鍣�
map.put("res", String.valueOf(System.currentTimeMillis()));
String mapString = com.alibaba.fastjson.JSON.toJSONString(map);
- MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
- mqttCustomerClient.connect(carId+"change");
- mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
+ EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+ emqClient.connect();
+ emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
log.info("杞﹁締"+carId+"瑙e皝鍛戒护鍙戦�佹垚鍔燂紒");
// mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"瑙e皝");
}
@@ -484,9 +486,9 @@
map.put(key, 0.01);
map.put("res", String.valueOf(System.currentTimeMillis()));
String mapString = com.alibaba.fastjson.JSON.toJSONString(map);
- MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
- mqttCustomerClient.connect(carId+"change");
- mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),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);
@@ -504,9 +506,9 @@
map.put("A02", 100000);//鏂紑绗簩璺户鐢靛櫒
map.put("res", String.valueOf(System.currentTimeMillis()));
String mapString = com.alibaba.fastjson.JSON.toJSONString(map);
- MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
- mqttCustomerClient.connect(carId+"change");
- mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
+ EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+ emqClient.connect();
+ emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
log.info("杞﹁締"+carId+"鏂藉皝鍛戒护鍙戦�佹垚鍔燂紒");
// mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"鏂藉皝");
}
diff --git a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarLockServiceImpl.java b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarLockServiceImpl.java
index 26b9f4d..e9dab35 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarLockServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarLockServiceImpl.java
@@ -19,7 +19,9 @@
import com.ruoyi.sy.vo.RtuVo;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.mapper.SysDeptMapper;
-import com.ruoyi.utils.qymqtt.MqttCustomerClient;
+import com.ruoyi.utils.qymqtt.newM.EmqClient;
+import com.ruoyi.utils.qymqtt.newM.QosEnum;
+import com.ruoyi.utils.qymqtt.oldM.MqttCustomerClient;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
@@ -251,15 +253,11 @@
map.put("A02", 110000);//瀵奸�氱浜岃矾缁х數鍣�
map.put("res", String.valueOf(System.currentTimeMillis()));
String mapString = JSON.toJSONString(map);
- try {
- MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
- mqttCustomerClient.connect(rtuTypeParam.getCarId()+"change");
- mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
- return AjaxResult.success("瑙e皝鍛戒护鍙戦�佹垚鍔燂紒");
+ EmqClient emqClient = new EmqClient(rtuTypeParam.getCarId()+"mqttPublish"+UUID.randomUUID());
+ emqClient.connect();
+ emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
+ return AjaxResult.success("瑙e皝鍛戒护鍙戦�佹垚鍔燂紒");
// return AjaxResult.success(mqttOnce.publishCar(rtuTypeParam.getCarId(),ardSyCarRtu.getTopicPublish(),String.valueOf(new com.alibaba.fastjson2.JSONObject(map)),"瑙e皝"));
- } catch (MqttException e) {
- log.debug("瑙e皝鎸囦护鍙戠敓澶辫触"+e);
- }
}
//0鏂藉皝
if(rtuTypeParam.getType()==0){
@@ -285,14 +283,10 @@
map.put(key, 0.01);
map.put("res", String.valueOf(System.currentTimeMillis()));
String mapString = JSON.toJSONString(map);
- try {
- MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
- mqttCustomerClient.connect(rtuTypeParam.getCarId()+"change");
- mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
+ EmqClient emqClient = new EmqClient(rtuTypeParam.getCarId()+"mqttPublish"+UUID.randomUUID());
+ emqClient.connect();
+ emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
// mqttOnce.publishCar("carId",ardSyCarRtu.getTopicPublish(),String.valueOf(new com.alibaba.fastjson2.JSONObject(map)),"寮�閿侊細"+currents);
- } catch (MqttException e) {
- log.debug("寮�閿佹寚浠ゅ彂鐢熷け璐�"+e);
- }
while(true){
ArdSyCarLock ardSyCarLock1 = getCurrentInfo(ardSyCarRtu.getId(),currents);
Double currentInfo1 = ardSyCarLock1.getCurrentInfo();
@@ -309,15 +303,11 @@
map.put("A02", 100000);//鏂紑绗簩璺户鐢靛櫒
map.put("res", String.valueOf(System.currentTimeMillis()));
String mapString = JSON.toJSONString(map);
- try {
- MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
- mqttCustomerClient.connect(rtuTypeParam.getCarId()+"change");
- mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
- return AjaxResult.success("鏂藉皝鍛戒护鍙戠敓鎴愬姛锛�");
+ EmqClient emqClient = new EmqClient(rtuTypeParam.getCarId()+"mqttPublish"+UUID.randomUUID());
+ emqClient.connect();
+ emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
+ return AjaxResult.success("鏂藉皝鍛戒护鍙戠敓鎴愬姛锛�");
// return AjaxResult.success(mqttOnce.publishCar(rtuTypeParam.getCarId(),ardSyCarRtu.getTopicPublish(),String.valueOf(new com.alibaba.fastjson2.JSONObject(map)),"鏂藉皝"));
- } catch (MqttException e) {
- log.debug("鏂藉皝鎸囦护鍙戠敓澶辫触"+e);
- }
}
}
return AjaxResult.success();
@@ -353,50 +343,13 @@
map.put("res", String.valueOf(System.currentTimeMillis()));
String mapString = JSON.toJSONString(map);
System.out.println(mapString);
- MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
- mqttCustomerClient.connect(lockTypeParam.getCarId()+"change"+UUID.randomUUID());
- mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
+ EmqClient emqClient = new EmqClient(lockTypeParam.getCarId()+"mqttPublish"+UUID.randomUUID());
+ emqClient.connect();
+ emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
+// MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+// mqttCustomerClient.connect(lockTypeParam.getCarId()+"change"+UUID.randomUUID());
+// mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
return AjaxResult.success("寮�鍏抽攣鍛戒护鍙戦�佹垚鍔�,鍙戦�佽繘搴︿负"+lockTypeParam.getNum());
-// QueryWrapper<SysConfig> queryWrapper1 = new QueryWrapper<>();
-// queryWrapper1.eq("config_key","ElectromagneticLockUrl");
-// SysConfig sysConfig = configMapper.selectOne(queryWrapper1);
-// String url = "";
-// if(sysConfig!=null){
-// url = sysConfig.getConfigValue();
-// }else {
-// return AjaxResult.error("閰嶇疆琛ㄦ棤鍦板潃鏁版嵁");
-// }
-// MqttConsumer mqttConsumer = new MqttConsumer();
-// mqttConsumer.getClientCar(url,lockTypeParam.getCarId());
-// mqttConsumer.publishCar(1,false,ardSyCarRtu.getTopicPublish(),mapString);
-// mqttConsumer.disConnect();
-// return AjaxResult.success();
- //MqttOnce瀹㈡埛绔�-----寮�濮�
-// MqttOnce mqttOnce = new MqttOnce();
-// return AjaxResult.success(mqttOnce.publishCar("carId",ardSyCarRtu.getTopicPublish(), mapString,"寮�鍏抽攣鎸囦护"+lockTypeParam.getNum()));
- //MqttOnce瀹㈡埛绔�-----缁撴潫
- //EmqClient瀹㈡埛绔�-----寮�濮�
-// EmqClient emqClient = new EmqClient("tcp://112.98.126.2:1883",String.valueOf(UUID.randomUUID()));
-// emqClient.connect("admin","xzx12345");
-// log.info("涓婚锛�"+ardSyCarRtu.getTopicPublish());
-// emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
-// System.out.println("////////////////////");
-// System.out.println(mapString);
-// emqClient.disConnect();
-// return AjaxResult.success(ardSyCarRtu.getTopicPublish()+"寮�鍏抽攣鎸囦护"+lockTypeParam.getNum()+"鍙戝竷鎴愬姛锛�");
- //EmqClient瀹㈡埛绔�-----缁撴潫
- //demo------寮�濮�
-// EmqClient emqClient = new EmqClient("tcp://112.98.126.2:1883","mqttTestp");
-// emqClient.connect("admin","xzx12345");
-// Map<String,Object> map = new HashMap();
-// map.put("D03", 99.99);//鑼冨洿鏄�0.01鍒�99.99
-// map.put("res", String.valueOf(new Date().getTime()));
-// System.out.println(map);
-// String msg = JSON.toJSONString(map);
-// emqClient.publish("/p14/set/",msg,QosEnum.QoS2,false);
-// emqClient.disConnect();
-// return AjaxResult.success();
- //demo----缁撴潫
}
@Override
diff --git a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/AutoMqtt.java b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/AutoMqtt.java
index 72cde30..d6bff1d 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/AutoMqtt.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/AutoMqtt.java
@@ -2,6 +2,8 @@
import com.ruoyi.sy.domain.ArdSyCarRtu;
import com.ruoyi.sy.service.ArdSyCarRtuService;
+import com.ruoyi.utils.qymqtt.newM.EmqClient;
+import com.ruoyi.utils.qymqtt.newM.QosEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -17,7 +19,7 @@
@Autowired
private ArdSyCarRtuService ardSyCarRtuService;
-// @PostConstruct
+ @PostConstruct
public void init() {
// ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
// //鑾峰彇鐢电閿佸湴鍧�
@@ -28,9 +30,13 @@
String carId = rtu.getCarId();
String subscribe = rtu.getTopicSubscribe();
try {
- MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
- mqttCustomerClient.connect(carId+"mqtt"+ UUID.randomUUID());
- mqttCustomerClient.subscribe(subscribe);
+// MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+// mqttCustomerClient.connect(carId+"mqtt"+ UUID.randomUUID());
+// mqttCustomerClient.subscribe(subscribe);
+ EmqClient emqClient = new EmqClient(carId+"mqttSubscribe");
+ emqClient.connect();
+ emqClient.subscribe(subscribe, QosEnum.QoS2);
+ log.info("璁㈤槄涓婚锛�"+subscribe);
}catch (Exception e) {
e.printStackTrace();
}
diff --git a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/EmqClient.java b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/EmqClient.java
new file mode 100644
index 0000000..16452c5
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/EmqClient.java
@@ -0,0 +1,115 @@
+package com.ruoyi.utils.qymqtt.newM;
+
+import javax.annotation.PreDestroy;
+
+import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.sy.service.ArdSyCarRtuService;
+import org.eclipse.paho.client.mqttv3.IMqttClient;
+import org.eclipse.paho.client.mqttv3.MqttClient;
+import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
+import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
+import org.eclipse.paho.client.mqttv3.MqttException;
+import org.eclipse.paho.client.mqttv3.MqttMessage;
+import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
+
+public class EmqClient {
+
+ private IMqttClient mqttClient;
+
+ private MessageCallback messageCallback;
+
+ public EmqClient(String clientId){
+ ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
+ //鑾峰彇鐢电閿佸湴鍧�
+ String mqttUrl = carRtuService.url("ElectromagneticLockUrl");
+ MqttClientPersistence mempersitence = new MemoryPersistence();//鎸佷箙鍖栨柟寮�
+ try {
+ this.mqttClient = new MqttClient(mqttUrl,clientId,mempersitence);//璁剧疆杩炴帴broker鐨刪ost鍙奵lientId
+ this.messageCallback = new MessageCallback();
+ } catch (MqttException e) {
+ System.out.println("鍒濆鍖栧鎴风mqttClient瀵硅薄澶辫触");
+ System.out.println("brokerUrl:"+mqttUrl);
+ System.out.println("clientId:"+clientId);
+ e.getMessage();
+ }
+ }
+
+
+ //杩炴帴broker
+ public void connect(){
+ MqttConnectOptions options = new MqttConnectOptions();
+ options.setAutomaticReconnect(true);
+ options.setUserName("admin");
+ options.setPassword("xzx12345".toCharArray());
+ options.setCleanSession(true);//璁剧疆涓轰复鏃朵細璇�
+
+ mqttClient.setCallback(messageCallback);//璁剧疆鍥炶皟
+
+ try {
+ mqttClient.connect(options);
+ } catch (MqttException e) {
+ System.out.println("mqtt瀹㈡埛绔繛鎺ユ湇鍔$澶辫触");
+ e.getMessage();
+ }
+ }
+
+ //鏂紑杩炴帴
+ @PreDestroy//璇ユ敞瑙e璞¢攢姣佸悗瑙﹀彂
+ public void disConnect(){
+ try {
+ mqttClient.disconnect();
+ } catch (MqttException e) {
+ System.out.println("鏂紑杩炴帴浜х敓寮傚父");
+ e.getMessage();
+ }
+ }
+
+ //閲嶈繛
+ public void reConnect(){
+ try {
+ mqttClient.reconnect();
+ } catch (MqttException e) {
+ System.out.println("閲嶈繛澶辫触,澶辫触鍘熷洜");
+ e.getMessage();
+ }
+ }
+
+ //鍙戝竷娑堟伅 浼犲弬涓轰富棰橈紝娑堟伅锛岀瓑绾э紝鏄惁淇濈暀娑堟伅
+ public void publish(String topic, String msg, QosEnum qos, boolean retain){
+ MqttMessage mqttMessage = new MqttMessage();
+ mqttMessage.setPayload(msg.getBytes());
+ mqttMessage.setQos(qos.value());
+ mqttMessage.setRetained(retain);
+ try {
+ mqttClient.publish(topic,mqttMessage);
+ mqttClient.disconnect();
+ } catch (MqttException e) {
+ System.out.println("鍙戝竷娑堟伅澶辫触");
+ System.out.println("涓婚:"+topic);
+ System.out.println("娑堟伅:"+msg);
+ System.out.println("qos绛夌骇:"+qos.value());
+ e.getMessage();
+ }
+ }
+
+ //璁㈤槄
+ public void subscribe(String topicFilter,QosEnum qos){
+ try {
+ mqttClient.subscribe(topicFilter,qos.value());
+ } catch (MqttException e) {
+ System.out.println("璁㈤槄涓婚"+topicFilter+"澶辫触");
+ System.out.println("qos绛夌骇:"+qos.value());
+ e.getMessage();
+ }
+ }
+
+ //鍙栨秷璁㈤槄
+ public void unSubscribe(String topicFilter){
+ try {
+ mqttClient.unsubscribe(topicFilter);
+ } catch (MqttException e) {
+ System.out.println("鍙栨秷璁㈤槄涓婚"+topicFilter+"澶辫触");
+ e.getMessage();
+ }
+ }
+}
diff --git a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/MessageCallback.java b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/MessageCallback.java
new file mode 100644
index 0000000..d143d79
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/MessageCallback.java
@@ -0,0 +1,104 @@
+package com.ruoyi.utils.qymqtt.newM;
+
+import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+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 lombok.extern.slf4j.Slf4j;
+import org.eclipse.paho.client.mqttv3.IMqttClient;
+import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
+import org.eclipse.paho.client.mqttv3.MqttCallback;
+import org.eclipse.paho.client.mqttv3.MqttMessage;
+
+import com.alibaba.fastjson.JSON;
+
+@Slf4j
+public class MessageCallback implements MqttCallback {
+
+ private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ //娉ㄥ叆鐢靛瓙閿丅ean
+ ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
+ ArdSyCarLockService carLockService = SpringUtils.getBean(ArdSyCarLockService.class);
+
+
+ @Override//涓㈠け浜嗗鏈嶅姟绔殑杩炴帴鍚庤Е鍙戠殑鍥炶皟
+ public void connectionLost(Throwable arg0) {
+ // 璧勬簮鐨勬竻鐞� 閲嶈繛
+ System.out.println(arg0.getMessage());
+ arg0.printStackTrace();
+ System.out.println("涓㈠け浜嗗鏈嶅姟绔殑杩炴帴");
+ }
+
+ @Override //娑堟伅鍙戝竷鑰呮秷鎭彂甯冨畬鎴愪骇鐢熺殑鍥炶皟
+ public void deliveryComplete(IMqttDeliveryToken token) {
+ System.out.println("deliveryComplete---------" + token.isComplete());
+ int messageId = token.getMessageId();
+ String[] topics = token.getTopics();
+ String clientId = token.getClient().getClientId();
+// byte[] msg = token.getMessage().getPayload();
+ String topicStr = "";
+ for(String topic : topics){
+ topicStr = topicStr + topic + ",";
+ }
+ topicStr = topicStr.substring(0, topicStr.length() - 1);
+ System.out.println("娑堟伅鍙戝竷瀹屾垚,messageId="+messageId+",topics="+topicStr+",clientId="+clientId);
+ }
+
+ @Override//娑堟伅璁㈤槄鑰呮敹鍒版秷鎭悗瑙﹀彂鐨勫洖璋�
+ public void messageArrived(String topic, MqttMessage message) throws Exception {
+ try {
+ System.out.println("銆愯溅杈嗛攣涓婚銆戯細"+topic+"銆愯溅杈嗛攣淇℃伅銆戯細"+new String(message.getPayload(), StandardCharsets.UTF_8));
+ //鍑烘潵鍥炶皟鏁版嵁
+ List<ArdSyCarLock> ardSyCarLocks = carLockService.data(new String(message.getPayload(), StandardCharsets.UTF_8));
+ //鏍规嵁topic鏌ヨRTUID
+ ArdSyCarRtu ardSyCarRtu = carRtuService.subscribeByCarId(topic);
+ String RTU = ardSyCarRtu.getId();
+ //鏍规嵁RTUID鏌ヨ閿�
+ List<ArdSyCarLock> ardSyCarLockList = carLockService.carLock(RTU);
+ for (int i = 0; i < ardSyCarLocks.size(); i++) {
+ ArdSyCarLock ardSyCarLockData = ardSyCarLocks.get(i);
+ String relay = ardSyCarLockData.getRelay();
+ Integer relayInfo = ardSyCarLockData.getRelayInfo();
+ String current = ardSyCarLockData.getCurrents();
+ Double currentInfo = ardSyCarLockData.getCurrentInfo();
+ for (int j = 0; j < ardSyCarLockList.size(); j++) {
+ ArdSyCarLock lock = ardSyCarLockList.get(j);
+ String relay1 = lock.getRelay();
+ String current1 = lock.getCurrents();
+ Integer relayInfo1 = lock.getRelayInfo();
+ Double currentInfo1 = lock.getCurrentInfo();
+ Boolean upd = false;
+ if(relay.equals(relay1)){
+ if(!relayInfo.equals(relayInfo1)){
+ lock.setRelayInfo(relayInfo);
+ upd = true;
+ }
+ }
+ if(current.equals(current1)){
+ if(!currentInfo.equals(currentInfo1)){
+ lock.setCurrentInfo(currentInfo);
+ upd = true;
+ }
+ }
+ if(upd){
+ int num = carLockService.updLock(lock);
+// log.debug("淇敼"+num+"鏁版嵁");
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.debug("杞﹁締鐢电閿佸鐞唌qtt娑堟伅寮傚父:" + e);
+ }
+
+ }
+
+}
diff --git a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/QosEnum.java b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/QosEnum.java
new file mode 100644
index 0000000..920e249
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/newM/QosEnum.java
@@ -0,0 +1,15 @@
+package com.ruoyi.utils.qymqtt.newM;
+
+public enum QosEnum {
+ QoS0(0),QoS1(1),QoS2(2);
+
+ private final int value;
+
+ QosEnum(int value) {
+ this.value = value;
+ }
+
+ public int value(){
+ return this.value;
+ }
+}
diff --git a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/MqttCustomerClient.java b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/oldM/MqttCustomerClient.java
similarity index 97%
rename from ard-work/src/main/java/com/ruoyi/utils/qymqtt/MqttCustomerClient.java
rename to ard-work/src/main/java/com/ruoyi/utils/qymqtt/oldM/MqttCustomerClient.java
index 4028ca6..9c38b19 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/MqttCustomerClient.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/oldM/MqttCustomerClient.java
@@ -1,11 +1,10 @@
-package com.ruoyi.utils.qymqtt;
+package com.ruoyi.utils.qymqtt.oldM;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.sy.service.ArdSyCarRtuService;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PreDestroy;
diff --git a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/PushCallback.java b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/oldM/PushCallback.java
similarity index 98%
rename from ard-work/src/main/java/com/ruoyi/utils/qymqtt/PushCallback.java
rename to ard-work/src/main/java/com/ruoyi/utils/qymqtt/oldM/PushCallback.java
index 910d32f..a955c6a 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/PushCallback.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/oldM/PushCallback.java
@@ -1,4 +1,4 @@
-package com.ruoyi.utils.qymqtt;
+package com.ruoyi.utils.qymqtt.oldM;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.sy.domain.ArdSyCarLock;
--
Gitblit v1.9.3