From f4e20b2dc544a188d0591c901022383e84fa8e9e Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期一, 13 十一月 2023 17:31:03 +0800
Subject: [PATCH] 清淤电磁锁
---
ard-work/src/main/java/com/ruoyi/sy/mapper/ArdSyCarLockMapper.java | 4
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarLockServiceImpl.java | 161 +++++++++++++++--
ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java | 72 +++++--
ard-work/src/main/resources/mapper/sy/ArdSyCarLockMapper.xml | 12 +
ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCarLock.java | 2
ard-work/src/main/java/com/ruoyi/sy/service/ArdAccessFenceService.java | 2
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarLockController.java | 16 +
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java | 164 ++++++++---------
ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarLockService.java | 9 +
ard-work/src/main/java/com/ruoyi/sy/param/LockTypeParam.java | 11 +
ard-work/src/main/java/com/ruoyi/sy/vo/WallCarVo.java | 13 +
ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnceCallback.java | 66 +++++-
12 files changed, 389 insertions(+), 143 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 ec3e0b4..87887bc 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
@@ -11,6 +11,7 @@
import com.ruoyi.sy.mapper.ArdAccessFenceMapper;
import com.ruoyi.sy.param.AddCarParam;
import com.ruoyi.sy.param.AddRtuParam;
+import com.ruoyi.sy.param.LockTypeParam;
import com.ruoyi.sy.service.*;
import com.ruoyi.sy.service.impl.ArdSyCarRtuServiceImpl;
import com.ruoyi.sy.vo.CarLockVo;
@@ -21,6 +22,7 @@
import com.ruoyi.utils.result.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
+import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -66,7 +68,7 @@
@PostMapping("/add")
@ApiOperation("娣诲姞rtu")
public AjaxResult add(@RequestBody AddRtuParam addRtuParam){
- return AjaxResult.success("鎴愬姛娣诲姞"+ardSyCarLockService.addRtu(addRtuParam)+"鏉℃暟鎹�");
+ return AjaxResult.success("鎴愬姛娣诲姞"+ardSyCarLockService.addRtu(addRtuParam)+"鏉℃暟鎹紝璁㈤槄杞﹁締"+addRtuParam.getCarId()+"鎴愬姛");
}
@DeleteMapping("/del")
@@ -183,10 +185,16 @@
return AjaxResult.success(ardAccessFenceService.updCarAlarm(id));
}
- @GetMapping("/openLock")
+ @GetMapping("/onOff")
@ApiOperation("杩滅▼寮�閿�")
- public AjaxResult openLock(String carId){
- return AjaxResult.success(ardSyCarRtuService.openLock(ardSyCarRtuService.one(carId)));
+ public AjaxResult onOff(@RequestBody LockTypeParam lockTypeParam) {
+ return AjaxResult.success(ardSyCarLockService.onOff(lockTypeParam));
+ }
+
+ @GetMapping("/seal")
+ @ApiOperation("杩滅▼灏佸嵃")
+ public AjaxResult seal(@RequestBody LockTypeParam lockTypeParam) {
+ return AjaxResult.success(ardSyCarLockService.seal(lockTypeParam));
}
diff --git a/ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCarLock.java b/ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCarLock.java
index 258acf5..fc42f6a 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCarLock.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCarLock.java
@@ -11,6 +11,6 @@
private String imgPositionLeft;
private String relay;
private String relayInfo;
- private String current;
+ private String currents;
private String currentInfo;
}
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 15f192c..d3faf70 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
@@ -15,17 +15,17 @@
import com.gps31.push.util.MapUtil;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.sy.domain.*;
-import com.ruoyi.sy.service.ArdAccessFenceService;
-import com.ruoyi.sy.service.ArdAccessNumService;
-import com.ruoyi.sy.service.ArdOilWallService;
-import com.ruoyi.sy.service.ArdSyCarRtuService;
+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 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.*;
@@ -104,6 +104,10 @@
ArdAccessNumService accessNumService = SpringUtils.getBean(ArdAccessNumService.class);
//娉ㄥ叆鐢靛瓙閿丅ean
ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
+ //娉ㄥ叆閿丅ean
+ ArdSyCarLockService lockService = SpringUtils.getBean(ArdSyCarLockService.class);
+ //鍒涘缓mqtt宸ュ叿绫诲璞�
+ MqttOnce mqttOnce = new MqttOnce();
//鏌ヨ瀹氫綅娌硅溅琛ㄤ腑鏄惁鏈夎杞﹁締
ArdAccessFence ardAccessFence = ardAccessFenceService.queryAccess(carId);
//鏌ヨ鎵�鏈夎娌圭偣鍥存爮
@@ -137,27 +141,8 @@
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)));
- }
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"瑁呮补鐐�",carRtuService,lockService,mqttOnce);
break;
}
}
@@ -216,27 +201,8 @@
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)));
- }
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"瑁呮补鐐�",carRtuService,lockService,mqttOnce);
break;
}
}
@@ -264,15 +230,7 @@
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)));
-
+ feng(carId,"鏂藉皝",carRtuService,lockService,mqttOnce);
}
}else {
//杞﹁締宸茬粡寮�鍑鸿娌圭偣锛屾煡鐪嬫槸鍚︽湁鍗告补鐐笽D
@@ -302,27 +260,8 @@
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)));
- }
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"鍗告补鐐�",carRtuService,lockService,mqttOnce);
break;
}
}
@@ -365,14 +304,7 @@
}
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)));
+ feng(carId,"鏂藉皝",carRtuService,lockService,mqttOnce);
//鍒犻櫎璇ユ潯杞﹁締鏁版嵁
ardAccessFenceService.delAccess(carId);
}else {
@@ -487,4 +419,68 @@
public void run() {
sendMassage();
}
+
+ private void feng(String carId,String type,ArdSyCarRtuService carRtuService,ArdSyCarLockService lockService,MqttOnce mqttOnce) throws MqttException {
+ //鏌ヨ瑁呮补鐐规棦瀹歊tu鐘舵��
+ ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId);
+ Integer fengType = null;
+ if("瑁呮补鐐�".equals(type)){
+ fengType = ardSyCarRtu.getInstallType();
+ }else if("鍗告补鐐�".equals(type)){
+ fengType = ardSyCarRtu.getUnloadType();
+ }else if("鏂藉皝".equals(type)){
+ fengType = 0;
+ }
+ //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皝");
+ }
+ //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();
+ String currentInfo = ardSyCarLock.getCurrentInfo();
+ //鐢垫祦鍊间负4.0鏄叧閿佺姸鎬�
+ if(currentInfo.equals(4.00)){
+ 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);
+ String currentInfo1 = ardSyCarLock1.getCurrentInfo();
+ if(currentInfo1.equals(4.00)){
+ 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)),"鏂藉皝");
+ }
+ }
+ }
+
}
diff --git a/ard-work/src/main/java/com/ruoyi/sy/mapper/ArdSyCarLockMapper.java b/ard-work/src/main/java/com/ruoyi/sy/mapper/ArdSyCarLockMapper.java
index 49ceb4f..f3a596a 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/mapper/ArdSyCarLockMapper.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/mapper/ArdSyCarLockMapper.java
@@ -3,5 +3,9 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.sy.domain.ArdSyCarLock;
+import java.util.List;
+
public interface ArdSyCarLockMapper extends BaseMapper<ArdSyCarLock> {
+
+ List<ArdSyCarLock> lockList(String rtuId);
}
diff --git a/ard-work/src/main/java/com/ruoyi/sy/param/LockTypeParam.java b/ard-work/src/main/java/com/ruoyi/sy/param/LockTypeParam.java
new file mode 100644
index 0000000..0e69512
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/sy/param/LockTypeParam.java
@@ -0,0 +1,11 @@
+package com.ruoyi.sy.param;
+
+import lombok.Data;
+
+@Data
+public class LockTypeParam {
+ private String carId;
+ private Integer type;
+ private String lockId;
+ private Integer num;
+}
diff --git a/ard-work/src/main/java/com/ruoyi/sy/service/ArdAccessFenceService.java b/ard-work/src/main/java/com/ruoyi/sy/service/ArdAccessFenceService.java
index 1c919ea..abd92c3 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/service/ArdAccessFenceService.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/service/ArdAccessFenceService.java
@@ -4,6 +4,7 @@
import com.ruoyi.sy.domain.ArdSyCar;
import com.ruoyi.sy.param.OilWallParam;
import com.ruoyi.sy.vo.CarVo;
+import com.ruoyi.sy.vo.WallCarVo;
import java.util.List;
@@ -19,6 +20,7 @@
List<ArdAccessFence> all(String url);
+
int delCar(String id);
int updCarAlarm(String id);
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 f953c42..c6d5243 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,13 @@
package com.ruoyi.sy.service;
+import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.sy.domain.ArdSyCarLock;
import com.ruoyi.sy.domain.ArdSyCarRtu;
import com.ruoyi.sy.param.AddRtuParam;
+import com.ruoyi.sy.param.LockTypeParam;
import com.ruoyi.sy.vo.CarVo;
import com.ruoyi.sy.vo.RtuVo;
+import org.eclipse.paho.client.mqttv3.MqttException;
import java.util.List;
@@ -41,4 +44,10 @@
int updLock(ArdSyCarLock ardSyCarLock);
+ ArdSyCarLock getCurrentInfo(String Rtu,String currents);
+
+ AjaxResult seal(LockTypeParam lockTypeParam);
+
+ AjaxResult onOff(LockTypeParam lockTypeParam);
+
}
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 d2ee258..0a39c98 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
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.sy.domain.ArdSyCar;
import com.ruoyi.sy.domain.ArdSyCarLock;
@@ -10,20 +11,24 @@
import com.ruoyi.sy.mapper.ArdSyCarMapper;
import com.ruoyi.sy.mapper.ArdSyCarRtuMapper;
import com.ruoyi.sy.param.AddRtuParam;
+import com.ruoyi.sy.param.LockTypeParam;
import com.ruoyi.sy.service.ArdSyCarLockService;
import com.ruoyi.sy.vo.CarVo;
import com.ruoyi.sy.vo.RtuVo;
import com.ruoyi.system.mapper.SysDeptMapper;
+import com.ruoyi.utils.mqtt.MqttOnce;
+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.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
+import java.text.DecimalFormat;
+import java.util.*;
/**
* @author Administrator
*/
+@Slf4j
@Service
public class ArdSyCarLockServiceImpl implements ArdSyCarLockService {
@@ -62,12 +67,15 @@
ardSyCarRtu.setTopicSubscribe("/p"+addRtuParam.getCarId()+"/set/");
ardSyCarRtu.setInstallType(addRtuParam.getInstallType());
ardSyCarRtu.setUnloadType(addRtuParam.getUnloadType());
- rtuMapper.insert(ardSyCarRtu);
+ int num = rtuMapper.insert(ardSyCarRtu);
QueryWrapper<ArdSyCar> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("car_id",addRtuParam.getCarId());
ArdSyCar ardSyCar = ardSyCarMapper.selectOne(queryWrapper);
ardSyCar.setReserved1(ardSyCarRtu.getId());
- return ardSyCarMapper.updateById(ardSyCar);
+ ardSyCarMapper.updateById(ardSyCar);
+ MqttOnce mqttOnce = new MqttOnce();
+ mqttOnce.subscribeCar(ardSyCarRtu);
+ return num;
}
@Override
@@ -109,15 +117,15 @@
@Override
public List<ArdSyCarLock> carLock(String rtu) {
- 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;
+// List<ArdSyCarLock> locks = new ArrayList<>();
+// try {
+// QueryWrapper<ArdSyCarLock> queryWrapper = new QueryWrapper<>();
+// queryWrapper.eq("rtu_id",rtu);
+// locks = lockMapper.selectList(queryWrapper);
+// }catch (Exception e){
+//
+// }
+ return lockMapper.lockList(rtu);
}
@Override
@@ -188,19 +196,21 @@
@Override
public List<ArdSyCarLock> data(String msg) {
+ String pattern = "0.00"; // 鎸囧畾淇濈暀涓や綅灏忔暟鐨勬牸寮�
+ DecimalFormat decimalFormat = new DecimalFormat(pattern); //
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")));
+ ardSyCarLock1.setCurrents("C01");
+ ardSyCarLock1.setCurrentInfo(decimalFormat.format(jsonObject.getDouble("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")));
+ ardSyCarLock2.setCurrents("C02");
+ ardSyCarLock2.setCurrentInfo(decimalFormat.format(jsonObject.getDouble("C02")));
lockList.add(ardSyCarLock2);
return lockList;
}
@@ -210,6 +220,121 @@
return lockMapper.updateById(ardSyCarLock);
}
+ @Override
+ public ArdSyCarLock getCurrentInfo(String Rtu, String currents) {
+ QueryWrapper<ArdSyCarLock> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("rtu_id",Rtu).eq("currents",currents);
+ return lockMapper.selectOne(queryWrapper);
+ }
+
+ @Override
+ public AjaxResult seal(LockTypeParam lockTypeParam) {
+ QueryWrapper<ArdSyCarRtu> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("carId",lockTypeParam.getCarId());
+ ArdSyCarRtu ardSyCarRtu = rtuMapper.selectOne(queryWrapper);
+ MqttOnce mqttOnce = new MqttOnce();
+ //1瑙e皝
+ if(lockTypeParam.getType()==1){
+ Map<String,Object> map = new HashMap<>();
+ map.put("A01", 110000);//瀵奸�氱涓�璺户鐢靛櫒
+ map.put("A02", 110000);//瀵奸�氱浜岃矾缁х數鍣�
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ try {
+ return AjaxResult.success(mqttOnce.publishCar(lockTypeParam.getCarId(),ardSyCarRtu.getTopicPublish(),String.valueOf(new com.alibaba.fastjson2.JSONObject(map)),"瑙e皝"));
+ } catch (MqttException e) {
+ log.debug("瑙e皝鎸囦护鍙戠敓澶辫触"+e);
+ }
+ }
+ //0鏂藉皝
+ if(lockTypeParam.getType()==0){
+ //閿佸紑鍏崇姸鎬�
+ int lockCloseNum = 0;
+ //鏌ヨ閿佷俊鎭�
+ List<ArdSyCarLock> ardSyCarLocks = carLock(ardSyCarRtu.getId());
+ for (int j = 0; j < ardSyCarLocks.size(); j++) {
+ ArdSyCarLock ardSyCarLock = ardSyCarLocks.get(j);
+ String currents = ardSyCarLock.getCurrents();
+ String currentInfo = ardSyCarLock.getCurrentInfo();
+ //鐢垫祦鍊间负4.0鏄叧閿佺姸鎬�
+ if(currentInfo.equals(4.00)){
+ 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()));
+ try {
+ 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);
+ String currentInfo1 = ardSyCarLock1.getCurrentInfo();
+ if(currentInfo1.equals(4.00)){
+ 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()));
+ try {
+ return AjaxResult.success(mqttOnce.publishCar(lockTypeParam.getCarId(),ardSyCarRtu.getTopicPublish(),String.valueOf(new com.alibaba.fastjson2.JSONObject(map)),"鏂藉皝"));
+ } catch (MqttException e) {
+ log.debug("鏂藉皝鎸囦护鍙戠敓澶辫触"+e);
+ }
+ }
+ }
+ return AjaxResult.success();
+ }
+
+ @Override
+ public AjaxResult onOff(LockTypeParam lockTypeParam) {
+ QueryWrapper<ArdSyCarRtu> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("car_id",lockTypeParam.getCarId());
+ ArdSyCarRtu ardSyCarRtu = rtuMapper.selectOne(queryWrapper);
+ ArdSyCarLock ardSyCarLock = lockMapper.selectById(lockTypeParam.getLockId());
+ String relay = ardSyCarLock.getRelayInfo();
+ if(relay.equals("1")){
+ AjaxResult.error(0,"璇ラ攣澶勪簬瑙e皝鐘舵��,杩滅▼鏃犳硶鎿嶆帶,璇峰厛鎵ц鏂藉皝鎿嶄綔!");
+ }
+ String key = "";
+ String currentInfo = ardSyCarLock.getCurrentInfo();
+ if(currentInfo.equals("C01")){
+ key = "D03";
+ }else if(currentInfo.equals("C02")){
+ key = "D04";
+ }
+ Number lockState = (Number) lockTypeParam.getNum();
+ if(lockState.equals(100)){
+ lockState = 99.99;
+ }else if(lockState.equals(0)){
+ lockState = 0.01;
+ }else{
+ lockState = lockState.doubleValue() + 0.01;
+ }
+ Map<String,Object> map = new HashMap();
+ map.put(key, lockState);//鑼冨洿鏄�0.01鍒�99.99
+ map.put("res", String.valueOf(System.currentTimeMillis()));
+ MqttOnce mqttOnce = new MqttOnce();
+ try {
+ return AjaxResult.success(mqttOnce.publishCar("carId",ardSyCarRtu.getTopicPublish(),String.valueOf(new com.alibaba.fastjson2.JSONObject(map)),"寮�鍏抽攣鎸囦护"+lockState));
+ } catch (MqttException e) {
+ log.debug("寮�鍏抽攣鎸囦护鍙戦�佸け璐�"+e);
+ }
+ return AjaxResult.success();
+ }
+
//杞﹁締鍒楄〃灏佽
public List<CarVo> carAnalysis(List<ArdSyCar> ardSyCars){
diff --git a/ard-work/src/main/java/com/ruoyi/sy/vo/WallCarVo.java b/ard-work/src/main/java/com/ruoyi/sy/vo/WallCarVo.java
new file mode 100644
index 0000000..5725b6c
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/sy/vo/WallCarVo.java
@@ -0,0 +1,13 @@
+package com.ruoyi.sy.vo;
+
+import com.ruoyi.sy.domain.ArdAccessFence;
+import com.ruoyi.sy.domain.ArdSyCarLock;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class WallCarVo {
+ private ArdAccessFence ardAccessFence;
+ private List<ArdSyCarLock> lock;
+}
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 3b88ad2..70d9196 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,29 +29,16 @@
@Autowired
private ISysConfigService sysConfigService;
- @PostConstruct
+// @PostConstruct
public void init() {
- //鑾峰彇鐢电閿佸湴鍧�
- String mqttUrl = sysConfigService.selectConfigByKey("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 {
- MqttClient client = new MqttClient(mqttUrl,carId);
-// log.debug("--鍒涘缓"+carId+"鍙疯溅杈嗙數瀛愰攣mqtt瀹㈡埛绔�");
- 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閰嶇疆瀵硅薄");
+ MqttClient client = getMqttClient(carId);
+ MqttConnectOptions options = getMqttConnectOptions();
client.setCallback(new MqttOnceCallback(client,options,subscribe,2));
// log.debug("--娣诲姞杞﹁締鐢电閿佸洖璋冨鐞嗙被");
client.connect(options);
@@ -59,10 +46,53 @@
e.printStackTrace();
}
}
-// MqttConsumer mqttConsumer = new MqttConsumer();
-// for (int i = 0; i < topic.length; i++) {
-// mqttConsumer.subscribe(topic[i],2);
-// }
-// log.info("mqtt璁㈤槄娓呮筏杞﹁締閿佷俊鎭細"+Arrays.toString(topic));
}
+
+ 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 {
+ //鑾峰彇鐢电閿佸湴鍧�
+ String mqttUrl = sysConfigService.selectConfigByKey("ElectromagneticLockUrl");
+ MqttClient client = new MqttClient(mqttUrl,carId);
+ //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();
+ MqttMessage msg = new MqttMessage(message.getBytes());
+ msg.setQos(2);
+ client.publish(topic,msg);
+ client.disconnect();
+ return "鍙戝竷"+type+"鎸囦护鎴愬姛锛�";
+ }
+
}
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 d89ef67..e469e7f 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
@@ -79,24 +79,60 @@
// 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());
+ //鏍规嵁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();
+ String relayInfo = ardSyCarLockData.getRelayInfo();
+ String current = ardSyCarLockData.getCurrents();
+ String currentInfo = ardSyCarLockData.getCurrentInfo();
+ for (int j = 0; j < ardSyCarLockList.size(); j++) {
+ ArdSyCarLock lock = ardSyCarLockList.get(j);
+ String relay1 = lock.getRelay();
+ String current1 = lock.getCurrents();
+ String relayInfo1 = lock.getRelayInfo();
+ String currentInfo1 = lock.getCurrentInfo();
+ Boolean upd = false;
+ if(relay.equals(relay1)){
+ if(!relayInfo.equals(relayInfo1)){
+ lock.setRelayInfo(relayInfo);
+ upd = true;
+ }
}
- Map<String,List<ArdSyCarLock>> newMap = new HashMap<>();
- newMap.put("topic",ardSyCarLocks);
- PositionContainer.setTopicSubscribe(newMap);
+ if(current.equals(current1)){
+ if(!currentInfo.equals(currentInfo1)){
+ lock.setCurrentInfo(currentInfo);
+ upd = true;
+ }
+ }
+ if(upd){
+ int num = carLockService.updLock(lock);
+// log.debug("淇敼"+num+"鏁版嵁");
+ }
}
}
- log.debug(String.valueOf(map));
+// //瀛樺叆闆嗗悎
+// 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);
}
diff --git a/ard-work/src/main/resources/mapper/sy/ArdSyCarLockMapper.xml b/ard-work/src/main/resources/mapper/sy/ArdSyCarLockMapper.xml
new file mode 100644
index 0000000..b91c775
--- /dev/null
+++ b/ard-work/src/main/resources/mapper/sy/ArdSyCarLockMapper.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.sy.mapper.ArdSyCarLockMapper">
+
+ <select id="lockList" parameterType="String" resultType="com.ruoyi.sy.domain.ArdSyCarLock">
+ SELECT id,currents,rtu_id,current_info,relay,img_position_left,img_position_top,relay_info,lock_name FROM ard_sy_car_lock
+ WHERE rtu_id = #{rtuId}
+ </select>
+
+</mapper>
\ No newline at end of file
--
Gitblit v1.9.3