From cf6488f8cfa4b78b1495f35cb6811e237cba53de Mon Sep 17 00:00:00 2001 From: zack Date: Mon, 26 Apr 2021 19:11:15 +0800 Subject: [PATCH 1/7] =?UTF-8?q?REPORT-50963=20=E4=BC=98=E5=8C=96=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E6=95=B0=E6=8D=AE=E9=9B=86=E4=B8=8A=E5=B1=82=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1(abstracttabledata)=EF=BC=8C=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=96=B0demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/data/SimpleParamTableDataDemo.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/main/java/com/fr/data/SimpleParamTableDataDemo.java diff --git a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java new file mode 100644 index 0000000..dc1b7fd --- /dev/null +++ b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java @@ -0,0 +1,77 @@ +package com.fr.data; + +import com.fr.file.DatasourceManager; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.ParameterProvider; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +/** + * 带参数的程序数据集Demo 跟ParamTableDataDemo功能一样,但实现更简单 + * + * @author fanruan + */ +public class SimpleParamTableDataDemo extends SimpleTableData { + + @Override + public String[] initColumnNames() { + String[] columnNames = new String[10]; + for (int i = 0; i < 10; i++) { + columnNames[i] = "column#" + i; + } + return columnNames; + } + + @Override + public List loadData() { + // 保存得到的数据库表名 + String tableName = ((ParameterProvider) (parameters.get().toArray())[0]).getValue().toString(); + + // 构造SQL语句,并打印出来 + String sql = "select * from " + tableName; + FineLoggerFactory.getLogger().info("Query SQL of ParamTableDataDemo: \n" + sql); + // 保存得到的结果集 + ArrayList valueList = new ArrayList(); + // 下面开始建立数据库连接,按照刚才的SQL语句进行查询 + com.fr.data.impl.Connection conn = DatasourceManager.getInstance().getConnection("FRDemo"); + Connection con = null; + try { + con = conn.createConnection(); + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + // 获得记录的详细信息,然后获得总列数 + ResultSetMetaData rsmd = rs.getMetaData(); + int colNum = rsmd.getColumnCount(); + // 用对象保存数据 + Object[] objArray = null; + while (rs.next()) { + objArray = new Object[colNum]; + for (int i = 0; i < colNum; i++) { + objArray[i] = rs.getObject(i + 1); + } + // 在valueList中加入这一行数据 + valueList.add(objArray); + } + // 释放数据库资源 + rs.close(); + stmt.close(); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } finally { + try { + if (con != null) { + con.close(); + } + } catch (SQLException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + return valueList; + } +} \ No newline at end of file From 8ec9a4a4ee0b129b0223b216e3a48745e95767f7 Mon Sep 17 00:00:00 2001 From: zack Date: Mon, 26 Apr 2021 19:23:12 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E8=A1=A5=E4=B8=80=E4=B8=8B=E7=AE=80?= =?UTF-8?q?=E5=8D=95=E7=A8=8B=E5=BA=8F=E6=95=B0=E6=8D=AE=E9=9B=86demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/data/SimpleArrayTableDataDemo.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/com/fr/data/SimpleArrayTableDataDemo.java diff --git a/src/main/java/com/fr/data/SimpleArrayTableDataDemo.java b/src/main/java/com/fr/data/SimpleArrayTableDataDemo.java new file mode 100644 index 0000000..47eddf2 --- /dev/null +++ b/src/main/java/com/fr/data/SimpleArrayTableDataDemo.java @@ -0,0 +1,29 @@ +package com.fr.data; + +import java.util.ArrayList; +import java.util.List; + +public class SimpleArrayTableDataDemo extends SimpleTableData { + + /** + * 初始化列头 + * @return + */ + @Override + public String[] initColumnNames() { + return new String[]{"Name", "Score"}; + } + + /** + * 加载行列数据 + * @return + */ + @Override + public List loadData() { + ArrayList valueList = new ArrayList(); + valueList.add(new Object[]{"Alex", 15}); + valueList.add(new Object[]{"Helly", 22}); + valueList.add(new Object[]{"Bobby", 99}); + return valueList; + } +} \ No newline at end of file From bc90de3c16e5e96ba4bcb5d84df5016c968fa4ec Mon Sep 17 00:00:00 2001 From: zack Date: Tue, 27 Apr 2021 17:06:02 +0800 Subject: [PATCH 3/7] =?UTF-8?q?REPORT-50963=20=E6=96=B0demo=E9=87=8C?= =?UTF-8?q?=E9=9D=A2=E8=8E=B7=E5=8F=96=E8=BF=9E=E6=8E=A5=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E8=B7=9F=E8=80=81demo=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/data/SimpleParamTableDataDemo.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java index dc1b7fd..b7ef716 100644 --- a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java +++ b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java @@ -1,10 +1,10 @@ package com.fr.data; -import com.fr.file.DatasourceManager; import com.fr.log.FineLoggerFactory; import com.fr.stable.ParameterProvider; import java.sql.Connection; +import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; @@ -38,11 +38,9 @@ public class SimpleParamTableDataDemo extends SimpleTableData { FineLoggerFactory.getLogger().info("Query SQL of ParamTableDataDemo: \n" + sql); // 保存得到的结果集 ArrayList valueList = new ArrayList(); - // 下面开始建立数据库连接,按照刚才的SQL语句进行查询 - com.fr.data.impl.Connection conn = DatasourceManager.getInstance().getConnection("FRDemo"); Connection con = null; try { - con = conn.createConnection(); + con = getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql); // 获得记录的详细信息,然后获得总列数 @@ -74,4 +72,26 @@ public class SimpleParamTableDataDemo extends SimpleTableData { } return valueList; } + /** + * 获取数据库连接 driverName和 url 可以换成您需要的 + * + * @return Connection + */ + private Connection getConnection() { + + String driverName = "org.sqlite.JDBC"; + String url = "jdbc:sqlite:////Applications//FineReport10_325//webapps//webroot//help//FRDemo.db"; + String username = ""; + String password = ""; + Connection con; + try { + Class.forName(driverName); + con = DriverManager.getConnection(url, username, password); + + } catch (Exception e) { + e.printStackTrace(); + return null; + } + return con; + } } \ No newline at end of file From 471a43570cb34d7855e8c208617dd52141fb3bc5 Mon Sep 17 00:00:00 2001 From: zack Date: Tue, 27 Apr 2021 17:09:10 +0800 Subject: [PATCH 4/7] rt --- src/main/java/com/fr/data/ParamTableDataDemo.java | 6 +++--- src/main/java/com/fr/data/SimpleParamTableDataDemo.java | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/fr/data/ParamTableDataDemo.java b/src/main/java/com/fr/data/ParamTableDataDemo.java index b5c2cd8..2d7f562 100644 --- a/src/main/java/com/fr/data/ParamTableDataDemo.java +++ b/src/main/java/com/fr/data/ParamTableDataDemo.java @@ -2,6 +2,7 @@ package com.fr.data; import com.fr.base.FRContext; import com.fr.file.DatasourceManager; +import com.fr.log.FineLoggerFactory; import com.fr.stable.ParameterProvider; import java.sql.Connection; import java.sql.DriverManager; @@ -133,14 +134,13 @@ public class ParamTableDataDemo extends AbstractTableData { String url = "jdbc:sqlite:////Applications//FineReport10_325//webapps//webroot//help//FRDemo.db"; String username = ""; String password = ""; - Connection con; + Connection con = null; try { Class.forName(driverName); con = DriverManager.getConnection(url, username, password); } catch (Exception e) { - e.printStackTrace(); - return null; + FineLoggerFactory.getLogger().error(e.getMessage(), e); } return con; } diff --git a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java index b7ef716..0bb630e 100644 --- a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java +++ b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java @@ -83,14 +83,13 @@ public class SimpleParamTableDataDemo extends SimpleTableData { String url = "jdbc:sqlite:////Applications//FineReport10_325//webapps//webroot//help//FRDemo.db"; String username = ""; String password = ""; - Connection con; + Connection con = null; try { Class.forName(driverName); con = DriverManager.getConnection(url, username, password); } catch (Exception e) { - e.printStackTrace(); - return null; + FineLoggerFactory.getLogger().error(e.getMessage(), e); } return con; } From 3f6541199b0246c93515739ece0db4c0df2a57f1 Mon Sep 17 00:00:00 2001 From: zack Date: Thu, 29 Apr 2021 09:42:09 +0800 Subject: [PATCH 5/7] =?UTF-8?q?REPORT-50963=20=E4=BC=98=E5=8C=96=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E6=95=B0=E6=8D=AE=E9=9B=86=E4=B8=8A=E5=B1=82=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1(abstracttabledata)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/data/ParamTableDataDemo.java | 17 ++++++++++++++--- .../com/fr/data/SimpleParamTableDataDemo.java | 6 +++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/fr/data/ParamTableDataDemo.java b/src/main/java/com/fr/data/ParamTableDataDemo.java index 2d7f562..1cd5251 100644 --- a/src/main/java/com/fr/data/ParamTableDataDemo.java +++ b/src/main/java/com/fr/data/ParamTableDataDemo.java @@ -4,10 +4,12 @@ import com.fr.base.FRContext; import com.fr.file.DatasourceManager; import com.fr.log.FineLoggerFactory; import com.fr.stable.ParameterProvider; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; +import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; @@ -93,10 +95,11 @@ public class ParamTableDataDemo extends AbstractTableData { // 保存得到的结果集 valueList = new ArrayList(); // 下面开始建立数据库连接,按照刚才的SQL语句进行查询 + // 根据连接名获取FR数据连接定义的数据连接,如果没有定义,也可以参考getConnection方法自己创建连接 com.fr.data.impl.Connection conn = DatasourceManager.getInstance().getConnection("FRDemo"); - + Connection con = null; try { - Connection con = conn.createConnection(); + con = conn.createConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql); // 获得记录的详细信息,然后获得总列数 @@ -119,7 +122,15 @@ public class ParamTableDataDemo extends AbstractTableData { // 打印一共取到的数据行数量 } catch (Exception e) { - e.printStackTrace(); + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } finally { + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } } } diff --git a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java index 0bb630e..44263a1 100644 --- a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java +++ b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java @@ -1,5 +1,6 @@ package com.fr.data; +import com.fr.file.ConnectionConfig; import com.fr.log.FineLoggerFactory; import com.fr.stable.ParameterProvider; @@ -38,9 +39,12 @@ public class SimpleParamTableDataDemo extends SimpleTableData { FineLoggerFactory.getLogger().info("Query SQL of ParamTableDataDemo: \n" + sql); // 保存得到的结果集 ArrayList valueList = new ArrayList(); + // 下面开始建立数据库连接,按照刚才的SQL语句进行查询 + // 根据连接名获取FR数据连接定义的数据连接,如果没有定义,也可以参考getConnection方法自己创建连接 + com.fr.data.impl.Connection conn = ConnectionConfig.getInstance().getConnection("FRDemo"); Connection con = null; try { - con = getConnection(); + con = conn.createConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql); // 获得记录的详细信息,然后获得总列数 From 283f40f697b4ad0e5d7fe033910407d8d812c39a Mon Sep 17 00:00:00 2001 From: pengda Date: Thu, 29 Apr 2021 15:57:09 +0800 Subject: [PATCH 6/7] =?UTF-8?q?REPORT-50982=20=E4=BF=9D=E5=AD=98=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E8=87=B3=E6=95=B0=E6=8D=AE=E5=BA=93=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=B8=A6=E5=8F=82=E6=95=B0=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E7=9A=84=E6=8A=A5=E8=A1=A8=E4=BC=9A=E6=8A=A5=E9=94=99=E7=A9=BA?= =?UTF-8?q?=E6=8C=87=E9=92=88=EF=BC=8C=E4=B8=8D=E5=B8=A6=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E6=8A=A5=E8=A1=A8=E5=8F=AF=E4=BB=A5=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/demo/NewReadFrmFromDatabase.java | 70 +++++++++++++++++++ .../java/com/fr/demo/ReadfrmFromDatabase.java | 2 +- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/fr/demo/NewReadFrmFromDatabase.java diff --git a/src/main/java/com/fr/demo/NewReadFrmFromDatabase.java b/src/main/java/com/fr/demo/NewReadFrmFromDatabase.java new file mode 100644 index 0000000..8186fe9 --- /dev/null +++ b/src/main/java/com/fr/demo/NewReadFrmFromDatabase.java @@ -0,0 +1,70 @@ +package com.fr.demo; + +import com.fr.data.core.db.DBUtils; +import com.fr.web.weblet.DBFormlet; +import com.fr.form.main.Form; +import java.sql.SQLException; +import javax.servlet.http.HttpServletRequest; +import com.fr.log.FineLoggerFactory; +import java.io.InputStream; +import java.sql.Blob; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.Map; + + + +public class NewReadFrmFromDatabase extends DBFormlet { + + @Override + public Form createForm(HttpServletRequest reportletRequest) { + String name = reportletRequest.getParameter("reportname"); + return createForm(name); + } + + @Override + public Form createForm(String reportName) { + Form form = new Form(); + Connection connection = null; + try { + connection = getConnection(); + // 从数据库中读模板 + String sql = "select frm from report where frmname = '" + reportName + + "'"; + Statement smt = connection.createStatement(); + ResultSet rs = smt.executeQuery(sql); + while (rs.next()) { + Blob blob = rs.getBlob(1); + FineLoggerFactory.getLogger().info(blob.toString()); + InputStream ins = blob.getBinaryStream(); + form.readStream(ins); + return form; + } + } catch (Exception e) { + e.printStackTrace(); + }finally { + DBUtils.closeConnection(connection); + } + + return null; + } + + private static Connection getConnection() throws ClassNotFoundException, SQLException { + // 定义数据连接(根据你实际数据库信息进行修改) + String driver = "com.mysql.jdbc.Driver"; + String url = "jdbc:mysql://localhost:3306/test"; + String user = "root"; + String pass = "123456"; + Class.forName(driver); + Connection conn = DriverManager.getConnection(url, user, pass); + return conn; + } + + @Override + public void setParameterMap(Map arg0) { + // TODO Auto-generated method stub + + } +} diff --git a/src/main/java/com/fr/demo/ReadfrmFromDatabase.java b/src/main/java/com/fr/demo/ReadfrmFromDatabase.java index 5180fee..601fca0 100644 --- a/src/main/java/com/fr/demo/ReadfrmFromDatabase.java +++ b/src/main/java/com/fr/demo/ReadfrmFromDatabase.java @@ -31,7 +31,7 @@ public class ReadfrmFromDatabase extends Formlet { Class.forName(driver); Connection conn = DriverManager.getConnection(url, user, pass); // 从数据库中读模板 - String sql = "select B from report where A = '" + name + String sql = "select frm from report where frmname = '" + name + "'"; Statement smt = conn.createStatement(); ResultSet rs = smt.executeQuery(sql); From cbdac5146e7ed7aa5e9c901f59e5112f8e1f4660 Mon Sep 17 00:00:00 2001 From: zack Date: Fri, 30 Apr 2021 15:53:05 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E7=BC=96=E8=AF=91=E5=8F=91=E7=8E=B0=E8=BF=99=E4=B8=AA?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=8F=92=E4=BB=B6=E9=87=8C=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E7=BC=96=E8=AF=91=E4=B8=8D=E9=80=9A=E8=BF=87=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E7=BA=A0=E6=AD=A3=E4=B8=8B=EF=BC=8C=E8=BF=99=E4=B8=AA?= =?UTF-8?q?=E7=B1=BB=E5=9C=A8=E6=96=87=E6=A1=A3=E9=87=8C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E7=94=A8=E5=88=B0=EF=BC=8C=E6=97=A0=E9=9C=80=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fr/function/ReportCheck.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/fr/function/ReportCheck.java b/src/main/java/com/fr/function/ReportCheck.java index 21d57da..9620d4f 100644 --- a/src/main/java/com/fr/function/ReportCheck.java +++ b/src/main/java/com/fr/function/ReportCheck.java @@ -1,13 +1,11 @@ // 自定义函数实现表间校验 package com.fr.function; -import java.util.HashMap; import com.fr.base.ResultFormula; import com.fr.base.operator.common.CommonOperator; import com.fr.chart.activator.ChartBaseActivator; import com.fr.config.activator.BaseDBActivator; import com.fr.config.activator.ConfigurationActivator; -import com.fr.data.impl.config.activator.RestrictionActivator; import com.fr.env.operator.CommonOperatorImpl; import com.fr.io.TemplateWorkBookIO; import com.fr.json.JSONArray; @@ -17,15 +15,18 @@ import com.fr.main.workbook.ResultWorkBook; import com.fr.module.Module; import com.fr.module.tool.ActivatorToolBox; import com.fr.report.ReportActivator; +import com.fr.report.RestrictionActivator; import com.fr.report.cell.CellElement; import com.fr.report.module.ReportBaseActivator; import com.fr.report.report.ResultReport; import com.fr.script.AbstractFunction; import com.fr.stable.WriteActor; -import com.fr.store.StateServerActivator; +import com.fr.store.StateServiceActivator; import com.fr.workspace.simple.SimpleWork; import com.fr.write.cal.WB; +import java.util.HashMap; + public class ReportCheck extends AbstractFunction { private static HashMap wMap = new HashMap(); @@ -39,7 +40,7 @@ public class ReportCheck extends AbstractFunction { // 定义报表运行环境,用于执行报表 Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(), new ConfigurationActivator(), - new StateServerActivator(), + new StateServiceActivator(), new ReportBaseActivator(), new RestrictionActivator(), new ReportActivator(),