From e5c8f327e3735a252610eb167d08ae3773b65184 Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期六, 20 一月 2024 15:20:46 +0800
Subject: [PATCH] 查询本部门在线PC端通过websocket判断提交
---
ard-work/src/main/java/com/ruoyi/app/position/service/impl/ArdAppPositionServiceImpl.java | 113 +++++++++++++++++++++++++++++++++-----------------------
1 files changed, 66 insertions(+), 47 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 614f958..95c1a94 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
@@ -14,6 +14,7 @@
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.scheduling.domian.SchedulingParam;
+import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.utils.gis.GisUtil;
import com.ruoyi.utils.gis.Point;
@@ -24,6 +25,8 @@
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
+
+import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS;
/**
@@ -39,7 +42,16 @@
private ArdAppPositionMapper ardAppPositionMapper;
@Resource
private ISysUserService iSysUserService;
+ @Resource
+ RedisCache redisCache;
+ @Resource
+ ArdWallMapper ardWallMapper;
+ @Resource
+ IArdAlarmWallService ardAlarmWallService;
+ @Resource
+ private SysUserMapper sysUserMapper;
+ Map<String, String> firstAlarmMap = new HashMap<>();//棣栨鎶ヨ缂撳瓨key:鐢ㄦ埛id_鍥存爮id value: 鎶ヨid
/**
* 鏌ヨapp浣嶇疆
*
@@ -222,35 +234,23 @@
return filteredList;
}
-
- @Resource
- RedisCache redisCache;
- @Resource
- ArdWallMapper ardWallMapper;
- @Resource
- IArdAlarmWallService ardAlarmWallService;
- Map<String, String> userInLastAlarm = new HashMap<>();
- Map<String, String> userOutLastAlarm = new HashMap<>();
/**
* 瀹炴椂浣嶇疆妫�娴嬪洿鏍忔姤璀�
* 鍒樿嫃涔�
* 2023/8/31 8:54:06
*/
public List<ArdAlarmWall> DetectionWallAlarm(ArdAppPosition ardAppPosition) {
- SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- List<ArdAlarmWall> ardAlarmWalls=new ArrayList<>();
+ 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 wallType = wall.getType();
+ String wallId = wall.getId();//鍥存爮ID
+ String wallType = wall.getType();//鍥存爮绫诲瀷
+ String wallPoi = wall.getWallPoi();//鍥存爮鍧愭爣闆嗗悎
//澶勭悊澶氳竟褰㈢殑姣忎釜鐐圭殑缁忕含搴�
String[] parts = wallPoi.split(",");
List<Point> pointList = new ArrayList<>();
@@ -260,8 +260,10 @@
point.setLatitude(Double.valueOf(parts[i + 1]));
pointList.add(point);
}
- Point userPoint=new Point(ardAppPosition.getLongitude(),ardAppPosition.getLatitude());
- boolean inPolygon = GisUtil.isInPolygon(userPoint, pointList);
+ //褰撳墠鐢ㄦ埛鐨勪綅缃�
+ 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());
@@ -271,59 +273,76 @@
ardAlarmWall.setLongitude(ardAppPosition.getLongitude());
ardAlarmWall.setLatitude(ardAppPosition.getLatitude());
ardAlarmWall.setAltitude(ardAppPosition.getAltitude());
- //绂佸叆
- if("1".equals(wallType)) {
- //鍒ゆ柇褰撳墠鐢ㄦ埛浣嶇疆鏄惁鍦ㄥ洿鏍忓唴
+ String key = userId + "_" + wallId;//鏈�鍚庝竴娆℃姤璀︾紦瀛榢ey
+ //鎸夌被鍨嬪尯鍒嗗洿鏍忕鍏ユ垨鑰呯鍑�
+ if ("1".equals(wallType)) {
if (inPolygon) {
- String lastInAlarmId = userInLastAlarm.get(userId);
+ //绂佸叆鍥存爮鍒欒嫢鍦ㄥ洿鏍忓唴,鑾峰彇棣栨杩涘叆鍥存爮鎶ヨID
+ String lastInAlarmId = firstAlarmMap.get(key);
+ //鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁棣栨杩涘叆鍥存爮鍐�
if (lastInAlarmId == null) {
+ //褰撳墠鐢ㄦ埛棣栨杩涘叆鐢熸垚鎶ヨ
String uuid = IdUtils.simpleUUID();
- //褰撳墠鐢ㄦ埛涓婁竴娆$姸鎬佹湭杩涘叆锛岀敓鎴愭姤璀�
ardAlarmWall.setId(uuid);
ardAlarmWallService.insertArdAlarmWall(ardAlarmWall);
- //鏇存柊鏈�鍚庢姤璀d
- userInLastAlarm.put(userId, uuid);
+ //璁板綍棣栨鎶ヨid
+ firstAlarmMap.put(key, uuid);
} else {
- //涓婁竴娆$敤鎴风姸鎬佸凡杩涘叆锛屾洿鏂版渶鍚庢姤璀�
+ //鐢ㄦ埛宸茶繘鍏ユ洿鏂版渶鍚庢姤璀�
ardAlarmWall.setId(lastInAlarmId);
ardAlarmWallService.updateArdAlarmWall(ardAlarmWall);
}
ardAlarmWalls.add(ardAlarmWall);
+ } else {
+ //绂佸叆鍥存爮鍒欒嫢鍦ㄥ洿鏍忓鍒欑Щ闄ゆ姤璀︾紦瀛�
+ firstAlarmMap.remove(key);
}
- else
- {
- //绉婚櫎鏈�鍚庢姤璀d
- userInLastAlarm.remove(userId);
- }
- }
- else//绂佸嚭
+ } else//绂佸嚭
{
//鍒ゆ柇褰撳墠鐢ㄦ埛浣嶇疆鏄惁鍦ㄥ洿鏍忓
if (!inPolygon) {
- String lastAlarmId = userOutLastAlarm.get(userId);
+ //绂佸嚭鍥存爮鍒欒嫢鍦ㄥ洿鏍忓,鑾峰彇棣栨璧板嚭鍥存爮鎶ヨID
+ String lastAlarmId = firstAlarmMap.get(key);
+ //鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁棣栨鍦ㄥ洿鏍忓
if (lastAlarmId == null) {
String uuid = IdUtils.simpleUUID();
- //褰撳墠鐢ㄦ埛涓婁竴娆$姸鎬佹湭杩涘叆锛岀敓鎴愭姤璀�
+ //褰撳墠鐢ㄦ埛棣栨鍑哄洿鏍忕敓鎴愭姤璀�
ardAlarmWall.setId(uuid);
ardAlarmWallService.insertArdAlarmWall(ardAlarmWall);
- //鏇存柊鏈�鍚庢姤璀d
- userOutLastAlarm.put(userId, uuid);
+ //璁板綍棣栨鎶ヨid
+ firstAlarmMap.put(key, uuid);
} else {
- //涓婁竴娆$敤鎴风姸鎬佸凡杩涘叆锛屾洿鏂版渶鍚庢姤璀�
+ //鐢ㄦ埛宸茬粡鍦ㄥ洿鏍忓鏇存柊鎶ヨ
ardAlarmWall.setId(lastAlarmId);
ardAlarmWallService.updateArdAlarmWall(ardAlarmWall);
}
ardAlarmWalls.add(ardAlarmWall);
- }
- else
- {
- //绉婚櫎鏈�鍚庢姤璀d
- userOutLastAlarm.remove(userId);
+ } else {
+ //绉婚櫎棣栨鎶ヨ缂撳瓨
+ 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;
+ }
}
--
Gitblit v1.9.3