| | |
| | | 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; |
| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS; |
| | | |
| | | |
| | | /** |
| | |
| | | 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位置 |
| | | * |
| | |
| | | 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<>(); |
| | |
| | | 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()); |
| | |
| | | ardAlarmWall.setLongitude(ardAppPosition.getLongitude()); |
| | | ardAlarmWall.setLatitude(ardAppPosition.getLatitude()); |
| | | ardAlarmWall.setAltitude(ardAppPosition.getAltitude()); |
| | | //禁入 |
| | | if("1".equals(wallType)) { |
| | | //判断当前用户位置是否在围栏内 |
| | | String key = userId + "_" + wallId;//最后一次报警缓存key |
| | | //按类型区分围栏禁入或者禁出 |
| | | 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); |
| | | //更新最后报警id |
| | | userInLastAlarm.put(userId, uuid); |
| | | //记录首次报警id |
| | | firstAlarmMap.put(key, uuid); |
| | | } else { |
| | | //上一次用户状态已进入,更新最后报警 |
| | | //用户已进入更新最后报警 |
| | | ardAlarmWall.setId(lastInAlarmId); |
| | | ardAlarmWallService.updateArdAlarmWall(ardAlarmWall); |
| | | } |
| | | ardAlarmWalls.add(ardAlarmWall); |
| | | } else { |
| | | //禁入围栏则若在围栏外则移除报警缓存 |
| | | firstAlarmMap.remove(key); |
| | | } |
| | | else |
| | | { |
| | | //移除最后报警id |
| | | 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); |
| | | //更新最后报警id |
| | | userOutLastAlarm.put(userId, uuid); |
| | | //记录首次报警id |
| | | firstAlarmMap.put(key, uuid); |
| | | } else { |
| | | //上一次用户状态已进入,更新最后报警 |
| | | //用户已经在围栏外更新报警 |
| | | ardAlarmWall.setId(lastAlarmId); |
| | | ardAlarmWallService.updateArdAlarmWall(ardAlarmWall); |
| | | } |
| | | ardAlarmWalls.add(ardAlarmWall); |
| | | } |
| | | else |
| | | { |
| | | //移除最后报警id |
| | | 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); |
| | | List<String> onLinePCIdList = new ArrayList(); |
| | | onLinePCIdList.addAll(ONLINE_USER_SESSIONS.keySet()); |
| | | List<SysUser> pcList = sysUserMapper.getOnlinePC(usersId,onLinePCIdList); |
| | | result.put("pc",pcList); |
| | | return result; |
| | | } |
| | | } |