From 2c2580fbf0bd6b28f84ab8f3949e1b5be464bcb3 Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期三, 08 十一月 2023 17:02:14 +0800
Subject: [PATCH] mqtt锁状态
---
ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarRtuService.java | 15 +++++
ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java | 32 ++++++++++
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java | 31 ++++++++--
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarRtuServiceImpl.java | 41 +++++++++++++
ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttConsumerCallback.java | 3 +
5 files changed, 116 insertions(+), 6 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 0c01de8..c5dd1f9 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
@@ -8,19 +8,18 @@
package com.ruoyi.sy.gps31;
import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
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.ArdAccessFence;
-import com.ruoyi.sy.domain.ArdAccessNum;
-import com.ruoyi.sy.domain.ArdOilWall;
-import com.ruoyi.sy.domain.ArdSyCarLock;
+import com.ruoyi.sy.domain.*;
import com.ruoyi.sy.service.ArdAccessFenceService;
import com.ruoyi.sy.service.ArdOilWallService;
import com.ruoyi.sy.service.impl.*;
import com.ruoyi.utils.gps.GeoTools;
+import com.ruoyi.utils.mqtt.MqttConsumer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -183,7 +182,6 @@
break;
}
}
- ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
}else {
//濡傛灉鏈夎繘鍏ュ洿鏍廔D锛屽垽鏂槸鍚﹀紑鍑鸿娌圭偣
String out = ardAccessFence.getOutShipmentId();
@@ -212,9 +210,10 @@
//濡傛灉unload涓虹┖锛屽垽鏂槸鍚﹁繘鍏ュ嵏娌圭偣
if (unload == null) {
//杞﹁締鏈繘鍏ュ嵏娌圭偣
- List<ArdOilWall> ardOilWallUpload = SpringUtils.getBean(ArdOilWallService.class).uploadAll();
+ List<ArdOilWall> ardOilWallUpload = ((ArdOilWallServiceImpl)SpringUtils.getBean("ArdOilWallServiceImpl")).uploadAll();
//鏄惁鍦ㄨ矾涓�
Boolean isRoad = true;
+ //鍒ゆ柇鏄惁杩涘幓鍗告补鐐�
for (int i = 0; i < ardOilWallUpload.size(); i++) {
pts.clear();
ArdOilWall ardOilWall = ardOilWallUpload.get(i);
@@ -231,6 +230,17 @@
ardAccessFence.setNowWallName(ardOilWall.getName());
ardAccessFence.setLastTime(time);
((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
+ //鍙戦�佽В灏佹寚浠�
+ ArdSyCarRtu ardSyCarRtu = ((ArdSyCarRtuServiceImpl) SpringUtils.getBean("ArdSyCarRtuServiceImpl")).one(carId);
+ if(ardSyCarRtu!=null){
+ Map<String,Object> map = new HashMap<>();
+ map.put("A01", 110000);//瀵奸�氱涓�璺户鐢靛櫒
+// map.put("A02", 110000);//瀵奸�氱浜岃矾缁х數鍣�
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttConsumer.publish(ardSyCarRtu.getTopicSubscribe(), String.valueOf(new JSONObject(map)));
+ }else {
+ log.error("杞﹁締"+carId+"鏃犻攣鐘舵��");
+ }
//宸茬粡杩涘叆鍗告补鐐癸紝涓嶅湪璺笂涓嶉渶瑕佸仠杞︽姤璀�
isRoad = false;
break;
@@ -273,6 +283,15 @@
}
if (!GeoTools.IsPtInPoly(point, pts)) {
//寮�鍑轰簡鍗告补鐐瑰洿鏍忥紝鍒犻櫎璇ユ潯杞﹁締鏁版嵁
+ //鍙戦�佽В灏佹寚浠�
+ ArdSyCarRtu ardSyCarRtu = ((ArdSyCarRtuServiceImpl) SpringUtils.getBean("ArdSyCarRtuServiceImpl")).one(carId);
+ if(ardSyCarRtu!=null) {
+ Map<String, Object> map = new HashMap<>();
+ map.put("A01", 100000);//鏂紑绗竴璺户鐢靛櫒
+// map.put("A02", 100000);//鏂紑绗簩璺户鐢靛櫒
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttConsumer.publish(ardSyCarRtu.getTopicSubscribe(), String.valueOf(new JSONObject(map)));
+ }
((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).delAccess(carId);
}else {
//鏈紑鍑哄嵏娌圭偣锛屾洿鏂扮粡绾害淇濆瓨
diff --git a/ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarRtuService.java b/ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarRtuService.java
new file mode 100644
index 0000000..2c37a81
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarRtuService.java
@@ -0,0 +1,15 @@
+package com.ruoyi.sy.service;
+
+import com.ruoyi.sy.domain.ArdSyCarRtu;
+
+import java.util.List;
+
+/**
+ * @author Administrator
+ */
+public interface ArdSyCarRtuService {
+
+ String allCarTopic();
+
+ ArdSyCarRtu one(String carId);
+}
diff --git a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarRtuServiceImpl.java b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarRtuServiceImpl.java
new file mode 100644
index 0000000..9536d9b
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarRtuServiceImpl.java
@@ -0,0 +1,41 @@
+package com.ruoyi.sy.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.sy.domain.ArdSyCarRtu;
+import com.ruoyi.sy.mapper.ArdSyCarRtuMapper;
+import com.ruoyi.sy.service.ArdSyCarRtuService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author Administrator
+ */
+@Service
+public class ArdSyCarRtuServiceImpl implements ArdSyCarRtuService {
+
+ @Autowired
+ private ArdSyCarRtuMapper ardSyCarRtuMapper;
+
+ @Override
+ public String allCarTopic() {
+ List<ArdSyCarRtu> carRtus = ardSyCarRtuMapper.selectList(null);
+ List<String> list = new ArrayList<>();
+ for (int i = 0; i < carRtus.size(); i++) {
+ list.add(carRtus.get(i).getTopicPublish());
+ }
+ String[] topicArray = list.toArray(new String[list.size()]);
+ return Arrays.toString(topicArray);
+ }
+
+ @Override
+ public ArdSyCarRtu one(String carId) {
+ QueryWrapper<ArdSyCarRtu> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("car_id",carId);
+ return ardSyCarRtuMapper.selectOne(queryWrapper);
+ }
+
+}
diff --git a/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttConsumerCallback.java b/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttConsumerCallback.java
index 29965fa..b172d0e 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttConsumerCallback.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttConsumerCallback.java
@@ -91,6 +91,9 @@
ArdRadarService ardRadarService = SpringUtils.getBean(ArdRadarService.class);
ardRadarService.forceGuide(new String(message.getPayload(), StandardCharsets.UTF_8));
}
+ if(topic.contains("/p")){
+ System.out.println(new String(message.getPayload(), StandardCharsets.UTF_8));
+ }
} catch (Exception e) {
log.debug("澶勭悊mqtt娑堟伅寮傚父:" + e);
}
diff --git a/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java b/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java
new file mode 100644
index 0000000..567b852
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java
@@ -0,0 +1,32 @@
+package com.ruoyi.utils.mqtt;
+
+import com.ruoyi.sy.domain.ArdSyCarRtu;
+import com.ruoyi.sy.mapper.ArdSyCarRtuMapper;
+import com.ruoyi.sy.service.ArdSyCarRtuService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author Administrator
+ */
+@Slf4j
+@Component
+public class MqttOnce implements CommandLineRunner {
+
+ @Autowired
+ private ArdSyCarRtuService ardSyCarRtuService;
+
+ @Override
+ public void run(String... args) throws Exception {
+ String topic = ardSyCarRtuService.allCarTopic();
+ MqttConsumer mqttConsumer = new MqttConsumer();
+ mqttConsumer.subscribe(topic,2);
+ log.info("mqtt璁㈤槄娓呮筏杞﹁締閿佷俊鎭細"+topic);
+ }
+}
--
Gitblit v1.9.3