فهرست منبع

初始化成功

龚成明 3 سال پیش
کامیت
29fd9386c1

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.debug
+.idea/
+target/

+ 91 - 0
pom.xml

@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.example</groupId>
+    <artifactId>ethereum_viewer_interface</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>war</packaging>
+
+    <name>ethereum viewer interface</name>
+    <url>http://www.example.com</url>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>1.7</maven.compiler.source>
+        <maven.compiler.target>1.7</maven.compiler.target>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.11</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.jfinal</groupId>
+            <artifactId>jfinal-undertow</artifactId>
+            <version>2.2</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.jfinal</groupId>
+            <artifactId>jfinal</artifactId>
+            <version>4.9.02</version>
+        </dependency>
+
+        <!--mysql驱动包-->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>8.0.12</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid</artifactId>
+            <version>1.1.6</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <finalName>ETH_Web</finalName>
+        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
+            <plugins>
+                <plugin>
+                    <artifactId>maven-clean-plugin</artifactId>
+                    <version>3.1.0</version>
+                </plugin>
+                <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
+                <plugin>
+                    <artifactId>maven-resources-plugin</artifactId>
+                    <version>3.0.2</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-compiler-plugin</artifactId>
+                    <version>3.8.0</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-surefire-plugin</artifactId>
+                    <version>2.22.1</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-war-plugin</artifactId>
+                    <version>3.2.2</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-install-plugin</artifactId>
+                    <version>2.5.2</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-deploy-plugin</artifactId>
+                    <version>2.8.2</version>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+</project>

+ 3 - 0
src/main/java/META-INF/MANIFEST.MF

@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: start.Start
+

+ 54 - 0
src/main/java/config/WebConfig.java

@@ -0,0 +1,54 @@
+package config;
+
+import com.jfinal.config.*;
+import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
+import com.jfinal.plugin.druid.DruidPlugin;
+import com.jfinal.template.Engine;
+import controller.ConfigController;
+import controller.HelloController;
+import controller.InputDataController;
+import model.Config;
+import model.InputData;
+
+public class WebConfig extends JFinalConfig {
+    @Override
+    public void configConstant(Constants constants) {
+        constants.setDevMode(true);
+    }
+
+    @Override
+    public void configRoute(Routes routes) {
+        routes.add("/", HelloController.class);
+        routes.add("/hello", HelloController.class);
+        routes.add("/data", InputDataController.class);
+        routes.add("/config", ConfigController.class);
+    }
+
+    @Override
+    public void configEngine(Engine engine) {
+
+    }
+
+    @Override
+    public void configPlugin(Plugins plugins) {
+        DruidPlugin dp = new DruidPlugin("jdbc:mysql://localhost:3306/input_data",
+                "root", "123456");
+        plugins.add(dp);
+
+        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
+        plugins.add(arp);
+
+        arp.addMapping("input_data", InputData.class);
+        arp.addMapping("t_config", "hs", Config.class);
+    }
+
+    @Override
+    public void configInterceptor(Interceptors interceptors) {
+
+    }
+
+    @Override
+    public void configHandler(Handlers handlers) {
+
+    }
+}

+ 92 - 0
src/main/java/controller/ConfigController.java

