Parcourir la source

update: coinwatchlist 加入优先级概念v1

lvzhiqiang il y a 1 an
Parent
commit
e2c16c8513

+ 4 - 4
src/main/java/top/lvzhiqiang/controller/CoinController.java

@@ -103,15 +103,15 @@ public class CoinController {
     }
 
     @PostMapping("/watchlistUpdate")
-    public Object watchlistUpdate(String symbol, String remark) {
+    public Object watchlistUpdate(String symbol, String remark, String score) {
         if (StringUtils.isEmpty(symbol)) {
             throw new ParameterException("symbol不能为空!");
         }
-        if (StringUtils.isEmpty(remark)) {
-            throw new ParameterException("remark不能为空!");
+        if (StringUtils.isEmpty(remark) && StringUtils.isEmpty(score)) {
+            throw new ParameterException("remark和score不能同时为空!");
         }
 
-        return R.ok().data(coinService.watchlistUpdate(symbol, remark));
+        return R.ok().data(coinService.watchlistUpdate(symbol, remark, score));
     }
 
     @GetMapping("/mainSearchDetail/{nameEn}/{id}")

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

@@ -136,4 +136,6 @@ public class CoinWatchlist implements Serializable {
     private Integer deleteFlag;
 
     private Integer filterFlag;
+
+    private String score;
 }

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

@@ -104,7 +104,19 @@ 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);
 
-    @Update("update coin_watchlist set remark=#{remark},modify_time=now() where symbol = #{symbol}")
+    @Update({"<script>" +
+            "update coin_watchlist " +
+            "<set>" +
+            "<if test=\"score != null and score != ''\">" +
+            "  score = #{score}," +
+            "</if>" +
+            "<if test=\"remark != null and remark != ''\">" +
+            "   remark = #{remark}," +
+            "</if>" +
+            "modify_time=now()" +
+            "</set>" +
+            "where symbol = #{symbol}" +
+            "</script>"})
     int updateCoinWatchlistRemark(CoinWatchlist coinWatchlist);
 
     @Select("select * from coin_watchlist where symbol = #{symbol} and delete_flag = 1")

+ 1 - 1
src/main/java/top/lvzhiqiang/service/CoinService.java

@@ -45,7 +45,7 @@ public interface CoinService {
 
     String watchlistDetail(String symbol, String operationType);
 
-    Object watchlistUpdate(String symbol, String remark);
+    Object watchlistUpdate(String symbol, String remark, String score);
 
     void syncCoinmarketcapCMap();
 

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

@@ -312,10 +312,11 @@ public class CoinServiceImpl implements CoinService {
     }
 
     @Override
-    public Object watchlistUpdate(String symbol, String remark) {
+    public Object watchlistUpdate(String symbol, String remark, String score) {
         CoinWatchlist coinWatchlist = new CoinWatchlist();
         coinWatchlist.setSymbol(symbol);
         coinWatchlist.setRemark(remark);
+        coinWatchlist.setScore(score);
         int num = coinMapper.updateCoinWatchlistRemark(coinWatchlist);
         return num;
     }
@@ -1402,7 +1403,19 @@ public class CoinServiceImpl implements CoinService {
             j++;
         }
 
+        String[] scoreTitleArr = {"很差", "较差", "还行", "推荐", "力荐"};
         for (CoinWatchlist coinWatchlist : watchlistList) {
+            // 优先级
+            Integer score = Integer.valueOf(coinWatchlist.getScore());
+            score = score > 5 ? 5 : score;
+            StringBuffer scoreSB = new StringBuffer("<ul class=\"rating\">");
+            for (int i = 0; i < scoreTitleArr.length; i++) {
+                String style = (i + 1) <= score ? "fa-star" : "fa-star-o";
+                scoreSB.append("<li id=\"" + coinWatchlist.getSymbol() + "\" title=\"" + scoreTitleArr[i] + "\" val=\"" + (i + 1) + "\"><i class=\"fa " + style + "\"></i></li>");
+            }
+            scoreSB.append("</ul>");
+            coinWatchlist.setScore(scoreSB.toString());
+
             // 流通市值
             if (null != coinWatchlist.getTotalMarketValue()) {
                 BigDecimal divide = coinWatchlist.getTotalMarketValue().divide(bigDecimal10000, 8, RoundingMode.HALF_UP);

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

@@ -94,6 +94,58 @@
         left: 50%;
         transform: translate(-50%, -25%);
     }
+
+    /*评分优先级*/
+    @font-face {
+        font-family: 'FontAwesome';
+        src: url('font/fontawesome-webfont.eot?v=4.7.0');
+        src: url('font/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'), url('font/fontawesome-webfont.woff2?v=4.7.0') format('woff2'), url('font/fontawesome-webfont.woff?v=4.7.0') format('woff'), url('font/fontawesome-webfont.ttf?v=4.7.0') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
+        font-weight: normal;
+        font-style: normal
+    }
+
+    .fa-star:before {
+        content: "\f005"
+    }
+
+    .fa-star-o:before {
+        content: "\f006"
+    }
+
+    ul.rating {
+        margin: 0;
+        padding: 0;
+        font-weight: normal;
+        box-sizing: border-box;
+        color: #000000;
+        display: inline-block;
+        position: relative;
+    }
+
+    ul.rating li {
+        margin: 0;
+        padding: 0;
+        list-style-type:none;
+        font-weight: normal;
+        box-sizing: border-box;
+        color: #000000;
+        cursor: pointer;
+        display: inline-block;
+    }
+
+    ul.rating li .fa {
+        margin: 0;
+        padding: 0;
+        list-style-type:none;
+        color: #ff9900;
+        display: inline-block;
+        font: normal normal normal 14px/1 FontAwesome;
+        font-size: inherit;
+        text-rendering: auto;
+        -webkit-font-smoothing: antialiased;
+        -moz-osx-font-smoothing: grayscale;
+        font-size: 24px;
+    }
 </style>
 <script type="text/javascript">
     function show() {
@@ -233,6 +285,7 @@
             </select>
             <select id="apis-quiet-div-watchlist-sortField" style="height: 24px;">
                 <option value="price_change_percentage_24h">24H涨跌幅</option>
+                <option value="score">优先级</option>
                 <option value="total_market_value">流通市值</option>
                 <option value="total_market_ranking">市值排名</option>
                 <option value="increase_multiple">涨幅倍数</option>

+ 28 - 0
src/main/resources/static/js/my-coin.js

@@ -460,6 +460,34 @@ function initContentEvent(nameEn) {
     }
 
     if (nameEn === 'watchlist') {
+        $("ul li").click(function () {
+            $.ajax({
+                url: "coin/watchlistUpdate", //请求的url地址
+                dataType: "json", //返回格式为json
+                data: {
+                    "symbol": $(this).attr("id"),
+                    "score": $(this).attr("val")
+                }, //参数值
+                type: "post", //请求方式
+                async: false, //请求是否异步,默认为异步,这也是ajax重要特性
+                success: function (data) {
+                    //请求成功时处理
+                    if (data != null && $.trim(data) != "" && data.success) {
+                        $(".apis-quiet-div-button2").click();
+                    } else {
+                        console.log("watchlistUpdate-score success error," + data);
+                    }
+                },
+                beforeSend: function () {
+                },
+                complete: function () {
+                },
+                error: function (data) {
+                    //请求出错处理
+                    console.log("watchlistUpdate-score error," + data);
+                }
+            });
+        });
         $(".apis-quiet-div-watchlist-detail,.apis-quiet-div-watchlist-update").click(function () {
             if ($("#watchlistpreview").css("display") === 'none') {
                 $("#watchlistpreview").css("display", "block");