From 7367cf50bcceb23194aa071b696f126935dfd069 Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期三, 31 一月 2024 09:19:35 +0800
Subject: [PATCH] 禁出电子围栏报警逻辑修改提交
---
ard-work/src/main/java/com/ruoyi/app/position/service/impl/ArdAppPositionServiceImpl.java | 141 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 140 insertions(+), 1 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/app/position/service/impl/ArdAppPositionServiceImpl.java b/ard-work/src/main/java/com/ruoyi/app/position/service/impl/ArdAppPositionServiceImpl.java
index d4ce82c..2a3b7ca 100644
--- a/ard-work/src/main/java/com/ruoyi/app/position/service/impl/ArdAppPositionServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/app/position/service/impl/ArdAppPositionServiceImpl.java
@@ -241,7 +241,7 @@
* 鍒樿嫃涔�
* 2023/8/31 8:54:06
*/
- public List<ArdAlarmWall> DetectionWallAlarm(ArdAppPosition ardAppPosition) {
+ /*public List<ArdAlarmWall> DetectionWallAlarm(ArdAppPosition ardAppPosition) {
List<ArdAlarmWall> ardAlarmWalls = new ArrayList<>();
//鑾峰彇褰撳墠鐢ㄦ埛鐨勯儴闂�
String userId = ardAppPosition.getUserId();
@@ -327,6 +327,145 @@
}
}
return ardAlarmWalls;
+ }*/
+
+ public List<ArdAlarmWall> DetectionWallAlarm(ArdAppPosition ardAppPosition) {
+ List<ArdAlarmWall> ardAlarmWalls = new ArrayList<>();
+ //鑾峰彇褰撳墠鐢ㄦ埛鐨勯儴闂�
+ String userId = ardAppPosition.getUserId();
+ //鑾峰彇鐢ㄦ埛鍏宠仈鐨勬墍鏈夌數瀛愬洿鏍�
+ List<ArdWall> ardWalls = ardWallMapper.selectArdWallListByUserId(userId);
+ List<ArdWall> ardWallsNoIn = new ArrayList();//绂佸叆鐢靛瓙鍥存爮
+ List<ArdWall> ardWallsNoOut = new ArrayList();//绂佸嚭鐢靛瓙鍥存爮
+ ardWallsNoIn = ardWalls.stream().filter(ardWall -> ardWall.getType().equals("1")).collect(Collectors.toList());
+ ardWallsNoOut = ardWalls.stream().filter(ardWall -> ardWall.getType().equals("0")).collect(Collectors.toList());
+ //褰撳墠鐢ㄦ埛鐨勪綅缃�
+ Point userPoint = new Point(ardAppPosition.getLongitude(), ardAppPosition.getLatitude());
+ if(ardWallsNoIn.size() > 0){//鍒ゆ柇绂佸叆
+ for(ArdWall wall : ardWallsNoIn){
+ String wallId = wall.getId();//鍥存爮ID
+ String wallPoi = wall.getWallPoi();//鍥存爮鍧愭爣闆嗗悎
+ //澶勭悊澶氳竟褰㈢殑姣忎釜鐐圭殑缁忕含搴�
+ String[] parts = wallPoi.split(",");
+ List<Point> pointList = new ArrayList<>();
+ for (int i = 0; i < parts.length; i += 3) {
+ Point point = new Point();
+ point.setLongitude(Double.valueOf(parts[i]));
+ point.setLatitude(Double.valueOf(parts[i + 1]));
+ pointList.add(point);
+ }
+ boolean inPolygon = GisUtil.isInPolygon(userPoint, pointList);//鍒ゆ柇鏄惁鍦ㄥ洿鏍忓唴
+ //鍒涘缓鍥存爮鎶ヨ瀹炰綋瀵硅薄
+ ArdAlarmWall ardAlarmWall = new ArdAlarmWall();
+ ardAlarmWall.setWallId(wall.getId());
+ ardAlarmWall.setWallName(wall.getWallName());
+ ardAlarmWall.setUserId(userId);
+ ardAlarmWall.setAlarmTime(DateUtils.getNowDate());
+ ardAlarmWall.setAlarmType(wall.getType());
+ ardAlarmWall.setLongitude(ardAppPosition.getLongitude());
+ ardAlarmWall.setLatitude(ardAppPosition.getLatitude());
+ ardAlarmWall.setAltitude(ardAppPosition.getAltitude());
+ String key = userId + "_" + wallId;//鏈�鍚庝竴娆℃姤璀︾紦瀛榢ey
+ if (inPolygon) {
+ //绂佸叆鍥存爮鍒欒嫢鍦ㄥ洿鏍忓唴,鑾峰彇棣栨杩涘叆鍥存爮鎶ヨID
+ String lastInAlarmId = firstAlarmMap.get(key);
+ //鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁棣栨杩涘叆鍥存爮鍐�
+ if (lastInAlarmId == null) {
+ //褰撳墠鐢ㄦ埛棣栨杩涘叆鐢熸垚鎶ヨ
+ String uuid = IdUtils.simpleUUID();
+ ardAlarmWall.setId(uuid);
+ ardAlarmWallService.insertArdAlarmWall(ardAlarmWall);
+ //璁板綍棣栨鎶ヨid
+ firstAlarmMap.put(key, uuid);
+ } else {
+ //鐢ㄦ埛宸茶繘鍏ユ洿鏂版渶鍚庢姤璀�
+ ardAlarmWall.setId(lastInAlarmId);
+ ardAlarmWallService.updateArdAlarmWall(ardAlarmWall);
+ }
+ ardAlarmWalls.add(ardAlarmWall);
+ } else {
+ //绂佸叆鍥存爮鍒欒嫢鍦ㄥ洿鏍忓鍒欑Щ闄ゆ姤璀︾紦瀛�
+ firstAlarmMap.remove(key);
+ }
+ }
+ }
+
+ Boolean noOutFlag = true;
+ if(ardWallsNoOut.size() > 0) {//鍒ゆ柇绂佸嚭
+ for(ArdWall wall : ardWallsNoOut){
+ String wallPoi = wall.getWallPoi();//鍥存爮鍧愭爣闆嗗悎
+ //澶勭悊澶氳竟褰㈢殑姣忎釜鐐圭殑缁忕含搴�
+ String[] parts = wallPoi.split(",");
+ List<Point> pointList = new ArrayList<>();
+ for (int i = 0; i < parts.length; i += 3) {
+ Point point = new Point();
+ point.setLongitude(Double.valueOf(parts[i]));
+ point.setLatitude(Double.valueOf(parts[i + 1]));
+ pointList.add(point);
+ }
+ boolean inPolygon = GisUtil.isInPolygon(userPoint, pointList);//鍒ゆ柇鏄惁鍦ㄥ洿鏍忓唴
+ if (!inPolygon) {
+ noOutFlag = true;
+ } else {
+ noOutFlag = false;
+ }
+ }
+ }
+ if(noOutFlag){//鍏ㄩ儴绂佸嚭鐢靛瓙鍥存爮閮藉嚭鍘讳簡
+ for(ArdWall wall : ardWallsNoOut){
+ String wallId = wall.getId();//鍥存爮ID
+ //String wallPoi = wall.getWallPoi();//鍥存爮鍧愭爣闆嗗悎
+ //澶勭悊澶氳竟褰㈢殑姣忎釜鐐圭殑缁忕含搴�
+ /*String[] parts = wallPoi.split(",");
+ List<Point> pointList = new ArrayList<>();
+ for (int i = 0; i < parts.length; i += 3) {
+ Point point = new Point();
+ point.setLongitude(Double.valueOf(parts[i]));
+ point.setLatitude(Double.valueOf(parts[i + 1]));
+ pointList.add(point);
+ }
+ boolean inPolygon = GisUtil.isInPolygon(userPoint, pointList);*///鍒ゆ柇鏄惁鍦ㄥ洿鏍忓唴
+ //鍒涘缓鍥存爮鎶ヨ瀹炰綋瀵硅薄
+ ArdAlarmWall ardAlarmWall = new ArdAlarmWall();
+ ardAlarmWall.setWallId(wall.getId());
+ ardAlarmWall.setWallName(wall.getWallName());
+ ardAlarmWall.setUserId(userId);
+ ardAlarmWall.setAlarmTime(DateUtils.getNowDate());
+ ardAlarmWall.setAlarmType(wall.getType());
+ ardAlarmWall.setLongitude(ardAppPosition.getLongitude());
+ ardAlarmWall.setLatitude(ardAppPosition.getLatitude());
+ ardAlarmWall.setAltitude(ardAppPosition.getAltitude());
+ String key = userId + "_" + wallId;//鏈�鍚庝竴娆℃姤璀︾紦瀛榢ey
+ //if (!inPolygon) {
+ //绂佸嚭鍥存爮鍒欒嫢鍦ㄥ洿鏍忓,鑾峰彇棣栨璧板嚭鍥存爮鎶ヨID
+ String lastAlarmId = firstAlarmMap.get(key);
+ //鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁棣栨鍦ㄥ洿鏍忓
+ if (lastAlarmId == null) {
+ String uuid = IdUtils.simpleUUID();
+ //褰撳墠鐢ㄦ埛棣栨鍑哄洿鏍忕敓鎴愭姤璀�
+ ardAlarmWall.setId(uuid);
+ ardAlarmWallService.insertArdAlarmWall(ardAlarmWall);
+ //璁板綍棣栨鎶ヨid
+ firstAlarmMap.put(key, uuid);
+ } else {
+ //鐢ㄦ埛宸茬粡鍦ㄥ洿鏍忓鏇存柊鎶ヨ
+ ardAlarmWall.setId(lastAlarmId);
+ ardAlarmWallService.updateArdAlarmWall(ardAlarmWall);
+ }
+ ardAlarmWalls.add(ardAlarmWall);
+ /*} else {
+ //绉婚櫎棣栨鎶ヨ缂撳瓨
+ firstAlarmMap.remove(key);
+ }*/
+ }
+ }else{
+ for(ArdWall wall : ardWallsNoOut){
+ String wallId = wall.getId();//鍥存爮ID
+ String key = userId + "_" + wallId;//鏈�鍚庝竴娆℃姤璀︾紦瀛榢ey
+ firstAlarmMap.remove(key);
+ }
+ }
+ return ardAlarmWalls;
}
@Override
--
Gitblit v1.9.3