瀏覽代碼

update:watchlist操作-UPDADTE V1

lvzhiqiang 2 年之前
父節點
當前提交
24a6d17b48

+ 13 - 1
src/main/java/top/lvzhiqiang/controller/CoinController.java

@@ -79,9 +79,21 @@ public class CoinController {
             throw new ParameterException("symbol不能为空!");
         }
         if (StringUtils.isEmpty(operationType)) {
-            throw new ParameterException("operationType!");
+            throw new ParameterException("operationType不能为空!");
         }
 
         return R.ok().data(coinService.watchlistDetail(symbol, operationType));
     }
+
+    @PostMapping("/watchlistUpdate")
+    public Object watchlistUpdate(String symbol, String remark) {
+        if (StringUtils.isEmpty(symbol)) {
+            throw new ParameterException("symbol不能为空!");
+        }
+        if (StringUtils.isEmpty(remark)) {
+            throw new ParameterException("remark不能为空!");
+        }
+
+        return R.ok().data(coinService.watchlistUpdate(symbol, remark));
+    }
 }

+ 3 - 0
src/main/java/top/lvzhiqiang/mapper/CoinMapper.java

@@ -103,6 +103,9 @@ public interface CoinMapper {
             "issuing_days=#{issuingDays},modify_time=now() where id = #{id}")
     int updateCoinWatchlist(CoinWatchlist coinWatchlist);
 
+    @Update("update coin_watchlist set remark=#{remark},modify_time=now() where symbol = #{symbol}")
+    int updateCoinWatchlistRemark(CoinWatchlist coinWatchlist);
+
     @Select("select * from coin_watchlist where symbol = #{symbol}")
     CoinWatchlist findWatchlistBySymbol(String symbol);
 }

+ 2 - 0
src/main/java/top/lvzhiqiang/service/CoinService.java

@@ -42,4 +42,6 @@ public interface CoinService {
     void syncData4TraderListSub(JSONArray dataList);
 
     String watchlistDetail(String symbol, String operationType);
+
+    Object watchlistUpdate(String symbol, String remark);
 }

+ 9 - 0
src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

@@ -218,6 +218,15 @@ public class CoinServiceImpl implements CoinService {
         }
     }
 
+    @Override
+    public Object watchlistUpdate(String symbol, String remark) {
+        CoinWatchlist coinWatchlist = new CoinWatchlist();
+        coinWatchlist.setSymbol(symbol);
+        coinWatchlist.setRemark(remark);
+        int num = coinMapper.updateCoinWatchlistRemark(coinWatchlist);
+        return num;
+    }
+
     private List<CoinTrader> parseMixTradeList(JSONArray dataList) {
         List<CoinTrader> mixTraderList = JSONArray.parseArray(dataList.toJSONString(), CoinTrader.class);
         mixTraderList.stream().forEach(e -> {

+ 31 - 2
src/main/resources/static/js/my-coin.js

@@ -396,6 +396,32 @@ function initContentEvent(nameEn) {
                     $("#watchlistpreview").css("display", "none");
                 }
                 $(this).unbind("click");
+                $(".watchlistpreview-top-submit").unbind("click");
+            });
+            $(".watchlistpreview-top-submit").click(function () {
+                $.ajax({
+                    url: "coin/watchlistUpdate", //请求的url地址
+                    dataType: "json", //返回格式为json
+                    data: {"symbol": $(".watchlistpreview-content").find(".watchlistpreview-symbol").val(), "remark": $(".watchlistpreview-content").find("textarea").val()}, //参数值
+                    type: "post", //请求方式
+                    async: false, //请求是否异步,默认为异步,这也是ajax重要特性
+                    success: function (data) {
+                        //请求成功时处理
+                        if (data != null && $.trim(data) != "" && data.success) {
+                            console.log("success");
+                        } else {
+                            //alert(data.message);
+                        }
+                    },
+                    beforeSend: function () {
+                    },
+                    complete: function () {
+                    },
+                    error: function (data) {
+                        //请求出错处理
+                        //alert('error:' + data);
+                    }
+                });
             });
 
             var operationType = $(this).attr("operationType");
@@ -404,8 +430,10 @@ function initContentEvent(nameEn) {
             } else if (operationType === 'update') {
                 $(".watchlistpreview-top-submit").css("display", "block");
             }
+
+            var symbol = $(this).attr("symbolName");
             $.ajax({
-                url: "coin/watchlistDetail/" + $(this).attr("symbolName") + "/" + operationType, //请求的url地址
+                url: "coin/watchlistDetail/" + symbol + "/" + operationType, //请求的url地址
                 type: "get", //请求方式
                 async: true, //请求是否异步,默认为异步,这也是ajax重要特性
                 success: function (data) {
@@ -416,7 +444,8 @@ function initContentEvent(nameEn) {
                         if (operationType === 'detail') {
                             $(".watchlistpreview-content").html(data);
                         } else if (operationType === 'update') {
-                            var update4Text = '<textarea rows="4" cols="50" style="width: 100%;height: 100%;">' + data + '</textarea>';
+                            var update4Text = '<textarea rows="4" cols="50" style="background: antiquewhite;width: 100%;height: 100%;">' + data + '</textarea>';
+                            update4Text += '<input type="hidden" class="watchlistpreview-symbol" value="' + symbol + '"/>';
                             $(".watchlistpreview-content").html(update4Text);
                         }
                     } else {