From f22a5485cbe6563447ace9cf7939405f7e06c6a6 Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期一, 13 十一月 2023 10:25:27 +0800
Subject: [PATCH] 车辆RTU
---
ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarRtuService.java | 2
ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCarRtu.java | 2
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarLockServiceImpl.java | 51 ++++++++++--
ard-work/src/main/java/com/ruoyi/sy/gps31/PositionContainer.java | 14 +++
ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java | 2
ard-work/src/main/java/com/ruoyi/sy/param/AddRtuParam.java | 10 ++
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarLockController.java | 21 ++--
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java | 85 +++++++++++++++++++-
ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarLockService.java | 8 +-
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarRtuServiceImpl.java | 7 +
ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnceCallback.java | 37 ++++++++-
11 files changed, 202 insertions(+), 37 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 86c0509..ec3e0b4 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
@@ -10,6 +10,7 @@
import com.ruoyi.sy.domain.ArdSyUser;
import com.ruoyi.sy.mapper.ArdAccessFenceMapper;
import com.ruoyi.sy.param.AddCarParam;
+import com.ruoyi.sy.param.AddRtuParam;
import com.ruoyi.sy.service.*;
import com.ruoyi.sy.service.impl.ArdSyCarRtuServiceImpl;
import com.ruoyi.sy.vo.CarLockVo;
@@ -48,35 +49,35 @@
@GetMapping("/car")
@ApiOperation("鏌ヨ鎵�鏈夋湭鎸傞攣鐨勮溅杈�")
- public Results car(){
+ public AjaxResult car(){
List<CarVo> list = ardSyCarLockService.car();
analysis(list);
- return Results.succeed(list);
+ return AjaxResult.success(list);
}
@GetMapping("/carAddOne")
@ApiOperation("鏌ヨ鎵�鏈夋湭鎸傞攣鐨勮溅杈嗗姞鏈溅杈嗕俊鎭�")
- public Results carAddOne(String carId){
+ public AjaxResult carAddOne(String carId){
List<CarVo> list = ardSyCarLockService.carAddOne(carId);
analysis(list);
- return Results.succeed(list);
+ return AjaxResult.success(list);
}
@PostMapping("/add")
@ApiOperation("娣诲姞rtu")
- public Results add(String carId){
- return Results.succeed("鎴愬姛娣诲姞"+ardSyCarLockService.addRtu(carId)+"鏉℃暟鎹�");
+ public AjaxResult add(@RequestBody AddRtuParam addRtuParam){
+ return AjaxResult.success("鎴愬姛娣诲姞"+ardSyCarLockService.addRtu(addRtuParam)+"鏉℃暟鎹�");
}
@DeleteMapping("/del")
@ApiOperation("鍒犻櫎rtu")
- public Results del(String id){
- return Results.succeed("鎴愬姛鍒犻櫎"+ardSyCarLockService.delCar(id)+"鏉℃暟鎹�");
+ public AjaxResult del(String id){
+ return AjaxResult.success("鎴愬姛鍒犻櫎"+ardSyCarLockService.delCar(id)+"鏉℃暟鎹�");
}
@GetMapping("/one")
@ApiOperation("鏌ヨ涓�鏉tu鍙婇攣")
- public Results one(String carId){
+ public AjaxResult one(String carId){
CarLockVo carLockVo = new CarLockVo();
CarVo carVo = ardSyCarLockService.carOne(carId);
String usersId = SecurityUtils.getUserId();
@@ -94,7 +95,7 @@
carLockVo.setCar(carVo);
String rtu = carVo.getRtu();
carLockVo.setCarLockList(ardSyCarLockService.carLock(rtu));
- return Results.succeed(carLockVo);
+ return AjaxResult.success(carLockVo);
}
@GetMapping("/query")
diff --git a/ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCarRtu.java b/ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCarRtu.java
index 7487879..79ade27 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCarRtu.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCarRtu.java
@@ -12,4 +12,6 @@
private String carId;
private String topicSubscribe; //璁㈤槄
private String topicPublish; //鍙戝竷
+ private Integer installType; //瑁呮补鐐� 0鏂藉皝 1瑙e皝
+ private Integer unloadType; //鍗告补鐐� 0鏂藉皝 1瑙e皝
}
diff --git a/ard-work/src/main/java/com/ruoyi/sy/gps31/PositionContainer.java b/ard-work/src/main/java/com/ruoyi/sy/gps31/PositionContainer.java
index e9f34fc..5075feb 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/gps31/PositionContainer.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/gps31/PositionContainer.java
@@ -1,6 +1,9 @@
package com.ruoyi.sy.gps31;
+import com.ruoyi.sy.domain.ArdSyCarLock;
+
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public class PositionContainer {
@@ -9,6 +12,17 @@
private static Map<String, Map<String,Map<String,Object>>> userPositionMap = new HashMap();//渚濈敤鎴峰瓨鏀惧疄鏂借溅杈嗕綅缃�:userId锛宑arId锛岃溅杈嗕綅缃�
+ public static Map<String, List<ArdSyCarLock>> getTopicSubscribe() {
+ return topicSubscribe;
+ }
+
+ public static void setTopicSubscribe(Map<String, List<ArdSyCarLock>> topicSubscribe) {
+ PositionContainer.topicSubscribe = topicSubscribe;
+ }
+
+ public static Map<String, List<ArdSyCarLock>> topicSubscribe;
+
+
public static synchronized Map<String, Map<String, Map<String,Object>>> getDeptPositionMap() {
return deptPositionMap;
}
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 e726cf5..15f192c 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
@@ -137,6 +137,27 @@
ardAccessFence1.setDrct(drct);
ardAccessFence1.setIsAlarm(0);
ardAccessFenceService.access(ardAccessFence1);
+ //鏌ヨ瑁呮补鐐规棦瀹歊tu鐘舵��
+ ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId);
+ Integer installType = ardSyCarRtu.getInstallType();
+ //1瑙e皝
+ if(installType==1){
+ Map<String,Object> map = new HashMap<>();
+ map.put("A01", 110000);//瀵奸�氱涓�璺户鐢靛櫒
+ map.put("A02", 110000);//瀵奸�氱浜岃矾缁х數鍣�
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttConsumer.publish(ardSyCarRtu.getTopicPublish(), String.valueOf(new JSONObject(map)));
+ }
+ //0鏂藉皝
+ if(installType==0){
+//鍏抽攣
+
+ Map<String,Object> map = new HashMap<>();
+ map.put("A01", 100000);//鏂紑绗竴璺户鐢靛櫒
+ map.put("A02", 100000);//鏂紑绗簩璺户鐢靛櫒
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttConsumer.publish(ardSyCarRtu.getTopicPublish(), String.valueOf(new JSONObject(map)));
+ }
break;
}
}
@@ -195,6 +216,27 @@
ardAccessFence.setIntoShipmentTime(time);
ardAccessFence.setNowWallName(ardOilWall.getName());
ardAccessFence.setLastTime(time);
+ //鏌ヨ瑁呮补鐐规棦瀹歊tu鐘舵��
+ ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId);
+ Integer installType = ardSyCarRtu.getInstallType();
+ //1瑙e皝
+ if(installType==1){
+ Map<String,Object> map = new HashMap<>();
+ map.put("A01", 110000);//瀵奸�氱涓�璺户鐢靛櫒
+ map.put("A02", 110000);//瀵奸�氱浜岃矾缁х數鍣�
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttConsumer.publish(ardSyCarRtu.getTopicPublish(), String.valueOf(new JSONObject(map)));
+ }
+ //0鏂藉皝
+ if(installType==0){
+//鍏抽攣
+
+ Map<String,Object> map = new HashMap<>();
+ map.put("A01", 100000);//鏂紑绗竴璺户鐢靛櫒
+ map.put("A02", 100000);//鏂紑绗簩璺户鐢靛櫒
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttConsumer.publish(ardSyCarRtu.getTopicPublish(), String.valueOf(new JSONObject(map)));
+ }
break;
}
}
@@ -221,10 +263,15 @@
ardAccessFence.setLng(lng);
ardAccessFence.setLat(lat);
ardAccessFenceService.updAccess(ardAccessFence);
-//寮�鍑鸿娌圭偣鍥存爮锛屽彂閫佷笂閿佸強鏂藉皝鍛戒护
+ //寮�鍑鸿娌圭偣鍥存爮锛屽彂閫佷笂閿佸強鏂藉皝鍛戒护
+ ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId);
+//鍏抽攣
-
-
+ Map<String,Object> map = new HashMap<>();
+ map.put("A01", 100000);//鏂紑绗竴璺户鐢靛櫒
+ map.put("A02", 100000);//鏂紑绗簩璺户鐢靛櫒
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttConsumer.publish(ardSyCarRtu.getTopicPublish(), String.valueOf(new JSONObject(map)));
}
}else {
@@ -255,6 +302,27 @@
ardAccessFenceService.updAccess(ardAccessFence);
//宸茬粡杩涘叆鍗告补鐐癸紝涓嶅湪璺笂涓嶉渶瑕佸仠杞︽姤璀�
isRoad = false;
+ //鏌ヨ瑁呮补鐐规棦瀹歊tu鐘舵��
+ ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId);
+ Integer unloadType = ardSyCarRtu.getUnloadType();
+ //1瑙e皝
+ if(unloadType==1){
+ Map<String,Object> map = new HashMap<>();
+ map.put("A01", 110000);//瀵奸�氱涓�璺户鐢靛櫒
+ map.put("A02", 110000);//瀵奸�氱浜岃矾缁х數鍣�
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttConsumer.publish(ardSyCarRtu.getTopicPublish(), String.valueOf(new JSONObject(map)));
+ }
+ //0鏂藉皝
+ if(unloadType==0){
+//鍏抽攣
+
+ Map<String,Object> map = new HashMap<>();
+ map.put("A01", 100000);//鏂紑绗竴璺户鐢靛櫒
+ map.put("A02", 100000);//鏂紑绗簩璺户鐢靛櫒
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttConsumer.publish(ardSyCarRtu.getTopicPublish(), String.valueOf(new JSONObject(map)));
+ }
break;
}
}
@@ -296,10 +364,15 @@
pts.add(new Point2D.Double(Double.parseDouble(coord[j]), Double.parseDouble(coord[j + 1])));
}
if (!GeoTools.IsPtInPoly(point, pts)) {
-//寮�鍑轰簡鍗告补鐐瑰洿鏍忥紝鍙戦�佷笂閿佸強鏂借В灏佹寚浠�
+ //寮�鍑轰簡鍗告补鐐瑰洿鏍忥紝鍙戦�佷笂閿佸強鏂借В灏佹寚浠�
+ ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId);
+//鍏抽攣
-
-
+ Map<String,Object> map = new HashMap<>();
+ map.put("A01", 100000);//鏂紑绗竴璺户鐢靛櫒
+ map.put("A02", 100000);//鏂紑绗簩璺户鐢靛櫒
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttConsumer.publish(ardSyCarRtu.getTopicPublish(), String.valueOf(new JSONObject(map)));
//鍒犻櫎璇ユ潯杞﹁締鏁版嵁
ardAccessFenceService.delAccess(carId);
}else {
diff --git a/ard-work/src/main/java/com/ruoyi/sy/param/AddRtuParam.java b/ard-work/src/main/java/com/ruoyi/sy/param/AddRtuParam.java
new file mode 100644
index 0000000..fc54249
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/sy/param/AddRtuParam.java
@@ -0,0 +1,10 @@
+package com.ruoyi.sy.param;
+
+import lombok.Data;
+
+@Data
+public class AddRtuParam {
+ private String carId;
+ private Integer installType; //瑁呮补鐐� 0鏂藉皝 1瑙e皝
+ private Integer unloadType; //鍗告补鐐� 0鏂藉皝 1瑙e皝
+}
diff --git a/ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarLockService.java b/ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarLockService.java
index df4d06e..f953c42 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarLockService.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarLockService.java
@@ -1,10 +1,8 @@
package com.ruoyi.sy.service;
-import com.ruoyi.sy.domain.ArdAccessFence;
-import com.ruoyi.sy.domain.ArdSyCar;
import com.ruoyi.sy.domain.ArdSyCarLock;
import com.ruoyi.sy.domain.ArdSyCarRtu;
-import com.ruoyi.sy.vo.CarLockVo;
+import com.ruoyi.sy.param.AddRtuParam;
import com.ruoyi.sy.vo.CarVo;
import com.ruoyi.sy.vo.RtuVo;
@@ -18,7 +16,7 @@
List<CarVo> car();
List<CarVo> carAddOne(String carId);
- int addRtu(String carId);
+ int addRtu(AddRtuParam addRtuParam);
/**
* 鎵�鏈夋寕閿佺殑杞﹁締
@@ -39,6 +37,8 @@
List<CarVo> addCarBefore(String id);
+ List<ArdSyCarLock> data(String msg);
+ int updLock(ArdSyCarLock ardSyCarLock);
}
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 6b7f196..15783b1 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
@@ -15,4 +15,6 @@
ArdSyCarRtu one(String carId);
String openLock(ArdSyCarRtu ardSyCarRtu);
+
+ ArdSyCarRtu subscribeByCarId(String subscribe);
}
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 f16e24a..d2ee258 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
@@ -1,17 +1,16 @@
package com.ruoyi.sy.service.impl;
+import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.entity.SysDept;
-import com.ruoyi.sy.domain.ArdAccessFence;
import com.ruoyi.sy.domain.ArdSyCar;
import com.ruoyi.sy.domain.ArdSyCarLock;
import com.ruoyi.sy.domain.ArdSyCarRtu;
-import com.ruoyi.sy.mapper.ArdAccessFenceMapper;
import com.ruoyi.sy.mapper.ArdSyCarLockMapper;
import com.ruoyi.sy.mapper.ArdSyCarMapper;
import com.ruoyi.sy.mapper.ArdSyCarRtuMapper;
+import com.ruoyi.sy.param.AddRtuParam;
import com.ruoyi.sy.service.ArdSyCarLockService;
-import com.ruoyi.sy.vo.CarLockVo;
import com.ruoyi.sy.vo.CarVo;
import com.ruoyi.sy.vo.RtuVo;
import com.ruoyi.system.mapper.SysDeptMapper;
@@ -55,15 +54,17 @@
}
@Override
- public int addRtu(String carId) {
+ public int addRtu(AddRtuParam addRtuParam) {
ArdSyCarRtu ardSyCarRtu = new ArdSyCarRtu();
ardSyCarRtu.setId(String.valueOf(UUID.randomUUID()));
- ardSyCarRtu.setCarId(carId);
- ardSyCarRtu.setTopicPublish("/p"+carId+"/");
- ardSyCarRtu.setTopicSubscribe("/p"+carId+"/set/");
+ ardSyCarRtu.setCarId(addRtuParam.getCarId());
+ ardSyCarRtu.setTopicPublish("/p"+addRtuParam.getCarId()+"/");
+ ardSyCarRtu.setTopicSubscribe("/p"+addRtuParam.getCarId()+"/set/");
+ ardSyCarRtu.setInstallType(addRtuParam.getInstallType());
+ ardSyCarRtu.setUnloadType(addRtuParam.getUnloadType());
rtuMapper.insert(ardSyCarRtu);
QueryWrapper<ArdSyCar> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("car_id",carId);
+ queryWrapper.eq("car_id",addRtuParam.getCarId());
ArdSyCar ardSyCar = ardSyCarMapper.selectOne(queryWrapper);
ardSyCar.setReserved1(ardSyCarRtu.getId());
return ardSyCarMapper.updateById(ardSyCar);
@@ -108,9 +109,15 @@
@Override
public List<ArdSyCarLock> carLock(String rtu) {
- QueryWrapper<ArdSyCarLock> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("rtu_id",rtu);
- return lockMapper.selectList(queryWrapper);
+ List<ArdSyCarLock> locks = new ArrayList<>();
+ try {
+ QueryWrapper<ArdSyCarLock> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("rtu_id",rtu);
+ locks = lockMapper.selectList(queryWrapper);
+ }catch (Exception e){
+
+ }
+ return locks;
}
@Override
@@ -179,7 +186,29 @@
return carAnalysis(carList);
}
+ @Override
+ public List<ArdSyCarLock> data(String msg) {
+ JSONObject jsonObject = JSONObject.parseObject(msg);
+ List<ArdSyCarLock> lockList = new ArrayList<>();
+ ArdSyCarLock ardSyCarLock1 = new ArdSyCarLock();
+ ardSyCarLock1.setRelay("A01");
+ ardSyCarLock1.setRelayInfo(String.valueOf(jsonObject.getInteger("A01")));
+ ardSyCarLock1.setCurrent("C01");
+ ardSyCarLock1.setCurrentInfo(String.valueOf(jsonObject.getFloat("C01")));
+ lockList.add(ardSyCarLock1);
+ ArdSyCarLock ardSyCarLock2 = new ArdSyCarLock();
+ ardSyCarLock2.setRelay("A02");
+ ardSyCarLock2.setRelayInfo(String.valueOf(jsonObject.getInteger("A02")));
+ ardSyCarLock2.setCurrent("C02");
+ ardSyCarLock2.setCurrentInfo(String.valueOf(jsonObject.getFloat("C02")));
+ lockList.add(ardSyCarLock2);
+ return lockList;
+ }
+ @Override
+ public int updLock(ArdSyCarLock ardSyCarLock) {
+ return lockMapper.updateById(ardSyCarLock);
+ }
//杞﹁締鍒楄〃灏佽
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 025ca99..fce9045 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
@@ -53,4 +53,11 @@
return "宸插彂閫佸紑閿佹寚浠�";
}
+ @Override
+ public ArdSyCarRtu subscribeByCarId(String subscribe) {
+ QueryWrapper<ArdSyCarRtu> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("topic_subscribe",subscribe);
+ return ardSyCarRtuMapper.selectOne(queryWrapper);
+ }
+
}
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 3c25919..3b88ad2 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
@@ -29,7 +29,7 @@
@Autowired
private ISysConfigService sysConfigService;
-// @PostConstruct
+ @PostConstruct
public void init() {
//鑾峰彇鐢电閿佸湴鍧�
String mqttUrl = sysConfigService.selectConfigByKey("ElectromagneticLockUrl");
diff --git a/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnceCallback.java b/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnceCallback.java
index 5010300..d89ef67 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnceCallback.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnceCallback.java
@@ -1,15 +1,19 @@
package com.ruoyi.utils.mqtt;
-import com.ruoyi.alarm.global.service.impl.GlobalAlarmServiceImpl;
-import com.ruoyi.alarm.radar.service.ArdRadarService;
+import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.utils.spring.SpringUtils;
-import com.ruoyi.statistical.service.StatisticalService;
-import com.ruoyi.storage.minio.service.IStorageMinioEventService;
+import com.ruoyi.sy.domain.ArdSyCarLock;
+import com.ruoyi.sy.domain.ArdSyCarRtu;
+import com.ruoyi.sy.gps31.PositionContainer;
+import com.ruoyi.sy.service.ArdSyCarLockService;
+import com.ruoyi.sy.service.ArdSyCarRtuService;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.*;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* @Description: mqtt鍥炶皟澶勭悊绫�
@@ -25,6 +29,9 @@
private MqttConnectOptions options;
private String topic;
private int qos;
+ //娉ㄥ叆鐢靛瓙閿丅ean
+ ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
+ ArdSyCarLockService carLockService = SpringUtils.getBean(ArdSyCarLockService.class);
public MqttOnceCallback(MqttClient client, MqttConnectOptions options, String topic, int qos) {
this.client = client;
@@ -70,6 +77,26 @@
public void messageArrived(String topic, MqttMessage message) {
try {
// System.out.println("銆愯溅杈嗛攣涓婚銆戯細"+topic+"銆愯溅杈嗛攣淇℃伅銆戯細"+new String(message.getPayload(), StandardCharsets.UTF_8));
+ //鍑烘潵鍥炶皟鏁版嵁
+ List<ArdSyCarLock> ardSyCarLocks = carLockService.data(new String(message.getPayload(), StandardCharsets.UTF_8));
+ //瀛樺叆闆嗗悎
+ Map<String,List<ArdSyCarLock>> map = PositionContainer.getTopicSubscribe();
+ if(map==null){
+ Map<String,List<ArdSyCarLock>> newMap = new HashMap<>();
+ newMap.put("topic",ardSyCarLocks);
+ PositionContainer.setTopicSubscribe(newMap);
+ }else {
+ for(Map.Entry entry : map.entrySet()){
+ String mapTopic = (String) entry.getKey();
+ if(topic.equals(mapTopic)){
+ map.remove(entry.getKey());
+ }
+ Map<String,List<ArdSyCarLock>> newMap = new HashMap<>();
+ newMap.put("topic",ardSyCarLocks);
+ PositionContainer.setTopicSubscribe(newMap);
+ }
+ }
+ log.debug(String.valueOf(map));
} catch (Exception e) {
log.debug("杞﹁締鐢电閿佸鐞唌qtt娑堟伅寮傚父:" + e);
}
--
Gitblit v1.9.3