Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vehicle-quality-review
Project
Project
Details
Activity
Releases
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
王飞
vehicle-quality-review
Commits
2d015e58
Commit
2d015e58
authored
Apr 12, 2024
by
盖献康
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
原始记录PDF - 第一页、页眉页脚、h5导入cell
parent
9db3176b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
142 additions
and
24 deletions
+142
-24
pom.xml
quality-review/pom.xml
+11
-0
PdfTemplateManagementService.java
.../java/com/ruoyi/service/PdfTemplateManagementService.java
+2
-1
PdfTemplateManagementServiceImpl.java
.../ruoyi/service/impl/PdfTemplateManagementServiceImpl.java
+127
-21
PdfTemplateManagementController.java
...n/java/com/ruoyi/web/PdfTemplateManagementController.java
+2
-2
No files found.
quality-review/pom.xml
View file @
2d015e58
...
@@ -61,6 +61,11 @@
...
@@ -61,6 +61,11 @@
<artifactId>
itext-asian
</artifactId>
<artifactId>
itext-asian
</artifactId>
<version>
5.2.0
</version>
<version>
5.2.0
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.itextpdf.tool
</groupId>
<artifactId>
xmlworker
</artifactId>
<version>
5.5.13
</version>
</dependency>
<dependency>
<dependency>
<groupId>
com.ruoyi
</groupId>
<groupId>
com.ruoyi
</groupId>
<artifactId>
ruoyi-framework
</artifactId>
<artifactId>
ruoyi-framework
</artifactId>
...
@@ -70,6 +75,12 @@
...
@@ -70,6 +75,12 @@
<artifactId>
httpclient
</artifactId>
<artifactId>
httpclient
</artifactId>
<version>
4.5.1
</version>
<version>
4.5.1
</version>
</dependency>
</dependency>
<!-- markdown->h5 -->
<dependency>
<groupId>
com.atlassian.commonmark
</groupId>
<artifactId>
commonmark
</artifactId>
<version>
0.15.2
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
quality-review/src/main/java/com/ruoyi/service/PdfTemplateManagementService.java
View file @
2d015e58
...
@@ -27,7 +27,8 @@ public interface PdfTemplateManagementService {
...
@@ -27,7 +27,8 @@ public interface PdfTemplateManagementService {
* 原始记录PDF下载
* 原始记录PDF下载
* @param taskId
* @param taskId
* @return
* @return
* @throws Exception
*/
*/
String
generateOriginalRecord
(
Long
taskId
);
String
generateOriginalRecord
(
Long
taskId
)
throws
Exception
;
}
}
quality-review/src/main/java/com/ruoyi/service/impl/PdfTemplateManagementServiceImpl.java
View file @
2d015e58
...
@@ -2,6 +2,9 @@ package com.ruoyi.service.impl;
...
@@ -2,6 +2,9 @@ package com.ruoyi.service.impl;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.itextpdf.text.*
;
import
com.itextpdf.text.*
;
import
com.itextpdf.text.Font
;
import
com.itextpdf.text.Image
;
import
com.itextpdf.text.Rectangle
;
import
com.itextpdf.text.pdf.*
;
import
com.itextpdf.text.pdf.*
;
import
com.ruoyi.common.core.domain.entity.SysDictData
;
import
com.ruoyi.common.core.domain.entity.SysDictData
;
import
com.ruoyi.common.utils.DateUtils
;
import
com.ruoyi.common.utils.DateUtils
;
...
@@ -18,14 +21,14 @@ import io.minio.MinioClient;
...
@@ -18,14 +21,14 @@ import io.minio.MinioClient;
import
io.minio.ObjectWriteArgs
;
import
io.minio.ObjectWriteArgs
;
import
io.minio.PutObjectArgs
;
import
io.minio.PutObjectArgs
;
import
lombok.SneakyThrows
;
import
lombok.SneakyThrows
;
import
org.commonmark.node.Node
;
import
org.commonmark.parser.Parser
;
import
org.commonmark.renderer.html.HtmlRenderer
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.io.*
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.*
;
...
@@ -265,33 +268,136 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
...
@@ -265,33 +268,136 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
* @return
* @return
*/
*/
@Override
@Override
public
String
generateOriginalRecord
(
Long
taskId
)
{
public
String
generateOriginalRecord
(
Long
taskId
)
throws
Exception
{
return
null
;
// 创建一张PDF文件
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
PdfBaseWriter
document
=
new
PdfBaseWriter
(
outputStream
);
document
.
setMargins
(
50
,
50
,
80
,
40
);
PdfWriter
writer
=
PdfWriter
.
getInstance
(
document
,
outputStream
);
OriginalRecordHeaderFooter
headerFooter
=
new
OriginalRecordHeaderFooter
();
writer
.
setPageEvent
(
headerFooter
);
// open
document
.
open
();
// 内容
// 1.检验依据
PdfPTable
reportNumberTable
=
new
PdfPTable
(
new
float
[]{
30
,
15
});
reportNumberTable
.
setWidthPercentage
(
100
);
reportNumberTable
.
setSpacingBefore
(
40
);
document
.
writeNoBorderCell
(
"报告编号:"
,
Element
.
ALIGN_RIGHT
,
1
,
1
,
reportNumberTable
);
document
.
writeBottomCell
(
""
,
Element
.
ALIGN_RIGHT
,
1
,
1
,
reportNumberTable
);
document
.
addContent
(
reportNumberTable
);
document
.
setParagraph
(
"1.检验依据"
,
10
f
,
Element
.
ALIGN_LEFT
,
0
,
10
f
,
10
f
);
document
.
setParagraph
(
"口《汽车整车信息安全技术要求》"
,
10
f
,
Element
.
ALIGN_LEFT
,
14
,
0
f
,
0
f
);
// 2.样品情况
document
.
setParagraph
(
"2.样品情况"
,
10
f
,
Element
.
ALIGN_LEFT
,
0
,
10
f
,
10
f
);
PdfPTable
sampleConditionTable
=
new
PdfPTable
(
new
float
[]{
30
,
20
,
30
,
20
});
sampleConditionTable
.
setWidthPercentage
(
100
);
document
.
writeCell
(
"样品名称"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"xxxxxxx"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"生产企业"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"xxxxxxx"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"样品型号"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"xxxxxxx"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"样品编号"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"xxxxxxx"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"样品数量"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"xxxxxxx"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"商标"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"xxxxxxx"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
sampleConditionTable
);
document
.
writeCell
(
"备注:"
,
Element
.
ALIGN_LEFT
,
4
,
1
,
sampleConditionTable
);
document
.
addContent
(
sampleConditionTable
);
// 3.仪器设备信息
document
.
setParagraph
(
"3.仪器设备信息"
,
10
f
,
Element
.
ALIGN_LEFT
,
0
,
10
f
,
0
f
);
List
<
String
>
equipmentList
=
Arrays
.
asList
(
"设备编号"
,
"设备名称"
,
"溯源有效期"
);
float
[]
columnWidths
=
{
20
,
20
,
60
};
PdfPTable
equipmentTable
=
document
.
createWithHeaderTable
(
equipmentList
,
columnWidths
);
document
.
writeCell
(
"xxxx"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
equipmentTable
);
document
.
writeCell
(
"xxxxxxxxx"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
equipmentTable
);
document
.
writeCell
(
"xxxx-xx-xx"
,
Element
.
ALIGN_CENTER
,
1
,
1
,
equipmentTable
);
document
.
add
(
equipmentTable
);
// 第一页下方信息
PdfPTable
inspectorTable
=
new
PdfPTable
(
new
float
[]{
20
,
20
,
10
,
40
});
inspectorTable
.
setWidthPercentage
(
100
);
inspectorTable
.
setTotalWidth
(
PageSize
.
A4
.
getWidth
()
-
80
);
document
.
writeNoBorderCell
(
"检验人员:"
,
Element
.
ALIGN_LEFT
,
1
,
1
,
inspectorTable
);
document
.
writeNoBorderCell
(
""
,
Element
.
ALIGN_LEFT
,
1
,
1
,
inspectorTable
);
document
.
writeNoBorderCell
(
"检验日期:"
,
Element
.
ALIGN_LEFT
,
1
,
1
,
inspectorTable
);
document
.
writeNoBorderCell
(
""
,
Element
.
ALIGN_LEFT
,
1
,
1
,
inspectorTable
);
document
.
writeBottomCell
(
"检验负责人:"
,
Element
.
ALIGN_LEFT
,
1
,
1
,
inspectorTable
);
document
.
writeBottomCell
(
""
,
Element
.
ALIGN_LEFT
,
1
,
1
,
inspectorTable
);
document
.
writeBottomCell
(
"检验地点:"
,
Element
.
ALIGN_LEFT
,
1
,
1
,
inspectorTable
);
document
.
writeBottomCell
(
"口中汽研软件测评有限公司 口其他:"
,
Element
.
ALIGN_LEFT
,
1
,
1
,
inspectorTable
);
inspectorTable
.
writeSelectedRows
(
0
,
-
1
,
document
.
left
(),
document
.
bottom
()
+
60
,
writer
.
getDirectContent
());
// close
document
.
close
();
writer
.
close
();
return
uploadMinio
(
outputStream
,
"原始记录"
);
}
}
public
static
class
OriginalRecordHeaderFooter
extends
PdfPageEventHelper
{
public
static
class
OriginalRecordHeaderFooter
extends
PdfPageEventHelper
{
// 一页加载完成触发,写入页眉和页脚
/**
* 一页加载完成触发,写入页眉和页脚
*/
@Override
@Override
@SneakyThrows
public
void
onEndPage
(
PdfWriter
writer
,
Document
document
)
{
public
void
onEndPage
(
PdfWriter
writer
,
Document
document
)
{
BaseFont
font
=
BaseFont
.
createFont
(
"/fonts/STSong.TTF"
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
EMBEDDED
);
PdfPTable
table
=
new
PdfPTable
(
2
);
PdfPTable
table
=
new
PdfPTable
(
2
);
try
{
table
.
setTotalWidth
(
PageSize
.
A4
.
getWidth
()
-
80
);
table
.
setTotalWidth
(
PageSize
.
A4
.
getWidth
()
-
80
);
table
.
setWidths
(
new
int
[]
{
60
,
40
});
table
.
setWidths
(
new
int
[]
{
40
,
40
});
table
.
setLockedWidth
(
true
);
table
.
setLockedWidth
(
true
);
table
.
getDefaultCell
().
setFixedHeight
(
30
);
table
.
getDefaultCell
().
setFixedHeight
(-
10
);
table
.
getDefaultCell
().
setBorder
(
Rectangle
.
BOX
);
table
.
getDefaultCell
().
setBorder
(
Rectangle
.
BOTTOM
);
table
.
getDefaultCell
().
setBorderWidth
(
0.5f
);
table
.
getDefaultCell
().
setBorderWidth
(
0.6f
);
table
.
getDefaultCell
().
setVerticalAlignment
(
Element
.
ALIGN_MIDDLE
);
BaseFont
font
=
BaseFont
.
createFont
(
"/fonts/STSong.TTF"
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
EMBEDDED
);
table
.
getDefaultCell
().
setHorizontalAlignment
(
Element
.
ALIGN_CENTER
);
table
.
addCell
(
new
Paragraph
(
headerText
,
new
Font
(
font
)));
// 可以直接使用addCell(str),不过不能指定字体,中文无法显示
table
.
getDefaultCell
().
setRowspan
(
1
);
// 将页眉写到document中,位置可以指定,指定到下面就是页脚
table
.
getDefaultCell
().
setColspan
(
2
);
table
.
writeSelectedRows
(
0
,
-
1
,
40
,
PageSize
.
A4
.
getHeight
()
-
20
,
writer
.
getDirectContent
());
table
.
addCell
(
new
Paragraph
(
"中汽研软件测评有限公司"
,
new
Font
(
font
)));
}
catch
(
Exception
de
)
{
table
.
getDefaultCell
().
setRowspan
(
1
);
throw
new
ExceptionConverter
(
de
);
table
.
getDefaultCell
().
setColspan
(
1
);
}
table
.
addCell
(
new
Paragraph
(
"检验记录"
,
new
Font
(
font
)));
table
.
getDefaultCell
().
setRowspan
(
1
);
table
.
getDefaultCell
().
setColspan
(
1
);
table
.
addCell
(
new
Paragraph
(
"第 "
+
writer
.
getPageNumber
()
+
" 页"
,
new
Font
(
font
)));
// 将页眉写到document中,位置可以指定,指定到下面就是页脚
table
.
writeSelectedRows
(
0
,
-
1
,
40
,
PageSize
.
A4
.
getHeight
()
-
20
,
writer
.
getDirectContent
());
// 页脚
PdfPTable
bottomTable
=
new
PdfPTable
(
1
);
bottomTable
.
setTotalWidth
(
PageSize
.
A4
.
getWidth
()
-
80
);
bottomTable
.
setWidths
(
new
int
[]
{
50
});
bottomTable
.
setLockedWidth
(
true
);
bottomTable
.
getDefaultCell
().
setFixedHeight
(-
10
);
bottomTable
.
getDefaultCell
().
setBorder
(
Rectangle
.
NO_BORDER
);
bottomTable
.
getDefaultCell
().
setBorderWidth
(
0.5f
);
bottomTable
.
getDefaultCell
().
setHorizontalAlignment
(
Element
.
ALIGN_CENTER
);
bottomTable
.
addCell
(
new
Paragraph
(
String
.
valueOf
(
writer
.
getPageNumber
()),
new
Font
(
font
)));
bottomTable
.
writeSelectedRows
(
0
,
-
1
,
40
,
40
,
writer
.
getDirectContent
());
}
}
}
}
/**
*
* @param markdownContent
* @return
*/
public
static
String
convertMarkdownToHtml
(
String
markdownContent
)
{
// 创建 Markdown 解析器
Parser
parser
=
Parser
.
builder
().
build
();
// 解析 Markdown
Node
document
=
parser
.
parse
(
markdownContent
);
// 创建 HTML 渲染器
HtmlRenderer
renderer
=
HtmlRenderer
.
builder
().
build
();
// 渲染 HTML
return
renderer
.
render
(
document
);
}
private
static
String
headerText
;
private
static
String
headerText
;
public
static
class
MyHeaderFooter
extends
PdfPageEventHelper
{
public
static
class
MyHeaderFooter
extends
PdfPageEventHelper
{
...
...
quality-review/src/main/java/com/ruoyi/web/PdfTemplateManagementController.java
View file @
2d015e58
...
@@ -101,7 +101,7 @@ public class PdfTemplateManagementController {
...
@@ -101,7 +101,7 @@ public class PdfTemplateManagementController {
if
(
StrUtil
.
isBlank
(
url
))
{
if
(
StrUtil
.
isBlank
(
url
))
{
// TODO 生成车型
// TODO 生成车型
url
=
pdfTemplateManagementService
.
generateOriginalRecord
(
request
.
getTaskId
());
url
=
pdfTemplateManagementService
.
generateOriginalRecord
(
request
.
getTaskId
());
taskService
.
update
(
new
UpdateWrapper
<
Task
>().
lambda
().
eq
(
Task:
:
getId
,
request
.
getTaskId
()).
set
(
Task:
:
getModelTest
TaskId
,
url
));
taskService
.
update
(
new
UpdateWrapper
<
Task
>().
lambda
().
eq
(
Task:
:
getId
,
request
.
getTaskId
()).
set
(
Task:
:
getModelTest
Url
,
url
));
}
}
break
;
break
;
default
:
default
:
...
@@ -139,7 +139,7 @@ public class PdfTemplateManagementController {
...
@@ -139,7 +139,7 @@ public class PdfTemplateManagementController {
case
2
:
case
2
:
// 更新
// 更新
url
=
pdfTemplateManagementService
.
generateOriginalRecord
(
request
.
getTaskId
());
url
=
pdfTemplateManagementService
.
generateOriginalRecord
(
request
.
getTaskId
());
taskService
.
update
(
new
UpdateWrapper
<
Task
>().
lambda
().
eq
(
Task:
:
getId
,
request
.
getTaskId
()).
set
(
Task:
:
getModelTest
TaskId
,
url
));
taskService
.
update
(
new
UpdateWrapper
<
Task
>().
lambda
().
eq
(
Task:
:
getId
,
request
.
getTaskId
()).
set
(
Task:
:
getModelTest
Url
,
url
));
break
;
break
;
default
:
default
:
break
;
break
;
...
...
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