|
@@ -25,6 +25,7 @@ import top.lvzhiqiang.config.WorkWeixinProperties;
|
|
|
import top.lvzhiqiang.entity.CoinHistoryOrder;
|
|
import top.lvzhiqiang.entity.CoinHistoryOrder;
|
|
|
import top.lvzhiqiang.entity.CoinMonitorCurrency;
|
|
import top.lvzhiqiang.entity.CoinMonitorCurrency;
|
|
|
import top.lvzhiqiang.entity.CoinTrader;
|
|
import top.lvzhiqiang.entity.CoinTrader;
|
|
|
|
|
+import top.lvzhiqiang.entity.CoinWatchlist;
|
|
|
import top.lvzhiqiang.mapper.CoinMapper;
|
|
import top.lvzhiqiang.mapper.CoinMapper;
|
|
|
import top.lvzhiqiang.service.CoinService;
|
|
import top.lvzhiqiang.service.CoinService;
|
|
|
import top.lvzhiqiang.util.*;
|
|
import top.lvzhiqiang.util.*;
|
|
@@ -36,7 +37,9 @@ import java.math.RoundingMode;
|
|
|
import java.security.InvalidKeyException;
|
|
import java.security.InvalidKeyException;
|
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.*;
|
|
import java.util.concurrent.*;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
@@ -93,6 +96,7 @@ public class CoinServiceImpl implements CoinService {
|
|
|
private final ForkJoinPool forkJoinPool4 = new ForkJoinPool(16);
|
|
private final ForkJoinPool forkJoinPool4 = new ForkJoinPool(16);
|
|
|
private final ForkJoinPool forkJoinPool5 = new ForkJoinPool(16);
|
|
private final ForkJoinPool forkJoinPool5 = new ForkJoinPool(16);
|
|
|
private static final DecimalFormat df1 = new DecimalFormat("#,##0.00");
|
|
private static final DecimalFormat df1 = new DecimalFormat("#,##0.00");
|
|
|
|
|
+ private static final DecimalFormat df2 = new DecimalFormat("#,##0");
|
|
|
|
|
|
|
|
private static final WxCpServiceImpl wxCpService4News;
|
|
private static final WxCpServiceImpl wxCpService4News;
|
|
|
|
|
|
|
@@ -654,6 +658,63 @@ public class CoinServiceImpl implements CoinService {
|
|
|
}
|
|
}
|
|
|
}, 0, 3, TimeUnit.SECONDS);
|
|
}, 0, 3, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
|
|
+ // coingecko
|
|
|
|
|
+ scheduler.scheduleAtFixedRate(() -> {
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("sortField", "create_time");
|
|
|
|
|
+ params.put("sort", "desc");
|
|
|
|
|
+ List<CoinWatchlist> watchlistList = coinMapper.findWatchlistList(params);
|
|
|
|
|
+
|
|
|
|
|
+ for (CoinWatchlist coinWatchlist : watchlistList) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(5000L);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Connection.Response response = JsoupUtil.requestBody(coinWatchlist.getCollectUrl(), JsoupUtil.HTTP_GET, InitRunner.proxy, new HashMap<>(), new HashMap<>());
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(response.body());
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject marketData = jsonObject.getJSONObject("market_data");
|
|
|
|
|
+ // 总市值排名
|
|
|
|
|
+ Integer totalMarketRanking = marketData.getInteger("market_cap_rank");
|
|
|
|
|
+ coinWatchlist.setTotalMarketRanking(totalMarketRanking);
|
|
|
|
|
+ // 总市值
|
|
|
|
|
+ BigDecimal totalMarketValue = marketData.getJSONObject("market_cap").getBigDecimal("usd");
|
|
|
|
|
+ coinWatchlist.setTotalMarketValue(totalMarketValue);
|
|
|
|
|
+ // 市场价格
|
|
|
|
|
+ String markPrice = marketData.getJSONObject("current_price").getString("usd");
|
|
|
|
|
+ coinWatchlist.setMarkPrice(markPrice);
|
|
|
|
|
+ // 历史最高价格
|
|
|
|
|
+ String highestHistoricalPrice = marketData.getJSONObject("ath").getString("usd");
|
|
|
|
|
+ coinWatchlist.setHighestHistoricalPrice(highestHistoricalPrice);
|
|
|
|
|
+ // 历史最高日期
|
|
|
|
|
+ LocalDate highestHistoricalDate = LocalDate.parse(marketData.getJSONObject("ath_date").getString("usd"), DateUtils.utcTimeFormatter);
|
|
|
|
|
+ coinWatchlist.setHighestHistoricalDate(highestHistoricalDate);
|
|
|
|
|
+ // 历史最低价格
|
|
|
|
|
+ String lowestHistoricalPrice = marketData.getJSONObject("atl").getString("usd");
|
|
|
|
|
+ coinWatchlist.setLowestHistoricalPrice(lowestHistoricalPrice);
|
|
|
|
|
+ // 历史最低日期
|
|
|
|
|
+ LocalDate lowestHistoricalDate = LocalDate.parse(marketData.getJSONObject("atl_date").getString("usd"), DateUtils.utcTimeFormatter);
|
|
|
|
|
+ coinWatchlist.setLowestHistoricalDate(lowestHistoricalDate);
|
|
|
|
|
+ // 涨幅倍数
|
|
|
|
|
+ BigDecimal increaseMultiple = new BigDecimal(highestHistoricalPrice).divide(new BigDecimal(lowestHistoricalPrice), 0, RoundingMode.HALF_UP);
|
|
|
|
|
+ coinWatchlist.setIncreaseMultiple(increaseMultiple.intValue());
|
|
|
|
|
+ // 发行日期
|
|
|
|
|
+ // 发行天数
|
|
|
|
|
+ if (coinWatchlist.getIssuingDate() != null) {
|
|
|
|
|
+ long totalDays = ChronoUnit.DAYS.between(coinWatchlist.getIssuingDate(), LocalDate.now());
|
|
|
|
|
+ coinWatchlist.setIssuingDays((int) totalDays);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ coinMapper.updateCoinWatchlist(coinWatchlist);
|
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
+ log.error("jsoup CoinWatchlist error,coinWatchlist={}", coinWatchlist, ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 0, 1, TimeUnit.HOURS);
|
|
|
|
|
+
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -938,6 +999,14 @@ public class CoinServiceImpl implements CoinService {
|
|
|
renderMainSearch4TraderList(mixTraderList);
|
|
renderMainSearch4TraderList(mixTraderList);
|
|
|
//result = (JSONArray) JSON.toJSON(mixTraderList);
|
|
//result = (JSONArray) JSON.toJSON(mixTraderList);
|
|
|
return coinTraderPageInfo;
|
|
return coinTraderPageInfo;
|
|
|
|
|
+ } else if (params.getString("nameEn").equals("watchlist")) {
|
|
|
|
|
+ PageHelper.startPage(params.getInteger("pageNo"), params.getInteger("pageSize"), true);
|
|
|
|
|
+ List<CoinWatchlist> watchlistList = coinMapper.findWatchlistList(params.toJavaObject(Map.class));
|
|
|
|
|
+
|
|
|
|
|
+ PageInfo<CoinWatchlist> watchlistPageInfo = new PageInfo<>(watchlistList);
|
|
|
|
|
+
|
|
|
|
|
+ renderMainSearch4Watchlist(watchlistList);
|
|
|
|
|
+ return watchlistPageInfo;
|
|
|
} else if (params.getString("nameEn").equals("monitorCurrency")) {
|
|
} else if (params.getString("nameEn").equals("monitorCurrency")) {
|
|
|
List<CoinMonitorCurrency> monitorCurrencyList = coinMapper.findMonitorCurrencyList();
|
|
List<CoinMonitorCurrency> monitorCurrencyList = coinMapper.findMonitorCurrencyList();
|
|
|
|
|
|
|
@@ -971,6 +1040,12 @@ public class CoinServiceImpl implements CoinService {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void renderMainSearch4Watchlist(List<CoinWatchlist> watchlistList) {
|
|
|
|
|
+ for (CoinWatchlist coinWatchlist : watchlistList) {
|
|
|
|
|
+ coinWatchlist.setTotalMarketValueStr(df2.format(coinWatchlist.getTotalMarketValue()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void renderMainSearch4TraderList(List<CoinTrader> mixTraderList) {
|
|
private void renderMainSearch4TraderList(List<CoinTrader> mixTraderList) {
|
|
|
for (CoinTrader mixTrader : mixTraderList) {
|
|
for (CoinTrader mixTrader : mixTraderList) {
|
|
|
|
|
|