浏览代码

add:币种监控增加排序筛选展示v1

tujidelv 2 年之前
父节点
当前提交
8f829931d3

+ 28 - 12
src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

@@ -349,7 +349,7 @@ public class CoinServiceImpl implements CoinService {
 
             result = response.getJSONArray("data");
 
-            renderMainSearch4AllPositionv2(result);
+            renderMainSearch4AllPositionv2(result, params.getInteger("unrealizedPLSort"));
         } else if (params.getString("nameEn").equals("orderMarginCoinCurrent")) {
             Map<String, String> paramMap = new LinkedHashMap<>();
             paramMap.put("productType", "umcbl");
@@ -361,7 +361,7 @@ public class CoinServiceImpl implements CoinService {
 
             result = response.getJSONArray("data");
 
-            renderMainSearch4OrderMarginCoinCurrent(result);
+            renderMainSearch4OrderMarginCoinCurrent(result, params.getInteger("chaRateSort"));
         } else if (params.getString("nameEn").equals("orderHistoryProductType")) {
             List<CoinHistoryOrder> historyOrderList = coinMapper.findByParams();
 
@@ -374,7 +374,7 @@ public class CoinServiceImpl implements CoinService {
             Connection.Response response = JsoupUtil.requestBody(requestUrl, JsoupUtil.HTTP_GET, InitRunner.proxy, null, null);
             result = JSONObject.parseObject(response.body()).getJSONArray("data");
 
-            result = renderMainSearch4MonitorCurrency(result, monitorCurrencyList);
+            result = renderMainSearch4MonitorCurrency(result, monitorCurrencyList, params.getInteger("changeUtcSort"));
         } else if (params.getString("nameEn").equals("currentPlan")) {
             Map<String, String> paramMap = new LinkedHashMap<>();
             paramMap.put("productType", "umcbl");
@@ -387,7 +387,7 @@ public class CoinServiceImpl implements CoinService {
 
             result = response.getJSONArray("data");
 
-            renderMainSearch4CurrentPlan(result);
+            renderMainSearch4CurrentPlan(result, params.getInteger("chaRateSort"));
         }
 
         return result;
@@ -398,7 +398,7 @@ public class CoinServiceImpl implements CoinService {
      *
      * @param result
      */
-    private void renderMainSearch4CurrentPlan(JSONArray result) {
+    private void renderMainSearch4CurrentPlan(JSONArray result, Integer chaRateSort) {
         forkJoinPool3.submit(() -> result.parallelStream().forEach(e -> {
             JSONObject jsonObject = (JSONObject) e;
 
@@ -432,7 +432,7 @@ public class CoinServiceImpl implements CoinService {
                 Connection.Response response = JsoupUtil.requestBody(requestUrl, JsoupUtil.HTTP_GET, InitRunner.proxy, null, null);
                 String last = JSONObject.parseObject(response.body()).getJSONObject("data").getString("last");
 
-                BigDecimal chaRate = null;
+                BigDecimal chaRate = BigDecimal.ZERO;
                 if ("open_long".equals(side)) {
                     chaRate = new BigDecimal(last).divide(new BigDecimal(jsonObject.getString("triggerPrice")), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
                 } else if ("open_short".equals(side)) {
@@ -441,12 +441,16 @@ public class CoinServiceImpl implements CoinService {
 
                 jsonObject.put("last", last);
                 jsonObject.put("lastStyle", " style=\"color:#252B31;background-color:#C4ADE9;font-weight:bold;\"");
-                jsonObject.put("chaRate", chaRate != null ? chaRate : "--");
+                jsonObject.put("chaRate", chaRate);
                 jsonObject.put("chaRateStyle", " style=\"color:#FFFFFF;background-color:#5EA294;\"");
             } catch (Exception ex) {
                 throw new RuntimeException(ex);
             }
         })).join();
+
+        if (chaRateSort != 0) {
+            Collections.sort(result, (o1, o2) -> chaRateSort * (((JSONObject) o1).getBigDecimal("chaRate").compareTo(((JSONObject) o2).getBigDecimal("chaRate"))));
+        }
     }
 
     /**
@@ -454,7 +458,7 @@ public class CoinServiceImpl implements CoinService {
      *
      * @param monitorCurrencyList
      */
-    private JSONArray renderMainSearch4MonitorCurrency(JSONArray result, List<String> monitorCurrencyList) {
+    private JSONArray renderMainSearch4MonitorCurrency(JSONArray result, List<String> monitorCurrencyList, Integer changeUtcSort) {
         JSONArray array = result.stream()
                 .filter(iter -> monitorCurrencyList.contains(((JSONObject) iter).getString("symbol")))
                 .collect(Collectors.toCollection(JSONArray::new));
@@ -488,6 +492,10 @@ public class CoinServiceImpl implements CoinService {
             jsonObject.put("usdtVol", readableFileSize(jsonObject.getDouble("usdtVol")));
         })).join();
 
+        if (changeUtcSort != 0) {
+            Collections.sort(array, (o1, o2) -> changeUtcSort * (((JSONObject) o1).getBigDecimal("changeUtc").compareTo(((JSONObject) o2).getBigDecimal("changeUtc"))));
+        }
+
         return array;
     }
 
@@ -539,7 +547,7 @@ public class CoinServiceImpl implements CoinService {
      *
      * @param result
      */
-    private void renderMainSearch4OrderMarginCoinCurrent(JSONArray result) {
+    private void renderMainSearch4OrderMarginCoinCurrent(JSONArray result, Integer chaRateSort) {
         forkJoinPool2.submit(() -> result.parallelStream().forEach(e -> {
             JSONObject jsonObject = (JSONObject) e;
             // 币对名称
@@ -577,7 +585,7 @@ public class CoinServiceImpl implements CoinService {
                 Connection.Response response = JsoupUtil.requestBody(requestUrl, JsoupUtil.HTTP_GET, InitRunner.proxy, null, null);
                 String last = JSONObject.parseObject(response.body()).getJSONObject("data").getString("last");
 
-                BigDecimal chaRate = null;
+                BigDecimal chaRate = BigDecimal.ZERO;
                 if ("open_short".equals(side)) {
                     chaRate = new BigDecimal(last).divide(new BigDecimal(jsonObject.getString("price")), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
                 } else if ("open_long".equals(side)) {
@@ -586,12 +594,16 @@ public class CoinServiceImpl implements CoinService {
 
                 jsonObject.put("last", last);
                 jsonObject.put("lastStyle", " style=\"color:#252B31;background-color:#C4ADE9;font-weight:bold;\"");
-                jsonObject.put("chaRate", chaRate != null ? chaRate : "--");
+                jsonObject.put("chaRate", chaRate);
                 jsonObject.put("chaRateStyle", " style=\"color:#FFFFFF;background-color:#5EA294;\"");
             } catch (Exception ex) {
                 throw new RuntimeException(ex);
             }
         })).join();
+
+        if (chaRateSort != 0) {
+            Collections.sort(result, (o1, o2) -> chaRateSort * (((JSONObject) o1).getBigDecimal("chaRate").compareTo(((JSONObject) o2).getBigDecimal("chaRate"))));
+        }
     }
 
     /**
@@ -599,7 +611,7 @@ public class CoinServiceImpl implements CoinService {
      *
      * @param result
      */
-    private void renderMainSearch4AllPositionv2(JSONArray result) {
+    private void renderMainSearch4AllPositionv2(JSONArray result, Integer unrealizedPLSort) {
         forkJoinPool4.submit(() -> result.parallelStream().forEach(e -> {
             JSONObject jsonObject = (JSONObject) e;
 
@@ -638,6 +650,10 @@ public class CoinServiceImpl implements CoinService {
             jsonObject.put("marketPriceStyle", " style=\"color:#252B31;background-color:#C4ADE9;font-weight:bold;\"");
 
         })).join();
+
+        if (unrealizedPLSort != 0) {
+            Collections.sort(result, (o1, o2) -> unrealizedPLSort * (((JSONObject) o1).getBigDecimal("unrealizedPL").compareTo(((JSONObject) o2).getBigDecimal("unrealizedPL"))));
+        }
     }
 
     /**

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

@@ -44,10 +44,28 @@
             <button class = "apis-move-div-button1" slideDiv="apis-move-content">展开</button>
             <button class="apis-move-div-button2" slideDiv="apis-move-content">实时启动</button>
             <button class="apis-move-div-button3">实时停止</button>
+
+            <select id="chaRateSort" style="height: 24px;">
+                <option value="0">chaRate</option>
+                <option value="-1">desc</option>
+                <option value="1">asc</option>
+            </select>
+            <select id="changeUtcSort" style="height: 24px;">
+                <option value="0">changeUtc</option>
+                <option value="-1">desc</option>
+                <option value="1">asc</option>
+            </select>
+            <select id="unrealizedPLSort" style="height: 24px;">
+                <option value="0">unrealizedPL</option>
+                <option value="-1">desc</option>
+                <option value="1">asc</option>
+            </select>
+
             <input type="text" style="width: 100px;padding-top: 3px;" class="apis-move-div-input1">
             <input type="hidden" id="allPositionv2" class="needCustomInput">
             <input type="hidden" id="orderMarginCoinCurrent" class="needCustomInput">
             <input type="hidden" id="currentPlan" class="needCustomInput">
+            <input type="hidden" id="monitorCurrency" class="needCustomInput">
         </div>
     </div>
     <div id="apis-move-content" style="display: none;">
@@ -84,6 +102,17 @@
                 </tbody>
             </table>
         </div>
+        <div id="apis-move-content-monitorCurrency">
+            total:<span class="contentSPAN">0</span>
+            <table border="1" cellspacing="0">
+                <thead>
+                <tr class="contentTH">
+                </tr>
+                </thead>
+                <tbody class="contentTD">
+                </tbody>
+            </table>
+        </div>
         <div id="apis-move-content-other">
             total:<span class="contentSPAN">0</span>
             <table border="1" cellspacing="0">

+ 6 - 3
src/main/resources/static/js/my-coin.js

@@ -85,8 +85,8 @@ function ownClearInterval() {
             });
         }
 
-        $("#apis-move-content").find("tbody.contentTD").html('');
-        $("#apis-move-content").find("span.contentSPAN").html('');
+        //$("#apis-move-content").find("tbody.contentTD").html('');
+        //$("#apis-move-content").find("span.contentSPAN").html('');
 
         actualFlag = false;
     }
@@ -220,7 +220,10 @@ function mainSearch(url, nameEn, slideDiv, needCustomFlag) {
         dataType: "json", //返回格式为json
         data: JSON.stringify({
             "url": url,
-            "nameEn": nameEn
+            "nameEn": nameEn,
+            "chaRateSort": $("#chaRateSort").val(),
+            "changeUtcSort": $("#changeUtcSort").val(),
+            "unrealizedPLSort": $("#unrealizedPLSort").val()
         }), //参数值
         type: "post", //请求方式
         contentType: "application/json;charset=utf-8",