| | |
| | | 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.domain.ArdAppPosition; |
| | | import com.ruoyi.app.position.mapper.ArdAppPositionMapper; |
| | | import com.ruoyi.app.position.service.IArdAppPositionService; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.scheduling.domian.SchedulingParam; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.utils.tools.GisTool; |
| | | import com.ruoyi.utils.gis.GisUtil; |
| | | import com.ruoyi.utils.gis.Point; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertArdAppPosition(ArdAppPosition ardAppPosition) { |
| | | public List<ArdAlarmWall> insertArdAppPosition(ArdAppPosition ardAppPosition) { |
| | | ardAppPosition.setId(IdUtils.simpleUUID()); |
| | | ardAppPosition.setCreateTime(DateUtils.getNowDate()); |
| | | return ardAppPositionMapper.insertArdAppPosition(ardAppPosition); |
| | | ardAppPositionMapper.insertArdAppPosition(ardAppPosition); |
| | | return DetectionWallAlarm(ardAppPosition); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public List<SysUser> getNearAppUsers(SchedulingParam param) { |
| | | Double longitude = param.getLongitude(); |
| | | Double latitude = param.getLatitude(); |
| | | if (longitude == null && latitude == null) { |
| | | log.debug("原点坐标为空"); |
| | | return null; |
| | | } |
| | | Integer radius = param.getSealingRadius(); |
| | | |
| | | if (radius == null) { |
| | | log.debug("半径距离为空"); |
| | | return null; |
| | | } |
| | | |
| | | SysUser user = new SysUser(); |
| | | List<SysUser> appUserList = iSysUserService.selectAllAppUserList(user); |
| | | //过滤在线 |
| | | List<SysUser> onLineList = appUserList.stream() |
| | | .filter(sysUser -> (sysUser.getAppOnlineState().equals("1"))) |
| | | .collect(Collectors.toList()); |
| | | //过滤范围 |
| | | List<SysUser> filteredList = new ArrayList<>(); |
| | | for(SysUser sysUser:onLineList) { |
| | | ArdAppPosition ardAppPosition = ardAppPositionMapper.selectLastArdAppPositionByUserId(sysUser.getUserId()); |
| | | if (ardAppPosition != null) { |
| | | Double lon = ardAppPosition.getLongitude(); |
| | | Double lat = ardAppPosition.getLatitude(); |
| | | if(longitude==null||latitude==null) |
| | | { |
| | | continue; |
| | | } |
| | | double distance = GisTool.getDistance(new double[]{ longitude, latitude}, new double[]{ lon, lat}); |
| | | if (distance <= radius) { |
| | | filteredList.add(sysUser); // 将满足条件的用户添加到筛选列表中 |
| | | try { |
| | | Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId(); |
| | | Double longitude = param.getLongitude(); |
| | | Double latitude = param.getLatitude(); |
| | | if (longitude == null && latitude == null) { |
| | | log.debug("原点坐标为空"); |
| | | return null; |
| | | } |
| | | Integer radius = param.getSealingRadius(); |
| | | |
| | | if (radius == null) { |
| | | log.debug("半径距离为空"); |
| | | return null; |
| | | } |
| | | |
| | | SysUser user = new SysUser(); |
| | | user.setDeptId(deptId); |
| | | List<SysUser> appUserList = iSysUserService.selectAllAppUserList(user); |
| | | //过滤在线和单兵端 |
| | | List<SysUser> onLineList = appUserList.stream() |
| | | .filter(sysUser -> (sysUser.getAppOnlineState().equals("1"))) |
| | | .filter(sysUser -> (sysUser.getAppUserType().equals("1"))) |
| | | .collect(Collectors.toList()); |
| | | //过滤范围 |
| | | for (SysUser sysUser : onLineList) { |
| | | ArdAppPosition ardAppPosition = ardAppPositionMapper.selectLastArdAppPositionByUserId(sysUser.getUserId()); |
| | | if (ardAppPosition != null) { |
| | | Double lon = ardAppPosition.getLongitude(); |
| | | Double lat = ardAppPosition.getLatitude(); |
| | | if (longitude == null || latitude == null) { |
| | | continue; |
| | | } |
| | | double distance = GisUtil.getDistance(new double[]{longitude, latitude}, new double[]{lon, lat}); |
| | | if (distance <= radius) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("longitude", lon); |
| | | params.put("latitude", lat); |
| | | sysUser.setParams(params); |
| | | filteredList.add(sysUser); // 将满足条件的用户添加到筛选列表中 |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("获取封控圈内所有在线app用户异常" + ex.getMessage()); |
| | | } |
| | | return filteredList; |
| | | } |
| | | |
| | | /** |
| | | * 获取封控圈内所有在线app用户(多边形) |
| | | * 刘苏义 |
| | | * 2023/8/17 13:56:36 |
| | | */ |
| | | @Override |
| | | public List<SysUser> getNearAppUsersWithPolygon(SchedulingParam param) { |
| | | List<SysUser> filteredList = new ArrayList<>(); |
| | | try { |
| | | Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId(); |
| | | List<Point> partitionLocation = param.getPartitionLocation(); |
| | | |
| | | SysUser user = new SysUser(); |
| | | user.setDeptId(deptId); |
| | | List<SysUser> appUserList = iSysUserService.selectAllAppUserList(user); |
| | | //过滤在线 |
| | | List<SysUser> onLineList = appUserList.stream() |
| | | .filter(sysUser -> (sysUser.getAppOnlineState().equals("1"))) |
| | | .filter(sysUser -> (sysUser.getAppUserType().equals("1"))) |
| | | .collect(Collectors.toList()); |
| | | //过滤范围 |
| | | for (SysUser sysUser : onLineList) { |
| | | ArdAppPosition ardAppPosition = ardAppPositionMapper.selectLastArdAppPositionByUserId(sysUser.getUserId()); |
| | | if (ardAppPosition != null) { |
| | | Double lon = ardAppPosition.getLongitude(); |
| | | Double lat = ardAppPosition.getLatitude(); |
| | | if (lon == null || lat == null) { |
| | | continue; |
| | | } |
| | | Point point2D = new Point(lon, lat); |
| | | boolean inPolygon = GisUtil.isInPolygon(point2D, partitionLocation); |
| | | if (inPolygon) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("longitude", lon); |
| | | params.put("latitude", lat); |
| | | sysUser.setParams(params); |
| | | filteredList.add(sysUser); // 将满足条件的用户添加到筛选列表中 |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("获取封控圈内所有在线app用户异常" + ex.getMessage()); |
| | | } |
| | | 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<>(); |
| | | //获取当前用户的部门 |
| | | 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); |
| | | if (ardWalls.size() > 0) { |
| | | for (ArdWall wall : ardWalls) { |
| | | 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); |
| | | } |
| | | |
| | | //判断当前用户位置是否在围栏内 |
| | | 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); |
| | | //更新最后报警id |
| | | userLastAlarm.put(userId, uuid); |
| | | } else { |
| | | // 上一次用户状态已进入,更新最后报警 |
| | | ardAlarmWall.setId(lastAlarmId); |
| | | ardAlarmWallService.updateArdAlarmWall(ardAlarmWall); |
| | | } |
| | | ardAlarmWalls.add(ardAlarmWall); |
| | | } |
| | | else |
| | | { |
| | | //移除最后报警id |
| | | userLastAlarm.remove(userId); |
| | | } |
| | | } |
| | | } |
| | | return ardAlarmWalls; |
| | | } |
| | | } |