| | |
| | | package org.example.websocket.server; |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.google.common.reflect.TypeToken; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import lombok.NonNull; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.example.pojo.ConfigCurrency; |
| | | import org.example.pojo.MarketDataOut; |
| | | import org.example.pojo.bo.WsBo; |
| | | import org.example.util.RedisUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | |
| | |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session) { |
| | | WsBo wsBo = getWsBoForSession(session.getId()); |
| | | String s = RedisUtil.get("user_" + wsBo.getUserId()); |
| | | if(null == s || s.isEmpty()){ |
| | | closeSession(session, "用户未登录"); |
| | | } |
| | | this.session = session; |
| | | int count = onlineCount.incrementAndGet(); |
| | | wsServers.add(this); |
| | |
| | | |
| | | private Map<Session, Long> lastMessageTimeMap = new ConcurrentHashMap<>(); |
| | | |
| | | private void schedulePushMessage(Session session, String message) { |
| | | private void schedulePushMessage(Session session, String message) throws JsonProcessingException { |
| | | WsBo wsBo = getWsBoForSession(session.getId()); |
| | | if (wsBo != null) { |
| | | long currentTime = System.currentTimeMillis(); |
| | |
| | | } |
| | | } |
| | | private static final Gson gson = new Gson(); |
| | | private String megFiltration(WsBo wsBo,String message){ |
| | | private String megFiltration(WsBo wsBo,String message) throws JsonProcessingException { |
| | | List<MarketDataOut> redisValueMap = gson.fromJson(message, new TypeToken<List<MarketDataOut>>() {}.getType()); |
| | | |
| | | String key = "config_"; |
| | | String value = RedisUtil.get(key + wsBo.getUserId()); |
| | | List<ConfigCurrency> currencies = null; |
| | | if(null != value && !value.isEmpty()){ |
| | | 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(null != wsBo.getCurrency()){ |
| | | redisValueMap = redisValueMap.stream() |