97 Star 254 Fork 74

hacken / EasyReport

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

EasyReport

A simple and easy to use Web Report System for java

EasyReport是一个简单易用的Web报表工具,它的主要功能是把SQL语句查询出的行列结构转换成HTML表格(Table),并支持表格的跨行(RowSpan)与跨列(ColSpan)。同时它还支持报表Excel导出、图表显示及固定表头与左边列的功能。
欢迎加入QQ群交流:(365582678)

声明:此项目是GitHub上 @TomDeng 作者的作品 ,在开源中国只是个人迁移过来的(并非此项目作者),以供自己和各位技术同仁学习参考!

目录

1.开发环境(Development Environment)

jdk1.8
maven3
eclipsejee-luna
tomcat7+
MySQL5+

2.安装与部署(Installation & Deployment)

2.1 从源代码安装(From Source Code)

首先确定安装好jdk1.8maven3MySQL5+,并配置好maven仓库,然后按如下步骤操作:
step1:git clone https://github.com/xianrendzw/EasyReport.git
step2:在MySQL中创建名为easy_report的数据库,然后解压yourgitrepository/EasyReport/docs/db/mysql.zip,并执行easy_report_mysql.sql创建表结构与导入初始数据
step3:cd yourgitrepository/EasyReport/easyreport-web
step4:修改 src\main\resources${env}\resource.properties 数据库连接字符串的IP、用户与密码
step5:mvn clean package -Dskiptest=true -P${env} (${env}变量说明:dev表示开发环境,prod表示生产,test表示测试)
step6:经过step4之后会在target目录生成easyreport-web.war文件,然后把这个文件部署到tomcat,jboss,jetty等容器中

2.2 从发布包安装(From Release Packages)

首先确定安装好jre1.8jdk1.8MySQL5+,然后按如下步骤操作:
step1:直接从release下载war文件
step2:在MySQL中创建名为easy_report的数据库,然后解压mysql.zip,并执行easy_report_mysql.sql创建表结构与导入初始数据
step3:修改war文件里WEB-INF\classes\resource.properties中数据库连接字符串的IP、用户与密码
step4:然后把war这个文件部署到tomcat,jboss,jetty等容器中

2.3 定时任务程序部署(Scheduled Task Deamon)

有时需要把报表定时(每天、每月,每季度等)以邮件形式发布给相关的人员,因此需要定时任务调度程序,常用的调度程序也很多(linux:at,crontab;windows:计划任务),本工具实现一个简单的调度程序。
**说明:**该程序是可选的,如果不需要定时把报表以邮件方式发布,则可不部署该程序。 具体安装与部署步骤如下:
step1:cd yourgitrepository/EasyReport/easyreport-scheduler
step2:修改 src\main\resources${env}\resource.properties 数据库连接,用户与密码
step3:mvn clean package -P${env} (${env}变量说明:dev表示开发环境,prod表示生产,test表示测试)
step4:经过step3之后会在target目录生成easyreport-scheduler.jar文件。然后在linux中执行如下shell命令:

nohup java -jar easyreport-scheduler.jar >log.log 2>&1 &

3.使用说明(User Guide)

3.1 预备知识(Prerequisites)

简单的说,报表就是用表格、图表等格式来动态显示数据。它是数据可视化的重要部分。尤其在当今大数据泛滥的时代,到处都需要各种各样的报表。在使用该工具之前您应该先了解一下数据仓库、维度、度量、事实表等相关概念,这将会对你制作报表有一定的帮助。

本工具只是简单的从数据库(MySQL,Oracle,SQLServer,HBase等)中的事实表读取数据,并转换成HTML表格形式展示。不支持CUBE、钻取、切片等复杂OLAP相关的功能。

3.2 数据源设置(DataSource Configuration)

在制作报表前需要先设置数据源,本工具只支持在单一数据源(即数据库)生成报表。ds-1

3.3 配置管理(Configuration)

配置管理主要于在制作报表时自动匹配一些常用的列名对应的中文描述。如:dt,date(日期)、title(标题)等。config-1

3.4 报表设计(Reporting Design)

通常,只要把数据源配置成功就可以开始报表设计了,报表设计主要分两个步骤:基本设置与查询参数设置。且必须先把基本设置保存后方可进行查询参数设置 ,查询参数设置是可选的,主要看报表设计者的意图。

3.4.1 基本设置(Basic Settings)

rp-1 报表的基本设置由4部分组成(如上图所示):报表树型列表、报表基本属性、报表SQL查询语句、报表元数据列配置。 在设计报表之前,先简单介绍几个名词,我们从数据仓库概念了解到维度与度量这两个概念,事实上一条SQL语句查询的结果就是一张二维表格,即由行与列组成的表格,在统计分析时,我们把有些列称为维度列,有些列称为度量列。有时事实表里有好几个维度与度量列,但是SQL查询结果只能是二维表格,它不能把维度层次化,展示方式固定而不能灵活变动,这样在观察与分析数据时多有不便,因此一些报表工具就解决了这些问题。本工具把事实表中的维度列与度量列进行再次划分如下表所示:

类型 子类型
维度列 布局维度列、简称布局列
  | 一般维度列、简称维度列

度量列 | 统计列 | 计算列

  1. 布局列主要用于报表展示方式上,如果布局列为横向展示,则报表在绘制时会把布局列的内容绘制表报表表头,维度列的内容绘制报表表体的左边;如果布局列为纵向展示,则报表在绘制时会把布局列的内容绘制表报表表体的左边,维度列的内容绘制报表表头。

  2. 计算列是根据SQL查询结果中列的值再根据其配置的计算表达式动态运算出来的,它不存在于SQL语句或事实表中,其中使用的表达式引擎为aviator

