From 5fe02f6f3c1a9df1b6d86e87329137cd57de0d00 Mon Sep 17 00:00:00 2001 From: aijinhui <aijinhui> Date: 星期三, 15 十一月 2023 10:32:31 +0800 Subject: [PATCH] 锁判断 --- ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java | 180 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 129 insertions(+), 51 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 c5dd1f9..98f2840 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,15 +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.ArdOilWallService; +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.*; @@ -82,7 +84,7 @@ ((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").toString();//鑾峰彇缁忓害 String lat = (String) gpsMap.get("lat").toString();//鑾峰彇绾害 String carName = (String) gpsMap.get("carName");//鑾峰彇杞︾墝鍙� @@ -90,14 +92,26 @@ String deptNum = (String) result.get("deptId").toString();//鑾峰彇閮ㄩ棬ID String deptName = (String) result.get("deptName");//鑾峰彇閮ㄩ棬鍚嶇О String carModel = (String) result.get("carModel");//鑾峰彇杞﹁締妯″瀷 - String drct = (String) gpsMap.get("drct");//鑾峰彇杞﹁締妯″瀷 + Integer drct = (Integer) gpsMap.get("drct");//鑾峰彇杞﹁締妯″瀷 //瀹氫箟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); + //鍒涘缓mqtt宸ュ叿绫诲璞� + MqttOnce mqttOnce = new MqttOnce(); //鏌ヨ瀹氫綅娌硅溅琛ㄤ腑鏄惁鏈夎杞﹁締 - 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 +139,22 @@ ardAccessFence1.setCarModel(carModel); ardAccessFence1.setIsWarning(0); ardAccessFence1.setDrct(drct); - ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).access(ardAccessFence1); + ardAccessFence1.setIsAlarm(0); + ardAccessFenceService.access(ardAccessFence1); + //mqtt鍙戦�佹棦瀹歊tu鐘舵�� + feng(carId,"瑁呮补鐐�",carRtuService,lockService,mqttOnce); 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 +163,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 +179,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); @@ -179,16 +201,20 @@ ardAccessFence.setIntoShipmentTime(time); ardAccessFence.setNowWallName(ardOilWall.getName()); ardAccessFence.setLastTime(time); + //mqtt鍙戦�佹棦瀹歊tu鐘舵�� + feng(carId,"瑁呮补鐐�",carRtuService,lockService,mqttOnce); 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 +226,19 @@ ardAccessFence.setOutShipmentTime(time); ardAccessFence.setNowWallName(ardOilWall.getName()); ardAccessFence.setLastTime(time); + ardAccessFence.setLng(lng); + ardAccessFence.setLat(lat); + ardAccessFenceService.updAccess(ardAccessFence); + //寮�鍑鸿娌圭偣鍥存爮锛屽彂閫佷笂閿佸強鏂藉皝鍛戒护 + feng(carId,"鏂藉皝",carRtuService,lockService,mqttOnce); } - 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 +257,17 @@ 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; + //mqtt鍙戦�佹棦瀹歊tu鐘舵�� + feng(carId,"鍗告补鐐�",carRtuService,lockService,mqttOnce); break; } } + //涓嶅湪鍗告补鐐瑰氨鏄湪璺笂 if(isRoad){ + //鎵�鍦ㄥ洿鏍忓悕绉拌祴null ardAccessFence.setNowWallName(null); //濡傛灉鍦ㄨ矾涓婂垽鏂潗鏍囨槸鍚︿笌涓婃涓�鏍� if(ardAccessFence.getLng().equals(lng) && ardAccessFence.getLat().equals(lat)){ @@ -255,14 +276,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 +291,28 @@ 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); + //寮�鍑轰簡鍗告补鐐瑰洿鏍忥紝鍙戦�佷笂閿佸強鏂借В灏佹寚浠� + feng(carId,"鏂藉皝",carRtuService,lockService,mqttOnce); + //鍒犻櫎璇ユ潯杞﹁締鏁版嵁 + ardAccessFenceService.delAccess(carId); }else { //鏈紑鍑哄嵏娌圭偣锛屾洿鏂扮粡绾害淇濆瓨 ardAccessFence.setLng(lng); ardAccessFence.setLat(lat); ardAccessFence.setLastTime(time); - ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence); + ardAccessFenceService.updAccess(ardAccessFence); } } } @@ -405,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(); + 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(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)),"鏂藉皝"); + } + } + } + } -- Gitblit v1.9.3