Browse Source

add: coinwatchlist查看详情时以表格形式展示OTHER表的数据v1

tujidelv 1 year ago
parent
commit
1a689ae1f7

+ 6 - 4
src/main/java/top/lvzhiqiang/mapper/CoinMapper.java

@@ -111,15 +111,18 @@ public interface CoinMapper {
             "issuing_days=#{issuingDays},coingecko_url=#{coingeckoUrl},cmc_url=#{cmcUrl},feixiaohao_url=#{feixiaohaoUrl},modify_time=now() where id = #{id}")
     int updateCoinWatchlist(CoinWatchlist coinWatchlist);
 
-    @Insert("INSERT INTO coin_watchlist_other(symbol, max_supply, circulating_supply, circulating_rate, total_supply, market_cap, fully_diluted_market_cap, cex_spot, cex_perpetual, create_time, modify_time) " +
-            "VALUES (#{symbol}, #{maxSupply}, #{circulatingSupply}, #{circulatingRate}, #{totalSupply}, #{marketCap}, #{fullyDilutedMarketCap}, #{cexSpot}, #{cexPerpetual}, now(), now())" +
+    @Insert("INSERT INTO coin_watchlist_other(symbol, max_supply, circulating_supply, circulating_rate, total_supply, market_cap, fully_diluted_market_cap, create_time, modify_time) " +
+            "VALUES (#{symbol}, #{maxSupply}, #{circulatingSupply}, #{circulatingRate}, #{totalSupply}, #{marketCap}, #{fullyDilutedMarketCap}, now(), now())" +
             " ON DUPLICATE KEY UPDATE max_supply=values(max_supply),circulating_supply=values(circulating_supply),circulating_rate=values(circulating_rate),total_supply=values(total_supply)" +
-            ",market_cap=values(market_cap),fully_diluted_market_cap=values(fully_diluted_market_cap),cex_spot=values(cex_spot),cex_perpetual=values(cex_perpetual),modify_time=now()")
+            ",market_cap=values(market_cap),fully_diluted_market_cap=values(fully_diluted_market_cap),modify_time=now()")
     int insertOrUpdateCoinWatchlistOther(CoinWatchlistOther coinWatchlistOther);
 
     @Select("select a.*,b.coingecko_id from coin_watchlist_other a left join coin_watchlist b on a.symbol=b.symbol where a.delete_flag = 1 and a.symbol not in ('BTC','ETH')")
     List<CoinWatchlistOther> findAllCoinWatchlistOther();
 
+    @Select("select * from coin_watchlist_other where symbol = #{symbol} and delete_flag = 1")
+    CoinWatchlistOther findWatchlistOtherBySymbol(String symbol);
+
     @Insert({"<script>" +
             "INSERT INTO coin_watchlist_other(symbol,cex_spot,cex_perpetual,create_time,modify_time)" +
             " VALUES " +
@@ -148,7 +151,6 @@ public interface CoinMapper {
     @Select("select * from coin_watchlist where symbol = #{symbol} and delete_flag = 1")
     CoinWatchlist findWatchlistBySymbol(String symbol);
 
-
     @Insert("INSERT INTO file_image(old_name, new_name, category_id, size, path, remark, create_time, modify_time) " +
             "VALUES (#{oldName}, #{newName}, #{categoryId}, #{size}, #{path}, #{remark}, now(), now())")
     int insertFileImage(FileImage fileImage);

+ 35 - 1
src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

@@ -2138,7 +2138,41 @@ public class CoinServiceImpl implements CoinService {
             return fileImage;
         } else if ("watchlist".equals(nameEn)) {
             CoinWatchlist coinWatchlist = coinMapper.findWatchlistBySymbol(id);
-            coinWatchlist.setRemark(MarkdownToHtmlUtils.markdownToHtmlExtensions(coinWatchlist.getRemark()));
+
+            CoinWatchlistOther coinWatchlistOther = coinMapper.findWatchlistOtherBySymbol(id);
+
+            StringBuffer sb =  new StringBuffer();
+            sb.append("<table border=\"1\" cellspacing=\"0\">");
+            sb.append("<tr><td>").append("流通市值").append("</td>").append("<td>").append(coinWatchlistOther.getMarketCap()).append("</td></tr>");
+            sb.append("<tr><td>").append("流通供应量").append("</td>").append("<td>").append(coinWatchlistOther.getCirculatingSupply()).append("</td></tr>");
+            sb.append("<tr><td>").append("流通率").append("</td>").append("<td>").append(coinWatchlistOther.getCirculatingRate()).append("</td></tr>");
+            sb.append("<tr><td>").append("总供应量").append("</td>").append("<td>").append(coinWatchlistOther.getTotalSupply()).append("</td></tr>");
+            sb.append("<tr><td>").append("最大供应量").append("</td>").append("<td>").append(coinWatchlistOther.getMaxSupply()).append("</td></tr>");
+            sb.append("<tr><td>").append("完全稀释的市值").append("</td>").append("<td>").append(coinWatchlistOther.getFullyDilutedMarketCap()).append("</td></tr>");
+
+            String[] coingeckoExchangeNameArr = InitRunner.dicCodeMap.get("coingecko_exchange_names").getCodeValue().split(",");
+            List<String> coingeckoExchangeNameList = new ArrayList<>();
+            if (StringUtils.isNotEmpty(coinWatchlistOther.getCexSpot()) && coingeckoExchangeNameArr.length == coinWatchlistOther.getCexSpot().length()) {
+                for (int i = 0; i < coingeckoExchangeNameArr.length; i++) {
+                    if ("1".equals(String.valueOf(coinWatchlistOther.getCexSpot().charAt(i)))) {
+                        coingeckoExchangeNameList.add(coingeckoExchangeNameArr[i]);
+                    }
+                }
+            }
+            sb.append("<tr><td>").append("现货").append("</td>").append("<td>").append(String.join("、", coingeckoExchangeNameList)).append("</td></tr>");
+            String[] coingeckoExchangeFuturesNameArr = InitRunner.dicCodeMap.get("coingecko_exchange_futures_names").getCodeValue().split(",");
+            List<String> coingeckoExchangeFuturesNameList = new ArrayList<>();
+            if (StringUtils.isNotEmpty(coinWatchlistOther.getCexPerpetual()) && coingeckoExchangeFuturesNameArr.length == coinWatchlistOther.getCexPerpetual().length()) {
+                for (int i = 0; i < coingeckoExchangeFuturesNameArr.length; i++) {
+                    if ("1".equals(String.valueOf(coinWatchlistOther.getCexPerpetual().charAt(i)))) {
+                        coingeckoExchangeFuturesNameList.add(coingeckoExchangeFuturesNameArr[i]);
+                    }
+                }
+            }
+            sb.append("<tr><td>").append("合约").append("</td>").append("<td>").append(String.join("、", coingeckoExchangeFuturesNameList)).append("</td></tr>");
+            sb.append("</table>");
+
+            coinWatchlist.setRemark(sb + MarkdownToHtmlUtils.markdownToHtmlExtensions(coinWatchlist.getRemark()));
             coinWatchlist.setFeixiaohaoUrl("https://www.feixiaohao.com/currencies/" + coinWatchlist.getFeixiaohaoUrl());
             coinWatchlist.setCmcUrl("https://coinmarketcap.com/zh/currencies/" + coinWatchlist.getCmcUrl());
             coinWatchlist.setCoingeckoUrl("https://www.coingecko.com/zh/%E6%95%B0%E5%AD%97%E8%B4%A7%E5%B8%81/" + coinWatchlist.getCoingeckoUrl());