From 0771b90c0e49714e1682dc133d1bebafb545dd5a Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期六, 02 三月 2024 19:45:12 +0800
Subject: [PATCH] app无人机航线管理提交
---
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java | 515 ++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 437 insertions(+), 78 deletions(-)
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 04f03c5..bf31f63 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
@@ -13,15 +13,21 @@
import com.gps31.push.netty.client.TcpClient;
import com.gps31.push.util.MapUtil;
import com.ruoyi.common.utils.spring.SpringUtils;
-import com.ruoyi.sy.domain.ArdAccessFence;
-import com.ruoyi.sy.domain.ArdOilWall;
-import com.ruoyi.sy.domain.ArdSyCarLock;
+import com.ruoyi.sy.domain.*;
+import com.ruoyi.sy.service.*;
import com.ruoyi.sy.service.impl.*;
import com.ruoyi.utils.gps.GeoTools;
+import com.ruoyi.utils.qymqtt.newM.EmqClient;
+import com.ruoyi.utils.qymqtt.newM.QosEnum;
+import com.ruoyi.utils.qymqtt.oldM.MqttCustomerClient;
+import lombok.extern.slf4j.Slf4j;
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.*;
/**
@@ -31,9 +37,10 @@
* @author chencq
* @version 1.0
*/
+@Slf4j(topic = "mqttCar")
public class PushClientImplPosition extends PushClient implements Runnable {
- private static final Log log = LogFactory.getLog(PushClientImplPosition.class);
+// private static final Log log = LogFactory.getLog(PushClientImplPosition.class);
private String ip;
@@ -74,101 +81,300 @@
/*String carName = MapUtil.getStrVal(gpsMap, "carName","");//鑾峰彇杞︾墝鍙�
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.format(new Date()));*/
-// log.error(String.format(" ---->鏀跺埌瀹氫綅鏁版嵁:%s",JSON.toJSONString(gpsMap)));
+ log.debug(String.format(" ---->----鏀跺埌瀹氫綅鏁版嵁濡備笅:%s",JSON.toJSONString(gpsMap)));
String carId = (String)gpsMap.get("carId");
((ArdSyCarDayServiceImpl)SpringUtils.getBean("ardSyCarDayServiceImpl")).insertArdSyCarDay(carId);//鏂板杞﹁締涓婃姤鏃堕棿
Map<String,Object> result = ((ArdSyCarServiceImpl)SpringUtils.getBean("ardSyCarServiceImpl")).getArdSyCarAndDeptByCarId(carId);//鏌ヨ杞﹁締鍙婇儴闂�
if(result != null){
- //娓呮筏鍏ユ爮寮�濮�----------
- String lng = (String) gpsMap.get("lng");//鑾峰彇缁忓害
- String lat = (String) gpsMap.get("lat");//鑾峰彇绾害
- String carName = (String) gpsMap.get("carName");//鑾峰彇杞︾墝鍙�
- String time = (String) gpsMap.get("result");//瀹氫綅鏃堕棿
- String deptNum = (String) result.get("deptId");//鑾峰彇閮ㄩ棬ID
- String deptName = (String) result.get("deptName");//鑾峰彇閮ㄩ棬鍚嶇О
-// String carId = "13";
-// String lng = "124.74695492384757";
-// String lat = "46.09510768522894";
-// String carName = "榛慐21397";//鑾峰彇杞︾墝鍙�
-// String time = "20231019161815";//瀹氫綅鏃堕棿
-// String deptNum = "100";//鑾峰彇閮ㄩ棬ID
-// String deptName = "鍘傜骇";//鑾峰彇閮ㄩ棬鍚嶇О
- //瀹氫箟2缁寸┖闂�
- Point2D.Double point = new Point2D.Double(Double.parseDouble(lng), Double.parseDouble(lat));
- List<Point2D.Double> pts = new ArrayList<Point2D.Double>();
- //鏌ヨ瀹氫綅娌硅溅琛ㄤ腑鏄惁鏈夎杞﹁締
- ArdAccessFence ardAccessFence = ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).queryAccess(carId);
- //濡傛灉娌℃湁璇存槑杞﹁締鏈繘鍏ヨ娌圭偣锛岄渶瑕佸尮閰嶆墍鏈夎娌圭偣鍥存爮
- if(ardAccessFence==null){
- //鍖归厤鍏ㄩ儴瑁呮补鐐瑰洿鏍�
- List<ArdOilWall> ardOilWalls = ((ArdOilWallServiceImpl)SpringUtils.getBean("ArdOilWallServiceImpl")).accessAll();
- for (int i = 0; i < ardOilWalls.size(); i++) {
- pts.clear();
- ArdOilWall ardOilWall = ardOilWalls.get(i);
- 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)){
- //杩涘叆浜嗗洿鏍忓叆搴�
- ArdAccessFence ardAccessFence1 = new ArdAccessFence();
- ardAccessFence1.setId(String.valueOf(UUID.randomUUID()));
- ardAccessFence1.setCarId(carId);
- ardAccessFence1.setCarName(carName);
- ardAccessFence1.setDeptId(deptNum);
- ardAccessFence1.setDeptName(deptName);
- ardAccessFence1.setIntoShipment("杩涘叆瑁呮补鐐�");
- ardAccessFence1.setIntoShipmentTime(time);
- ardAccessFence1.setLng(lng);
- ardAccessFence1.setLat(lat);
- ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).access(ardAccessFence1);
- break;
- }
+ //娓呮筏寮�濮�----------
+ try{
+ String lng = (String) gpsMap.get("lng").toString();//鑾峰彇缁忓害
+ String lat = (String) gpsMap.get("lat").toString();//鑾峰彇绾害
+ String carName = (String) gpsMap.get("carName");//鑾峰彇杞︾墝鍙�
+ String time = (String) gpsMap.get("time");//瀹氫綅鏃堕棿
+ //鏃堕棿鐘舵��
+ Boolean timeType = true;
+ if(time==null || time == ""){
+ timeType = false;
}
- }else {
- String unload = ardAccessFence.getIntoUnloadId();
- //濡傛灉unload涓虹┖锛屽垽鏂槸鍚﹁繘鍏ュ嵏娌圭偣
- if(unload==null){
- //鏌ヨ鍏ㄩ儴鍗告补鐐�
- List<ArdOilWall> ardOilWalls = ((ArdOilWallServiceImpl) SpringUtils.getBean("ArdOilWallServiceImpl")).uploadAll();
+ String deptNum = (String) result.get("deptId").toString();//鑾峰彇閮ㄩ棬ID
+ String deptName = (String) result.get("deptName");//鑾峰彇閮ㄩ棬鍚嶇О
+ String carModel = (String) result.get("carModel");//鑾峰彇杞﹁締妯″瀷
+ Integer drct = (Integer) gpsMap.get("drct");//鑾峰彇杞﹁締妯″瀷
+ Integer speed = (Integer) gpsMap.get("speed");//杞﹂��
+ String reserved = (String) result.get("reserved_1");//rtu鍏宠仈
+ //rtu鏍囪瘑
+ boolean rtuType = true;
+ if(reserved==null || reserved==""){
+ //鏃犻攣
+ rtuType = false;
+ }
+ // log.debug("瀹氫綅鏁版嵁锛氳溅杈哻arId:"+carId+"缁忓害lng:"+lng+"绾害lat:"+lat);
+ //瀹氫箟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);
+ //娉ㄥ叆閿丅ean
+ ArdSyCarLockService lockService = SpringUtils.getBean(ArdSyCarLockService.class);
+ //鏌ヨ瀹氫綅娌硅溅琛ㄤ腑鏄惁鏈夎杞﹁締
+ ArdAccessFence ardAccessFence = ardAccessFenceService.queryAccess(carId);
+ //鏌ヨ鎵�鏈夎娌圭偣鍥存爮
+ List<ArdOilWall> ardOilWalls = ardOilWallService.accessAll();
+ //鏃ユ湡鏍煎紡
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+ //濡傛灉娌℃湁璇存槑杞﹁締鏈繘鍏ヨ娌圭偣锛岄渶瑕佸尮閰嶆墍鏈夎娌圭偣鍥存爮
+ if(ardAccessFence==null){
+ //杞﹁締鏈繘鍏ヨ娌圭偣
for (int i = 0; i < ardOilWalls.size(); i++) {
pts.clear();
ArdOilWall ardOilWall = ardOilWalls.get(i);
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])));
+ pts.add(new Point2D.Double(Double.parseDouble(coord[j]), Double.parseDouble(coord[j+1])));
}
- if (GeoTools.IsPtInPoly(point, pts)) {
- //杩涘叆鍗告补鐐�,瀛樺叆鍗告补鐐瑰洿鏍廔D
- ardAccessFence.setIntoUnloadId(ardOilWall.getId());
- ardAccessFence.setIntoUnloadTime(time);
- break;
+ if(GeoTools.IsPtInPoly(point, pts)){
+ //杩涘叆瑁呮补鐐瑰叆搴�
+ ArdAccessFence ardAccessFence1 = new ArdAccessFence();
+ ardAccessFence1.setId(String.valueOf(UUID.randomUUID()));
+ ardAccessFence1.setCarId(carId);
+ ardAccessFence1.setCarName(carName);
+ ardAccessFence1.setDeptId(deptNum);
+ ardAccessFence1.setDeptName(deptName);
+ ardAccessFence1.setIntoShipmentId(ardOilWall.getId());
+ ardAccessFence1.setIntoShipmentTime(time);
+ ardAccessFence1.setLng(lng);
+ ardAccessFence1.setLat(lat);
+ ardAccessFence1.setLastTime(time);
+ ardAccessFence1.setNowWallName("杩涘叆瑁呮补鐐癸細"+ardOilWall.getName());
+ ardAccessFence1.setCarModel(carModel);
+ ardAccessFence1.setIsWarning(0);
+ ardAccessFence1.setDrct(drct);
+ ardAccessFence1.setIsAlarm(0);
+ ardAccessFenceService.access(ardAccessFence1);
+ if(rtuType){
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"瑁呮补鐐�",carRtuService,lockService);
+ break;
+ }
}
}
- ardAccessFence.setLng(lng);
- ardAccessFence.setLat(lat);
- ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
}else {
- //濡傛灉unload鏈夊�硷紝鍒欑户缁垽鏂槸鍚﹀嚭浜嗗嵏娌圭偣锛屽尮閰嶅嵏娌圭偣鐨勫敮涓�ID
- ArdOilWall ardOilWall = ((ArdOilWallServiceImpl) SpringUtils.getBean("ArdOilWallServiceImpl")).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])));
+ //杞﹂�熸爣璁�
+ Boolean stop = true;
+ //鍒ゆ柇杞﹂��
+ if(rtuType){
+ if(speed>5){
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"鏂藉皝",carRtuService,lockService);
+ stop = false;
+ }
}
- if (!GeoTools.IsPtInPoly(point, pts)) {
- //寮�鍑轰簡鍗告补鐐瑰洿鏍忥紝鍒犻櫎璇ユ潯杞﹁締鏁版嵁
- ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).delAccess(carId);
- }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);
+ 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)){
+ //杩涘叆瑁呮补鐐瑰叆搴�
+ ardAccessFence.setIntoShipmentId(ardOilWall.getId());
+ ardAccessFence.setIntoShipmentTime(time);
+ ardAccessFence.setNowWallName("杩涘叆瑁呮补鐐癸細"+ardOilWall.getName());
+ ardAccessFence.setLastTime(time);
+ if(rtuType){
+ if(stop){
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"瑁呮补鐐�",carRtuService,lockService);
+ }
+ }
+ break;
+ }
+ }
+ ardAccessFenceService.updAccess(ardAccessFence);
+ }else {
+ //濡傛灉鏈夎繘鍏ュ洿鏍廔D锛屽垽鏂槸鍚﹀紑鍑鸿娌圭偣
+ String out = ardAccessFence.getOutShipmentId();
+ //鍑鸿娌圭偣ID涓虹┖
+ if(out == null){
+ //杞﹁締鏈紑鍑鸿娌圭偣,鍒ゆ柇鏄惁寮�鍑鸿娌圭偣
+ String into = ardAccessFence.getIntoShipmentId();
+ ArdOilWall ardOilWall = ardOilWallService.one(into);
+ 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)) {
+ //杞﹁締寮�鍑鸿娌圭偣
+ ardAccessFence.setOutShipmentId(into);
+ ardAccessFence.setOutShipmentTime(time);
+ ardAccessFence.setNowWallName("寮�鍑鸿娌圭偣锛�"+ardOilWall.getName());
+ ardAccessFence.setLastTime(time);
+ ardAccessFence.setLng(lng);
+ ardAccessFence.setLat(lat);
+ ardAccessFenceService.updAccess(ardAccessFence);
+ if(rtuType){
+ //寮�鍑鸿娌圭偣鍥存爮锛屽彂閫佷笂閿佸強鏂藉皝鍛戒护
+ feng(carId,"鏂藉皝",carRtuService,lockService);
+ }
+ }
+ }else {
+ //杞﹁締宸茬粡寮�鍑鸿娌圭偣锛屾煡鐪嬫槸鍚︽湁鍗告补鐐笽D
+ String unload = ardAccessFence.getIntoUnloadId();
+ //濡傛灉unload涓虹┖锛屽垽鏂槸鍚﹁繘鍏ュ嵏娌圭偣
+ if (unload == null) {
+ //杞﹁締鏈繘鍏ュ嵏娌圭偣
+ List<ArdOilWall> ardOilWallUpload = ardOilWallService.uploadAll();
+ //鏄惁鍦ㄨ矾涓�
+ Boolean isRoad = true;
+ //鍒ゆ柇鏄惁杩涘幓鍗告补鐐�
+ for (int i = 0; i < ardOilWallUpload.size(); i++) {
+ pts.clear();
+ ArdOilWall ardOilWall = ardOilWallUpload.get(i);
+ 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)) {
+ //杩涘叆鍗告补鐐�,瀛樺叆鍗告补鐐瑰洿鏍廔D
+ ardAccessFence.setIntoUnloadId(ardOilWall.getId());
+ ardAccessFence.setIntoUnloadTime(time);
+ ardAccessFence.setLng(lng);
+ ardAccessFence.setLat(lat);
+ ardAccessFence.setNowWallName("杩涘叆鍗告补鐐癸細"+ardOilWall.getName());
+ ardAccessFence.setLastTime(time);
+ ardAccessFenceService.updAccess(ardAccessFence);
+ //宸茬粡杩涘叆鍗告补鐐癸紝涓嶅湪璺笂涓嶉渶瑕佸仠杞︽姤璀�
+ isRoad = false;
+ if(rtuType){
+ if(stop){
+ //mqtt鍙戦�佹棦瀹歊tu鐘舵��
+ feng(carId,"鍗告补鐐�",carRtuService,lockService);
+ }
+ }
+ break;
+ }
+ }
+ //涓嶅湪鍗告补鐐瑰氨鏄湪璺笂
+ if(isRoad){
+ //鎵�鍦ㄥ洿鏍忓悕绉拌祴null
+ ardAccessFence.setNowWallName("鍦ㄨ矾涓�");
+ //濡傛灉鍦ㄨ矾涓婂垽鏂潗鏍囨槸鍚︿笌涓婃涓�鏍�
+ if(ardAccessFence.getLng().equals(lng) && ardAccessFence.getLat().equals(lat)){
+ if(ardAccessFence.getLastTime()!=null){
+ if(timeType){
+ //濡傛灉鍧愭爣涓�鏍风浉鍑�
+ Date nowTime = sdf.parse(time);
+ Date lastTime = sdf.parse(ardAccessFence.getLastTime());
+ Long diff = (nowTime.getTime() - lastTime.getTime())/1000;
+ ArdAccessNum list = accessNumService.queryNum();
+ if(list!=null){
+ int alarm = list.getAlarm();
+ if(diff>=alarm){
+ ardAccessFence.setIsWarning(1);
+ ardAccessFence.setAlarmLat(lat);
+ ardAccessFence.setAlarmLng(lng);
+ ardAccessFenceService.updAccess(ardAccessFence);
+ }
+ }
+ }else {
+ log.debug(carId+"鍙疯溅瀹氫綅鏃堕棿涓虹┖");
+ }
+ }else {
+ ardAccessFence.setLastTime(time);
+ ardAccessFenceService.updAccess(ardAccessFence);
+ }
+ }else {
+ //濡傛灉涓嶄竴鏍锋洿鏂板潗鏍�
+ ardAccessFence.setLat(lat);
+ ardAccessFence.setLng(lng);
+ ardAccessFence.setLastTime(time);
+ ardAccessFenceService.updAccess(ardAccessFence);
+ }
+ }
+ }else {
+ //杞﹁締宸茬粡杩涘叆鍗告补鐐癸紝鍒ゆ柇鏄惁宸茬粡寮�鍑哄嵏娌圭偣
+ 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)) {
+ if(rtuType){
+ //寮�鍑轰簡鍗告补鐐瑰洿鏍忥紝鍙戦�佷笂閿佸強鏂借В灏佹寚浠�
+ feng(carId,"鏂藉皝",carRtuService,lockService);
+ }
+ //鍒犻櫎璇ユ潯杞﹁締鏁版嵁
+ ardAccessFenceService.delAccess(carId);
+ }else {
+ //鏈紑鍑哄嵏娌圭偣锛屾洿鏂扮粡绾害淇濆瓨
+ ardAccessFence.setLng(lng);
+ ardAccessFence.setLat(lat);
+ ardAccessFence.setLastTime(time);
+ ardAccessFenceService.updAccess(ardAccessFence);
+ }
+ }
+ }
+ }
+ }else
+ if(ardAccessFence.getIsAlarm()==1){
+ //1涓烘墜鍔ㄦ坊鍔犺溅杈嗘棤闇�鎶ヨ淇℃伅锛屾洿鏂颁綅缃嵆鍙�
ardAccessFence.setLng(lng);
ardAccessFence.setLat(lat);
- ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
+ ardAccessFenceService.updAccess(ardAccessFence);
+ }else if(ardAccessFence.getIsAlarm() == 2){
+ //2涓烘墜鍔ㄦ坊鍔犳姤璀﹁溅杈嗘湁鎶ヨ锛屾墍鍦ㄥ洿鏍忓悕绉拌祴null,鎺掓煡鎶ヨ淇℃伅,鍙渶澶勭悊璺笂鎯呭喌
+ ardAccessFence.setNowWallName(null);
+ //濡傛灉鍦ㄨ矾涓婂垽鏂潗鏍囨槸鍚︿笌涓婃涓�鏍�
+ if(ardAccessFence.getLng().equals(lng) && ardAccessFence.getLat().equals(lat)){
+ if(timeType){
+ Date nowTime = sdf.parse(time);
+ Date lastTime = sdf.parse(ardAccessFence.getLastTime());
+ Long diff = (nowTime.getTime() - lastTime.getTime())/1000;
+ ArdAccessNum list = accessNumService.queryNum();
+ if(list!=null){
+ int alarm = list.getAlarm();
+ if(diff>=alarm){
+ //鎶ヨ瀛楁涓�1鎻愮ず鎶ヨ
+ ardAccessFence.setIsWarning(1);
+ ardAccessFence.setAlarmLat(lat);
+ ardAccessFence.setAlarmLng(lng);
+ ardAccessFenceService.updAccess(ardAccessFence);
+ }
+ }
+ }else {
+ log.debug(carId+"鍙疯溅瀹氫綅鏃堕棿涓虹┖");
+ }
+ }else {
+ //濡傛灉涓嶄竴鏍锋洿鏂板潗鏍�
+ ardAccessFence.setLat(lat);
+ ardAccessFence.setLng(lng);
+ ardAccessFence.setLastTime(time);
+ ardAccessFenceService.updAccess(ardAccessFence);
+ }
}
}
+ //娓呮筏缁撴潫------------
+ }catch(Exception e){
}
- //娓呮筏鍏ユ爮缁撴潫------------
gpsMap.putAll(result);
String ancestors = (String) gpsMap.get("ancestors");//鑾峰彇鐖剁骇閮ㄩ棬
@@ -207,6 +413,30 @@
}
}
}
+ //鑻ユ湁鐢ㄦ埛闇�瑕佽拷韪溅杈嗭紝鍒欒绠楅浼颁綅缃�
+ if(PositionContainer.getUserPositionMap().size() != 0){
+ for(String userId : PositionContainer.getUserPositionMap().keySet()){
+ Map<String,Map<String,Object>> carIdCarMap = PositionContainer.getUserPositionMap().get(userId);
+ if(carIdCarMap != null){
+ if(carIdCarMap.keySet().contains(carId)){
+ if(PositionContainer.getCarPositionMap().get(carId) == null){
+ gpsMap.put("elng",gpsMap.get("lng"));
+ gpsMap.put("elat",gpsMap.get("lat"));
+ }else{
+ Double velocityOld = ((Integer) PositionContainer.getCarPositionMap().get(carId).get("speed")).doubleValue();
+ Double velocityNew = ((Integer) gpsMap.get("speed")).doubleValue();
+ Double acceleration = Double.valueOf(1000*(velocityNew - velocityOld)/3600);
+ Double distance = getDistance(velocityNew, acceleration ,"1.5");
+ Double[] eposition = azimuth_offset(((BigDecimal)gpsMap.get("lng")).doubleValue(),((BigDecimal)gpsMap.get("lat")).doubleValue(),(Integer)gpsMap.get("drct"),distance);
+ gpsMap.put("elng",eposition[0]);
+ gpsMap.put("elat",eposition[1]);
+ }
+ }
+ }
+ }
+ }
+ //瀛樺叆瀹炴椂浣嶇疆瀹瑰櫒
+ PositionContainer.getCarPositionMap().put(carId,gpsMap);
//瀛樺叆鐢ㄦ埛瀹瑰櫒
if(PositionContainer.getUserPositionMap().size() != 0){
for(String userId : PositionContainer.getUserPositionMap().keySet()){
@@ -268,4 +498,133 @@
public void run() {
sendMassage();
}
+
+ private void feng(String carId,String type,ArdSyCarRtuService carRtuService,ArdSyCarLockService lockService) throws MqttException {
+ //鏌ヨ瑁呮补鐐规棦瀹歊tu鐘舵��
+ ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId);
+ if(ardSyCarRtu!=null){
+ //鏌ヨ閿佷俊鎭�
+ List<ArdSyCarLock> ardSyCarLocks = lockService.carLock(ardSyCarRtu.getId());
+ if(ardSyCarLocks.size()>0){
+ 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){
+ //濡傛灉涓嶆槸瑙e皝灏佺姸鎬侊紝鍒欏彂閫佹柦灏佸懡浠�
+ if(ardSyCarLocks.get(0).getRelayInfo()==0 || ardSyCarLocks.get(0).getRelayInfo()==null){
+// 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);
+ String mapString = "{\"A01\":110000,\"A02\":110000,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}";
+ log.debug("鑷姩瑙e皝锛�"+mapString);
+ EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+ emqClient.connect();
+ emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
+ log.debug("杞﹁締"+carId+"瑙e皝鍛戒护鍙戦�佹垚鍔燂紒");
+ // mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"瑙e皝");
+ }
+ }
+
+ //0鏂藉皝
+ if(fengType==0){
+ if(ardSyCarLocks.get(0).getRelayInfo()==1 || ardSyCarLocks.get(0).getRelayInfo()==null){
+ //閿佸紑鍏崇姸鎬�
+ int lockCloseNum = 0;
+ String mapString1 = "{\"A01\":100000,\"A02\":100000,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}";
+ System.out.println("鑷姩鏂藉皝锛�"+mapString1);
+ EmqClient emqClient1 = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+ emqClient1.connect();
+ emqClient1.publish(ardSyCarRtu.getTopicPublish(),mapString1, QosEnum.QoS2,false);
+ //濡傛灉涓嶆槸鏂藉皝鐘舵�侊紝鍒欏彂閫佹柦灏佸懡浠�
+ if(ardSyCarLocks.get(0).getRelayInfo()!=null){
+ 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);
+ String mapString = "{\""+key+"\":0.01,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}";
+ log.debug("鑷姩鍏抽攣锛�"+mapString);
+ EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+ emqClient.connect();
+ emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
+ // 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()));
+// String mapString = com.alibaba.fastjson.JSON.toJSONString(map);
+ log.debug("杞﹁締"+carId+"鏂藉皝鍛戒护鍙戦�佹垚鍔燂紒");
+ // mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"鏂藉皝");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public Double[] azimuth_offset(double origin_lon, double origin_lat, Integer direction,double distance){
+ Double[] lonlat = new Double[2];
+ if(direction != null && distance > 0){
+ lonlat[0] = origin_lon + distance * Math.sin(direction* Math.PI / 180) * 180 / ( Math.PI * 6371229 * Math.cos(origin_lat * Math.PI / 180));
+ lonlat[1] = origin_lat + distance * Math.cos(direction* Math.PI / 180) / ( Math.PI * 6371229 / 180);
+ }else{
+ lonlat[0] = origin_lon;
+ lonlat[1] = origin_lat;
+ }
+ return lonlat;
+ }
+
+ public Double getDistance(Double velocity ,Double acceleration ,String time){
+ Double distance = velocity*Double.parseDouble(time) + 0.5*acceleration*Double.parseDouble(time)*Double.parseDouble(time);
+ return distance;
+ }
+
+ /*public Double getVelocity(Double velocity ,Double acceleration ,String time){
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Long t = (long) 0;
+ try {
+ t = (new Date().getTime() - simpleDateFormat.parse(time).getTime())/1000;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Double velocityt = velocity + acceleration*t;
+ return velocityt;
+ }*/
+
}
--
Gitblit v1.9.3