Compare commits

..

15 Commits

Author SHA1 Message Date
Icey.Zhang c974449e23 Pull request #52: 10.0.16-0526号版本插件代码合并 4 years ago
Lanlan c21ebed9f4 Pull request #45: 误删自定义函数,恢复 4 years ago
Okcean ce7482718d Pull request #40: 10.0.14-0311号版本插件代码合并 4 years ago
Okcean 26e083a658 Pull request #36: 1127插件代码合并 4 years ago
Bruce.Deng d1776fa526 Pull request #31: 无JIRA任务 插件发布,release合persist 4 years ago
Leo.Tsai ca629a1ff6 Pull request #27: Release/10.0 4 years ago
Leo.Cai 99ff96fea6 代码做了修改,而且要导入一个新的JAR包:slf4j-simple-1.7.25.jar,JAR包下载参见文档https://help.finereport.com/doc-view-735.html 的3.1节 4 years ago
Lanlan e1f402023f Pull request #25: 无JIRA任务 插件发布,release合persist 5 years ago
Lanlan 5a3d9301af Merge pull request #23 in PG/plugin-report-doc-demo from release/10.0 to persist/10.0 5 years ago
susie 34ec362f64 Merge pull request #21 in PG/plugin-report-doc-demo from ~HARRISON/plugin-report-doc-demo:persist/10.0 to persist/10.0 5 years ago
Harrison c81c49f7ad DEMO-3230 Release10 module无法引用 5 years ago
Lanlan 9a474478b3 Merge pull request #19 in PG/plugin-report-doc-demo from release/10.0 to persist/10.0 5 years ago
Lanlan 10e88848e4 Merge pull request #12 in PG/plugin-report-doc-demo from release/10.0 to persist/10.0 5 years ago
Lanlan d6274eea84 Merge pull request #10 in PG/plugin-report-doc-demo from release/10.0 to persist/10.0 5 years ago
Lanlan de51123131 Merge pull request #8 in PG/plugin-report-doc-demo from release/10.0 to persist/10.0 5 years ago
  1. 4
      build.xml
  2. 93
      src/main/java/com/fr/data/WebServiceTableData.java
  3. 4
      src/main/java/com/fr/data/XMLDemoTableData.java
  4. 12
      src/main/java/com/fr/demo/NewReadFrmFromDatabase.java
  5. 4
      src/main/java/com/fr/demo/ReadFromDatabase.java
  6. 8
      src/main/java/com/fr/demo/ReadfrmFromDatabase.java
  7. 89
      src/main/java/com/fr/io/ExportApi.java
  8. 58
      src/main/java/com/fr/io/ExportApi_frm.java
  9. 78
      src/main/java/com/fr/io/SaveReportToDatabase.java
  10. 2
      src/test/main/java/com/fr/demo/ExportApiTest.java
  11. 2
      src/test/main/java/com/fr/demo/ModuleStartTest.java

4
build.xml

@ -84,8 +84,8 @@
<param name="resources_from" value="${basedir}"/>
</antcall>
<antcall target="compile_javas">
<param name="source_jdk_version" value="1.8"/>
<param name="target_jdk_version" value="1.8"/>
<param name="source_jdk_version" value="1.6"/>
<param name="target_jdk_version" value="1.6"/>
<param name="compile_jdk_version" value="${jdk.home}"/>
<param name="compile_files" value="${basedir}/src"/>
</antcall>

93
src/main/java/com/fr/data/WebServiceTableData.java

