浏览代码

update:watchlist显示优化v3

lvzhiqiang 1 年之前
父节点
当前提交
ba1a305303

+ 9 - 0
src/main/java/top/lvzhiqiang/entity/CoinWatchlist.java

@@ -34,6 +34,9 @@ public class CoinWatchlist implements Serializable {
      * 市场价格
      * 市场价格
      */
      */
     private String markPrice;
     private String markPrice;
+    private String markPriceStyle;
+    private BigDecimal priceChangePercentage24h;
+    private String priceChangePercentage24hStyle;
 
 
     /**
     /**
      * 总市值
      * 总市值
@@ -56,11 +59,15 @@ public class CoinWatchlist implements Serializable {
      * 历史最高价格
      * 历史最高价格
      */
      */
     private String highestHistoricalPrice;
     private String highestHistoricalPrice;
+    private BigDecimal athChangePercentage;
+    private String athChangePercentageStyle;
 
 
     /**
     /**
      * 历史最低价格
      * 历史最低价格
      */
      */
     private String lowestHistoricalPrice;
     private String lowestHistoricalPrice;
+    private BigDecimal atlChangePercentage;
+    private String atlChangePercentageStyle;
 
 
     /**
     /**
      * 历史最高日期
      * 历史最高日期
@@ -78,6 +85,8 @@ public class CoinWatchlist implements Serializable {
      * 涨幅倍数
      * 涨幅倍数
      */
      */
     private Integer increaseMultiple;
     private Integer increaseMultiple;
+    private String increaseMultiple2;
+    private String increaseMultiple2Style;
 
 
     /**
     /**
      * 发行日期
      * 发行日期

+ 1 - 1
src/main/java/top/lvzhiqiang/mapper/CoinMapper.java

@@ -98,7 +98,7 @@ public interface CoinMapper {
     List<CoinWatchlist> findWatchlistList(Map<String, Object> params);
     List<CoinWatchlist> findWatchlistList(Map<String, Object> params);
 
 
     @Update("update coin_watchlist set cmc_id=#{cmcId},total_market_ranking=#{totalMarketRanking},total_market_value=#{totalMarketValue}," +
     @Update("update coin_watchlist set cmc_id=#{cmcId},total_market_ranking=#{totalMarketRanking},total_market_value=#{totalMarketValue}," +
-            "mark_price=#{markPrice},highest_historical_price=#{highestHistoricalPrice},lowest_historical_price=#{lowestHistoricalPrice}," +
+            "mark_price=#{markPrice},price_change_percentage_24h=#{priceChangePercentage24h},highest_historical_price=#{highestHistoricalPrice},ath_change_percentage=#{athChangePercentage},atl_change_percentage=#{atlChangePercentage},lowest_historical_price=#{lowestHistoricalPrice}," +
             "highest_historical_date=#{highestHistoricalDate},lowest_historical_date=#{lowestHistoricalDate},increase_multiple=#{increaseMultiple}," +
             "highest_historical_date=#{highestHistoricalDate},lowest_historical_date=#{lowestHistoricalDate},increase_multiple=#{increaseMultiple}," +
             "issuing_days=#{issuingDays},modify_time=now() where id = #{id}")
             "issuing_days=#{issuingDays},modify_time=now() where id = #{id}")
     int updateCoinWatchlist(CoinWatchlist coinWatchlist);
     int updateCoinWatchlist(CoinWatchlist coinWatchlist);

+ 56 - 2
src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

@@ -886,12 +886,22 @@ public class CoinServiceImpl implements CoinService {
                         String markPrice = marketData.getBigDecimal("current_price").toPlainString();
                         String markPrice = marketData.getBigDecimal("current_price").toPlainString();
                         coinWatchlist.setMarkPrice(markPrice);
                         coinWatchlist.setMarkPrice(markPrice);
                     }
                     }
+                    // 24小时价格变化
+                    if (marketData.containsKey("price_change_percentage_24h") && null != marketData.get("price_change_percentage_24h")) {
+                        BigDecimal priceChangePercentage24h = marketData.getBigDecimal("price_change_percentage_24h").setScale(2, RoundingMode.HALF_UP);
+                        coinWatchlist.setPriceChangePercentage24h(priceChangePercentage24h);
+                    }
 
 
                     // 历史最高价格
                     // 历史最高价格
                     if (marketData.containsKey("ath") && null != marketData.get("ath")) {
                     if (marketData.containsKey("ath") && null != marketData.get("ath")) {
                         String highestHistoricalPrice = marketData.getBigDecimal("ath").toPlainString();
                         String highestHistoricalPrice = marketData.getBigDecimal("ath").toPlainString();
                         coinWatchlist.setHighestHistoricalPrice(highestHistoricalPrice);
                         coinWatchlist.setHighestHistoricalPrice(highestHistoricalPrice);
                     }
                     }
+                    // 历史最高点涨幅比例
+                    if (marketData.containsKey("ath_change_percentage") && null != marketData.get("ath_change_percentage")) {
+                        BigDecimal athChangePercentage = marketData.getBigDecimal("ath_change_percentage").setScale(2, RoundingMode.HALF_UP);
+                        coinWatchlist.setAthChangePercentage(athChangePercentage);
+                    }
 
 
                     // 历史最高日期
                     // 历史最高日期
                     if (marketData.containsKey("ath_date") && null != marketData.get("ath_date")) {
                     if (marketData.containsKey("ath_date") && null != marketData.get("ath_date")) {
@@ -901,9 +911,14 @@ public class CoinServiceImpl implements CoinService {
 
 
                     // 历史最低价格
                     // 历史最低价格
                     if (marketData.containsKey("atl") && null != marketData.get("atl")) {
                     if (marketData.containsKey("atl") && null != marketData.get("atl")) {
-                        String lowestHistoricalPrice = marketData.getBigDecimal("atl").toPlainString();
+                        String lowestHistoricalPrice = marketData.getString("atl");
                         coinWatchlist.setLowestHistoricalPrice(lowestHistoricalPrice);
                         coinWatchlist.setLowestHistoricalPrice(lowestHistoricalPrice);
                     }
                     }
+                    // 历史最低点涨幅比例
+                    if (marketData.containsKey("atl_change_percentage") && null != marketData.get("atl_change_percentage")) {
+                        BigDecimal atlChangePercentage = marketData.getBigDecimal("atl_change_percentage").setScale(2, RoundingMode.HALF_UP);
+                        coinWatchlist.setAtlChangePercentage(atlChangePercentage);
+                    }
 
 
                     // 历史最低日期
                     // 历史最低日期
                     if (marketData.containsKey("atl_date") && null != marketData.get("atl_date")) {
                     if (marketData.containsKey("atl_date") && null != marketData.get("atl_date")) {
@@ -1327,6 +1342,7 @@ public class CoinServiceImpl implements CoinService {
     private void renderMainSearch4Watchlist(List<CoinWatchlist> watchlistList) {
     private void renderMainSearch4Watchlist(List<CoinWatchlist> watchlistList) {
         BigDecimal bigDecimal10000 = new BigDecimal("10000");
         BigDecimal bigDecimal10000 = new BigDecimal("10000");
 
 
+        // 赛道分类预处理
         List<String> trackCategoryList = coinApiConfigMapper.findTrackCategoryList();
         List<String> trackCategoryList = coinApiConfigMapper.findTrackCategoryList();
         Map<String, String> trackCategoryMap = new HashMap<>();
         Map<String, String> trackCategoryMap = new HashMap<>();
         List<String> colorList = coinApiConfigMapper.findColorStyleList();
         List<String> colorList = coinApiConfigMapper.findColorStyleList();
@@ -1338,6 +1354,8 @@ public class CoinServiceImpl implements CoinService {
             trackCategoryMap.put(trackCategoryList.get(i), colorList.get(j));
             trackCategoryMap.put(trackCategoryList.get(i), colorList.get(j));
             j++;
             j++;
         }
         }
+
+        // 流通市值
         for (CoinWatchlist coinWatchlist : watchlistList) {
         for (CoinWatchlist coinWatchlist : watchlistList) {
             if (null != coinWatchlist.getTotalMarketValue()) {
             if (null != coinWatchlist.getTotalMarketValue()) {
                 BigDecimal divide = coinWatchlist.getTotalMarketValue().divide(bigDecimal10000, 8, RoundingMode.HALF_UP);
                 BigDecimal divide = coinWatchlist.getTotalMarketValue().divide(bigDecimal10000, 8, RoundingMode.HALF_UP);
@@ -1364,6 +1382,42 @@ public class CoinServiceImpl implements CoinService {
 
 
             // 名称
             // 名称
             coinWatchlist.setSymbolStyle(" style=\"background-color:rgba(70,169,244,.72);font-weight: bold;\"");
             coinWatchlist.setSymbolStyle(" style=\"background-color:rgba(70,169,244,.72);font-weight: bold;\"");
+            // 市场价格
+            coinWatchlist.setMarkPriceStyle(" style=\"color:#252B31;background-color:#C4ADE9;\"");
+            // 24小时价格变化
+            if (coinWatchlist.getPriceChangePercentage24h() == null) {
+            } else if (coinWatchlist.getPriceChangePercentage24h().compareTo(BigDecimal.ZERO) < 0) {
+                coinWatchlist.setPriceChangePercentage24hStyle(" style=\"color:#000000;background-color:#f1a8a4;\"");
+            } else {
+                coinWatchlist.setPriceChangePercentage24hStyle(" style=\"color:#000000;background-color:#aad6f5;\"");
+            }
+            /*// 历史最高点涨幅比例
+            if (coinWatchlist.getAthChangePercentage() == null) {
+            } else if (coinWatchlist.getAthChangePercentage().compareTo(BigDecimal.ZERO) < 0) {
+                coinWatchlist.setAthChangePercentageStyle(" style=\"color:#FFFFFF;background-color:#F1493F;\"");
+            } else {
+                coinWatchlist.setAthChangePercentageStyle(" style=\"color:#FFFFFF;background-color:#1DA2B4;\"");
+            }
+            // 历史最低点涨幅比例
+            if (coinWatchlist.getAtlChangePercentage() == null) {
+            } else if (coinWatchlist.getAtlChangePercentage().compareTo(BigDecimal.ZERO) < 0) {
+                coinWatchlist.setAtlChangePercentageStyle(" style=\"color:#FFFFFF;background-color:#F1493F;\"");
+            } else {
+                coinWatchlist.setAtlChangePercentageStyle(" style=\"color:#FFFFFF;background-color:#1DA2B4;\"");
+            }*/
+
+            // 涨幅倍数2
+            if (StringUtils.isNotEmpty(coinWatchlist.getHighestHistoricalPrice()) && StringUtils.isNotEmpty(coinWatchlist.getMarkPrice())) {
+                BigDecimal increaseMultiple = new BigDecimal(coinWatchlist.getHighestHistoricalPrice()).divide(new BigDecimal(coinWatchlist.getMarkPrice()), 1, RoundingMode.HALF_UP);
+                coinWatchlist.setIncreaseMultiple2(increaseMultiple.toPlainString());
+                if (increaseMultiple.compareTo(new BigDecimal("50")) >= 0) {
+                    coinWatchlist.setIncreaseMultiple2Style(" style=\"color:#000000;background-color:#5a964e;\"");
+                } else if (increaseMultiple.compareTo(new BigDecimal("10")) >= 0) {
+                    coinWatchlist.setIncreaseMultiple2Style(" style=\"color:#000000;background-color:#9cc494;\"");
+                } else {
+                    coinWatchlist.setIncreaseMultiple2Style(" style=\"color:#000000;background-color:#dae8d7;\"");
+                }
+            }
         }
         }
     }
     }
 
 
@@ -1437,7 +1491,7 @@ public class CoinServiceImpl implements CoinService {
     }
     }
 
 
     /**
     /**
-     * 渲染获取监控币种列表
+     * 渲染监控币种列表
      *
      *
      * @param monitorCurrencyList
      * @param monitorCurrencyList
      */
      */

+ 1 - 0
src/main/resources/static/coin.html

@@ -211,6 +211,7 @@
             <select id="apis-quiet-div-watchlist-sortField" style="height: 24px;">
             <select id="apis-quiet-div-watchlist-sortField" style="height: 24px;">
                 <option value="total_market_value">流通市值</option>
                 <option value="total_market_value">流通市值</option>
                 <option value="total_market_ranking">市值排名</option>
                 <option value="total_market_ranking">市值排名</option>
+                <option value="price_change_percentage_24h">24H涨跌幅</option>
                 <option value="increase_multiple">涨幅倍数</option>
                 <option value="increase_multiple">涨幅倍数</option>
                 <option value="issuing_days">发行天数</option>
                 <option value="issuing_days">发行天数</option>
             </select>
             </select>