Browse Source

支持根据LP查询相关swappath(2阶)

龚成明 3 năm trước cách đây
mục cha
commit
5a8204b651

+ 22 - 0
src/main/java/controller/SwapPathController.java

@@ -1,13 +1,17 @@
 package controller;
 
+import com.alibaba.fastjson.JSONArray;
 import com.jfinal.aop.Before;
 import com.jfinal.core.Controller;
 import com.jfinal.kit.StrKit;
 import interceptor.AuthInterceptor;
 import model.SwapPath;
+import service.SwapPathService;
 import util.MyRet;
 
 public class SwapPathController extends Controller {
+    SwapPathService service = new SwapPathService();
+
     @Before(AuthInterceptor.class)
     public void appendOrUpdate() {
         if (StrKit.isBlank(getPara("sum_value"))
@@ -42,6 +46,7 @@ public class SwapPathController extends Controller {
         if (StrKit.isBlank(getPara("sum_value"))
         || StrKit.isBlank(getPara("level"))) {
             renderJson(MyRet.create().setFail().setMsg("缺少参数,请检查参数[sum_value, level]。"));
+            return;
         }
 
         String sumValueAndLevel = getPara("sum_value") + "_" + getPara("level");
@@ -54,4 +59,21 @@ public class SwapPathController extends Controller {
             renderJson(MyRet.create().setFail().setMsg("查询失败,没有找到。"));
         }
     }
+
+    @Before(AuthInterceptor.class)
+    public void findLevel2PathByLpAddress() {
+        if (StrKit.isBlank(getPara("lp_address"))) {
+            renderJson(MyRet.create().setFail().setMsg("缺少参数,请检查参数[lp_address]。"));
+            return;
+        }
+
+        String lpAddress = getPara("lp_address");
+        JSONArray pathList = service.generatePathListByLpAddress(lpAddress);
+
+        if (pathList.size() == 0) {
+            renderJson(MyRet.create().setOk().setMsg("没有找到LP:" + lpAddress + "相关路径。").setData(pathList));
+        } else {
+            renderJson(MyRet.create().setOk().setMsg("查询成功,LP:" + lpAddress + "。").setData(pathList));
+        }
+    }
 }

+ 31 - 0
src/main/java/service/SwapPathService.java

@@ -0,0 +1,31 @@
+package service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import model.SwapPath;
+
+public class SwapPathService {
+    public JSONArray generatePathListByLpAddress(String lpAddress) {
+        lpAddress = lpAddress.toLowerCase();
+        JSONArray swapPathList = JSONArray.parseArray("[]");
+
+        String sql = "select * from t_swap_path where instr(lower(data), ?)";
+        SwapPath pathObj = SwapPath.dao.findFirst(sql, lpAddress);
+
+        if (pathObj != null) {
+            JSONArray unFilterSwapPathList = JSONArray.parseArray(pathObj.getStr("data"));
+
+            for (JSONArray swapPath : unFilterSwapPathList.toJavaList(JSONArray.class)) {
+                JSONObject aLp = swapPath.getJSONObject(0);
+                JSONObject bLp = swapPath.getJSONObject(1);
+
+                if (aLp.getString("LP").toLowerCase().equals(lpAddress)
+                || bLp.getString("LP").toLowerCase().equals(lpAddress)) {
+                    swapPathList.add(swapPath);
+                }
+            }
+        }
+
+        return swapPathList;
+    }
+}

+ 8 - 0
src/main/test/http/SwapPathTest.http

@@ -0,0 +1,8 @@
+###
+POST http://localhost:8088/swappath/findLevel2PathByLpAddress
+Content-Type: application/x-www-form-urlencoded
+
+lp_address=0x397FF1542f962076d0BFE58eA045FfA2d347ACa0&timestamp=12345&auth=338209cfc53e9db6d344073335e47cf0
+
+
+###