@ -1,87 +1,38 @@
package com.fr.data;
import com.fr.general.data.TableDataException;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ParameterProvider;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import com.fr.data.AbstractTableData;
import com.fr.general.data.TableDataException;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
/**
* WebService程序数据集
*
* @author Roger
* @since 11.0
* Created on 2024/1/8
*/
public class WebServiceTableData extends SimpleTableData {
private static final int COLUMN_COUNT = 10;
public class WebServiceTableData extends AbstractTableData{
private String[][] data;
/**
* 初始化列名数组
*
* @return {col1,col2,col3...}
* @throws TableDataException
*/
@Override
public String[] initColumnNames() {
String[] columnNames = new String[COLUMN_COUNT];
for (int i = 0; i < COLUMN_COUNT; i++) {
columnNames[i] = "column#" + i;
}
return columnNames;
public WebServiceTableData() {
this.data = this.createData();
}
/**
* 加载数据
*
* @return 行列数据
*/
@Override
public List<Object[]> loadData() {
String tableName = ((ParameterProvider) (parameters.get().toArray())[0]).getValue().toString();
FineLoggerFactory.getLogger().info("Query SQL of ParamTableDataDemo: {}", tableName);
// 保存得到的结果集
ArrayList<Object[]> valueList = new ArrayList();
try {
// 调用 Web 服务获取数据
String[][] data = createData();
//获取列数
public int getColumnCount() throws TableDataException {
return data[0].length;
}
// 如果数据为空,直接返回空列表
if (data == null || data.length == 0) {
return valueList;
}
//获取列的名称为数组中第一行的值
public String getColumnName(int columnIndex) throws TableDataException {
return data[0][columnIndex];
}
// 获得总列数
int colNum = data[0].length;
//获取行数为数据的长度-1
public int getRowCount() throws TableDataException {
return data.length - 1;
}
// 用对象保存数据
Object[] objArray = null;
for (int rowIndex = 1; rowIndex < data.length; rowIndex++) {
objArray = new Object[colNum];
for (int i = 0; i < colNum; i++) {
objArray[i] = data[rowIndex][i];
}
// 在valueList中加入这一行数据
valueList.add(objArray);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return valueList;
//获取值
public Object getValueAt(int rowIndex, int columnIndex) {
return data[rowIndex + 1][columnIndex];
}
/**
* 调用 Web 服务获取数据
*
* @return
*/
public String[][] createData() {
try {
String endpoint = "http://localhost:8080/axis/TestWS2TDClient.jws";

4
src/main/java/com/fr/data/XMLDemoTableData.java

@ -77,8 +77,6 @@ public class XMLDemoTableData extends AbstractParameterTableData {
try {
in = new BufferedInputStream(new FileInputStream(new File(filePath)));
XMLEventReader reader = inputFactory.createXMLEventReader(in);
deep=0;
flag=false;
readCol(reader,list);
in.close();
} catch (Exception e) {
@ -197,4 +195,4 @@ public class XMLDemoTableData extends AbstractParameterTableData {
e.printStackTrace();
}
}
}
}

12
src/main/java/com/fr/demo/NewReadFrmFromDatabase.java

@ -1,18 +1,16 @@
package com.fr.demo;
import com.fr.data.core.db.DBUtils;
import com.fr.form.main.Form;
import com.fr.log.FineLoggerFactory;
import com.fr.web.session.SessionLocalManager;
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.SQLException;
import java.sql.Statement;
import java.util.Map;
@ -45,12 +43,12 @@ public class NewReadFrmFromDatabase extends DBFormlet {
return form;
}
} catch (Exception e) {
throw SessionLocalManager.createLogPackedException(e);
e.printStackTrace();
}finally {
DBUtils.closeConnection(connection);
}
return form;
return null;
}
private static Connection getConnection() throws ClassNotFoundException, SQLException {

4
src/main/java/com/fr/demo/ReadFromDatabase.java

@ -5,8 +5,6 @@ import com.fr.main.impl.WorkBook;
import com.fr.web.core.Reportlet;
import com.fr.web.request.ReportletRequest;
import com.fr.log.FineLoggerFactory;
import com.fr.web.session.SessionLocalManager;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
@ -42,7 +40,7 @@ public class ReadFromDatabase extends Reportlet {
workbook.readStream(ins);
}
} catch (Exception e) {
throw SessionLocalManager.createLogPackedException(e);
e.printStackTrace();
}
return workbook;
}

8
src/main/java/com/fr/demo/ReadfrmFromDatabase.java

@ -1,12 +1,10 @@
package com.fr.demo;
import com.fr.form.main.Form;
import com.fr.io.utils.ResourceIOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.web.session.SessionLocalManager;
import com.fr.web.weblet.Formlet;
import com.fr.form.main.Form;
import javax.servlet.http.HttpServletRequest;
import com.fr.log.FineLoggerFactory;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
@ -44,7 +42,7 @@ public class ReadfrmFromDatabase extends Formlet {
form.readStream(ins);
}
} catch (Exception e) {
throw SessionLocalManager.createLogPackedException(e);
e.printStackTrace();
}
System.out.println(ResourceIOUtils.getRealPath("assets"));
return form;

89
src/main/java/com/fr/io/ExportApi.java

@ -7,6 +7,8 @@ import com.fr.config.activator.BaseDBActivator;
import com.fr.config.activator.ConfigurationActivator;
import com.fr.env.operator.CommonOperatorImpl;
import com.fr.general.I18nResource;
import com.fr.general.log.Log4jConfig;
import com.fr.general.log.parser.ExtraPatternParserManager;
import com.fr.health.activator.ModuleHealActivator;
import com.fr.io.exporter.CSVExporter;
import com.fr.io.exporter.EmbeddedTableDataExporter;
@ -18,52 +20,53 @@ import com.fr.io.exporter.TextExporter;
import com.fr.io.exporter.WordExporter;
import com.fr.io.exporter.excel.stream.StreamExcel2007Exporter;
import com.fr.main.impl.WorkBook;
import com.fr.module.ModuleRole;
import com.fr.module.tool.ActivatorToolBox;
import com.fr.report.ReportActivator;
import com.fr.report.RestrictionActivator;
import com.fr.report.module.ReportBaseActivator;
import com.fr.report.write.WriteActivator;
import com.fr.scheduler.SchedulerActivator;
import com.fr.stable.WriteActor;
import com.fr.stable.resource.ResourceLoader;
import com.fr.store.StateServiceActivator;
import com.fr.third.apache.log4j.Level;
import com.fr.third.apache.log4j.PropertyConfigurator;
import com.fr.workspace.simple.SimpleWork;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class ExportApi {
public static void main(String[] args) {
/**
* 以下这段if判断仅在main函数测试时使用
* 实际生产环境中一般使用web容器集成帆软后帆软服务会自动启动不再需要下面的if判断直接写导出的业务逻辑即可
* web集成注意事项
* 1集成环境需要依赖当前使用jdk对应版本的tools.jar一般从jdk中直接复制即可;
* 2帆软服务自动启动成功后使用的工作目录自动识别为集成应用下的WEB-INF目录所以需要把下面代码中envpath指向的工作目录拷贝到集成环境下web应用的WEB-INF目录
* 正式发布时需要拷贝生产环境的帆软WEB-INF如果有的话这样才能沿用原先帆软的配置及模板如果是集群环境会自动使用文件服务器的模板本地测试时envpath需要指向单机非集群的帆软工程
* 3可以访问集成环境的地址 ip:port/应用名/decision 如果能成功访问且不需要初始化配置则代表帆软服务启动成功
*/
if (!ModuleRole.Root.isPresent()) {
/**定义报表运行环境,用于执行报表*/
com.fr.module.Module module = ActivatorToolBox.simpleLink(
new BaseDBActivator(),
new ConfigurationActivator(),
new ResourceRepositoryActivator(),
new StandaloneModeActivator(),
new ModuleHealActivator(),
//2020.4.26jar包之前的版本,替换成StateServerActivator()
new StateServiceActivator(),
new ReportBaseActivator(),
new RestrictionActivator(),
new ReportActivator(),
new ChartBaseActivator());
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl());
//定义工程路径
String envpath = "D:\\FineReport_11.0\\webapps\\webroot\\WEB-INF\\";
SimpleWork.checkIn(envpath);
I18nResource.getInstance();
module.start();
}
initLog4j();
/**定义报表运行环境,用于执行报表*/
com.fr.module.Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(),
new ConfigurationActivator(),
new ResourceRepositoryActivator(),
new StandaloneModeActivator(),
new ModuleHealActivator(),
//2020.4.26jar包之前的版本,替换成StateServerActivator()
new StateServiceActivator(),
new SchedulerActivator(),
new ReportBaseActivator(),
new RestrictionActivator(),
new ReportActivator(),
new WriteActivator(),
new ChartBaseActivator());
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl());
//定义工程路径
String envpath = "D:\\javatools\\FineReport_10.0\\webapps\\webroot\\WEB-INF\\";
SimpleWork.checkIn(envpath);
I18nResource.getInstance();
module.start();
/**输出模板*/
try {
// 定义输出的模板路径,以reportlets为根目录
@ -88,7 +91,6 @@ public class ExportApi {
/**将结果工作薄导出为2003Excel文件*/
outputStream = new FileOutputStream(new java.io.File(outputUrl+"ExcelExport2003.xls"));
ExcelExporter ExcelExport = new ExcelExporter();
ExcelExport.setVersion(true);
ExcelExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
/**将结果工作薄导出为2007Excel文件*/
@ -127,9 +129,32 @@ public class ExportApi {
ImageExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
outputStream.close();
module.stop();
} catch (Exception e) {
e.printStackTrace();
} finally {
SimpleWork.checkOut();
}
}
private static void initLog4j() {
PropertyConfigurator.configure(loadLog4jPropertiesFromJar(Level.toLevel("INFO")));
}
private static Properties loadLog4jPropertiesFromJar(Level level) {
Properties properties = new Properties();
System.setProperty("LOG_HOME", System.getProperty("user.dir"));
System.setProperty("LOG_ROOT_LEVEL", level.toString());
ExtraPatternParserManager.setSystemProperty();
try {
properties.load(ResourceLoader.getResourceAsStream("/com/fr/general/log/log4j.properties", Log4jConfig.class));
} catch (IOException ignore) {
//do nothing
}
return properties;
}
}

58
src/main/java/com/fr/io/ExportApi_frm.java

@ -13,50 +13,39 @@ import com.fr.io.exporter.ImageExporter;
import com.fr.io.exporter.PDFExporter;
import com.fr.io.exporter.excel.stream.StreamExcel2007Exporter;
import com.fr.main.workbook.ResultWorkBook;
import com.fr.module.ModuleRole;
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.module.ReportBaseActivator;
import com.fr.report.write.WriteActivator;
import com.fr.scheduler.SchedulerActivator;
import com.fr.store.StateServiceActivator;
import com.fr.workspace.simple.SimpleWork;
import java.io.File;
import java.io.FileOutputStream;
public class ExportApi_frm {
public class ExportApi_frm {
public static void main(String[] args) {
/**
* 以下这段if判断仅在main函数测试时使用
* 实际生产环境中一般使用web容器集成帆软后帆软服务会自动启动不再需要下面的if判断直接写导出的业务逻辑即可
* web集成注意事项
* 1集成环境需要依赖当前使用jdk对应版本的tools.jar一般从jdk中直接复制即可;
* 2帆软服务自动启动成功后使用的工作目录自动识别为集成应用下的WEB-INF目录所以需要把下面代码中envpath指向的工作目录拷贝到集成环境下web应用的WEB-INF目录
* 正式发布时需要拷贝生产环境的帆软WEB-INF如果有的话这样才能沿用原先帆软的配置及模板如果是集群环境会自动使用文件服务器的模板本地测试时envpath需要指向单机非集群的帆软工程
* 3可以访问集成环境的地址 ip:port/应用名/decision 如果能成功访问且不需要初始化配置则代表帆软服务启动成功
*/
if (!ModuleRole.Root.isPresent()) {
/**定义报表运行环境,用于执行报表*/
com.fr.module.Module module = ActivatorToolBox.simpleLink(
new BaseDBActivator(),
new ConfigurationActivator(),
new ResourceRepositoryActivator(),
new StandaloneModeActivator(),
new ModuleHealActivator(),
//2020.4.26jar包之前的版本,替换成StateServerActivator()
new StateServiceActivator(),
new ReportBaseActivator(),
new RestrictionActivator(),
new ReportActivator(),
new ChartBaseActivator());
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl());
//定义工程路径
String envpath = "D:\\FineReport_11.0\\webapps\\webroot\\WEB-INF\\";
SimpleWork.checkIn(envpath);
I18nResource.getInstance();
module.start();
}
// 定义报表运行环境,用于执行报表
Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(),
new ConfigurationActivator(),
new ResourceRepositoryActivator(),
new StandaloneModeActivator(),
new ModuleHealActivator(),
new StateServiceActivator(),
new SchedulerActivator(),
new ReportBaseActivator(),
new RestrictionActivator(),
new ReportActivator(),
new WriteActivator(),
new ChartBaseActivator());
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl());
String envpath = "C:\\Users\\hipsh\\Desktop\\apache-tomcat-8.5.38-10.0\\webapps\\webroot\\WEB-INF\\";//工程路径
SimpleWork.checkIn(envpath);
I18nResource.getInstance();
module.start();
try {
java.util.Map parameterMap = new java.util.HashMap();
@ -77,8 +66,11 @@ public class ExportApi_frm {
ImageExporter ImageExport = new ImageExporter();
ImageExport.export(outputStream, re);
outputStream.close();
module.stop();
} catch (Exception e) {
e.printStackTrace();
} finally {
SimpleWork.checkOut();
}
}
}

78
src/main/java/com/fr/io/SaveReportToDatabase.java

@ -0,0 +1,78 @@
package com.fr.io;
import com.fr.base.operator.common.CommonOperator;
import com.fr.chart.activator.ChartBaseActivator;
import com.fr.cluster.engine.activator.standalone.StandaloneModeActivator;
import com.fr.config.activator.BaseDBActivator;
import com.fr.config.activator.ConfigurationActivator;
import com.fr.env.operator.CommonOperatorImpl;
import com.fr.general.I18nResource;
import com.fr.health.activator.ModuleHealActivator;
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.module.ReportBaseActivator;
import com.fr.report.write.WriteActivator;
import com.fr.scheduler.SchedulerActivator;
import com.fr.store.StateServiceActivator;
import com.fr.workspace.simple.SimpleWork;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class SaveReportToDatabase {
public static void main(String[] args) {
SaveReport();
}
private static void SaveReport() {
try {
// 连接数据库
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://review.finedevelop.com:3306/susie";
String user = "root";
String pass = "ilovejava";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, pass);
PreparedStatement presmt = conn
.prepareStatement("insert into report values(?,?)");
// 读进需要保存入库的模板文件
// 首先需要定义执行所在的环境,这样才能正确读取数据库信息
// 定义报表运行环境,用于执行报表
Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(),
new ConfigurationActivator(),
new ResourceRepositoryActivator(),
new StandaloneModeActivator(),
new ModuleHealActivator(),
new StateServiceActivator(),
new ChartBaseActivator(),
new SchedulerActivator(),
new ReportBaseActivator(),
new RestrictionActivator(),
new ReportActivator(),
new WriteActivator());
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl());
String envpath = "//Applications//FineReport10_325//webapps//webroot//WEB-INF";//工程路径
SimpleWork.checkIn(envpath);
I18nResource.getInstance();
module.start();
File cptfile = new File("//doc//Primary//Parameter//Parameter.cpt");
int lens = (int) cptfile.length();
InputStream ins = new FileInputStream(cptfile);
// 将模板保存入库
presmt.setString(1, "Parameter.cpt"); // 第一个字段存放模板相对路径
presmt.setBinaryStream(2, ins, lens); // 第二个字段存放模板文件的二进制流
presmt.execute();
conn.commit();
presmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

2
src/test/main/java/com/fr/demo/ExportApiTest.java

@ -7,8 +7,6 @@ import com.fr.config.activator.BaseDBActivator;
import com.fr.config.activator.ConfigurationActivator;
import com.fr.env.operator.CommonOperatorImpl;
import com.fr.general.I18nResource;
import com.fr.health.activator.ModuleHealActivator;
import com.fr.io.ResourceRepositoryActivator;
import com.fr.io.TemplateWorkBookIO;
import com.fr.io.exporter.excel.stream.StreamExcel2007Exporter;
import com.fr.log.FineLoggerFactory;

2
src/test/main/java/com/fr/demo/ModuleStartTest.java

@ -8,8 +8,6 @@ import com.fr.config.activator.ConfigurationActivator;
import com.fr.env.operator.CommonOperatorImpl;
import com.fr.general.FRLogger;
import com.fr.general.I18nResource;
import com.fr.health.activator.ModuleHealActivator;
import com.fr.io.ResourceRepositoryActivator;
import com.fr.io.TemplateWorkBookIO;
import com.fr.log.FineLoggerFactory;
import com.fr.log.LogHandler;

Loading…
Cancel
Save