@@ -0,0 +1,92 @@
+package controller;
+
+import com.jfinal.core.Controller;
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import model.Config;
+import util.MyRet;
+
+public class ConfigController extends Controller {
+    public void add() {
+        int ts = (int)(System.currentTimeMillis() / 1000);
+        String hs = getPara("hs");
+        String type = getPara("type");
+        String o = getPara("o");
+
+        if (StrKit.isBlank(hs) || StrKit.isBlank(type) || StrKit.isBlank(o)) {
+            renderJson(MyRet.create().setFail().setMsg("参数不合法。"));
+            return;
+        }
+
+        o = o.replaceAll("【", "[").replaceAll("】", "]");
+
+        if (Db.queryInt("select count(1) from t_config where hs = ?", hs) == 1) {
+            renderJson(MyRet.create().setFail().setMsg("Hash已存在。"));
+            return;
+        }
+
+        Config config = getModel(Config.class, "", true);
+        config.set("o", o);
+        config.set("ts", ts);
+
+        if (!config.save()) {
+            renderJson(MyRet.create().setFail().setMsg("保存失败,请联系开发者。"));
+            return;
+        }
+
+        renderJson(MyRet.create().setOk().setMsg("保存成功").setData(config));
+    }
+
+    public void get() {
+        Page<Config> rst = Config.dao.paginate(1, 1000, "select *", "from t_config");
+
+        renderJson(MyRet
+                .create()
+                .setOk()
+                .setMsg("请求成功")
+                .setData(rst));
+    }
+
+    public void update() {
+        Config config = getModel(Config.class, "", true);
+
+        if (StrKit.isBlank(config.getStr("ts"))
+            || StrKit.isBlank(config.getStr("hs"))
+            || StrKit.isBlank(config.getStr("type"))
+            || StrKit.isBlank(config.getStr("o"))) {
+            renderJson(MyRet.create().setFail().setMsg("参数不合法。"));
+            return;
+        }
+
+        config.set("o", config.getStr("o").replaceAll("【", "[").replaceAll("】", "]"));
+
+        if (Db.queryInt("select count(1) from t_config where hs = ?", config.getStr("hs")) == 0) {
+            renderJson(MyRet.create().setFail().setMsg("Hash不存在!请勿修改Hash值!"));
+            return;
+        }
+
+        if (!config.update()) {
+            renderJson(MyRet.create().setFail().setMsg("更新失败,请联系开发者。"));
+            return;
+        }
+
+        renderJson(MyRet.create().setOk().setMsg("更新成功").setData(config));
+    }
+
+    public void delete() {
+        String hs = getPara("hs");
+
+        if (StrKit.isBlank("hs")) {
+            renderJson(MyRet.create().setFail().setMsg("参数不合法。"));
+            return;
+        }
+
+        if (Db.update("delete from t_config where hs = ?", hs) == 0) {
+            renderJson(MyRet.create().setFail().setMsg("删除失败,请联系开发者。"));
+            return;
+        }
+
+        renderJson(MyRet.create().setOk().setMsg("删除成功"));
+    }
+}

+ 10 - 0
src/main/java/controller/HelloController.java

@@ -0,0 +1,10 @@
+package controller;
+
+import com.jfinal.core.Controller;
+import model.InputData;
+
+public class HelloController extends Controller {
+    public void index() {
+        render("index.html");
+    }
+}

+ 134 - 0
src/main/java/controller/InputDataController.java

@@ -0,0 +1,134 @@
+package controller;
+
+import com.jfinal.core.Controller;
+import com.jfinal.kit.Ret;
+import com.jfinal.plugin.activerecord.Page;
+import model.InputData;
+
+import java.util.Date;
+
+public class InputDataController extends Controller {
+    public void getRecord() {
+        // timestamp start
+        long t1 = (new Date().getTime() / 1000) - (10 * 60);
+        // timestamp end
+        long t2 = 9999999999999999L;
+        // from
+        String fm = "%";
+        // to
+        String t = "%";
+        // hash
+        String hs = "%";
+        // state
+        String state = "%";
+        // page?
+        boolean isDynamic = false;
+        // pageSize
+        int pageSize = 200;
+        if (getPara("fm") != null) {
+//            t1 = 0;
+            fm = getPara("fm");
+        }
+        if (getPara("t") != null) {
+//            t1 = 0;
+            t = getPara("t");
+        }
+        if (getPara("hs") != null) {
+//            t1 = 0;
+            hs = getPara("hs");
+        }
+        if (getPara("state") != null) {
+//            t1 = 0;
+            state = getPara("state");
+        }
+        if (getPara("t1") != null) {
+            if (getParaToLong("t1") > t1 + 60 * 7) {
+                isDynamic = true;
+                t1 = 0;
+            } else {
+                t1 = getParaToLong("t1");
+            }
+        }
+        if (getPara("t2") != null) {
+            t2 = getParaToLong("t2");
+        }
+        if (getPara("pageSize") != null) {
+            pageSize = getParaToInt("pageSize");
+        }
+        System.out.println(t1 + ", " + t2 + ", " + isDynamic);
+        String from = "from input_data where ts>? and ts<? and fm like ? and t like ? and hs like ? and state like ? "
+                + "and (o like '%\"intoken\": \"WETH\"%' or o like \"%'intoken': 'WETH'%\")"
+                + (isDynamic ? " and state != 'cancel'" : "");
+        String totalSQL = "select count(1) " + from;
+        String findSQL = "select * " + from + " order by ts desc";
+        Page<InputData> rst = InputData.dao.paginateByFullSql(1, isDynamic ? pageSize : 9999,
+                totalSQL, findSQL, t1, t2, fm, t, hs, state);
+
+        Ret ret = new Ret();
+        ret.set("data", rst.getList());
+        ret.set("count", rst.getList().size());
+        ret.setOk();
+
+        renderJson(ret);
+    }
+
+    public void getRecordByMySelf() {
+        // timestamp start
+        long t1 = (new Date().getTime() / 1000) - (10 * 60);
+        // timestamp end
+        long t2 = 9999999999999999L;
+        // from
+        String fm = "%";
+        // to
+        String t = "%";
+        // hash
+        String hs = "%";
+        // state
+        String state = "%";
+        // pageSize
+        int pageSize = 400;
+        if (getPara("fm") != null) {
+//            t1 = 0;
+            fm = getPara("fm");
+        }
+        if (getPara("t") != null) {
+//            t1 = 0;
+            t = getPara("t");
+        }
+        if (getPara("hs") != null) {
+//            t1 = 0;
+            hs = getPara("hs");
+        }
+        if (getPara("state") != null) {
+//            t1 = 0;
+            state = getPara("state");
+        }
+        if (getPara("t1") != null) {
+            if (getParaToLong("t1") > t1 + 60 * 7) {
+                t1 = 0;
+            } else {
+                t1 = getParaToLong("t1");
+            }
+        }
+        if (getPara("t2") != null) {
+            t2 = getParaToLong("t2");
+        }
+        if (getPara("pageSize") != null) {
+            pageSize = getParaToInt("pageSize");
+        }
+
+        String from = "from input_data where ts>? and ts<? and fm like ? and t like ? and hs like ? and state like ? and o like '%ZIJI%'";
+        String totalSQL = "select count(1) " + from;
+        String findSQL = "select * " + from + " order by ts desc";
+
+        Page<InputData> rst = InputData.dao.paginateByFullSql(1, pageSize,
+                totalSQL, findSQL, t1, t2, fm, t, hs, state);
+
+        Ret ret = new Ret();
+        ret.set("data", rst.getList());
+        ret.set("count", rst.getList().size());
+        ret.setOk();
+
+        renderJson(ret);
+    }
+}

