diff --git a/JSD-8235-需求确认书V1.2(1).docx b/JSD-8235-需求确认书V1.2(1).docx
new file mode 100644
index 0000000..b29e3f6
Binary files /dev/null and b/JSD-8235-需求确认书V1.2(1).docx differ
diff --git a/README.md b/README.md
index e68c960..1f0c759 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
# open-JSD-8235
-JSD-8235 开源任务材料
\ No newline at end of file
+JSD-8235 开源任务材料\
+免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
+仅作为开发者学习参考使用!禁止用于任何商业用途!\
+为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。
\ No newline at end of file
diff --git a/plugin.xml b/plugin.xml
new file mode 100644
index 0000000..047a94d
--- /dev/null
+++ b/plugin.xml
@@ -0,0 +1,20 @@
+
+ com.fr.plugin.jh.export
+
+ yes
+ 1.0.2
+ 10.0
+ 2018-07-31
+ fr.open
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/fr/plugin/JHHandlerProvider.java b/src/main/java/com/fr/plugin/JHHandlerProvider.java
new file mode 100644
index 0000000..f72e0d2
--- /dev/null
+++ b/src/main/java/com/fr/plugin/JHHandlerProvider.java
@@ -0,0 +1,23 @@
+package com.fr.plugin;
+
+import com.fr.decision.fun.HttpHandler;
+import com.fr.decision.fun.impl.AbstractHttpHandlerProvider;
+import com.fr.plugin.api.DataTableExport;
+import com.fr.plugin.api.SQLQueryApi;
+import com.fr.plugin.api.SQLUpdateApi;
+import com.fr.plugin.transform.ExecuteFunctionRecord;
+import com.fr.plugin.transform.FunctionRecorder;
+
+@FunctionRecorder
+public class JHHandlerProvider extends AbstractHttpHandlerProvider {
+ @Override
+ @ExecuteFunctionRecord
+ public HttpHandler[] registerHandlers() {
+ return new HttpHandler[]{
+ new DataTableExport(),
+ new SQLQueryApi(),
+ new SQLUpdateApi()
+ };
+ }
+
+}
diff --git a/src/main/java/com/fr/plugin/JHURLAliasBridge.java b/src/main/java/com/fr/plugin/JHURLAliasBridge.java
new file mode 100644
index 0000000..78dc82b
--- /dev/null
+++ b/src/main/java/com/fr/plugin/JHURLAliasBridge.java
@@ -0,0 +1,29 @@
+package com.fr.plugin;
+
+import com.fr.decision.fun.impl.AbstractURLAliasProvider;
+import com.fr.decision.webservice.url.alias.URLAlias;
+import com.fr.decision.webservice.url.alias.URLAliasFactory;
+import com.fr.general.IOUtils;
+import com.fr.stable.StringUtils;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.Scanner;
+import java.util.Set;
+
+public class JHURLAliasBridge extends AbstractURLAliasProvider {
+
+ @Override
+ public URLAlias[] registerAlias() {
+ return new URLAlias[]{
+ URLAliasFactory.createPluginAlias("/dynamic/dataresource/api/update", "/update", false),
+ URLAliasFactory.createPluginAlias("/dynamic/dataresource/api/query", "/query", false),
+ URLAliasFactory.createPluginAlias("/dynamic/dataresource/api/output", "/output", false),
+ };
+ }
+
+
+}
diff --git a/src/main/java/com/fr/plugin/api/DataTableExport.java b/src/main/java/com/fr/plugin/api/DataTableExport.java
new file mode 100644
index 0000000..cfff48e
--- /dev/null
+++ b/src/main/java/com/fr/plugin/api/DataTableExport.java
@@ -0,0 +1,165 @@
+package com.fr.plugin.api;
+
+import com.fr.decision.fun.impl.BaseHttpHandler;
+import com.fr.log.FineLoggerFactory;
+import com.fr.plugin.utils.AesUtils;
+import com.fr.plugin.utils.DbUtils;
+import com.fr.plugin.utils.RespUtils;
+import com.fr.third.org.apache.commons.lang3.time.DateFormatUtils;
+import com.fr.third.springframework.util.StringUtils;
+import com.fr.third.springframework.web.bind.annotation.RequestMethod;
+import com.fr.web.utils.WebUtils;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedWriter;
+import java.io.OutputStreamWriter;
+import java.util.*;
+
+
+public class DataTableExport extends BaseHttpHandler {
+
+ @Override
+ public RequestMethod getMethod() {
+ return RequestMethod.POST;
+ }
+
+ @Override
+ public String getPath() {
+ return "/output";
+ }
+
+
+ @Override
+ public boolean isPublic() {
+ return false;
+ }
+
+ @Override
+ public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception {
+ //获取参数
+ List keys = new ArrayList<>();
+ keys.add("table_name");
+ keys.add("where");
+ keys.add("field_break");
+ keys.add("fields");
+ keys.add("need_title");
+ keys.add("line_break");
+ keys.add("m_flag");
+
+ Map params = new HashMap<>();
+ FineLoggerFactory.getLogger().info("加密fine_user为:{}", AesUtils.encryptPassword("find_user"));
+ FineLoggerFactory.getLogger().info("加密后在解密测试:{}", AesUtils.decryptPassword(AesUtils.encryptPassword("find_user")));
+ for (String key : keys) {
+ String value = WebUtils.getHTTPRequestParameter(request, key);
+ if (StringUtils.isEmpty(value)) {
+ FineLoggerFactory.getLogger().info("导出接口:传入的{}为空", key);
+ httpServletResponse.setStatus(500);
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-100, "未提供" + key + "参数"));
+ return;
+ }
+ try {
+ FineLoggerFactory.getLogger().info("导出接口:待解密{}:{}", key, value);
+ String temp = AesUtils.decryptPassword(value);
+ if (temp == null) {
+ temp = "";
+ }
+ FineLoggerFactory.getLogger().info("导出接口:解密{} 之后为:{}", key, temp);
+ params.put(key, temp);
+ } catch (Exception e) {
+ FineLoggerFactory.getLogger().error("导出接口:解密SQL异常 ", e);
+ httpServletResponse.setStatus(500);
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-102, "解密query参数失败"));
+ return;
+ }
+ }
+
+
+ try {
+ String tableName = params.get("table_name");
+ DbUtils dbUtils = new DbUtils();
+ if (StringUtils.isEmpty(tableName) || !dbUtils.checkTableExit(tableName)) {
+ FineLoggerFactory.getLogger().error("导出接口:传过来的表不存在{} ", tableName);
+ httpServletResponse.setStatus(500);
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-103, "表不存在:" + tableName));
+ return;
+ }
+ String where = params.get("where");
+ String countSql = String.format("select count(1) from %s %s", tableName, where);
+ int rowCount = dbUtils.countRows(countSql);
+ int pageSize = 2000;
+ int totalPage = rowCount % pageSize == 0 ? rowCount / pageSize : (rowCount / pageSize) + 1;
+ String fields = params.get("fields");
+ String m_flag = params.get("m_flag");
+ //获取一个写出的流
+ String date = DateFormatUtils.format(new Date(), "yyyyMMddHHmmssSSS");
+ httpServletResponse.setHeader("file_name", String.format("{%s}__%s__%s__%d.dat", m_flag, tableName, date, rowCount));
+ ServletOutputStream outputStream = httpServletResponse.getOutputStream();
+ BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
+ String line_break = params.get("line_break");
+ if (StringUtils.isEmpty(line_break)) {
+ line_break = "\n";
+ }
+ String field_break = params.get("field_break");
+ if (StringUtils.isEmpty(field_break)) {
+ field_break = "|@|";
+ }
+ String need_title = params.get("need_title");
+ boolean needTitle = com.fr.stable.StringUtils.equals(need_title, "true");
+ //如果需要标题,先做一次预查寻,把表头查出来
+
+ if (needTitle) {
+ String preSql = String.format("select %s from %s %s limit 1",fields,tableName,where);
+ List lists = dbUtils.getQueryFields(preSql);
+ StringBuilder builder = new StringBuilder();
+ boolean isFirst = true;
+ for (String name : lists) {
+ String temp = StringUtils.trimAllWhitespace(name);
+ if (isFirst) {
+ isFirst = false;
+ }else{
+ builder.append(field_break);
+ }
+ builder.append(temp);
+ }
+ builder.append(line_break);
+ bufferedWriter.write(builder.toString());
+ }
+
+ for (int i = 0; i < totalPage; i++) {
+ List dataByPage = getDataByPage(tableName, fields, where, i, pageSize, dbUtils, line_break, field_break);
+ for (String line : dataByPage) {
+ bufferedWriter.write(line);
+ }
+ }
+ bufferedWriter.flush();
+ } catch (Exception e) {
+ FineLoggerFactory.getLogger().error("导出接口:执行SQL异常 ", e);
+ httpServletResponse.setStatus(500);
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-103, "SQL执行失败:" + RespUtils.Exception2String(e)));
+ }
+ }
+
+ private List getDataByPage(String tableName, String fields, String where, int page, int pageSize, DbUtils dbUtils, String line_break, String field_break) throws Exception {
+ String sql = String.format("select %s from %s %s limit %d,%d", fields, tableName, where, page, pageSize);
+ return dbUtils.query(sql, line_break, field_break);
+ }
+
+ public static void main(String[] args) {
+// String table_name = AesUtils.encryptPassword("fine_user");
+// String where = AesUtils.encryptPassword("where id>100");
+// String fields = AesUtils.encryptPassword("id,name,xxxxx,xxx");
+// String field_break = AesUtils.encryptPassword("xxx");
+// //以及剩下的
+// StringBuilder builder = new StringBuilder();
+// builder.append("table_name=").append(table_name)
+// .append("&where=").append(where)
+// .append("&fields=").append(fields)
+// .append("&field_break=").append(field_break);
+// //以及剩下的,按照这种格式弄
+// String params = builder.toString();
+// HttpUtils.doPostToFile("/output", params, null, "xxx地址");
+ }
+
+}
diff --git a/src/main/java/com/fr/plugin/api/SQLQueryApi.java b/src/main/java/com/fr/plugin/api/SQLQueryApi.java
new file mode 100644
index 0000000..209cece
--- /dev/null
+++ b/src/main/java/com/fr/plugin/api/SQLQueryApi.java
@@ -0,0 +1,67 @@
+package com.fr.plugin.api;
+
+import com.fr.decision.fun.impl.BaseHttpHandler;
+import com.fr.json.JSONArray;
+import com.fr.log.FineLoggerFactory;
+import com.fr.plugin.utils.AesUtils;
+import com.fr.plugin.utils.DbUtils;
+import com.fr.plugin.utils.RespUtils;
+import com.fr.stable.StringUtils;
+import com.fr.third.springframework.web.bind.annotation.RequestMethod;
+import com.fr.web.utils.WebUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+public class SQLQueryApi extends BaseHttpHandler {
+
+ @Override
+ public RequestMethod getMethod() {
+ return RequestMethod.POST;
+ }
+
+ @Override
+ public String getPath() {
+ return "/query";
+ }
+
+ @Override
+ public boolean isPublic() {
+ return false;
+ }
+
+ @Override
+ public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception {
+ //获取参数
+ String query = WebUtils.getHTTPRequestParameter(request, "query");
+ if (StringUtils.isBlank(query)) {
+ FineLoggerFactory.getLogger().info("查询接口:传入的sql为空");
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-100, "未提供query参数"));
+ return;
+ }
+ String sql = "";
+ try {
+ FineLoggerFactory.getLogger().info("查询接口:待解密query:{}", query);
+ sql = AesUtils.decryptPassword(query);
+ FineLoggerFactory.getLogger().info("查询接口:解密之后为:{}", sql);
+ if (StringUtils.isBlank(sql)) {
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-101, "解密之后的SQL为空"));
+ return;
+ }
+ } catch (Exception e) {
+ FineLoggerFactory.getLogger().error("查询接口:解密SQL异常 ", e);
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-102, "解密query参数失败"));
+ return;
+ }
+ try {
+ DbUtils dbUtils = new DbUtils();
+ JSONArray jsonArray = dbUtils.exQuery(sql);
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildSuccess(jsonArray));
+ } catch (Exception e) {
+ FineLoggerFactory.getLogger().error("查询接口:执行SQL异常 ", e);
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-103, "SQL执行失败:" + RespUtils.Exception2String(e)));
+ return;
+ }
+ }
+}
diff --git a/src/main/java/com/fr/plugin/api/SQLUpdateApi.java b/src/main/java/com/fr/plugin/api/SQLUpdateApi.java
new file mode 100644
index 0000000..378d4cb
--- /dev/null
+++ b/src/main/java/com/fr/plugin/api/SQLUpdateApi.java
@@ -0,0 +1,71 @@
+package com.fr.plugin.api;
+
+import com.fr.decision.fun.impl.BaseHttpHandler;
+import com.fr.json.JSONArray;
+import com.fr.json.JSONObject;
+import com.fr.log.FineLoggerFactory;
+import com.fr.plugin.utils.AesUtils;
+import com.fr.plugin.utils.DbUtils;
+import com.fr.plugin.utils.RespUtils;
+import com.fr.stable.StringUtils;
+import com.fr.third.springframework.web.bind.annotation.RequestMethod;
+import com.fr.web.utils.WebUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+public class SQLUpdateApi extends BaseHttpHandler {
+
+ @Override
+ public RequestMethod getMethod() {
+ return RequestMethod.POST;
+ }
+
+ @Override
+ public String getPath() {
+ return "/update";
+ }
+
+
+ @Override
+ public boolean isPublic() {
+ return false;
+ }
+
+ @Override
+ public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception {
+ //获取参数
+ String query = WebUtils.getHTTPRequestParameter(request, "query");
+ if (StringUtils.isBlank(query)) {
+ FineLoggerFactory.getLogger().info("更新接口:传入的sql为空");
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-100, "未提供query参数"));
+ return;
+ }
+ String sql = "";
+ try {
+ FineLoggerFactory.getLogger().info("更新接口:待解密query:{}", query);
+ sql = AesUtils.decryptPassword(query);
+ FineLoggerFactory.getLogger().info("更新接口:解密之后为:{}", sql);
+ if (StringUtils.isBlank(sql)) {
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-101, "解密之后的SQL为空"));
+ return;
+ }
+ } catch (Exception e) {
+ FineLoggerFactory.getLogger().error("更新接口:解密SQL异常 ", e);
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-102, "解密query参数失败"));
+ return;
+ }
+ try {
+ DbUtils dbUtils = new DbUtils();
+ int rows = dbUtils.exSqlUpdate(sql);
+ JSONObject resp=new JSONObject();
+ resp.put("rows", rows);
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildSuccess(resp));
+ } catch (Exception e) {
+ FineLoggerFactory.getLogger().error("更新接口:执行SQL异常 ", e);
+ WebUtils.printAsJSON(httpServletResponse, RespUtils.buildError(-103, "SQL执行失败:" + RespUtils.Exception2String(e)));
+ return;
+ }
+ }
+}
diff --git a/src/main/java/com/fr/plugin/utils/AesUtils.java b/src/main/java/com/fr/plugin/utils/AesUtils.java
new file mode 100644
index 0000000..c35761b
--- /dev/null
+++ b/src/main/java/com/fr/plugin/utils/AesUtils.java
@@ -0,0 +1,89 @@
+package com.fr.plugin.utils;
+
+
+import com.fr.log.FineLoggerFactory;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+
+public class AesUtils {
+ public static String encrypt(byte[] byteContent, String keyPass) {
+ try {
+ SecretKeySpec secretKey = new SecretKeySpec(keyPass.getBytes(), "AES");
+ Cipher cipher = Cipher.getInstance("AES");// 创建密码器
+ cipher.init(Cipher.ENCRYPT_MODE, secretKey);// 初始化
+ byte[] result = cipher.doFinal(byteContent);
+ return Base64.getUrlEncoder().encodeToString(result);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static String encrypt(String keyPass, String content) {
+ try {
+ SecretKeySpec secretKey = new SecretKeySpec(keyPass.getBytes(), "AES");
+ Cipher cipher = Cipher.getInstance("AES");// 创建密码器
+ byte[] byteContent = content.getBytes(Charset.forName("UTF-8"));
+ cipher.init(Cipher.ENCRYPT_MODE, secretKey);// 初始化
+ byte[] result = cipher.doFinal(byteContent);
+ return Base64.getUrlEncoder().encodeToString(result);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static String decrypt(byte[] content, String keyPass) {
+ try {
+ SecretKeySpec secretKey = new SecretKeySpec(keyPass.getBytes(), "AES");
+ Cipher cipher = Cipher.getInstance("AES");// 创建密码器
+ cipher.init(Cipher.DECRYPT_MODE, secretKey);// 初始化
+ byte[] result = cipher.doFinal(content);
+ return new String(result, StandardCharsets.UTF_8);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static String decrypt(String keyPass, String source) {
+ byte[] content = Base64.getUrlDecoder().decode(source);
+
+ try {
+ SecretKeySpec secretKey = new SecretKeySpec(keyPass.getBytes(), "AES");
+ Cipher cipher = Cipher.getInstance("AES");// 创建密码器
+ cipher.init(Cipher.DECRYPT_MODE, secretKey);// 初始化
+ byte[] result = cipher.doFinal(content);
+
+ return new String(result, StandardCharsets.UTF_8);
+ } catch (Exception e) {
+ FineLoggerFactory.getLogger().error("解密数据出错,");
+ printException2Frlog(e);
+ }
+ return null;
+ }
+
+ public static void printException2Frlog(Exception e) {
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ String s = writer.toString();
+ FineLoggerFactory.getLogger().error("错误:{}", s);
+ }
+ public static String decryptPassword(String source) {
+ return decrypt("xxxxx", source);
+ }
+
+ public static String encryptPassword(String source) {
+ return encrypt("xxxxx", source);
+ }
+
+ public static void main(String[] args) {
+ System.out.println(encryptPassword("fine_user"));
+ System.out.println(decryptPassword(encryptPassword("fine_user")));
+ }
+
+}
diff --git a/src/main/java/com/fr/plugin/utils/DbUtils.java b/src/main/java/com/fr/plugin/utils/DbUtils.java
new file mode 100644
index 0000000..38516b7
--- /dev/null
+++ b/src/main/java/com/fr/plugin/utils/DbUtils.java
@@ -0,0 +1,212 @@
+package com.fr.plugin.utils;
+
+import com.fr.file.ConnectionConfig;
+import com.fr.json.JSONArray;
+import com.fr.json.JSONObject;
+import com.fr.log.FineLoggerFactory;
+import com.fr.log.FineLoggerProvider;
+import com.fr.third.springframework.util.StringUtils;
+
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class DbUtils {
+ String db_name = "finedb";
+
+ FineLoggerProvider logger = FineLoggerFactory.getLogger();
+
+
+ public com.fr.data.impl.Connection getDbConnect() {
+ return ConnectionConfig.getInstance().getConnection(db_name);
+ }
+
+ public JSONArray select(String sql, Object... params) {
+ logger.info("query data by sql:" + sql + Arrays.toString(params));
+ try {
+ com.fr.data.impl.Connection dbConnect = getDbConnect();
+
+ Connection con = dbConnect.createConnection();
+ PreparedStatement preparedStatement = con.prepareStatement(sql);
+ setParams(preparedStatement, params);
+ ResultSet rs = preparedStatement.executeQuery(sql);
+ // 获得记录的详细信息,然后获得总列数
+ ResultSetMetaData resMetaData = rs.getMetaData();
+ int colNum = resMetaData.getColumnCount();
+ // 用对象保存数据
+ String name = "";
+ String value = "";
+ JSONArray list = new JSONArray();
+ while (rs.next()) {
+ JSONObject cells = new JSONObject();
+ for (int i = 0; i < colNum; i++) {
+ name = resMetaData.getColumnLabel(i);
+ if (cells.get(name) != null) {
+ name = resMetaData.getColumnLabel(i);
+ }
+ if (rs.getObject(i) != null && resMetaData.getColumnTypeName(i).equals("DATETIME") || resMetaData.getColumnTypeName(i).equals("TIMESTAMP")) {
+ value = rs.getObject(i).toString();
+ cells.put(name, value.substring(0, value.length() - 2));
+ } else {
+ cells.put(name, rs.getString(i));
+ }
+ }
+ list.add(cells);
+ }
+ // 释放数据库资源
+ rs.close();
+ preparedStatement.close();
+ con.close();
+ return list;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public JSONObject findOneRow(String sql, Object... params) {
+ JSONArray select = select(sql, params);
+ if (select != null) {
+ if (!select.isEmpty()) {
+ return select.getJSONObject(0);
+ }
+ }
+ return null;
+ }
+
+ public int countRows(String sql, Object... params) throws Exception {
+ PreparedStatement pstmt = getDbConnect().createConnection().prepareStatement(sql);
+ setParams(pstmt, params);
+ ResultSet resultSet = pstmt.executeQuery();
+ if (resultSet.next()) {
+ return resultSet.getInt(1);
+ }
+ return 0;
+ }
+
+ public boolean checkExist(String sql, Object... params) throws Exception {
+ PreparedStatement pstmt = getDbConnect().createConnection().prepareStatement(sql);
+ setParams(pstmt, params);
+ ResultSet resultSet = pstmt.executeQuery();
+ if (resultSet.next()) {
+ return resultSet.getInt(1) > 0;
+ }
+ return false;
+ }
+
+ public boolean checkTableExit(String tableName) throws Exception {
+ String sql = "SELECT\n" +
+ "\tcount(1) \n" +
+ "FROM\n" +
+ "\t" + tableName + " \n";
+ return checkExist(sql);
+ }
+
+ private void setParams(PreparedStatement pstmt, Object... params) throws SQLException {
+ if (params.length > 0) {
+ int length = params.length;
+ for (int i = 1; i <= length; i++) {
+ pstmt.setObject(i, params[i - 1]);
+ }
+ }
+ }
+
+ public int exSqlUpdate(String sql, Object... params) throws Exception {
+ logger.info("update data by sql:" + sql + " params " + Arrays.toString(params));
+ com.fr.data.impl.Connection dbConnect = getDbConnect();
+ Connection connection = dbConnect.createConnection();
+ PreparedStatement pstmt = connection.prepareStatement(sql);
+ setParams(pstmt, params);
+ int i = pstmt.executeUpdate();
+ pstmt.close();
+ connection.close();
+ return i;
+ }
+
+ /**
+ * 取查询结果集字段
+ *
+ * @param sql
+ * @param params
+ * @return
+ * @throws Exception
+ */
+ public JSONArray exQuery(String sql, Object... params) throws Exception {
+ logger.info("query data by sql:" + sql + " params " + Arrays.toString(params));
+ com.fr.data.impl.Connection dbConnect = getDbConnect();
+ Connection connection = dbConnect.createConnection();
+ PreparedStatement pstmt = connection.prepareStatement(sql);
+ setParams(pstmt, params);
+ ResultSet resultSet = pstmt.executeQuery();
+ ResultSetMetaData resMetaData = resultSet.getMetaData();
+ int columnCount = resMetaData.getColumnCount();
+ JSONArray arrs = new JSONArray();
+ while (resultSet.next()) {
+ String name;
+ String value;
+ JSONObject one = new JSONObject();
+ for (int i = 1; i <= columnCount; i++) {
+ name = resMetaData.getColumnLabel(i);
+ if (one.get(name) != null) {
+ name = resMetaData.getColumnLabel(i);
+ }
+ if (resultSet.getObject(i) != null && resMetaData.getColumnTypeName(i).equals("DATETIME") || resMetaData.getColumnTypeName(i).equals("TIMESTAMP")) {
+ value = resultSet.getObject(i).toString();
+ one.put(name, value.substring(0, value.length() - 2));
+ } else {
+ one.put(name, resultSet.getString(i));
+ }
+ }
+ arrs.add(one);
+ }
+
+ pstmt.close();
+ connection.close();
+ logger.info("查询结果:" + arrs);
+ return arrs;
+ }
+
+ public List query(String sql,String line_break,String field_break) throws Exception {
+ com.fr.data.impl.Connection dbConnect = getDbConnect();
+ Connection connection = dbConnect.createConnection();
+ PreparedStatement pstmt = connection.prepareStatement(sql);
+ ResultSet resultSet = pstmt.executeQuery();
+ ResultSetMetaData resMetaData = resultSet.getMetaData();
+ int columnCount = resMetaData.getColumnCount();
+ List arrs = new ArrayList<>();
+ while (resultSet.next()) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 1; i <= columnCount; i++) {
+ if(i !=1 ){
+ builder.append(field_break);
+ }
+ String data = resultSet.getString(i);
+ builder.append(StringUtils.trimAllWhitespace(data));
+ }
+ builder.append(line_break);
+ arrs.add(builder.toString());
+ }
+ pstmt.close();
+ connection.close();
+ return arrs;
+ }
+
+ public List getQueryFields(String preSql, Object... params) throws Exception {
+ com.fr.data.impl.Connection dbConnect = getDbConnect();
+ Connection connection = dbConnect.createConnection();
+ PreparedStatement pstmt = connection.prepareStatement(preSql);
+ setParams(pstmt, params);
+ ResultSet resultSet = pstmt.executeQuery();
+ ResultSetMetaData resMetaData = resultSet.getMetaData();
+ int columnCount = resMetaData.getColumnCount();
+ List arrs = new ArrayList<>();
+ for (int i = 0; i < columnCount; i++) {
+ String columnName = resMetaData.getColumnName(i + 1);
+ arrs.add(columnName);
+ }
+ pstmt.close();
+ connection.close();
+ return arrs;
+ }
+}
diff --git a/src/main/java/com/fr/plugin/utils/RespUtils.java b/src/main/java/com/fr/plugin/utils/RespUtils.java
new file mode 100644
index 0000000..f479337
--- /dev/null
+++ b/src/main/java/com/fr/plugin/utils/RespUtils.java
@@ -0,0 +1,34 @@
+package com.fr.plugin.utils;
+
+
+import com.fr.json.JSONObject;
+import com.fr.log.FineLoggerFactory;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+public class RespUtils {
+ public static JSONObject buildResp(int code, String msg, Object data) {
+ JSONObject res = new JSONObject();
+ res.put("code", code);
+ res.put("msg", msg);
+ res.put("data", data);
+ return res;
+ }
+ public static String Exception2String(Throwable e) {
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ return writer.toString();
+ }
+ public static JSONObject buildError(int code, String msg) {
+ return buildResp(code, msg, "");
+ }
+
+ public static JSONObject buildNormalError(String msg) {
+ return buildResp(-1, msg, "");
+ }
+
+ public static JSONObject buildSuccess(Object data) {
+ return buildResp(0, "success", data);
+ }
+}
diff --git a/src/main/resources/com/fr/plugin/alert.html b/src/main/resources/com/fr/plugin/alert.html
new file mode 100644
index 0000000..bfb2ea2
--- /dev/null
+++ b/src/main/resources/com/fr/plugin/alert.html
@@ -0,0 +1,35 @@
+
+
+
+
+ alert
+
+
+
+
+
+
+