| | |
| | | //app位置上传 |
| | | public static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(20); |
| | | public static final Map<Session, ScheduledFuture<?>> taskMap = new HashMap<>(); |
| | | public static final Map<String, List<ArdAppPosition>> defaultDataMap = new HashMap<>();//默认会话发送数据map |
| | | public static final Map<String, List<ArdAppPosition>> initDataMap = new HashMap<>();//每个会话初始发送数据map |
| | | |
| | | // 初始定时任务,根据用户设置的频率定期推送实时位置信息 |
| | | public static void initPushTask(String userId,Session session, int pushFrequency) { |
| | | defaultDataMap.put(userId,getAppPositionList()); |
| | | public static void initPushTask(String userId, Session session, int pushFrequency) { |
| | | initDataMap.put(userId, getAppPositionList()); |
| | | // 启动新的定时任务 |
| | | if (pushFrequency > 0) { |
| | | scheduler.scheduleAtFixedRate(() -> { |
| | | List<ArdAppPosition> appPositionList = defaultDataMap.get(userId); |
| | | List<ArdAppPosition> appPositionList = initDataMap.get(userId); |
| | | Map newMap = new HashMap<>(); |
| | | newMap.put("50000", appPositionList); |
| | | WebSocketUtils.sendMessage(session, newMap); |
| | |
| | | } |
| | | |
| | | // 新的定时任务,根据用户设置的频率定期推送实时位置信息 |
| | | public static void startLocationPushTask(String userId, Session session,String guideUserId, int pushFrequency) { |
| | | public static void startLocationPushTask(String userId, Session session, String guideUserId, int pushFrequency) { |
| | | // 取消之前设置的定时任务 |
| | | stopLocationPushTask(session); |
| | | // 启动新的定时任务 |
| | | if (pushFrequency > 0) { |
| | | ScheduledFuture<?> task = ScheduledFutureTask(session, userId,guideUserId, pushFrequency); |
| | | ScheduledFuture<?> task = scheduler.scheduleAtFixedRate(() -> { |
| | | List<ArdAppPosition> appPositionList = getAppPositionList().stream() |
| | | .filter(obj -> obj.getUserId().equals(guideUserId)) |
| | | .collect(Collectors.toList()); |
| | | Map newMap = new HashMap<>(); |
| | | newMap.put("50000", appPositionList); |
| | | WebSocketUtils.sendMessage(session, newMap); |
| | | }, 0, pushFrequency, TimeUnit.MILLISECONDS); |
| | | taskMap.put(session, task); // 存储新的定时任务 |
| | | } |
| | | } |
| | | |
| | | public static ScheduledFuture<?> ScheduledFutureTask(Session session, String userId,String guideUserId, Integer pushFrequency) { |
| | | return scheduler.scheduleAtFixedRate(() -> { |
| | | List<ArdAppPosition> appPositionList = getAppPositionList().stream() |
| | | .filter(obj -> obj.getUserId().equals(guideUserId)) |
| | | .collect(Collectors.toList()); |
| | | Map newMap = new HashMap<>(); |
| | | newMap.put("50000", appPositionList); |
| | | WebSocketUtils.sendMessage(session, newMap); |
| | | }, 0, pushFrequency, TimeUnit.MILLISECONDS); |
| | | } |
| | | |
| | | //取消定时任务 |
| | |
| | | |
| | | //查询所有app用户的位置信息 |
| | | public static List<ArdAppPosition> getAppPositionList() { |
| | | List<ArdAppPosition>ArdAppPositions = new ArrayList<>(); |
| | | List<ArdAppPosition> ArdAppPositions = new ArrayList<>(); |
| | | ISysUserService sysUserService = SpringUtils.getBean(ISysUserService.class); |
| | | //获取所有app用户 |
| | | List<SysUser> list = sysUserService.selectAllAppUserList(new SysUser()); |