From af0829b98126c3680ceefdc17621473fa3f97750 Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期三, 22 十一月 2023 11:33:34 +0800
Subject: [PATCH] 清淤锁
---
/dev/null | 161 -------------
ard-work/src/main/java/com/ruoyi/utils/qymqtt/PushCallback.java | 108 +++++++++
ard-work/src/main/java/com/ruoyi/utils/qymqtt/MqttCustomerClient.java | 141 +++++++++++
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarLockServiceImpl.java | 101 ++++++-
ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java | 1
ard-work/src/main/java/com/ruoyi/utils/qymqtt/AutoMqtt.java | 38 +++
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarLockController.java | 2
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java | 136 ++++++----
ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarLockService.java | 2
9 files changed, 456 insertions(+), 234 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java b/ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java
index 6637e42..8e4e345 100644
--- a/ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java
+++ b/ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java
@@ -84,6 +84,7 @@
List<TreeDeptWell> treeDeptWells = new ArrayList<>();
if ((int) mapResult.get("code") == 200) {
List<Map<String, Object>> listResult = (List<Map<String, Object>>) JSON.parse((String) mapResult.get("resdata"));
+// System.out.println(String.valueOf(listResult));
//寰幆寰楀埌鏉冮檺涓嬪尮閰嶆暟鎹�
for (int i = 0; i < listResult.size(); i++) {
String equipNumber = (String) listResult.get(i).get("EquipNumber");
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 b9510e0..3ad7937 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
@@ -188,7 +188,7 @@
@PostMapping("/onOff")
@ApiOperation("杩滅▼寮�閿�")
- public AjaxResult onOff(@RequestBody LockTypeParam lockTypeParam) {
+ public AjaxResult onOff(@RequestBody LockTypeParam lockTypeParam) throws MqttException {
return AjaxResult.success(ardSyCarLockService.onOff(lockTypeParam));
}
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 98f2840..cc3d87e 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,7 +8,6 @@
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;
@@ -18,14 +17,12 @@
import com.ruoyi.sy.service.*;
import com.ruoyi.sy.service.impl.*;
import com.ruoyi.utils.gps.GeoTools;
-import com.ruoyi.utils.mqtt.MqttConsumer;
-import com.ruoyi.utils.mqtt.MqttOnce;
+import com.ruoyi.utils.qymqtt.MqttCustomerClient;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.paho.client.mqttv3.MqttException;
import java.awt.geom.Point2D;
-import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -93,6 +90,7 @@
String deptName = (String) result.get("deptName");//鑾峰彇閮ㄩ棬鍚嶇О
String carModel = (String) result.get("carModel");//鑾峰彇杞﹁締妯″瀷
Integer drct = (Integer) gpsMap.get("drct");//鑾峰彇杞﹁締妯″瀷
+ Integer speed = (Integer) gpsMap.get("speed");
//瀹氫箟2缁寸┖闂�
Point2D.Double point = new Point2D.Double(Double.parseDouble(lng), Double.parseDouble(lat));
List<Point2D.Double> pts = new ArrayList<Point2D.Double>();
@@ -106,12 +104,18 @@
ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
//娉ㄥ叆閿丅ean
ArdSyCarLockService lockService = SpringUtils.getBean(ArdSyCarLockService.class);
- //鍒涘缓mqtt宸ュ叿绫诲璞�
- MqttOnce mqttOnce = new MqttOnce();
//鏌ヨ瀹氫綅娌硅溅琛ㄤ腑鏄惁鏈夎杞﹁締
ArdAccessFence ardAccessFence = ardAccessFenceService.queryAccess(carId);
//鏌ヨ鎵�鏈夎娌圭偣鍥存爮
List<ArdOilWall> ardOilWalls = ardOilWallService.accessAll();
+ //杞﹂�熸爣璁�
+ Boolean stop = true;
+ //鍒ゆ柇杞﹂��
+ if(speed>5){
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"鏂藉皝",carRtuService,lockService);
+ stop = false;
+ }
//濡傛灉娌℃湁璇存槑杞﹁締鏈繘鍏ヨ娌圭偣锛岄渶瑕佸尮閰嶆墍鏈夎娌圭偣鍥存爮
if(ardAccessFence==null){
//杞﹁締鏈繘鍏ヨ娌圭偣
@@ -141,8 +145,10 @@
ardAccessFence1.setDrct(drct);
ardAccessFence1.setIsAlarm(0);
ardAccessFenceService.access(ardAccessFence1);
- //mqtt鍙戦�佹棦瀹歊tu鐘舵��
- feng(carId,"瑁呮补鐐�",carRtuService,lockService,mqttOnce);
+ if(stop){
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"瑁呮补鐐�",carRtuService,lockService);
+ }
break;
}
}
@@ -201,8 +207,10 @@
ardAccessFence.setIntoShipmentTime(time);
ardAccessFence.setNowWallName(ardOilWall.getName());
ardAccessFence.setLastTime(time);
- //mqtt鍙戦�佹棦瀹歊tu鐘舵��
- feng(carId,"瑁呮补鐐�",carRtuService,lockService,mqttOnce);
+ if(stop){
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"瑁呮补鐐�",carRtuService,lockService);
+ }
break;
}
}
@@ -230,7 +238,7 @@
ardAccessFence.setLat(lat);
ardAccessFenceService.updAccess(ardAccessFence);
//寮�鍑鸿娌圭偣鍥存爮锛屽彂閫佷笂閿佸強鏂藉皝鍛戒护
- feng(carId,"鏂藉皝",carRtuService,lockService,mqttOnce);
+ feng(carId,"鏂藉皝",carRtuService,lockService);
}
}else {
//杞﹁締宸茬粡寮�鍑鸿娌圭偣锛屾煡鐪嬫槸鍚︽湁鍗告补鐐笽D
@@ -260,8 +268,10 @@
ardAccessFenceService.updAccess(ardAccessFence);
//宸茬粡杩涘叆鍗告补鐐癸紝涓嶅湪璺笂涓嶉渶瑕佸仠杞︽姤璀�
isRoad = false;
- //mqtt鍙戦�佹棦瀹歊tu鐘舵��
- feng(carId,"鍗告补鐐�",carRtuService,lockService,mqttOnce);
+ if(stop){
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"鍗告补鐐�",carRtuService,lockService);
+ }
break;
}
}
@@ -304,7 +314,7 @@
}
if (!GeoTools.IsPtInPoly(point, pts)) {
//寮�鍑轰簡鍗告补鐐瑰洿鏍忥紝鍙戦�佷笂閿佸強鏂借В灏佹寚浠�
- feng(carId,"鏂藉皝",carRtuService,lockService,mqttOnce);
+ feng(carId,"鏂藉皝",carRtuService,lockService);
//鍒犻櫎璇ユ潯杞﹁締鏁版嵁
ardAccessFenceService.delAccess(carId);
}else {
@@ -420,9 +430,11 @@
sendMassage();
}
- private void feng(String carId,String type,ArdSyCarRtuService carRtuService,ArdSyCarLockService lockService,MqttOnce mqttOnce) throws MqttException {
+ private void feng(String carId,String type,ArdSyCarRtuService carRtuService,ArdSyCarLockService lockService) throws MqttException {
//鏌ヨ瑁呮补鐐规棦瀹歊tu鐘舵��
ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId);
+ //鏌ヨ閿佷俊鎭�
+ List<ArdSyCarLock> ardSyCarLocks = lockService.carLock(ardSyCarRtu.getId());
Integer fengType = null;
if("瑁呮补鐐�".equals(type)){
fengType = ardSyCarRtu.getInstallType();
@@ -433,52 +445,70 @@
}
//1瑙e皝
if(fengType==1){
- Map<String,Object> map = new HashMap<>();
- map.put("A01", 110000);//瀵奸�氱涓�璺户鐢靛櫒
- map.put("A02", 110000);//瀵奸�氱浜岃矾缁х數鍣�
- map.put("res", String.valueOf(System.currentTimeMillis()));
- mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"瑙e皝");
+ //濡傛灉涓嶆槸瑙e皝灏佺姸鎬侊紝鍒欏彂閫佹柦灏佸懡浠�
+ if(ardSyCarLocks.get(0).getRelayInfo()==0){
+ 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);
+ MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+ mqttCustomerClient.connect(carId+"change");
+ mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
+ log.info("杞﹁締"+carId+"瑙e皝鍛戒护鍙戦�佹垚鍔燂紒");
+// mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"瑙e皝");
+ }
}
//0鏂藉皝
if(fengType==0){
//閿佸紑鍏崇姸鎬�
int lockCloseNum = 0;
- //鏌ヨ閿佷俊鎭�
- List<ArdSyCarLock> ardSyCarLocks = lockService.carLock(ardSyCarRtu.getId());
- 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()));
- 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)){
- lockCloseNum +=1;
- break;
+ //濡傛灉涓嶆槸鏂藉皝鐘舵�侊紝鍒欏彂閫佹柦灏佸懡浠�
+ 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);
+ MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+ mqttCustomerClient.connect(carId+"change");
+ mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
+// 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()));
- mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"鏂藉皝");
+ 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);
+ MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+ mqttCustomerClient.connect(carId+"change");
+ mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
+ 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/ArdSyCarLockService.java b/ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarLockService.java
index 1042150..de77d89 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
@@ -49,7 +49,7 @@
AjaxResult seal(RtuTypeParam rtuTypeParam);
- AjaxResult onOff(LockTypeParam lockTypeParam);
+ AjaxResult onOff(LockTypeParam lockTypeParam) throws MqttException;
List<ArdSyCarLock> lockIng(String carId);
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 7390c64..a761b97 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
@@ -17,14 +17,14 @@
import com.ruoyi.sy.service.ArdSyCarLockService;
import com.ruoyi.sy.vo.CarVo;
import com.ruoyi.sy.vo.RtuVo;
+import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.mapper.SysDeptMapper;
-import com.ruoyi.utils.mqtt.MqttOnce;
+import com.ruoyi.utils.qymqtt.MqttCustomerClient;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.text.DecimalFormat;
import java.util.*;
/**
@@ -42,6 +42,8 @@
private ArdSyCarRtuMapper rtuMapper;
@Autowired
private ArdSyCarLockMapper lockMapper;
+ @Autowired
+ private SysConfigMapper configMapper;
@Override
@@ -75,8 +77,9 @@
ArdSyCar ardSyCar = ardSyCarMapper.selectOne(queryWrapper);
ardSyCar.setReserved1(ardSyCarRtu.getId());
ardSyCarMapper.updateById(ardSyCar);
- MqttOnce mqttOnce = new MqttOnce();
- mqttOnce.subscribeCar(ardSyCarRtu);
+ MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+ mqttCustomerClient.connect(addRtuParam.getCarId()+"mqtt");
+ mqttCustomerClient.subscribe(ardSyCarRtu.getTopicSubscribe());
return num;
}
@@ -90,6 +93,11 @@
@Override
public int delCar(String id) {
+ ArdSyCarRtu ardSyCarRtu = rtuMapper.selectById(id);
+ String subscribe = ardSyCarRtu.getTopicSubscribe();
+ MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+ mqttCustomerClient.connect(ardSyCarRtu.getCarId()+"del");
+ mqttCustomerClient.unSubscribe(subscribe);
rtuMapper.deleteById(id);
QueryWrapper<ArdSyCarLock> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.eq("rtu_id",id);
@@ -236,15 +244,19 @@
QueryWrapper<ArdSyCarRtu> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("carId",rtuTypeParam.getCarId());
ArdSyCarRtu ardSyCarRtu = rtuMapper.selectOne(queryWrapper);
- MqttOnce mqttOnce = new MqttOnce();
//1瑙e皝
if(rtuTypeParam.getType()==1){
Map<String,Object> map = new HashMap<>();
map.put("A01", 110000);//瀵奸�氱涓�璺户鐢靛櫒
map.put("A02", 110000);//瀵奸�氱浜岃矾缁х數鍣�
map.put("res", String.valueOf(System.currentTimeMillis()));
+ String mapString = JSON.toJSONString(map);
try {
- return AjaxResult.success(mqttOnce.publishCar(rtuTypeParam.getCarId(),ardSyCarRtu.getTopicPublish(),String.valueOf(new com.alibaba.fastjson2.JSONObject(map)),"瑙e皝"));
+ MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+ mqttCustomerClient.connect(rtuTypeParam.getCarId()+"change");
+ mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
+ 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);
}
@@ -272,15 +284,19 @@
Map<String,Object> map = new HashMap();
map.put(key, 0.01);
map.put("res", String.valueOf(System.currentTimeMillis()));
+ String mapString = JSON.toJSONString(map);
try {
- mqttOnce.publishCar("carId",ardSyCarRtu.getTopicPublish(),String.valueOf(new com.alibaba.fastjson2.JSONObject(map)),"寮�閿侊細"+currents);
+ MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+ mqttCustomerClient.connect(rtuTypeParam.getCarId()+"change");
+ mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
+// 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();
- if(currentInfo1.equals(4.00)){
+ if(currentInfo1.equals(4.00) || currentInfo1.equals(4)){
lockCloseNum +=1;
break;
}
@@ -292,8 +308,13 @@
map.put("A01", 100000);//鏂紑绗竴璺户鐢靛櫒
map.put("A02", 100000);//鏂紑绗簩璺户鐢靛櫒
map.put("res", String.valueOf(System.currentTimeMillis()));
+ String mapString = JSON.toJSONString(map);
try {
- return AjaxResult.success(mqttOnce.publishCar(rtuTypeParam.getCarId(),ardSyCarRtu.getTopicPublish(),String.valueOf(new com.alibaba.fastjson2.JSONObject(map)),"鏂藉皝"));
+ MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+ mqttCustomerClient.connect(rtuTypeParam.getCarId()+"change");
+ mqttCustomerClient.pushlish(ardSyCarRtu.getTopicPublish(),mapString);
+ 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);
}
@@ -303,7 +324,7 @@
}
@Override
- public AjaxResult onOff(LockTypeParam lockTypeParam) {
+ public AjaxResult onOff(LockTypeParam lockTypeParam) throws MqttException {
QueryWrapper<ArdSyCarRtu> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("car_id",lockTypeParam.getCarId());
ArdSyCarRtu ardSyCarRtu = rtuMapper.selectOne(queryWrapper);
@@ -332,13 +353,50 @@
map.put("res", String.valueOf(System.currentTimeMillis()));
String mapString = JSON.toJSONString(map);
System.out.println(mapString);
- MqttOnce mqttOnce = new MqttOnce();
- try {
- return AjaxResult.success(mqttOnce.publishCar("carId",ardSyCarRtu.getTopicPublish(), mapString,"寮�鍏抽攣鎸囦护"+lockTypeParam.getNum()));
- } catch (MqttException e) {
- log.debug("寮�鍏抽攣鎸囦护鍙戦�佸け璐�"+e);
- }
- return AjaxResult.success();
+ MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+ mqttCustomerClient.connect(lockTypeParam.getCarId()+"change");
+ 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
@@ -346,7 +404,14 @@
QueryWrapper<ArdSyCarRtu> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("car_id",carId);
ArdSyCarRtu ardSyCarRtu = rtuMapper.selectOne(queryWrapper);
- return lockMapper.lockList(ardSyCarRtu.getId());
+ List<ArdSyCarLock> locks = lockMapper.lockList(ardSyCarRtu.getId());
+ for (int i = 0; i < locks.size(); i++) {
+ ArdSyCarLock ardSyCarLock = locks.get(i);
+ double info = ardSyCarLock.getCurrentInfo();
+ int d = (int) ((int)(info*150/138.3 - 4)/0.16);
+ ardSyCarLock.setCurrentInfo((double) d);
+ }
+ return locks;
}
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
deleted file mode 100644
index 9f1f0fd..0000000
--- a/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package com.ruoyi.utils.mqtt;
-
-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.system.service.ISysConfigService;
-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.boot.CommandLineRunner;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.PostConstruct;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * @author Administrator
- */
-@Slf4j
-@Component
-public class MqttOnce{
-
- @Autowired
- private ArdSyCarRtuService ardSyCarRtuService;
-
- @PostConstruct
- public void init() {
- List<ArdSyCarRtu> rtus = ardSyCarRtuService.allCarTopicList();
- for (int i = 0; i < rtus.size(); i++) {
- ArdSyCarRtu rtu = rtus.get(i);
- String carId = rtu.getCarId();
- String subscribe = rtu.getTopicSubscribe();
- try {
- MqttClient client = getMqttClient(carId);
- MqttConnectOptions options = getMqttConnectOptions();
- client.setCallback(new MqttOnceCallback(client,options,subscribe,2));
-// log.debug("--娣诲姞杞﹁締鐢电閿佸洖璋冨鐞嗙被");
- client.connect(options);
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- public void subscribeCar(ArdSyCarRtu ardSyCarRtu){
- String carId = ardSyCarRtu.getCarId();
- String subscribe = ardSyCarRtu.getTopicSubscribe();
- try {
- MqttClient client = getMqttClient(carId);
- MqttConnectOptions options = getMqttConnectOptions();
- client.setCallback(new MqttOnceCallback(client,options,subscribe,2));
-// log.debug("--娣诲姞杞﹁締鐢电閿佸洖璋冨鐞嗙被");
- client.connect(options);
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public MqttClient getMqttClient(String carId) throws MqttException {
- ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
- //鑾峰彇鐢电閿佸湴鍧�
- String mqttUrl = carRtuService.url("ElectromagneticLockUrl");
- MqttClient client = new MqttClient(mqttUrl,carId+"mqTest");
- //log.debug("--鍒涘缓"+carId+"鍙疯溅杈嗙數瀛愰攣mqtt瀹㈡埛绔�");
- return client;
- }
-
- public MqttConnectOptions getMqttConnectOptions(){
- MqttConnectOptions options = new MqttConnectOptions();
- //璁剧疆鐢ㄦ埛鍚嶅瘑鐮�
- options.setUserName("admin");
- options.setPassword("xzx12345".toCharArray());
- // 璁剧疆瓒呮椂鏃堕棿
- options.setConnectionTimeout(100);
- // 璁剧疆浼氳瘽蹇冭烦鏃堕棿
- options.setKeepAliveInterval(60);
- // 鏄惁娓呴櫎session
- options.setCleanSession(true);
-// log.debug("--鐢熸垚"+carId+"鍙疯溅杈嗙數瀛愰攣mqtt閰嶇疆瀵硅薄");
- return options;
- }
-
- public String publishCar(String carId,String topic,String message,String type) throws MqttException {
- MqttClient client = getMqttClient(carId);
- MqttConnectOptions options = getMqttConnectOptions();
- client.connect(options);
- MqttMessage msg = new MqttMessage(message.getBytes());
- msg.setQos(2);
- try{
- client.publish(topic,msg);
- }catch (Exception e){
- log.debug("鍙戝竷娑堟伅澶辫触"+topic+"娑堟伅:"+msg);
- e.getMessage();
- }
- client.disconnect();
- return topic+"鍙戝竷"+type+"鎸囦护鎴愬姛锛佹秷鎭�:"+msg;
- }
-
-}
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
deleted file mode 100644
index 98675bc..0000000
--- a/ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnceCallback.java
+++ /dev/null
@@ -1,161 +0,0 @@
-package com.ruoyi.utils.mqtt;
-
-import com.ruoyi.common.annotation.Log;
-import com.ruoyi.common.utils.spring.SpringUtils;
-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.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @Description: mqtt鍥炶皟澶勭悊绫�
- * @ClassName: MqttConsumerCallback
- * @Author: 鍒樿嫃涔�
- * @Date: 2023骞�05鏈�29鏃�9:55
- * @Version: 1.0
- **/
-@Slf4j(topic = "mqtt")
-public class MqttOnceCallback implements MqttCallbackExtended {
-
- private MqttClient client;
- 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;
- this.options = options;
- this.topic = topic;
- this.qos = qos;
- }
-
- /**
- * 鏂紑閲嶈繛
- */
- @Override
- public void connectionLost(Throwable cause) {
-// log.info("杞﹁締鐢电閿丮QTT杩炴帴鏂紑锛屽彂璧烽噸杩�......");
- while (!client.isConnected()) {
- try {
- Thread.sleep(10000);
- if (null != client && !client.isConnected()) {
- client.reconnect();
-// log.error("杞﹁締鐢电閿佸皾璇曢噸鏂拌繛鎺�");
- } else {
- client.connect(options);
-// log.error("杞﹁締鐢电閿佸皾璇曞缓绔嬫柊杩炴帴");
- }
- } catch (Exception e) {
-// log.error("杞﹁締鐢电閿佹柇寮�閲嶈繛寮傚父:" + e.getMessage());
- }
- }
- }
-
- /**
- * 鎺ユ敹鍒版秷鎭皟鐢ㄤ护鐗屼腑璋冪敤
- */
- @Override
- public void deliveryComplete(IMqttDeliveryToken token) {
- //log.info("deliveryComplete---------" + Arrays.toString(topic));
- }
-
- /**
- * 娑堟伅澶勭悊
- */
- @Override
- 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));
- //鏍规嵁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+"鏁版嵁");
- }
- }
- }
-// //瀛樺叆闆嗗悎
-// 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);
- }
- }
-
- /**
- * mqtt杩炴帴鍚庤闃呬富棰�
- */
- @Override
- public void connectComplete(boolean b, String s) {
- try {
- if (null != topic) {
- if (client.isConnected()) {
- client.subscribe(topic, qos);
-// log.info("杞﹁締鐢电閿乵qtt杩炴帴鎴愬姛" );
-// log.info("--杞﹁締鐢电閿佽闃呬富棰�:锛�" + topic);
- } else {
- log.info("杞﹁締鐢电閿乵qtt杩炴帴澶辫触");
- }
- }
- } catch (Exception e) {
- log.info("杞﹁締鐢电閿乵qtt璁㈤槄涓婚寮傚父:" + e);
- }
- }
-}
-
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
new file mode 100644
index 0000000..455d8a1
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/AutoMqtt.java
@@ -0,0 +1,38 @@
+package com.ruoyi.utils.qymqtt;
+
+import com.ruoyi.sy.domain.ArdSyCarRtu;
+import com.ruoyi.sy.service.ArdSyCarRtuService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+
+@Slf4j
+@Component
+public class AutoMqtt {
+
+ @Autowired
+ private ArdSyCarRtuService ardSyCarRtuService;
+
+ @PostConstruct
+ public void init() {
+// ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
+// //鑾峰彇鐢电閿佸湴鍧�
+// String mqttUrl = carRtuService.url("ElectromagneticLockUrl");
+ List<ArdSyCarRtu> rtus = ardSyCarRtuService.allCarTopicList();
+ for (int i = 0; i < rtus.size(); i++) {
+ ArdSyCarRtu rtu = rtus.get(i);
+ String carId = rtu.getCarId();
+ String subscribe = rtu.getTopicSubscribe();
+ try {
+ MqttCustomerClient mqttCustomerClient = new MqttCustomerClient();
+ mqttCustomerClient.connect(carId+"mqtt");
+ mqttCustomerClient.subscribe(subscribe);
+ }catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/MqttCustomerClient.java b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/MqttCustomerClient.java
new file mode 100644
index 0000000..6a6940d
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/MqttCustomerClient.java
@@ -0,0 +1,141 @@
+package com.ruoyi.utils.qymqtt;
+
+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;
+
+/**
+ * mqtt瀹㈡埛绔�
+ */
+@Slf4j
+@Component
+public class MqttCustomerClient {
+
+ private static MqttClient client;
+
+ private static MqttConnectOptions options;
+
+ private PushCallback pushCallback;
+
+ public static MqttClient getClient(){
+ return client;
+ }
+
+ public static void setClient(MqttClient client){
+ MqttCustomerClient.client=client;
+ }
+
+ public static MqttConnectOptions getOptions() {
+ return options;
+ }
+
+ public static void setOptions(MqttConnectOptions options) {
+ MqttCustomerClient.options = options;
+ }
+
+ /**
+ * 瀹㈡埛绔繛鎺�
+ *
+ * @param clientID 瀹㈡埛绔疘d
+ */
+ public void connect(String clientID){
+ MqttClient client;
+ try {
+ ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
+ //鑾峰彇鐢电閿佸湴鍧�
+ String mqttUrl = carRtuService.url("ElectromagneticLockUrl");
+ client=new MqttClient(mqttUrl,clientID,new MemoryPersistence());
+ MqttConnectOptions options = new MqttConnectOptions();
+ options.setCleanSession(true);
+ options.setUserName("admin");
+ options.setPassword("xzx12345".toCharArray());
+ options.setConnectionTimeout(100);
+ options.setKeepAliveInterval(60);
+ options.setAutomaticReconnect(true);
+ MqttCustomerClient.setClient(client);
+ MqttCustomerClient.setOptions(options);
+ try {
+ client.setCallback(new PushCallback());
+ client.connect(options);
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 鍙戝竷
+ * @param topic
+ * @param pushMessage
+ */
+ public void pushlish(String topic,String pushMessage) throws MqttException {
+ pushlish(2,false,topic,pushMessage);
+ }
+
+ /**
+ * 鍙戝竷
+ *
+ * @param qos 杩炴帴鏂瑰紡
+ * @param retained 鏄惁淇濈暀
+ * @param topic 涓婚
+ * @param pushMessage 娑堟伅浣�
+ */
+ public void pushlish(int qos,boolean retained,String topic,String pushMessage) throws MqttException {
+ MqttMessage message=new MqttMessage();
+ message.setQos(qos);
+ message.setRetained(retained);
+ message.setPayload(pushMessage.getBytes());
+ try{
+ client.publish(topic,message);
+ }catch (Exception e){
+ log.error(topic+"鍙戝竷澶辫触锛�");
+ }
+ client.disconnect();
+ }
+
+ /**
+ * 璁㈤槄鏌愪釜涓婚
+ * @param topic
+ */
+ public void subscribe(String topic){
+ log.info("寮�濮嬭闃呬富棰�" + topic);
+ subscribe(topic,2);
+ }
+
+ public void subscribe(String topic,int qos){
+ try {
+ MqttCustomerClient.getClient().subscribe(topic,qos);
+ }catch (MqttException e){
+ e.printStackTrace();
+ }
+ }
+
+ //鍙栨秷璁㈤槄
+ public void unSubscribe(String topicFilter){
+ try {
+ client.unsubscribe(topicFilter);
+ } catch (MqttException e) {
+ System.out.println("鍙栨秷璁㈤槄涓婚"+topicFilter+"澶辫触");
+ e.getMessage();
+ }
+ }
+
+ //鏂紑杩炴帴
+ @PreDestroy//璇ユ敞瑙e璞¢攢姣佸悗瑙﹀彂
+ public void disConnect(){
+ try {
+ client.disconnect();
+ } catch (MqttException e) {
+ System.out.println("鏂紑杩炴帴浜х敓寮傚父");
+ e.getMessage();
+ }
+ }
+}
diff --git a/ard-work/src/main/java/com/ruoyi/utils/qymqtt/PushCallback.java b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/PushCallback.java
new file mode 100644
index 0000000..465ca05
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/utils/qymqtt/PushCallback.java
@@ -0,0 +1,108 @@
+package com.ruoyi.utils.qymqtt;
+
+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.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.eclipse.paho.client.mqttv3.*;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+/**
+ * 娑堣垂鐩戝惉
+ */
+@Slf4j
+public class PushCallback implements MqttCallback {
+
+ private MqttClient client;
+
+ //娉ㄥ叆鐢靛瓙閿丅ean
+ ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
+ ArdSyCarLockService carLockService = SpringUtils.getBean(ArdSyCarLockService.class);
+
+// private MqttClient client;
+// private MqttConnectOptions options;
+// private String topic;
+// private int qos;
+
+// public PushCallback(MqttClient client, MqttConnectOptions options, String topic, int qos) {
+// this.client = client;
+// this.options = options;
+// this.topic = topic;
+// this.qos = qos;
+// }
+
+ @Override
+ public void connectionLost(Throwable throwable) {
+ if (client == null || !client.isConnected()) {
+ System.out.println("杩炴帴鏂紑锛屾鍦ㄩ噸杩�....");
+ }
+ }
+
+ @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);
+ }
+ }
+
+ @SneakyThrows
+ @Override
+ public void deliveryComplete(IMqttDeliveryToken token) {
+ System.out.println("deliveryComplete---------" + token.isComplete());
+ int messageId = token.getMessageId();
+ String[] topics = token.getTopics();
+// 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);
+ }
+}
+
--
Gitblit v1.9.3