From ca0391eeab5a1586aed14018510cb4c3c0cd6131 Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期三, 28 二月 2024 09:17:12 +0800
Subject: [PATCH] 三一车辆用户查询修改提交
---
ard-work/src/main/java/com/ruoyi/app/position/service/impl/ArdAppPositionServiceImpl.java | 339 +++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 287 insertions(+), 52 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 db67b30..837d4fc 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
@@ -1,10 +1,10 @@
package com.ruoyi.app.position.service.impl;
import com.ruoyi.alarm.wall.domain.ArdAlarmWall;
-import com.ruoyi.alarm.wall.mapper.ArdAlarmWallMapper;
import com.ruoyi.alarm.wall.service.IArdAlarmWallService;
import com.ruoyi.alarmpoints.wall.domain.ArdWall;
import com.ruoyi.alarmpoints.wall.mapper.ArdWallMapper;
+import com.ruoyi.app.position.appcontainer.AppContainer;
import com.ruoyi.app.position.domain.ArdAppPosition;
import com.ruoyi.app.position.mapper.ArdAppPositionMapper;
import com.ruoyi.app.position.service.IArdAppPositionService;
@@ -14,6 +14,8 @@
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.scheduling.domian.SchedulingParam;
+import com.ruoyi.system.mapper.SysDeptMapper;
+import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.utils.gis.GisUtil;
import com.ruoyi.utils.gis.Point;
@@ -23,6 +25,8 @@
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
+
+import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS;
/**
@@ -38,7 +42,18 @@
private ArdAppPositionMapper ardAppPositionMapper;
@Resource
private ISysUserService iSysUserService;
+ @Resource
+ RedisCache redisCache;
+ @Resource
+ ArdWallMapper ardWallMapper;
+ @Resource
+ IArdAlarmWallService ardAlarmWallService;
+ @Resource
+ private SysUserMapper sysUserMapper;
+ @Resource
+ private SysDeptMapper sysDeptMapper;
+ Map<String, String> firstAlarmMap = new HashMap<>();//棣栨鎶ヨ缂撳瓨key:鐢ㄦ埛id_鍥存爮id value: 鎶ヨid
/**
* 鏌ヨapp浣嶇疆
*
@@ -83,7 +98,12 @@
ardAppPosition.setId(IdUtils.simpleUUID());
ardAppPosition.setCreateTime(DateUtils.getNowDate());
ardAppPositionMapper.insertArdAppPosition(ardAppPosition);
- return DetectionWallAlarm(ardAppPosition);
+ try{
+ return DetectionWallAlarm(ardAppPosition);
+ }finally {
+ AppContainer.getArdAppPositionMap().put(ardAppPosition.getUserId(),ardAppPosition);//瀹炴椂浣嶇疆瀛樺叆瀹瑰櫒
+ }
+
}
/**
@@ -221,33 +241,23 @@
return filteredList;
}
-
- @Resource
- RedisCache redisCache;
- @Resource
- ArdWallMapper ardWallMapper;
- @Resource
- IArdAlarmWallService ardAlarmWallService;
- Map<String, String> userLastAlarm = new HashMap<>();
-
/**
* 瀹炴椂浣嶇疆妫�娴嬪洿鏍忔姤璀�
* 鍒樿嫃涔�
* 2023/8/31 8:54:06
*/
- public List<ArdAlarmWall> DetectionWallAlarm(ArdAppPosition ardAppPosition) {
- List<ArdAlarmWall> ardAlarmWalls=new ArrayList<>();
+ /*public List<ArdAlarmWall> DetectionWallAlarm(ArdAppPosition ardAppPosition) {
+ List<ArdAlarmWall> ardAlarmWalls = new ArrayList<>();
//鑾峰彇褰撳墠鐢ㄦ埛鐨勯儴闂�
String userId = ardAppPosition.getUserId();
- SysUser sysUser = redisCache.getCacheObject("user_list:" + userId);
- Long deptId = sysUser.getDeptId();
- //鑾峰彇閮ㄩ棬涓嬬殑鎵�鏈夌數瀛愬洿鏍�
- ArdWall ardWall = new ArdWall();
- ardWall.setDeptId(deptId);
- List<ArdWall> ardWalls = ardWallMapper.selectArdWallList(ardWall);
+ //鑾峰彇鐢ㄦ埛鍏宠仈鐨勬墍鏈夌數瀛愬洿鏍�
+ List<ArdWall> ardWalls = ardWallMapper.selectArdWallListByUserId(userId);
if (ardWalls.size() > 0) {
+ //閬嶅巻鎵�鏈夌數瀛愬洿鏍�
for (ArdWall wall : ardWalls) {
- String wallPoi = wall.getWallPoi();
+ String wallId = wall.getId();//鍥存爮ID
+ String wallType = wall.getType();//鍥存爮绫诲瀷
+ String wallPoi = wall.getWallPoi();//鍥存爮鍧愭爣闆嗗悎
//澶勭悊澶氳竟褰㈢殑姣忎釜鐐圭殑缁忕含搴�
String[] parts = wallPoi.split(",");
List<Point> pointList = new ArrayList<>();
@@ -257,44 +267,269 @@
point.setLatitude(Double.valueOf(parts[i + 1]));
pointList.add(point);
}
-
- //鍒ゆ柇褰撳墠鐢ㄦ埛浣嶇疆鏄惁鍦ㄥ洿鏍忓唴
- Point userPoint=new Point();
- userPoint.setLongitude(ardAppPosition.getLongitude());
- userPoint.setLatitude(ardAppPosition.getLatitude());
- boolean inPolygon = GisUtil.isInPolygon(userPoint, pointList);
- if (inPolygon) {
- String lastAlarmId = userLastAlarm.get(userId);
- ArdAlarmWall ardAlarmWall = new ArdAlarmWall();
- ardAlarmWall.setWallId(wall.getId());
- ardAlarmWall.setWallName(wall.getWallName());
- ardAlarmWall.setUserId(userId);
- ardAlarmWall.setAlarmTime(new Date());
- ardAlarmWall.setAlarmType(wall.getType());
- ardAlarmWall.setLongitude(ardAppPosition.getLongitude());
- ardAlarmWall.setLatitude(ardAppPosition.getLatitude());
- ardAlarmWall.setAltitude(ardAppPosition.getAltitude());
- if (lastAlarmId == null) {
- String uuid = IdUtils.simpleUUID();
- // 褰撳墠鐢ㄦ埛涓婁竴娆$姸鎬佹湭杩涘叆锛岀敓鎴愭姤璀�
- ardAlarmWall.setId(uuid);
- ardAlarmWallService.insertArdAlarmWall(ardAlarmWall);
- //鏇存柊鏈�鍚庢姤璀d
- userLastAlarm.put(userId, uuid);
+ //褰撳墠鐢ㄦ埛鐨勪綅缃�
+ Point userPoint = new Point(ardAppPosition.getLongitude(), ardAppPosition.getLatitude());
+ 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 ("1".equals(wallType)) {
+ 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 {
- // 涓婁竴娆$敤鎴风姸鎬佸凡杩涘叆锛屾洿鏂版渶鍚庢姤璀�
- ardAlarmWall.setId(lastAlarmId);
- ardAlarmWallService.updateArdAlarmWall(ardAlarmWall);
+ //绂佸叆鍥存爮鍒欒嫢鍦ㄥ洿鏍忓鍒欑Щ闄ゆ姤璀︾紦瀛�
+ firstAlarmMap.remove(key);
}
- ardAlarmWalls.add(ardAlarmWall);
- }
- else
+ } else//绂佸嚭
{
- //绉婚櫎鏈�鍚庢姤璀d
- userLastAlarm.remove(userId);
+ //鍒ゆ柇褰撳墠鐢ㄦ埛浣嶇疆鏄惁鍦ㄥ洿鏍忓
+ 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);
+ }
}
}
}
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("2")).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;
+ break;
+ }
+ }
+ }
+ if(noOutFlag){//鍏ㄩ儴绂佸嚭鐢靛瓙鍥存爮閮藉嚭鍘讳簡
+ for(ArdWall wall : ardWallsNoOut){
+ String wallId = wall.getId();//鍥存爮ID
+ //鍒涘缓鍥存爮鎶ヨ瀹炰綋瀵硅薄
+ 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
+ //绂佸嚭鍥存爮鍒欒嫢鍦ㄥ洿鏍忓,鑾峰彇棣栨璧板嚭鍥存爮鎶ヨ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{
+ for(ArdWall wall : ardWallsNoOut){
+ String wallId = wall.getId();//鍥存爮ID
+ String key = userId + "_" + wallId;//鏈�鍚庝竴娆℃姤璀︾紦瀛榢ey
+ firstAlarmMap.remove(key);
+ }
+ }
+ return ardAlarmWalls;
}
+
+ @Override
+ public Map<String, List<SysUser>> getOnlinePCOrCommander(String usersId) {
+ Map<String, List<SysUser>> result = new HashMap();
+ List<SysUser> commanderList = sysUserMapper.getOnlineCommander(usersId);
+ result.put("commander",commanderList);
+ try{
+ List<String> onLinePCIdList = new ArrayList();
+ //onLinePCIdList.addAll(ONLINE_USER_SESSIONS.keySet());
+ for(String id : ONLINE_USER_SESSIONS.keySet()){
+ onLinePCIdList.add(id.split("_")[0]);
+ }
+ List<SysUser> pcList = sysUserMapper.getOnlinePC(usersId,onLinePCIdList);
+ result.put("pc",pcList);
+ }catch(Exception e){
+ result.put("pc",new ArrayList());
+ }
+ return result;
+ }
+
+ @Override
+ public List<Map<String,Object>> getOnlineCommanderPosition(String soilderId) {
+ List<Map<String,Object>> result = ardAppPositionMapper.getOnlineCommanderPosition(soilderId);
+ return result;
+ }
+
+ @Override
+ public List<ArdAppPosition> getAPPPositionByUserIdAndTime(Map<String, String> para) {
+ String userId = para.get("userId");
+ String beginTime = para.get("beginTime");
+ String endTime = para.get("endTime");
+ List<ArdAppPosition> result = ardAppPositionMapper.getAPPPositionByUserIdAndTime(userId,beginTime,endTime);
+ return result;
+ }
+
+ @Override
+ public List<Map<String,Object>> getOnlineAPPSoilderByCommanderId(String userId) {
+ SysUser sysUser = sysUserMapper.selectUserById(userId);//鑾峰彇绯荤粺鐢ㄦ埛
+ List<Long> deptIdList = new ArrayList();
+ deptIdList.add(sysUser.getDeptId());
+ deptIdList = getOwnAndChildrenDeptIdList(deptIdList,new ArrayList());//閫掑綊鏌ヨ涓嬪睘閮ㄩ棬涓婚敭
+ List<SysUser> result = sysUserMapper.getOwnAndChildrenOnlineSoilderList(deptIdList);
+ List<Map<String,Object>> resultList = new ArrayList();
+ for(SysUser sysUserIn : result){
+ Map<String,Object> map = new HashMap();
+ map.put("userId",sysUserIn.getUserId());
+ map.put("deptId",sysUserIn.getDeptId());
+ map.put("userName",sysUserIn.getUserName());
+ map.put("nickName",sysUserIn.getNickName());
+ try{
+ map.put("longitude",AppContainer.getArdAppPositionMap().get(sysUserIn.getUserId()).getLongitude());
+ map.put("latitude",AppContainer.getArdAppPositionMap().get(sysUserIn.getUserId()).getLatitude());
+ map.put("altitude",AppContainer.getArdAppPositionMap().get(sysUserIn.getUserId()).getAltitude());
+ }catch(Exception e){
+ ArdAppPosition ardAppPosition = ardAppPositionMapper.getLastAPPPositionByUserId(sysUserIn.getUserId());
+ map.put("longitude",ardAppPosition.getLongitude());
+ map.put("latitude",ardAppPosition.getLatitude());
+ map.put("altitude",ardAppPosition.getAltitude());
+ }
+ resultList.add(map);
+ }
+ return resultList;
+ }
+
+ public List<Long> getOwnAndChildrenDeptIdList(List<Long> deptIdList,List<Long> deptIdListr){
+ deptIdListr.addAll(deptIdList);
+ List<Long> result = sysDeptMapper.getChildrenDeptIdList(deptIdList);
+ if(result.size() != 0){
+ deptIdListr.addAll(result);
+ result = getOwnAndChildrenDeptIdList(result,deptIdListr);
+ }
+ deptIdListr = deptIdListr.stream().distinct().collect(Collectors.toList());
+ return deptIdListr;
+ }
+
}
--
Gitblit v1.9.3