From e2cc46293d84e49cf896b2ffd3494101712ac29e Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期四, 09 十一月 2023 11:32:04 +0800
Subject: [PATCH] rtu封
---
ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarRtuService.java | 4 +++-
ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java | 8 +++++---
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarLockController.java | 14 ++++++++++----
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarRtuServiceImpl.java | 22 ++++++++++++++++------
ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttConsumerCallback.java | 2 +-
5 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarLockController.java b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarLockController.java
index 17d103d..bd1d29e 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarLockController.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarLockController.java
@@ -9,10 +9,7 @@
import com.ruoyi.sy.domain.ArdSyUser;
import com.ruoyi.sy.mapper.ArdAccessFenceMapper;
import com.ruoyi.sy.param.AddCarParam;
-import com.ruoyi.sy.service.ArdAccessFenceService;
-import com.ruoyi.sy.service.ArdSyCarLockService;
-import com.ruoyi.sy.service.IArdSyCarService;
-import com.ruoyi.sy.service.IArdSyUserService;
+import com.ruoyi.sy.service.*;
import com.ruoyi.sy.vo.CarLockVo;
import com.ruoyi.sy.vo.CarVo;
import com.ruoyi.sy.vo.RtuVo;
@@ -43,6 +40,8 @@
private ArdSyCarLockService ardSyCarLockService;
@Autowired
private ArdAccessFenceService ardAccessFenceService;
+ @Autowired
+ private ArdSyCarRtuService ardSyCarRtuService;
@GetMapping("/car")
@ApiOperation("鏌ヨ鎵�鏈夋湭鎸傞攣鐨勮溅杈�")
@@ -180,6 +179,13 @@
return AjaxResult.success(ardAccessFenceService.updCarAlarm(id));
}
+ @GetMapping("/openLock")
+ @ApiOperation("杩滅▼寮�閿�")
+ public AjaxResult openLock(String carId){
+ return AjaxResult.success(ardSyCarRtuService.openLock(ardSyCarRtuService.one(carId)));
+ }
+
+
//鑾峰彇31杞﹁締杞︾墝鍙烽┚椹跺憳鍜岀數璇�
public List<CarVo> analysis(List<CarVo> list){
String usersId = SecurityUtils.getUserId();
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
index 2c37a81..f88c5da 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarRtuService.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarRtuService.java
@@ -9,7 +9,9 @@
*/
public interface ArdSyCarRtuService {
- String allCarTopic();
+ String[] allCarTopic();
ArdSyCarRtu one(String carId);
+
+ String openLock(ArdSyCarRtu ardSyCarRtu);
}
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
index 9536d9b..3f2436f 100644
--- 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
@@ -1,15 +1,16 @@
package com.ruoyi.sy.service.impl;
+import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.sy.domain.ArdSyCarRtu;
import com.ruoyi.sy.mapper.ArdSyCarRtuMapper;
import com.ruoyi.sy.service.ArdSyCarRtuService;
+import com.ruoyi.utils.mqtt.MqttConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
/**
* @author Administrator
@@ -21,14 +22,13 @@
private ArdSyCarRtuMapper ardSyCarRtuMapper;
@Override
- public String allCarTopic() {
+ 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);
+ return list.toArray(new String[list.size()]);
}
@Override
@@ -38,4 +38,14 @@
return ardSyCarRtuMapper.selectOne(queryWrapper);
}
+ @Override
+ public String openLock(ArdSyCarRtu ardSyCarRtu) {
+ 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)));
+ return "宸插彂閫佸紑閿佹寚浠�";
+ }
+
}
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 b172d0e..f25b749 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
@@ -92,7 +92,7 @@
ardRadarService.forceGuide(new String(message.getPayload(), StandardCharsets.UTF_8));
}
if(topic.contains("/p")){
- System.out.println(new String(message.getPayload(), StandardCharsets.UTF_8));
+ 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
index 567b852..e5e2825 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java
@@ -24,9 +24,11 @@
@Override
public void run(String... args) throws Exception {
- String topic = ardSyCarRtuService.allCarTopic();
+ String[] topic = ardSyCarRtuService.allCarTopic();
MqttConsumer mqttConsumer = new MqttConsumer();
- mqttConsumer.subscribe(topic,2);
- log.info("mqtt璁㈤槄娓呮筏杞﹁締閿佷俊鎭細"+topic);
+ for (int i = 0; i < topic.length; i++) {
+ mqttConsumer.subscribe(topic[i],2);
+ }
+ log.info("mqtt璁㈤槄娓呮筏杞﹁締閿佷俊鎭細"+Arrays.toString(topic));
}
}
--
Gitblit v1.9.3