了解了上述基本知识后,我们来看看一张报表的主要设计流程:
1.创建报表树型目录列表
rp-2 2.点击1新建根节点,也可以在树列表中右键创建子节点
rp-3
3.选择指定的目录,设置基本信息,如报表名称,数据源,布局与统计列展示方式
4.输入报表SQL查询语句
5.执行SQL查询语句并获取报表的列信息
6.配置报表的列
7.新增并保存基本设置信息到数据库
rp-4 新增成功后,就可以双击树列表中报表名称节点或点击报表预览按钮预览报表。如觉得报表展示的不够友好,可以通过修改布局列与统计列的展示方式来改变报表显示。 rp-5 上图是日期为布局列且横向显示的报表预览结果。我们可以修改一下相关配置让报表展示更直观些。 rp-6 由于列名dt已经在配置管理设置了默认标题,因此在执行SQL后会自动匹配它的标题,您也可以把其他的列名增加配置管理项中,这样下次设计报表时就会自动匹配默认标题。现在看修改后报表展示。 rp-7

3.4.2 查询参数(Query Parameter)

有时候报表需要根据指定条件动态生成,如要查看不同城市空气质量情况,这个时候,我就需要创建一个查询参数变量。 rp-8 其中表单控件用于报表查询参数显示形式,主要有下拉单选框(select)、下单多选框(select mul)、复选框(checkbox)及文本框(textbox)四种。下图1处为查询参数列表。 rp-9 当查询参的表单控件为下拉单选或多选时,内容来源有两种不同的形式。

内容来源 内容 备注
SQL语句 select col1 as name,col2 as text from table ... 只包含两列且列名必须为nametext,name列的值对应下拉框的value属性,text列的值对应下拉框的text属性
文本字符串 name1,text1|name2,text2|... 或name1|name2|... 多个值必须用’|’分隔,如果name与text值相同则只选择一个并用’|’分开也可

3.4.3 内置变量与函数(Build-in variables & functions)

有些常用的查询参数不需要用户每次都创建,因此集成在工具内,这些参数变量称为内置变量

有些报表的SQL语句很复杂,有时需要根据参数动态生成或需要用模板引擎(velocity)生成,因此需要一些能在模板引擎中应用的函数,这些函数称为内置函数

1.内置变量(区分大小写)

变量名 说明 返回值说明
startTime 开始日期 2015-02-04(默认结束日期的前七天,这个可以由报表基本设置的显示天数修改)
endTime 结束日期 2015-02-10(默认为当前天)
intStartTime 整型开始日期 20150204
intEndTime 整型结束日期 20150210
utcStartTime UTC开始日期 2015-02-04(UTC日期,中国为UTC+8区)
utcEndTime UTC结束日期 2015-02-10(UTC日期)
utcIntStartTime UTC整型开始日期 20150204
utcIntEndTime UTC整型结束日期 20150204

2.内置函数

3.4.4 图表显示(Charting)

rp-11 点击报表的图示展示按钮,出现如下界面: rp-12 如果要查看多个城市也可以通过对比来显示: rp-13 如果统计列只有一列时,图表显示就可以支持二个维度同时全部展示: rp-14

3.5 定时任务配置管理(Scheduled Task Configruation)

3.6 示例(Examples)

示例中的所有数据来源于:pm25.inaqistudy,如果您需要运行示例中的报表,需求在mysql中创建名为china_weather_air的数据库, 然后解压yourgitrepository/EasyReport/docs/db/mysql.zip,并执行china_weather_air_mysql.sql创建表结构与导入初始数据。

  1. 最简单报表,直接对应数据库二维表结构
    配置:
    ex-src-1 报表:
    ex-1
  2. 带内置变量与查询参数的报表
    配置: ex-src-2 查询参数:
    ex-param-2 报表:
    a. 布局列横向,统计列横向
    ex-2-1 b. 布局列纵向,统计列横向
    ex-2-2 c. 布局列横向,统计列纵向
    ex-2-3 d. 布局列纵向,统计列纵向
    ex-2-4
  3. 多布局列报表
    配置: ex-src-3 报表:
    a. 布局列横向,统计列横向
    ex-3-1 b. 布局列纵向,统计列横向
    ex-3-2 c. 布局列横向,统计列纵向
    ex-3-3 d. 布局列纵向,统计列纵向
    ex-3-4
  4. 统计列可选报表
    配置:
    ex-src-4 报表:
    ex-4-1
  5. 报表列的排序
    配置:
    ex-src-5 报表:
    ex-5
  6. 按百分比格式显示的列
    配置:
    ex-src-6 报表:
    ex-6
  7. 合并报表左边相同维度列
    合并前:
    ex-7-2 合并后:
    ex-7-1

3.7 相关参考(Referrence Links)

4.开发者(For Developers)

该系统总体架构图如下:
dev-1

4.1 报表引擎接口(Reporting Engine API)

4.2 自定义报表开发(Customsized Reporting Development)

5.常见问题(FAQ)

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

A simple and easy to use Web Report System for java.EasyReport是一个简单易用的Web报表工具,它的主要功能是把SQL语句查询出的行列结构转换成HTML表格(Table),并支持表格的跨行(RowSpan)与跨列(ColSpan)。同时它还支持报表Excel导出、图表显示及固定表头与左边列的功能。 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/hackenhu/EasyReport.git
git@gitee.com:hackenhu/EasyReport.git
hackenhu
EasyReport
EasyReport
master

搜索帮助