| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | ArdWallMapper ardWallMapper; |
| | | @Resource |
| | | IArdAlarmWallService ardAlarmWallService; |
| | | Map<String, String> userLastAlarm = new HashMap<>(); |
| | | |
| | | 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<>(); |
| | | //获取当前用户的部门 |
| | | String userId = ardAppPosition.getUserId(); |
| | |
| | | if (ardWalls.size() > 0) { |
| | | for (ArdWall wall : ardWalls) { |
| | | String wallPoi = wall.getWallPoi(); |
| | | String wallType = wall.getType(); |
| | | //处理多边形的每个点的经纬度 |
| | | String[] parts = wallPoi.split(","); |
| | | List<Point> pointList = new ArrayList<>(); |
| | |
| | | point.setLatitude(Double.valueOf(parts[i + 1])); |
| | | pointList.add(point); |
| | | } |
| | | |
| | | //判断当前用户位置是否在围栏内 |
| | | Point userPoint=new Point(); |
| | | userPoint.setLongitude(ardAppPosition.getLongitude()); |
| | | userPoint.setLatitude(ardAppPosition.getLatitude()); |
| | | Point userPoint=new Point(ardAppPosition.getLongitude(),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); |
| | | 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()); |
| | | //禁入 |
| | | if("1".equals(wallType)) { |
| | | //判断当前用户位置是否在围栏内 |
| | | if (inPolygon) { |
| | | String lastInAlarmId = userInLastAlarm.get(userId); |
| | | if (lastInAlarmId == null) { |
| | | String uuid = IdUtils.simpleUUID(); |
| | | //当前用户上一次状态未进入,生成报警 |
| | | ardAlarmWall.setId(uuid); |
| | | ardAlarmWallService.insertArdAlarmWall(ardAlarmWall); |
| | | //更新最后报警id |
| | | userInLastAlarm.put(userId, uuid); |
| | | } else { |
| | | //上一次用户状态已进入,更新最后报警 |
| | | ardAlarmWall.setId(lastInAlarmId); |
| | | ardAlarmWallService.updateArdAlarmWall(ardAlarmWall); |
| | | } |
| | | ardAlarmWalls.add(ardAlarmWall); |
| | | } |
| | | ardAlarmWalls.add(ardAlarmWall); |
| | | else |
| | | { |
| | | //移除最后报警id |
| | | userInLastAlarm.remove(userId); |
| | | } |
| | | } |
| | | else |
| | | else//禁出 |
| | | { |
| | | //移除最后报警id |
| | | userLastAlarm.remove(userId); |
| | | //判断当前用户位置是否在围栏外 |
| | | if (!inPolygon) { |
| | | String lastAlarmId = userOutLastAlarm.get(userId); |
| | | if (lastAlarmId == null) { |
| | | String uuid = IdUtils.simpleUUID(); |
| | | //当前用户上一次状态未进入,生成报警 |
| | | ardAlarmWall.setId(uuid); |
| | | ardAlarmWallService.insertArdAlarmWall(ardAlarmWall); |
| | | //更新最后报警id |
| | | userOutLastAlarm.put(userId, uuid); |
| | | } else { |
| | | //上一次用户状态已进入,更新最后报警 |
| | | ardAlarmWall.setId(lastAlarmId); |
| | | ardAlarmWallService.updateArdAlarmWall(ardAlarmWall); |
| | | } |
| | | ardAlarmWalls.add(ardAlarmWall); |
| | | } |
| | | else |
| | | { |
| | | //移除最后报警id |
| | | userOutLastAlarm.remove(userId); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | return ardAlarmWalls; |