From 97f4a9b9621eca21da79df727121f5fac12cc42a Mon Sep 17 00:00:00 2001 From: zhangnaisong <2434969829@qq.com> Date: 星期一, 22 一月 2024 10:01:41 +0800 Subject: [PATCH] app单兵端发起查看指挥端位置及车辆位置提交 --- ard-work/src/main/java/com/ruoyi/app/position/service/impl/ArdAppPositionServiceImpl.java | 177 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 128 insertions(+), 49 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..6fd2713 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,5 +1,6 @@ package com.ruoyi.app.position.service.impl; +import com.alibaba.fastjson2.JSON; import com.ruoyi.alarm.wall.domain.ArdAlarmWall; import com.ruoyi.alarm.wall.mapper.ArdAlarmWallMapper; import com.ruoyi.alarm.wall.service.IArdAlarmWallService; @@ -14,6 +15,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; @@ -21,8 +23,11 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; + +import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS; /** @@ -38,7 +43,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浣嶇疆 * @@ -221,33 +235,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<>(); + 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 +261,119 @@ 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; } + + @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 void sendCheckCommandersPosition(String usersId,Map<String, Object> para) { + String reason = (String) para.get("reason"); + List<String> usersIdList = (List<String>) para.get("usersIdList"); + for(String commanderId : usersIdList){ + //璁剧疆key涓篶heckCommanderPosition_鎸囨尌绔富閿甠鍗曞叺绔富閿� + String key = "checkCommanderPosition_" + commanderId + "_" + usersId; + Map<String,Object> value = new HashMap(); + value.put("reason",reason); + value.put("state","0"); + value.put("begin",""); + redisCache.setCacheObject(key, JSON.toJSONString(value)); + } + } + + @Override + public void sendCheckSYCarsPosition(String usersId, Map<String, Object> para) { + String reason = (String) para.get("reason"); + List<String> usersIdList = (List<String>) para.get("usersIdList"); + for(String commanderId : usersIdList){ + //璁剧疆key涓篶heckCommanderPosition_鎸囨尌绔富閿�/PC绔富閿甠鍗曞叺绔富閿� + String key = "checkSYCarsPosition_" + commanderId + "_" + usersId; + Map<String,Object> value = new HashMap(); + value.put("reason",reason); + value.put("state","0"); + value.put("begin",""); + redisCache.setCacheObject(key, JSON.toJSONString(value)); + } + } } -- Gitblit v1.9.3