+ 7 - 0
src/main/java/model/Config.java

@@ -0,0 +1,7 @@
+package model;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class Config extends Model<Config> {
+    public static final Config dao = new Config().dao();
+}

+ 7 - 0
src/main/java/model/InputData.java

@@ -0,0 +1,7 @@
+package model;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class InputData extends Model<InputData> {
+    public static final InputData dao = new InputData().dao();
+}

+ 10 - 0
src/main/java/start/Start.java

@@ -0,0 +1,10 @@
+package start;
+
+import com.jfinal.server.undertow.UndertowServer;
+import config.WebConfig;
+
+public class Start {
+    public static void main(String[] args) {
+        UndertowServer.start(WebConfig.class, 80, true);
+    }
+}

+ 52 - 0
src/main/java/util/MyRet.java

@@ -0,0 +1,52 @@
+package util;
+
+import com.jfinal.kit.Ret;
+
+public class MyRet extends Ret {
+
+    public static final int CODE_OK = 0;                // 正常
+
+    public static final int CODE_NO_LOGIN = 1;          // 未登录
+
+    public static final int CODE_NO_POWER = 2;          // 没有权限
+
+    public static MyRet create() {
+        return new MyRet();
+    }
+
+    @Override
+    public MyRet setOk() {
+        this.set("state", true);
+        this.setCode(MyRet.CODE_OK);
+
+        return this;
+    }
+
+    @Override
+    public MyRet setFail() {
+        this.set("state", false);
+
+        return this;
+    }
+
+    public boolean isOk() {
+        return this.getBoolean("state");
+    }
+
+    public MyRet setCode(int code) {
+        this.set("code", code);
+
+        return this;
+    }
+
+    public MyRet setMsg(String msg) {
+        this.set("msg", msg);
+
+        return this;
+    }
+
+    public MyRet setData(Object obj) {
+        this.set("data", obj);
+        return this;
+    }
+}

+ 7 - 0
src/main/webapp/WEB-INF/web.xml

@@ -0,0 +1,7 @@
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+  <display-name>Archetype Created Web Application</display-name>
+</web-app>

+ 5 - 0
src/main/webapp/index.jsp

@@ -0,0 +1,5 @@
+<html>
+<body>
+<h2>Hello World!</h2>
+</body>
+</html>