| | |
| | | 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.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.uuid.IdUtils; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | return filteredList; |
| | | } |
| | | |
| | | /** |
| | | * 获取封控圈内所有在线app用户(多边形) |
| | | * 刘苏义 |
| | |
| | | if (lon == null || lat == null) { |
| | | continue; |
| | | } |
| | | Point point2D=new Point(lon,lat); |
| | | Point point2D = new Point(lon, lat); |
| | | boolean inPolygon = GisUtil.isInPolygon(point2D, partitionLocation); |
| | | if (inPolygon) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | |
| | | } |
| | | 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; |
| | | } |
| | | } |