完成部分metaDetail函数
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package org.bdware.sc.registry;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bdware.sc.util.ExceptionUtil;
|
||||
|
||||
import javax.json.Json;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -103,7 +106,7 @@ public class DBConnector {
|
||||
connect();
|
||||
pstmt = jdbcConnection.prepareStatement(sql);
|
||||
pstmt.setString(1, doid);
|
||||
ResultSet rs = null;
|
||||
ResultSet rs;
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
ret = rs.getString("sample");
|
||||
@@ -117,4 +120,92 @@ public class DBConnector {
|
||||
connClose(jdbcConnection);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String queryInfoByMetaID(String doid) {
|
||||
String ret = "";
|
||||
String sql = "SELECT description FROM registry.meta_data WHERE doid = ?;";
|
||||
|
||||
// execute sql
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
connect();
|
||||
pstmt = jdbcConnection.prepareStatement(sql);
|
||||
pstmt.setString(1, doid);
|
||||
ResultSet rs;
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
ret = rs.getString("description");
|
||||
}
|
||||
pstmt.execute();
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
LOGGER.debug(ExceptionUtil.exceptionToString(e));
|
||||
}
|
||||
pstmtClose(pstmt);
|
||||
connClose(jdbcConnection);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static JsonObject queryMetaStandardByDate(Timestamp startTime, Timestamp endTime, int offset, int count) {
|
||||
String sql = "select * from registry.meta_data where \"createTime\" >= ? and \"createTime\" <= ? limit ? offset ? ;";
|
||||
|
||||
// execute sql
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
connect();
|
||||
pstmt = jdbcConnection.prepareStatement(sql);
|
||||
pstmt.setInt(3, count);
|
||||
pstmt.setInt(4, offset);
|
||||
pstmt.setObject(1, startTime);
|
||||
pstmt.setObject(2, endTime);
|
||||
|
||||
String[] columns = {
|
||||
"name",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"creator",
|
||||
"updater",
|
||||
"registryID",
|
||||
"controlType",
|
||||
"status",
|
||||
"version",
|
||||
"doid",
|
||||
"description",
|
||||
"fields"
|
||||
};
|
||||
|
||||
System.out.println(pstmt);
|
||||
|
||||
ResultSet rs = null;
|
||||
int total = 0;
|
||||
JsonObject ret = new JsonObject();
|
||||
JsonArray data = new JsonArray();
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
total ++;
|
||||
JsonObject row = new JsonObject();
|
||||
for (String col : columns) {
|
||||
if (col.equals("createTime") || col.equals("updateTime"))
|
||||
row.addProperty(col, rs.getTimestamp(col).toString());
|
||||
else if (col.equals("status"))
|
||||
row.addProperty(col, rs.getBoolean(col));
|
||||
else
|
||||
row.addProperty(col, rs.getString(col));
|
||||
}
|
||||
data.add(row);
|
||||
}
|
||||
ret.addProperty("total", total);
|
||||
ret.add("data", data);
|
||||
rs.close();
|
||||
|
||||
pstmtClose(pstmt);
|
||||
connClose(jdbcConnection);
|
||||
|
||||
return ret;
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
LOGGER.debug(ExceptionUtil.exceptionToString(e));
|
||||
}
|
||||
return new JsonObject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import org.bdware.sc.engine.JSONTool;
|
||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||
import java.sql.SQLException;
|
||||
import org.bdware.sc.util.JsonUtil;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -13,6 +15,8 @@ import static org.bdware.sc.engine.JSONTool.convertMirrorToJson;
|
||||
|
||||
|
||||
public class RegistryDB {
|
||||
private static int stateCode;
|
||||
|
||||
public static void init(ScriptObjectMirror arg, String requester) {
|
||||
try {
|
||||
JsonObject jsonData = convertMirrorToJson(arg).getAsJsonObject();
|
||||
@@ -32,14 +36,50 @@ public class RegistryDB {
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getRegistryInfo(ScriptObjectMirror scriptMirrorObject) {
|
||||
JsonObject jo = convertMirrorToJson(scriptMirrorObject).getAsJsonObject();
|
||||
JsonObject ret = new JsonObject();
|
||||
String info = DBConnector.queryInfoByMetaID(jo.get("doid").getAsString());
|
||||
if(!info.equals("")) {
|
||||
ret = JsonUtil.parseStringAsJsonObject(info);
|
||||
stateCode = 0;
|
||||
} else {
|
||||
stateCode = -1;
|
||||
}
|
||||
return JSONTool.convertJsonElementToMirror(ret);
|
||||
}
|
||||
|
||||
public static Object querySampleByMetaID(ScriptObjectMirror scriptMirrorObject) {
|
||||
JsonObject jo = convertMirrorToJson(scriptMirrorObject).getAsJsonObject();
|
||||
JsonObject ret = new JsonObject();
|
||||
String sample = DBConnector.querySampleByMetaID(jo.get("localMetaID").getAsString());
|
||||
if(!sample.equals("")) {
|
||||
ret = JsonUtil.parseStringAsJsonObject(sample);
|
||||
stateCode = 0;
|
||||
} else {
|
||||
stateCode = -1;
|
||||
}
|
||||
System.out.println(sample);
|
||||
return JSONTool.convertJsonElementToMirror(ret);
|
||||
}
|
||||
|
||||
public static Object queryMetaStandardsByTimeAndOffset(ScriptObjectMirror scriptMirrorObject) {
|
||||
JsonObject jo = convertMirrorToJson(scriptMirrorObject).getAsJsonObject();
|
||||
Timestamp startTime = new Timestamp(jo.get("createStartDate").getAsLong());
|
||||
Timestamp endTime = new Timestamp(jo.get("createEndDate").getAsLong());
|
||||
int offset = jo.get("offset").getAsInt();
|
||||
int count = jo.get("count").getAsInt();
|
||||
JsonObject ret = DBConnector.queryMetaStandardByDate(startTime, endTime, offset, count);
|
||||
if(ret == null) {
|
||||
stateCode = -1;
|
||||
} else {
|
||||
stateCode = 0;
|
||||
return JSONTool.convertJsonElementToMirror(ret);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getLastExecuteStatus() {
|
||||
return stateCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,9 +12,11 @@ import wrp.jdk.nashorn.internal.scripts.JO;
|
||||
|
||||
public class RuleExecutor {
|
||||
private static int executeCode;
|
||||
private static String executeMsg;
|
||||
|
||||
public static Object executeRule(ScriptObjectMirror som) {
|
||||
executeCode = 0;
|
||||
executeMsg = "success";
|
||||
JsonObject jo = JSONTool.convertMirrorToJson(som).getAsJsonObject();
|
||||
Object val = som.get("localDataSample");
|
||||
JsonObject rule = jo.get("mapRule").getAsJsonObject();
|
||||
@@ -39,6 +41,7 @@ public class RuleExecutor {
|
||||
e.printStackTrace();
|
||||
//TODO GREP....
|
||||
executeCode = 1;
|
||||
executeMsg = e.getMessage();
|
||||
return "exception:" + e.getMessage();
|
||||
}
|
||||
}
|
||||
@@ -46,5 +49,8 @@ public class RuleExecutor {
|
||||
public static int getLastExecuteStatus() {
|
||||
return executeCode;
|
||||
}
|
||||
public static String getLastExecuteMsg() {
|
||||
return executeMsg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user