|  |  |  | 
|---|
|  |  |  | * @Version 1.0 | 
|---|
|  |  |  | * {"enabled":false,"frequency":1000,"userId":"69cf75f289424a48ba10cf33fa324206"} | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | public class AppPositionPushService { | 
|---|
|  |  |  | public static Map<String, List<ArdAppPosition>> dataMap = new HashMap<>();//常规数据 每个用户关联 | 
|---|
|  |  |  | public static Map<String, List<ArdAppPosition>> tempDataMap = new HashMap<>();//临时数据 每个用户关联 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //接收处理器 | 
|---|
|  |  |  | public static void messageHandler(String userId, String message) { | 
|---|
|  |  |  | Map<String, Object> map = JSONObject.parseObject(message, Map.class); | 
|---|
|  |  |  | if (map.size() > 0) { | 
|---|
|  |  |  | Boolean enabled = (Boolean) map.get("enabled"); | 
|---|
|  |  |  | if (enabled) { | 
|---|
|  |  |  | //启动全局推送 | 
|---|
|  |  |  | List<ArdAppPosition> newList = new ArrayList<>(AppPositionPushService.getAppPositionList()); | 
|---|
|  |  |  | AppPositionPushService.dataMap.put(userId, newList); | 
|---|
|  |  |  | if (!AppPositionPushService.userTimerMap.containsKey(userId)) { | 
|---|
|  |  |  | Timer timer = AppPositionPushService.startTimerTask(userId, 3000); | 
|---|
|  |  |  | AppPositionPushService.userTimerMap.put(userId, timer);//将定时器关联用户 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Map<String, Object> map = JSONObject.parseObject(message, Map.class); | 
|---|
|  |  |  | if (map.size() > 0) { | 
|---|
|  |  |  | Boolean enabled = (Boolean) map.get("enabled"); | 
|---|
|  |  |  | if (enabled) { | 
|---|
|  |  |  | //启动全局推送 | 
|---|
|  |  |  | List<ArdAppPosition> newList = new ArrayList<>(AppPositionPushService.getAppPositionList()); | 
|---|
|  |  |  | AppPositionPushService.dataMap.put(userId, newList); | 
|---|
|  |  |  | if (!AppPositionPushService.userTimerMap.containsKey(userId)) { | 
|---|
|  |  |  | Timer timer = AppPositionPushService.startTimerTask(userId, 3000); | 
|---|
|  |  |  | AppPositionPushService.userTimerMap.put(userId, timer);//将定时器关联用户 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //停止全局推送 | 
|---|
|  |  |  | if (AppPositionPushService.userTimerMap.containsKey(userId)) { | 
|---|
|  |  |  | Timer timer = AppPositionPushService.userTimerMap.get(userId); | 
|---|
|  |  |  | AppPositionPushService.stopTimerTask(timer); | 
|---|
|  |  |  | AppPositionPushService.userTimerMap.remove(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (AppPositionPushService.tempUserTimerMap.containsKey(userId)) { | 
|---|
|  |  |  | Timer temptimer = AppPositionPushService.tempUserTimerMap.get(userId); | 
|---|
|  |  |  | AppPositionPushService.stopTimerTask(temptimer); | 
|---|
|  |  |  | AppPositionPushService.tempUserTimerMap.remove(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | AppPositionPushService.dataMap.remove(userId); | 
|---|
|  |  |  | AppPositionPushService.tempDataMap.remove(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //停止全局推送 | 
|---|
|  |  |  | if (AppPositionPushService.userTimerMap.containsKey(userId)) { | 
|---|
|  |  |  | Timer timer = AppPositionPushService.userTimerMap.get(userId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer frequency = (Integer) map.get("frequency"); | 
|---|
|  |  |  | String uId = (String) map.get("userId"); | 
|---|
|  |  |  | if (frequency > 0) { | 
|---|
|  |  |  | List<ArdAppPosition> List = AppPositionPushService.getAppPositionList().stream() | 
|---|
|  |  |  | .filter(obj -> !obj.getUserId().equals(uId)) | 
|---|
|  |  |  | .collect(Collectors.toList());//去除引导后的list | 
|---|
|  |  |  | AppPositionPushService.dataMap.put(userId, List); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ArdAppPosition> tempList = AppPositionPushService.getAppPositionList().stream() | 
|---|
|  |  |  | .filter(obj -> obj.getUserId().equals(uId)) | 
|---|
|  |  |  | .collect(Collectors.toList());//获取引导的list | 
|---|
|  |  |  | AppPositionPushService.tempDataMap.put(userId, tempList); | 
|---|
|  |  |  | Timer timer = AppPositionPushService.startTempTimerTask(userId, frequency); | 
|---|
|  |  |  | AppPositionPushService.tempUserTimerMap.put(userId, timer); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | List<ArdAppPosition> newList = new ArrayList<>(AppPositionPushService.getAppPositionList()); | 
|---|
|  |  |  | AppPositionPushService.dataMap.put(userId, newList); | 
|---|
|  |  |  | Timer timer = AppPositionPushService.tempUserTimerMap.get(userId); | 
|---|
|  |  |  | AppPositionPushService.stopTimerTask(timer); | 
|---|
|  |  |  | AppPositionPushService.userTimerMap.remove(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (AppPositionPushService.tempUserTimerMap.containsKey(userId)) { | 
|---|
|  |  |  | Timer temptimer = AppPositionPushService.tempUserTimerMap.get(userId); | 
|---|
|  |  |  | AppPositionPushService.stopTimerTask(temptimer); | 
|---|
|  |  |  | AppPositionPushService.tempUserTimerMap.remove(userId); | 
|---|
|  |  |  | AppPositionPushService.tempDataMap.remove(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | AppPositionPushService.dataMap.remove(userId); | 
|---|
|  |  |  | AppPositionPushService.tempDataMap.remove(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer frequency = (Integer) map.get("frequency"); | 
|---|
|  |  |  | String uId = (String) map.get("userId"); | 
|---|
|  |  |  | if (frequency > 0) { | 
|---|
|  |  |  | List<ArdAppPosition> List = AppPositionPushService.getAppPositionList().stream() | 
|---|
|  |  |  | .filter(obj -> !obj.getUserId().equals(uId)) | 
|---|
|  |  |  | .collect(Collectors.toList());//去除引导后的list | 
|---|
|  |  |  | AppPositionPushService.dataMap.put(userId, List); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ArdAppPosition> tempList = AppPositionPushService.getAppPositionList().stream() | 
|---|
|  |  |  | .filter(obj -> obj.getUserId().equals(uId)) | 
|---|
|  |  |  | .collect(Collectors.toList());//获取引导的list | 
|---|
|  |  |  | AppPositionPushService.tempDataMap.put(userId, tempList); | 
|---|
|  |  |  | Timer timer = AppPositionPushService.startTempTimerTask(userId, frequency); | 
|---|
|  |  |  | AppPositionPushService.tempUserTimerMap.put(userId, timer); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | List<ArdAppPosition> newList = new ArrayList<>(AppPositionPushService.getAppPositionList()); | 
|---|
|  |  |  | AppPositionPushService.dataMap.put(userId, newList); | 
|---|
|  |  |  | Timer timer = AppPositionPushService.tempUserTimerMap.get(userId); | 
|---|
|  |  |  | AppPositionPushService.stopTimerTask(timer); | 
|---|
|  |  |  | AppPositionPushService.tempUserTimerMap.remove(userId); | 
|---|
|  |  |  | AppPositionPushService.tempDataMap.remove(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //region 旧方法 | 
|---|
|  |  |  | //region 旧方法 | 
|---|
|  |  |  | //            Map<String, List<ArdAppPosition>> dataMap = new HashMap<>(); | 
|---|
|  |  |  | //            List<ArdAppPosition> positionList = AppPositionPush.initDataMap.get(userId);//获取当前用户的默认发送的数据map | 
|---|
|  |  |  | //            if(frequency>0) | 
|---|
|  |  |  | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            AppPositionPush.initDataMap.putAll(dataMap);//更新初始会话默认数据map | 
|---|
|  |  |  | //            AppPositionPush.startLocationPushTask(userId,session,uId, frequency);//开启新任务 | 
|---|
|  |  |  | //endregion | 
|---|
|  |  |  | //endregion | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | log.error(ex.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|