Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datax-cloud
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄营
datax-cloud
Commits
79a00cdd
Commit
79a00cdd
authored
May 13, 2020
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2.0.0项目初始化
parent
5c659856
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
234 additions
and
3 deletions
+234
-3
pom.xml
datax-common/datax-common-jasperreport/pom.xml
+26
-0
JasperReportUtil.java
.../cn/datax/common/jasperreport/utils/JasperReportUtil.java
+126
-0
jasperreports_extension.properties
...ort/src/main/resources/jasperreports_extension.properties
+3
-0
fonts.xml
...n-jasperreport/src/main/resources/jaspers/fonts/fonts.xml
+15
-0
msyh.ttf
...on-jasperreport/src/main/resources/jaspers/fonts/msyh.ttf
+0
-0
pom.xml
datax-common/pom.xml
+2
-0
pom.xml
datax-modules/system-service-parent/system-service/pom.xml
+5
-0
TestController.java
...va/cn/datax/service/system/controller/TestController.java
+56
-3
report.jasper
...t/system-service/src/main/resources/jaspers/report.jasper
+0
-0
report.jrxml
...nt/system-service/src/main/resources/jaspers/report.jrxml
+0
-0
pom.xml
pom.xml
+1
-0
No files found.
datax-common/datax-common-jasperreport/pom.xml
0 → 100644
View file @
79a00cdd
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
datax-common
</artifactId>
<groupId>
cn.datax
</groupId>
<version>
2.0.0
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<version>
2.0.0
</version>
<artifactId>
datax-common-jasperreport
</artifactId>
<dependencies>
<dependency>
<groupId>
net.sf.jasperreports
</groupId>
<artifactId>
jasperreports
</artifactId>
<version>
${jasperreports.version}
</version>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
javax.servlet-api
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
datax-common/datax-common-jasperreport/src/main/java/cn/datax/common/jasperreport/utils/JasperReportUtil.java
0 → 100644
View file @
79a00cdd
package
cn
.
datax
.
common
.
jasperreport
.
utils
;
import
lombok.extern.slf4j.Slf4j
;
import
net.sf.jasperreports.engine.*
;
import
net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
;
import
net.sf.jasperreports.engine.export.HtmlExporter
;
import
net.sf.jasperreports.export.HtmlExporterOutput
;
import
net.sf.jasperreports.export.SimpleExporterInput
;
import
net.sf.jasperreports.export.SimpleHtmlExporterOutput
;
import
net.sf.jasperreports.export.SimpleHtmlReportConfiguration
;
import
org.springframework.core.io.ClassPathResource
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.PrintWriter
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
public
class
JasperReportUtil
{
final
static
String
jasperDir
=
"jaspers"
;
public
static
String
getJasperFileDir
(
String
fileName
)
{
return
jasperDir
+
File
.
separator
+
fileName
+
".jasper"
;
}
private
static
String
getContentType
(
ReportType
type
)
{
String
contentType
;
switch
(
type
)
{
case
HTML:
contentType
=
"text/html;charset=utf-8"
;
break
;
case
PDF:
contentType
=
"application/pdf"
;
break
;
case
XLS:
contentType
=
"application/vnd.ms-excel"
;
break
;
case
XLSX:
contentType
=
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
;
break
;
case
XML:
contentType
=
"text/xml"
;
break
;
case
RTF:
contentType
=
"application/rtf"
;
break
;
case
CSV:
contentType
=
"text/plain"
;
break
;
case
DOC:
contentType
=
"application/msword"
;
break
;
default
:
contentType
=
"text/html;charset=utf-8"
;
}
return
contentType
;
}
static
JasperPrint
getJasperPrint
(
InputStream
jasperStream
,
Map
parameters
,
List
<?>
list
)
throws
JRException
{
JRDataSource
dataSource
;
if
(
null
==
list
||
list
.
size
()
==
0
)
{
dataSource
=
new
JREmptyDataSource
();
}
else
{
dataSource
=
new
JRBeanCollectionDataSource
(
list
);
}
JasperPrint
jasperPrint
=
JasperFillManager
.
fillReport
(
jasperStream
,
parameters
,
dataSource
);
return
jasperPrint
;
}
public
static
void
exportToPdf
(
String
jasperPath
,
Map
parameters
,
List
<?>
list
,
HttpServletResponse
response
)
throws
Exception
{
OutputStream
outputStream
=
response
.
getOutputStream
();
try
{
ClassPathResource
resource
=
new
ClassPathResource
(
jasperPath
);
response
.
setContentType
(
getContentType
(
ReportType
.
PDF
));
InputStream
jasperStream
=
resource
.
getInputStream
();
JasperPrint
jasperPrint
=
getJasperPrint
(
jasperStream
,
parameters
,
list
);
JasperExportManager
.
exportReportToPdfStream
(
jasperPrint
,
outputStream
);
}
catch
(
Exception
e
)
{
log
.
error
(
"读取报表异常"
,
e
);
outputStream
.
write
(
"读取报表异常"
.
getBytes
());
}
finally
{
outputStream
.
flush
();
outputStream
.
close
();
}
}
public
static
void
exportToHtml
(
String
jasperPath
,
Map
parameters
,
List
<?>
list
,
HttpServletResponse
response
)
throws
Exception
{
response
.
setHeader
(
"Content-type"
,
"text/html;charset=utf-8"
);
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setContentType
(
getContentType
(
ReportType
.
HTML
));
PrintWriter
out
=
response
.
getWriter
();
HtmlExporter
exporter
=
new
HtmlExporter
();
try
{
ClassPathResource
resource
=
new
ClassPathResource
(
jasperPath
);
InputStream
jasperStream
=
resource
.
getInputStream
();
JasperPrint
jasperPrint
=
getJasperPrint
(
jasperStream
,
parameters
,
list
);
exporter
.
setExporterInput
(
new
SimpleExporterInput
(
jasperPrint
));
SimpleHtmlReportConfiguration
configuration
=
new
SimpleHtmlReportConfiguration
();
exporter
.
setConfiguration
(
configuration
);
HtmlExporterOutput
outPut
=
new
SimpleHtmlExporterOutput
(
out
);
exporter
.
setExporterOutput
(
outPut
);
exporter
.
exportReport
();
}
catch
(
Exception
e
)
{
log
.
error
(
"读取报表异常"
,
e
);
out
.
write
(
"读取报表异常"
);
}
finally
{
out
.
flush
();
out
.
close
();
}
}
public
enum
ReportType
{
HTML
,
PDF
,
XLS
,
XLSX
,
XML
,
RTF
,
CSV
,
DOC
}
}
datax-common/datax-common-jasperreport/src/main/resources/jasperreports_extension.properties
0 → 100644
View file @
79a00cdd
net.sf.jasperreports.extension.registry.factory.simple.font.families
=
net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.dejavu
=
jaspers/fonts/fonts.xml
\ No newline at end of file
datax-common/datax-common-jasperreport/src/main/resources/jaspers/fonts/fonts.xml
0 → 100644
View file @
79a00cdd
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily
name=
"微软雅黑"
>
<normal>
jaspers/fonts/msyh.ttf
</normal>
<bold>
jaspers/fonts/msyh.ttf
</bold>
<italic>
jaspers/fonts/msyh.ttf
</italic>
<boldItalic>
jaspers/fonts/msyh.ttf
</boldItalic>
<pdfEncoding>
Identity-H
</pdfEncoding>
<pdfEmbedded>
true
</pdfEmbedded>
<exportFonts>
<export
key=
"net.sf.jasperreports.html"
>
'微软雅黑', Arial, Helvetica, sans-serif
</export>
<export
key=
"net.sf.jasperreports.xhtml"
>
'微软雅黑', Arial, Helvetica, sans-serif
</export>
</exportFonts>
</fontFamily>
</fontFamilies>
datax-common/datax-common-jasperreport/src/main/resources/jaspers/fonts/msyh.ttf
0 → 100644
View file @
79a00cdd
File added
datax-common/pom.xml
View file @
79a00cdd
...
@@ -22,5 +22,6 @@
...
@@ -22,5 +22,6 @@
<module>
datax-common-office
</module>
<module>
datax-common-office
</module>
<module>
datax-common-dictionary
</module>
<module>
datax-common-dictionary
</module>
<module>
datax-common-qrcode
</module>
<module>
datax-common-qrcode
</module>
<module>
datax-common-jasperreport
</module>
</modules>
</modules>
</project>
</project>
\ No newline at end of file
datax-modules/system-service-parent/system-service/pom.xml
View file @
79a00cdd
...
@@ -69,6 +69,11 @@
...
@@ -69,6 +69,11 @@
<artifactId>
system-service-api
</artifactId>
<artifactId>
system-service-api
</artifactId>
<version>
2.0.0
</version>
<version>
2.0.0
</version>
</dependency>
</dependency>
<dependency>
<groupId>
cn.datax
</groupId>
<artifactId>
datax-common-jasperreport
</artifactId>
<version>
2.0.0
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
datax-modules/system-service-parent/system-service/src/main/java/cn/datax/service/system/controller/TestController.java
View file @
79a00cdd
...
@@ -3,6 +3,7 @@ package cn.datax.service.system.controller;
...
@@ -3,6 +3,7 @@ package cn.datax.service.system.controller;
import
cn.datax.common.base.BaseController
;
import
cn.datax.common.base.BaseController
;
import
cn.datax.common.base.DataScope
;
import
cn.datax.common.base.DataScope
;
import
cn.datax.common.core.R
;
import
cn.datax.common.core.R
;
import
cn.datax.common.jasperreport.utils.JasperReportUtil
;
import
cn.datax.service.system.api.entity.UserEntity
;
import
cn.datax.service.system.api.entity.UserEntity
;
import
cn.datax.service.system.api.query.UserQuery
;
import
cn.datax.service.system.api.query.UserQuery
;
import
cn.datax.service.system.service.UserService
;
import
cn.datax.service.system.service.UserService
;
...
@@ -12,9 +13,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
...
@@ -12,9 +13,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@RestController
@RestController
@RequestMapping
(
"/test"
)
@RequestMapping
(
"/test"
)
...
@@ -36,4 +41,52 @@ public class TestController extends BaseController {
...
@@ -36,4 +41,52 @@ public class TestController extends BaseController {
IPage
<
UserEntity
>
page
=
userService
.
pageDataScope
(
new
Page
<>(
userQuery
.
getPageNum
(),
userQuery
.
getPageSize
()),
queryWrapper
,
new
DataScope
(
"dept_id"
,
"create_by"
));
IPage
<
UserEntity
>
page
=
userService
.
pageDataScope
(
new
Page
<>(
userQuery
.
getPageNum
(),
userQuery
.
getPageSize
()),
queryWrapper
,
new
DataScope
(
"dept_id"
,
"create_by"
));
return
R
.
ok
().
setData
(
page
);
return
R
.
ok
().
setData
(
page
);
}
}
@GetMapping
(
"/jasper/{type}"
)
public
void
getReport
(
@PathVariable
(
"type"
)
String
reportType
,
HttpServletResponse
response
)
throws
Exception
{
HashMap
<
String
,
Object
>
parameters
=
new
HashMap
<>();
List
<
Map
>
teachList
=
new
ArrayList
<>();
Map
t1
=
new
HashMap
();
t1
.
put
(
"name"
,
"张老师"
);
t1
.
put
(
"job"
,
"语文老师"
);
teachList
.
add
(
t1
);
Map
t2
=
new
HashMap
();
t2
.
put
(
"name"
,
"王老师"
);
t2
.
put
(
"job"
,
"数学老师"
);
teachList
.
add
(
t2
);
Map
t3
=
new
HashMap
();
t3
.
put
(
"name"
,
"刘老师"
);
t3
.
put
(
"job"
,
"英语老师"
);
teachList
.
add
(
t3
);
parameters
.
put
(
"teachList"
,
teachList
);
List
<
HashMap
>
list
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<
6
;
i
++)
{
HashMap
<
String
,
Object
>
item
=
new
HashMap
<>();
item
.
put
(
"grade"
,
i
+
"年级学生信息:"
);
List
<
Map
>
studentList
=
new
ArrayList
<>();
Map
s1
=
new
HashMap
();
s1
.
put
(
"name"
,
"张"
+
i
);
s1
.
put
(
"age"
,
i
+
""
);
s1
.
put
(
"sex"
,
i
%
2
==
0
?
"男"
:
"女"
);
studentList
.
add
(
s1
);
Map
s2
=
new
HashMap
();
s2
.
put
(
"name"
,
"王"
+
i
);
s2
.
put
(
"age"
,
i
+
""
);
s2
.
put
(
"sex"
,
i
%
2
==
0
?
"男"
:
"女"
);
studentList
.
add
(
s2
);
Map
s3
=
new
HashMap
();
s3
.
put
(
"name"
,
"刘"
+
i
);
s3
.
put
(
"age"
,
i
+
""
);
s3
.
put
(
"sex"
,
i
%
2
==
0
?
"男"
:
"女"
);
studentList
.
add
(
s3
);
item
.
put
(
"studentList"
,
studentList
);
list
.
add
(
item
);
}
String
jasperPath
=
JasperReportUtil
.
getJasperFileDir
(
"report"
);
if
(
reportType
.
equals
(
"pdf"
))
{
JasperReportUtil
.
exportToPdf
(
jasperPath
,
parameters
,
list
,
response
);
}
else
if
(
reportType
.
equals
(
"html"
))
{
JasperReportUtil
.
exportToHtml
(
jasperPath
,
parameters
,
list
,
response
);
}
}
}
}
datax-modules/system-service-parent/system-service/src/main/resources/jaspers/report.jasper
0 → 100644
View file @
79a00cdd
File added
datax-modules/system-service-parent/system-service/src/main/resources/jaspers/report.jrxml
0 → 100644
View file @
79a00cdd
This diff is collapsed.
Click to expand it.
pom.xml
View file @
79a00cdd
...
@@ -49,6 +49,7 @@
...
@@ -49,6 +49,7 @@
<zxing.version>
3.4.0
</zxing.version>
<zxing.version>
3.4.0
</zxing.version>
<aspose.version>
20.3
</aspose.version>
<aspose.version>
20.3
</aspose.version>
<redisson.version>
3.12.5
</redisson.version>
<redisson.version>
3.12.5
</redisson.version>
<jasperreports.version>
6.12.2
</jasperreports.version>
</properties>
</properties>
<modules>
<modules>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment