| | |
| | | @Override |
| | | public Results chaseCarByCarId(String usersId, String carId, String cycle) { |
| | | try{ |
| | | Map<String,Map<String,Object>> map = new HashMap(); |
| | | /*Map<String,Map<String,Object>> map = new HashMap(); |
| | | map.put(carId,new HashMap()); |
| | | PositionContainer.getUserPositionMap().put(usersId,map); |
| | | PositionContainer.getUserPositionMap().put(usersId,map);*/ |
| | | if(cycle.equals("0")){ |
| | | if(userCarTimerMap.get(usersId) != null){ |
| | | userCarTimerMap.get(usersId).cancel(); |
| | |
| | | userCarTimerMap.get(usersId).cancel(); |
| | | userCarTimerMap.remove(usersId); |
| | | PositionContainer.getUserPositionMap().remove(usersId); |
| | | Map<String,Map<String,Object>> map = new HashMap(); |
| | | map.put(carId,new HashMap()); |
| | | PositionContainer.getUserPositionMap().put(usersId,map); |
| | | Date date = new Date(); |
| | | Timer carPositionTimer = new Timer();//定时推送实时位置 |
| | | TimerTask carPositionTask =new TimerTask(){ |
| | | @Override |
| | | public void run(){ |
| | | Map<String,Object> position = PositionContainer.getUserPositionMap().get(usersId).get(carId); |
| | | Map<String,Map<String,Object>> data = new HashMap(); |
| | | data.put("31000",position); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(usersId), JSON.toJSONString(data)); |
| | | if(position != null){ |
| | | if(position.size() != 0){ |
| | | Map<String,Map<String,Object>> data = new HashMap(); |
| | | data.put("31000",position); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(usersId), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | carPositionTimer.scheduleAtFixedRate(carPositionTask,date,Integer.parseInt(cycle));//启用 |
| | | this.userCarTimerMap.put(usersId,carPositionTimer); |
| | | return Results.succeed("开始追踪"); |
| | | }else{ |
| | | Map<String,Map<String,Object>> map = new HashMap(); |
| | | map.put(carId,new HashMap()); |
| | | PositionContainer.getUserPositionMap().put(usersId,map); |
| | | Date date = new Date(); |
| | | Timer carPositionTimer = new Timer();//定时推送实时位置 |
| | | TimerTask carPositionTask =new TimerTask(){ |
| | | @Override |
| | | public void run(){ |
| | | Map<String,Object> position = PositionContainer.getUserPositionMap().get(usersId).get(carId); |
| | | Map<String,Map<String,Object>> data = new HashMap(); |
| | | data.put("31000",position); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(usersId), JSON.toJSONString(data)); |
| | | if(position != null){ |
| | | if(position.size() != 0){ |
| | | Map<String,Map<String,Object>> data = new HashMap(); |
| | | data.put("31000",position); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(usersId), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | carPositionTimer.scheduleAtFixedRate(carPositionTask,date,Integer.parseInt(cycle));//启用 |