From 9790a81eba8f0ffb88324c2dd92ad886d12fc910 Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期五, 10 十一月 2023 15:26:57 +0800
Subject: [PATCH] 清淤逻辑优化
---
ard-work/src/main/java/com/ruoyi/sy/service/ArdSyCarRtuService.java | 2
ard-work/src/main/java/com/ruoyi/utils/mqtt/MqttOnce.java | 27 ++++++--
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarLockController.java | 3 +
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java | 103 ++++++++++++++++++---------------
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarRtuServiceImpl.java | 9 --
5 files changed, 81 insertions(+), 63 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 bd1d29e..86c0509 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
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.sy.domain.ArdAccessFence;
import com.ruoyi.sy.domain.ArdSyCarLock;
import com.ruoyi.sy.domain.ArdSyCarRtu;
@@ -10,10 +11,12 @@
import com.ruoyi.sy.mapper.ArdAccessFenceMapper;
import com.ruoyi.sy.param.AddCarParam;
import com.ruoyi.sy.service.*;
+import com.ruoyi.sy.service.impl.ArdSyCarRtuServiceImpl;
import com.ruoyi.sy.vo.CarLockVo;
import com.ruoyi.sy.vo.CarVo;
import com.ruoyi.sy.vo.RtuVo;
import com.ruoyi.system.service.ISysConfigService;
+import com.ruoyi.utils.mqtt.MqttConsumer;
import com.ruoyi.utils.result.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 1dc9796..e726cf5 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
@@ -16,7 +16,9 @@
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.impl.*;
import com.ruoyi.utils.gps.GeoTools;
import com.ruoyi.utils.mqtt.MqttConsumer;
@@ -94,10 +96,18 @@
//瀹氫箟2缁寸┖闂�
Point2D.Double point = new Point2D.Double(Double.parseDouble(lng), Double.parseDouble(lat));
List<Point2D.Double> pts = new ArrayList<Point2D.Double>();
+ //娉ㄥ叆甯﹂攣杞﹁締Bean
+ ArdAccessFenceService ardAccessFenceService = SpringUtils.getBean(ArdAccessFenceService.class);
+ //娉ㄥ叆娌圭偣鍥存爮Bean
+ ArdOilWallService ardOilWallService = SpringUtils.getBean(ArdOilWallService.class);
+ //娉ㄥ叆鎶ヨ璁℃暟Bean
+ ArdAccessNumService accessNumService = SpringUtils.getBean(ArdAccessNumService.class);
+ //娉ㄥ叆鐢靛瓙閿丅ean
+ ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class);
//鏌ヨ瀹氫綅娌硅溅琛ㄤ腑鏄惁鏈夎杞﹁締
- ArdAccessFence ardAccessFence = SpringUtils.getBean(ArdAccessFenceService.class).queryAccess(carId);
+ ArdAccessFence ardAccessFence = ardAccessFenceService.queryAccess(carId);
//鏌ヨ鎵�鏈夎娌圭偣鍥存爮
- List<ArdOilWall> ardOilWalls = SpringUtils.getBean(ArdOilWallService.class).accessAll();
+ List<ArdOilWall> ardOilWalls = ardOilWallService.accessAll();
//濡傛灉娌℃湁璇存槑杞﹁締鏈繘鍏ヨ娌圭偣锛岄渶瑕佸尮閰嶆墍鏈夎娌圭偣鍥存爮
if(ardAccessFence==null){
//杞﹁締鏈繘鍏ヨ娌圭偣
@@ -125,17 +135,20 @@
ardAccessFence1.setCarModel(carModel);
ardAccessFence1.setIsWarning(0);
ardAccessFence1.setDrct(drct);
- ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).access(ardAccessFence1);
+ ardAccessFence1.setIsAlarm(0);
+ ardAccessFenceService.access(ardAccessFence1);
break;
}
}
}else {
- //鍒ゆ柇鏄惁涓烘墜鍔ㄦ坊鍔犺溅杈�
- if(ardAccessFence.getIsAlarm()==0){
+ //甯﹂攣杞﹁締鏈夊�间紭鍏堝垽鏂槸鍚︿负鎵嬪姩娣诲姞杞﹁締
+ if(ardAccessFence.getIsAlarm()==1){
+ //1涓烘墜鍔ㄦ坊鍔犺溅杈嗘棤闇�鎶ヨ淇℃伅锛屾洿鏂颁綅缃嵆鍙�
ardAccessFence.setLng(lng);
ardAccessFence.setLat(lat);
- ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
- }else if(ardAccessFence.getIsAlarm() == 1){
+ ardAccessFenceService.updAccess(ardAccessFence);
+ }else if(ardAccessFence.getIsAlarm() == 2){
+ //2涓烘墜鍔ㄦ坊鍔犳姤璀﹁溅杈嗘湁鎶ヨ锛屾墍鍦ㄥ洿鏍忓悕绉拌祴null,鎺掓煡鎶ヨ淇℃伅,鍙渶澶勭悊璺笂鎯呭喌
ardAccessFence.setNowWallName(null);
//濡傛灉鍦ㄨ矾涓婂垽鏂潗鏍囨槸鍚︿笌涓婃涓�鏍�
if(ardAccessFence.getLng().equals(lng) && ardAccessFence.getLat().equals(lat)){
@@ -144,14 +157,15 @@
Date nowTime = sdf.parse(time);
Date lastTime = sdf.parse(ardAccessFence.getLastTime());
Long diff = (nowTime.getTime() - lastTime.getTime())/1000;
- ArdAccessNum list = ((ArdAccessNumServiceImpl) SpringUtils.getBean("ArdAccessNumServiceImpl")).queryNum();
+ ArdAccessNum list = accessNumService.queryNum();
if(list==null){
int alarm = list.getAlarm();
if(diff>=alarm){
+ //鎶ヨ瀛楁涓�1鎻愮ず鎶ヨ
ardAccessFence.setIsWarning(1);
ardAccessFence.setAlarmLat(lat);
ardAccessFence.setAlarmLng(lng);
- ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
+ ardAccessFenceService.updAccess(ardAccessFence);
}
}
}else {
@@ -159,13 +173,15 @@
ardAccessFence.setLat(lat);
ardAccessFence.setLng(lng);
ardAccessFence.setLastTime(time);
- ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
+ ardAccessFenceService.updAccess(ardAccessFence);
}
- }else {
- //濡傛灉杞﹁締鏈夋暟鎹垽鏂槸鍚︽湁杩涘叆鍥存爮ID锛屽鏋滄病鏈夋洿鏂版垨璧嬪�肩粡绾害锛屽垽鏂槸鍚﹁繘鍏ュ洿鏍�
+ }else if(ardAccessFence.getIsAlarm() == 0 || ardAccessFence.getIsAlarm() == null){
+ //杞﹁締闈炴墜鍔ㄦ坊鍔犳暟鎹紝鍒ゆ柇鏄惁鏈夎繘鍏ュ洿鏍廔D
if(ardAccessFence.getIntoShipmentId()==null){
+ //娌℃湁杩涘叆瑁呮补鐐癸紝璧嬪�肩粡绾害
ardAccessFence.setLng(lng);
ardAccessFence.setLat(lat);
+ //鍒ゆ柇鏄惁杩涘叆瑁呮补鐐瑰洿鏍�
for (int i = 0; i < ardOilWalls.size(); i++) {
pts.clear();
ArdOilWall ardOilWall = ardOilWalls.get(i);
@@ -182,13 +198,15 @@
break;
}
}
+ ardAccessFenceService.updAccess(ardAccessFence);
}else {
//濡傛灉鏈夎繘鍏ュ洿鏍廔D锛屽垽鏂槸鍚﹀紑鍑鸿娌圭偣
String out = ardAccessFence.getOutShipmentId();
+ //鍑鸿娌圭偣ID涓虹┖
if(out == null){
- //杞﹁締鏈紑鍑鸿娌圭偣
+ //杞﹁締鏈紑鍑鸿娌圭偣,鍒ゆ柇鏄惁寮�鍑鸿娌圭偣
String into = ardAccessFence.getIntoShipmentId();
- ArdOilWall ardOilWall = SpringUtils.getBean(ArdOilWallService.class).one(into);
+ ArdOilWall ardOilWall = ardOilWallService.one(into);
pts.clear();
String[] coord = ardOilWall.getCoord().split(",");
for (int j = 0; j < coord.length; j = j + 3) {
@@ -200,17 +218,22 @@
ardAccessFence.setOutShipmentTime(time);
ardAccessFence.setNowWallName(ardOilWall.getName());
ardAccessFence.setLastTime(time);
+ ardAccessFence.setLng(lng);
+ ardAccessFence.setLat(lat);
+ ardAccessFenceService.updAccess(ardAccessFence);
+//寮�鍑鸿娌圭偣鍥存爮锛屽彂閫佷笂閿佸強鏂藉皝鍛戒护
+
+
+
+
}
- ardAccessFence.setLng(lng);
- ardAccessFence.setLat(lat);
- ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
}else {
- //杞﹁締宸茬粡寮�鍑鸿娌圭偣锛屽垽鏂槸鍚﹁繘鍏ュ嵏娌圭偣
+ //杞﹁締宸茬粡寮�鍑鸿娌圭偣锛屾煡鐪嬫槸鍚︽湁鍗告补鐐笽D
String unload = ardAccessFence.getIntoUnloadId();
//濡傛灉unload涓虹┖锛屽垽鏂槸鍚﹁繘鍏ュ嵏娌圭偣
if (unload == null) {
//杞﹁締鏈繘鍏ュ嵏娌圭偣
- List<ArdOilWall> ardOilWallUpload = ((ArdOilWallServiceImpl)SpringUtils.getBean("ArdOilWallServiceImpl")).uploadAll();
+ List<ArdOilWall> ardOilWallUpload = ardOilWallService.uploadAll();
//鏄惁鍦ㄨ矾涓�
Boolean isRoad = true;
//鍒ゆ柇鏄惁杩涘幓鍗告补鐐�
@@ -229,24 +252,15 @@
ardAccessFence.setLat(lat);
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+"鏃犻攣鐘舵��");
- }
+ ardAccessFenceService.updAccess(ardAccessFence);
//宸茬粡杩涘叆鍗告补鐐癸紝涓嶅湪璺笂涓嶉渶瑕佸仠杞︽姤璀�
isRoad = false;
break;
}
}
+ //涓嶅湪鍗告补鐐瑰氨鏄湪璺笂
if(isRoad){
+ //鎵�鍦ㄥ洿鏍忓悕绉拌祴null
ardAccessFence.setNowWallName(null);
//濡傛灉鍦ㄨ矾涓婂垽鏂潗鏍囨槸鍚︿笌涓婃涓�鏍�
if(ardAccessFence.getLng().equals(lng) && ardAccessFence.getLat().equals(lat)){
@@ -255,14 +269,14 @@
Date nowTime = sdf.parse(time);
Date lastTime = sdf.parse(ardAccessFence.getLastTime());
Long diff = (nowTime.getTime() - lastTime.getTime())/1000;
- ArdAccessNum list = ((ArdAccessNumServiceImpl) SpringUtils.getBean("ArdAccessNumServiceImpl")).queryNum();
+ ArdAccessNum list = accessNumService.queryNum();
if(list==null){
int alarm = list.getAlarm();
if(diff>=alarm){
ardAccessFence.setIsWarning(1);
ardAccessFence.setAlarmLat(lat);
ardAccessFence.setAlarmLng(lng);
- ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
+ ardAccessFenceService.updAccess(ardAccessFence);
}
}
}else {
@@ -270,35 +284,30 @@
ardAccessFence.setLat(lat);
ardAccessFence.setLng(lng);
ardAccessFence.setLastTime(time);
- ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
+ ardAccessFenceService.updAccess(ardAccessFence);
}
}
}else {
//杞﹁締宸茬粡杩涘叆鍗告补鐐癸紝鍒ゆ柇鏄惁宸茬粡寮�鍑哄嵏娌圭偣
- ArdOilWall ardOilWall = ((ArdOilWallServiceImpl) SpringUtils.getBean("ArdOilWallServiceImpl")).one(unload);
+ ArdOilWall ardOilWall = ardOilWallService.one(unload);
pts.clear();
String[] coord = ardOilWall.getCoord().split(",");
for (int j = 0; j < coord.length; j = j + 3) {
pts.add(new Point2D.Double(Double.parseDouble(coord[j]), Double.parseDouble(coord[j + 1])));
}
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);
+//寮�鍑轰簡鍗告补鐐瑰洿鏍忥紝鍙戦�佷笂閿佸強鏂借В灏佹寚浠�
+
+
+
+ //鍒犻櫎璇ユ潯杞﹁締鏁版嵁
+ ardAccessFenceService.delAccess(carId);
}else {
//鏈紑鍑哄嵏娌圭偣锛屾洿鏂扮粡绾害淇濆瓨
ardAccessFence.setLng(lng);
ardAccessFence.setLat(lat);
ardAccessFence.setLastTime(time);
- ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
+ ardAccessFenceService.updAccess(ardAccessFence);
}
}
}
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 f88c5da..0fd028f 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,7 @@
*/
public interface ArdSyCarRtuService {
- String[] allCarTopic();
+ List<ArdSyCarRtu> 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
index 3f2436f..8f94e14 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
@@ -22,13 +22,8 @@
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());
- }
- return list.toArray(new String[list.size()]);
+ public List<ArdSyCarRtu> allCarTopic() {
+ return ardSyCarRtuMapper.selectList(null);
}
@Override
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 e5e2825..b07a18b 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
@@ -3,11 +3,13 @@
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.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;
@@ -17,18 +19,27 @@
*/
@Slf4j
@Component
-public class MqttOnce implements CommandLineRunner {
+public class MqttOnce{
@Autowired
private ArdSyCarRtuService ardSyCarRtuService;
- @Override
- public void run(String... args) throws Exception {
- String[] topic = ardSyCarRtuService.allCarTopic();
- MqttConsumer mqttConsumer = new MqttConsumer();
- for (int i = 0; i < topic.length; i++) {
- mqttConsumer.subscribe(topic[i],2);
+ @Autowired
+ private ISysConfigService sysConfigService;
+
+ @PostConstruct
+ public void init() {
+ //鑾峰彇鐢电閿佸湴鍧�
+ String mqttUrl = sysConfigService.selectConfigByKey("ElectromagneticLockUrl");
+ List<ArdSyCarRtu> rtus = ardSyCarRtuService.allCarTopic();
+ for (int i = 0; i < rtus.size(); i++) {
+ ArdSyCarRtu rtu = rtus.get(i);
+ String publish = rtu.getTopicPublish();
}
- log.info("mqtt璁㈤槄娓呮筏杞﹁締閿佷俊鎭細"+Arrays.toString(topic));
+// MqttConsumer mqttConsumer = new MqttConsumer();
+// for (int i = 0; i < topic.length; i++) {
+// mqttConsumer.subscribe(topic[i],2);
+// }
+// log.info("mqtt璁㈤槄娓呮筏杞﹁締閿佷俊鎭細"+Arrays.toString(topic));
}
}
--
Gitblit v1.9.3