|
|
@@ -0,0 +1,256 @@
|
|
|
+package modules.ethmevftm;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.jfinal.aop.Before;
|
|
|
+import com.jfinal.aop.Inject;
|
|
|
+import com.jfinal.core.Controller;
|
|
|
+import com.jfinal.kit.StrKit;
|
|
|
+import common.model.EthMevFtm;
|
|
|
+import common.utils.http.MyRet;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Before(common.interceptor.AuthInterceptor.class)
|
|
|
+public class EthMevFtmController extends Controller {
|
|
|
+ @Inject
|
|
|
+ EthMevFtmService service;
|
|
|
+
|
|
|
+ public void appendOrUpdate() {
|
|
|
+ if (StrKit.isBlank(getPara("block"))
|
|
|
+ || StrKit.isBlank(getPara("hash"))
|
|
|
+ || StrKit.isBlank(getPara("data"))) {
|
|
|
+ renderJson(MyRet.create().setFail().setMsg("缺少参数,请检查参数。"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String block = getPara("block");
|
|
|
+ String hash = getPara("hash");
|
|
|
+ String data = getPara("data");
|
|
|
+
|
|
|
+ EthMevFtm ethMev = new EthMevFtm();
|
|
|
+ ethMev.set("block", block);
|
|
|
+ ethMev.set("hash", hash);
|
|
|
+ ethMev.set("data", data);
|
|
|
+
|
|
|
+ EthMevFtm originData = EthMevFtm.dao.findById(hash);
|
|
|
+ if (originData != null) {
|
|
|
+ if (ethMev.update()) {
|
|
|
+ renderJson(MyRet.create().setOk().setMsg("检测到hash存在,已执行更新逻辑,原始信息已返回").setData(originData));
|
|
|
+ } else {
|
|
|
+ renderJson(MyRet.create().setFail().setMsg("更新失败,请联系开发者,原始信息已返回").setData(originData));
|
|
|
+ }
|
|
|
+ } else if (ethMev.save()) {
|
|
|
+ renderJson(MyRet.create().setOk().setMsg("添加成功。"));
|
|
|
+ } else {
|
|
|
+ renderJson(MyRet.create().setFail().setMsg("添加失败,请联系开发人员。").setData(ethMev));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteByHash() {
|
|
|
+ if (StrKit.isBlank(getPara("hash"))) {
|
|
|
+ renderJson(MyRet.create().setFail().setMsg("请填写Hash,请检查参数。"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String hash = getPara("hash");
|
|
|
+
|
|
|
+ EthMevFtm ethMev = new EthMevFtm();
|
|
|
+ ethMev.set("hash", hash);
|
|
|
+
|
|
|
+ if (EthMevFtm.dao.findById(hash) == null) {
|
|
|
+ renderJson(MyRet.create().setOk().setMsg("查不到数据,无法执行删除操作。").setData(ethMev));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ethMev.delete()) {
|
|
|
+ renderJson(MyRet.create().setOk().setMsg("删除成功").setData(ethMev));
|
|
|
+ } else {
|
|
|
+ renderJson(MyRet.create().setFail().setMsg("删除失败,请联系开发人员。").setData(ethMev));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void findByHash() {
|
|
|
+ if (StrKit.isBlank(getPara("hash"))) {
|
|
|
+ renderJson(MyRet.create().setFail().setMsg("hash为空。"));
|
|
|
+ }
|
|
|
+
|
|
|
+ String hash = getPara("hash");
|
|
|
+
|
|
|
+ renderJson(MyRet.create().setOk().setMsg("查询成功").setData(
|
|
|
+ EthMevFtm.dao.find("select * from t_ethereum_mev_v1_ftm where hash=?", hash)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void findByBlock() {
|
|
|
+ if (StrKit.isBlank(getPara("block"))) {
|
|
|
+ renderJson(MyRet.create().setFail().setMsg("block为空。"));
|
|
|
+ }
|
|
|
+
|
|
|
+ renderJson(MyRet.create().setOk().setMsg("查询成功").setData(
|
|
|
+ EthMevFtm.dao.find("select * from t_ethereum_mev_v1_ftm where block=?", getPara("block"))
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void findByDataVague() {
|
|
|
+ if (StrKit.isBlank(getPara("dataVague"))) {
|
|
|
+ renderJson(MyRet.create().setFail().setMsg("data模糊值为空。"));
|
|
|
+ }
|
|
|
+
|
|
|
+ String dataVague = "%" + getPara("dataVague") + "%";
|
|
|
+
|
|
|
+ renderJson(MyRet.create().setOk().setMsg("查询成功").setData(
|
|
|
+ EthMevFtm.dao.find("select * from t_ethereum_mev_v1_ftm where data like ?", dataVague)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void findByHashOrBlockOrDataVague() {
|
|
|
+ String block = getPara("block");
|
|
|
+ String hash = getPara("hash");
|
|
|
+ String dataVague = getPara("dataVague");
|
|
|
+ String limit1Str = getPara("limit1");
|
|
|
+ String limit2Str = getPara("limit2");
|
|
|
+ int limit1 = 0;
|
|
|
+ int limit2 = 200;
|
|
|
+
|
|
|
+ if (!StrKit.isBlank(dataVague)) {
|
|
|
+ dataVague = "%" + dataVague + "%";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StrKit.isBlank(limit1Str) && !StrKit.isBlank(limit2Str)) {
|
|
|
+ limit1 = getParaToInt("limit1");
|
|
|
+ limit2 = getParaToInt("limit2");
|
|
|
+ }
|
|
|
+
|
|
|
+ String sql = "";
|
|
|
+ List<EthMevFtm> ethMevList = null;
|
|
|
+ if (StrKit.isBlank(getPara("block"))
|
|
|
+ && StrKit.isBlank(getPara("hash"))
|
|
|
+ && StrKit.isBlank(getPara("dataVague"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block regexp '^[-0-9]{8,10}' order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("block")) && StrKit.isBlank(getPara("hash"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block regexp '^[-0-9]{8,10}' and data like ? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, dataVague, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("block")) && StrKit.isBlank(getPara("dataVague"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block regexp '^[-0-9]{8,10}' and hash=? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, hash, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("hash")) && StrKit.isBlank(getPara("dataVague"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block=? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, block, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("block"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block regexp '^[-0-9]{8,10}' and hash=? and data like ? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, hash, dataVague, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("hash"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block=? and data like ? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, block, dataVague, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("dataVague"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block=? and hash=? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, block, hash, limit1, limit2);
|
|
|
+ } else {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block=? and hash=? and data like ? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, block, hash, dataVague, limit1, limit2);
|
|
|
+ }
|
|
|
+
|
|
|
+ service.buildDataObjByEthMevFtmList(ethMevList);
|
|
|
+
|
|
|
+ renderJson(MyRet.create().setOk().setMsg("查询成功").setData(ethMevList));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void findByHashOrBlockOrDataVaguePending() {
|
|
|
+ String block = getPara("block");
|
|
|
+ String hash = getPara("hash");
|
|
|
+ String dataVague = getPara("dataVague");
|
|
|
+ String limit1Str = getPara("limit1");
|
|
|
+ String limit2Str = getPara("limit2");
|
|
|
+ int limit1 = 0;
|
|
|
+ int limit2 = 200;
|
|
|
+
|
|
|
+ if (!StrKit.isBlank(dataVague)) {
|
|
|
+ dataVague = "%" + dataVague + "%";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StrKit.isBlank(limit1Str) && !StrKit.isBlank(limit2Str)) {
|
|
|
+ limit1 = getParaToInt("limit1");
|
|
|
+ limit2 = getParaToInt("limit2");
|
|
|
+ }
|
|
|
+
|
|
|
+ String sql = "";
|
|
|
+ List<EthMevFtm> ethMevList = null;
|
|
|
+ if (StrKit.isBlank(getPara("block"))
|
|
|
+ && StrKit.isBlank(getPara("hash"))
|
|
|
+ && StrKit.isBlank(getPara("dataVague"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block regexp '[-]' order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("block")) && StrKit.isBlank(getPara("hash"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block regexp '[-]' and data like ? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, dataVague, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("block")) && StrKit.isBlank(getPara("dataVague"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block regexp '[-]' and hash=? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, hash, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("hash")) && StrKit.isBlank(getPara("dataVague"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block=? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, block, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("block"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block regexp '[-]' and hash=? and data like ? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, hash, dataVague, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("hash"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block=? and data like ? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, block, dataVague, limit1, limit2);
|
|
|
+ } else if (StrKit.isBlank(getPara("dataVague"))) {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block=? and hash=? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, block, hash, limit1, limit2);
|
|
|
+ } else {
|
|
|
+ sql = "select * from t_ethereum_mev_v1_ftm where block=? and hash=? and data like ? order by block desc limit ?,?";
|
|
|
+ ethMevList = EthMevFtm.dao.find(sql, block, hash, dataVague, limit1, limit2);
|
|
|
+ }
|
|
|
+
|
|
|
+ service.buildDataObjByEthMevFtmList(ethMevList);
|
|
|
+
|
|
|
+ renderJson(MyRet.create().setOk().setMsg("查询成功").setData(ethMevList));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void findByJsonCondition() {
|
|
|
+ String jsonConditionStr = getPara("jsonCondition");
|
|
|
+
|
|
|
+ JSONObject jsonCondition = null;
|
|
|
+ try {
|
|
|
+ jsonCondition = JSONObject.parseObject(jsonConditionStr);
|
|
|
+ } catch (Exception e) {
|
|
|
+ renderJson(MyRet.create().setFail().setMsg("查询失败,请提供正确的查询条件"));
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从数据库读取EthMevFtm
|
|
|
+ List<EthMevFtm> ethMevList = EthMevFtm.dao.findAll();
|
|
|
+ List<EthMevFtm> rstEthMevFtmList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 批量过滤EthMevFtm数据
|
|
|
+ for (EthMevFtm ethMev : ethMevList) {
|
|
|
+ // 获取data的json
|
|
|
+ JSONObject dataJson = null;
|
|
|
+ try {
|
|
|
+ dataJson = JSONObject.parseObject(ethMev.getStr("data"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按条件过滤该ethMev
|
|
|
+ boolean isOk = true;
|
|
|
+ for (String key : jsonCondition.keySet()) {
|
|
|
+ String valueVague = jsonCondition.getString(key);
|
|
|
+ if (StrKit.isBlank(dataJson.getString(key))
|
|
|
+ || !dataJson.getString(key).contains(valueVague)) {
|
|
|
+ isOk = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 成功就添加了呀
|
|
|
+ if (isOk) rstEthMevFtmList.add(ethMev);
|
|
|
+ }
|
|
|
+
|
|
|
+ renderJson(MyRet.create().setOk().setMsg("搜索成功").setData(rstEthMevFtmList));
|
|
|
+ }
|
|
|
+}
|