1
zj
2024-08-14 5578112574d523d639765dc491ea6e0c6dc51ded
1
4 files modified
36 ■■■■■ changed files
websocketSerivce/src/main/java/org/example/task/BitgetStock.java 11 ●●●● patch | view | raw | blame | history
websocketSerivce/src/main/java/org/example/task/GateStock.java 7 ●●●● patch | view | raw | blame | history
websocketSerivce/src/main/java/org/example/task/KucoinStock.java 7 ●●●● patch | view | raw | blame | history
websocketSerivce/src/main/java/org/example/task/MexcStock.java 11 ●●●● patch | view | raw | blame | history
websocketSerivce/src/main/java/org/example/task/BitgetStock.java
@@ -1,5 +1,6 @@
package org.example.task;
import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@@ -9,6 +10,7 @@
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -20,6 +22,7 @@
import org.example.pojo.Currency;
import org.example.pojo.bo.CurrencyBitgetBo;
import org.example.server.impl.CurrencySerivceImpl;
import org.example.util.ConverterUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -29,6 +32,7 @@
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.SQLOutput;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -85,14 +89,10 @@
            }.getType());
            getList.parallelStream().forEach(person -> person.setSymbol(StringUtils.remove(person.getSymbol(), "-")));
            //  获取数据库中已有的symbol列表
            List<Currency> dbList = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource,"bitget"));
            Set<String> symbolSet = dbList.stream().map(Currency::getSymbol).collect(Collectors.toSet());
            currencyService.remove(new LambdaQueryWrapper<Currency>().eq(Currency::getSource,"bitget"));
            //  比对接口返回的数据和数据库中已有的数据,找出新增的数据
            List<Currency> saveList = getList.stream()
                    .filter(currency -> !symbolSet.contains(currency.getSymbol()))
                    .map(currency -> {
                        Currency newCurrency = new Currency();
                        newCurrency.setSymbol(currency.getSymbol());
@@ -102,7 +102,6 @@
                        return newCurrency;
                    })
                    .collect(Collectors.toList());
            //  批量保存新增数据到数据库
            if (CollectionUtils.isNotEmpty(saveList)) {
                currencyService.saveBatch(saveList);
websocketSerivce/src/main/java/org/example/task/GateStock.java
@@ -14,6 +14,7 @@
import org.example.pojo.bo.CurrencyMexcBo;
import org.example.server.impl.CurrencySerivceImpl;
import org.example.common.MarketDataClient;
import org.example.util.ConverterUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -73,13 +74,10 @@
            getList.parallelStream().forEach(person -> person.setId(StringUtils.remove(person.getId(), "_")));
            //  获取数据库中已有的symbol列表
            List<Currency> dbList = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "gate"));
            Set<String> symbolSet = dbList.stream().map(Currency::getSymbol).collect(Collectors.toSet());
            currencyService.remove(new LambdaQueryWrapper<Currency>().eq(Currency::getSource,"gate"));
            //  比对接口返回的数据和数据库中已有的数据,找出新增的数据
            List<Currency> saveList = getList.stream()
                    .filter(currency -> !symbolSet.contains(currency.getId()))
                    .map(currency -> {
                        Currency newCurrency = new Currency();
                        newCurrency.setSymbol(currency.getId());
@@ -89,7 +87,6 @@
                        return newCurrency;
                    })
                    .collect(Collectors.toList());
            //  批量保存新增数据到数据库
            if(CollectionUtils.isNotEmpty(saveList)){
                currencyService.saveBatch(saveList);
websocketSerivce/src/main/java/org/example/task/KucoinStock.java
@@ -13,6 +13,7 @@
import org.example.pojo.Currency;
import org.example.pojo.bo.CurrencyKucoin;
import org.example.server.impl.CurrencySerivceImpl;
import org.example.util.ConverterUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -72,14 +73,10 @@
            }.getType());
            getList.parallelStream().forEach(person -> person.setSymbol(StringUtils.remove(person.getSymbol(), "-")));
            //  获取数据库中已有的symbol列表
            List<Currency> dbList = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "kucoin"));
            Set<String> symbolSet = dbList.stream().map(Currency::getSymbol).collect(Collectors.toSet());
            currencyService.remove(new LambdaQueryWrapper<Currency>().eq(Currency::getSource,"kucoin"));
            //  比对接口返回的数据和数据库中已有的数据,找出新增的数据
            List<Currency> saveList = getList.stream()
                    .filter(currency -> !symbolSet.contains(currency.getSymbol()))
                    .map(currency -> {
                        Currency newCurrency = new Currency();
                        newCurrency.setSymbol(currency.getSymbol());
websocketSerivce/src/main/java/org/example/task/MexcStock.java
@@ -75,15 +75,8 @@
            List<CurrencyMexcBo> getList = gson.fromJson(symbolsJson, new TypeToken<List<CurrencyMexcBo>>() {
            }.getType());
            //  获取数据库中已有的symbol列表
            List<Currency> dbList = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "mexc"));
            Set<String> symbolSet = dbList.stream().map(Currency::getSymbol).collect(Collectors.toSet());
            //  比对接口返回的数据和数据库中已有的数据,找出新增的数据
            List<CurrencyMexcBo> saveList = getList.stream()
                    .filter(CurrencyMexcBo -> !symbolSet.contains(CurrencyMexcBo.getSymbol()))
                    .collect(Collectors.toList());
            List<Currency> currencies = ConverterUtil.convertToList(saveList, Currency.class);
            currencyService.remove(new LambdaQueryWrapper<Currency>().eq(Currency::getSource,"mexc"));
            List<Currency> currencies = ConverterUtil.convertToList(getList, Currency.class);
            //  批量保存新增数据到数据库
            if(CollectionUtils.isNotEmpty(currencies)){
                currencyService.saveBatch(currencies);