| | |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session) { |
| | | WsBo wsBo = getWsBoForSession(session.getId()); |
| | | String s = RedisUtil.get("user_" + wsBo.getUserId()); |
| | | if(null == s || s.isEmpty() && !wsBo.getToken().equals(s)){ |
| | | closeSession(session, "用户未登录"); |
| | | } |
| | | |
| | | this.session = session; |
| | | int count = onlineCount.incrementAndGet(); |
| | | wsServers.add(this); |
| | |
| | | |
| | | private boolean hasReceivedSubscription(Session session) { |
| | | WsBo wsBo = getWsBoForSession(session.getId()); |
| | | String s = RedisUtil.get("user_" + wsBo.getUserId()); |
| | | if(null == s || s.isEmpty() && !wsBo.getToken().equals(s)){ |
| | | closeSession(session, "用户未登录"); |
| | | } |
| | | return wsBo != null; |
| | | } |
| | | |
| | |
| | | @OnMessage |
| | | public void onMessage(String message, Session session) throws IOException { |
| | | try { |
| | | WsBo bean = JSONUtil.toBean(message, WsBo.class); |
| | | threadLocalData.put(session.getId(), bean); |
| | | if(!message.equals("ping")){ |
| | | WsBo bean = JSONUtil.toBean(message, WsBo.class); |
| | | threadLocalData.put(session.getId(), bean); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("客户段订阅消息格式错误"); |
| | | } |
| | |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | currencies = objectMapper.readValue(value, new TypeReference<List<ConfigCurrency>>() {}); |
| | | } |
| | | if(!CollectionUtils.isEmpty(currencies)){ |
| | | List<String> currency = currencies.stream().map(ConfigCurrency::getCurrency).collect(Collectors.toList()); |
| | | List<String> buy = currencies.stream().map(ConfigCurrency::getBuy).collect(Collectors.toList()); |
| | | List<String> sell = currencies.stream().map(ConfigCurrency::getSell).collect(Collectors.toList()); |
| | | redisValueMap = redisValueMap.stream() |
| | | .filter(data -> !currency.contains(data.getBaseAsset()) && !buy.contains(data.getBuyingPlatform()) && !sell.contains(data.getSellPlatform())) |
| | | .collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(currencies)) { |
| | | Set<String> filtrationSet = currencies.stream() |
| | | .map(f -> f.getCurrency() + f.getBuy() + f.getSell()) |
| | | .collect(Collectors.toSet()); |
| | | redisValueMap.removeIf(data -> filtrationSet.contains(data.getBuyAndSell())); |
| | | } |
| | | |
| | | |
| | | //查询币种 |
| | | if(null != wsBo.getCurrency()){ |
| | |
| | | .filter(data -> !list.contains(data.getBuyingPlatform()) && !list.contains(data.getSellPlatform())) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | //过滤数据 |
| | | if(null != wsBo.getBuyAndSell()){ |
| | | List<String> list = Arrays.asList(wsBo.getBuyAndSell().split(",")); |
| | | redisValueMap = redisValueMap.stream() |
| | | .filter(data -> !list.contains(data.getBuyAndSell())) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | //自选标记 |
| | | if(null != wsBo.getIsMarker()){ |
| | | List<String> list = Arrays.asList(wsBo.getIsMarker().split(",")); |
| | | redisValueMap.stream() |
| | | .filter(data -> list.contains(data.getBaseAsset())) |
| | | .filter(data -> list.contains(data.getBuyAndSell())) |
| | | .forEach(data -> data.setMarker(true)); |
| | | } |
| | | Gson gson = new GsonBuilder().setPrettyPrinting().create(); |