Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
Y
yn-health-science
Project
Project
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
徐俊
yn-health-science
Commits
401dd323
Commit
401dd323
authored
Feb 18, 2025
by
徐俊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xujun
parent
ef24d374
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
70 deletions
+95
-70
ComProjectController.java
...ava/com/yiboshi/science/rest/v1/ComProjectController.java
+25
-8
ProjectInfoToPDF.java
...main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
+70
-62
No files found.
science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectController.java
View file @
401dd323
...
@@ -214,15 +214,31 @@ public class ComProjectController extends BaseController<ComProjectService, ComP
...
@@ -214,15 +214,31 @@ public class ComProjectController extends BaseController<ComProjectService, ComP
return
ResponseDataModel
.
ok
(
comProjectService
.
projectImport
(
list
));
return
ResponseDataModel
.
ok
(
comProjectService
.
projectImport
(
list
));
}
}
@ApiOperation
(
value
=
"项目信息导出
1"
,
httpMethod
=
"POST"
,
notes
=
"项目信息导出1
"
)
@ApiOperation
(
value
=
"项目信息导出
"
,
httpMethod
=
"POST"
,
notes
=
"项目信息导出
"
)
@RequestMapping
(
"/projectExport/{id}"
)
@RequestMapping
(
"/projectExport/{id}"
)
@PostMapping
@PostMapping
public
ResponseDataModel
<
String
>
projectExport
(
@PathVariable
String
id
)
throws
DocumentException
,
IOException
{
public
void
projectExport
(
@PathVariable
String
id
)
throws
DocumentException
,
IOException
{
try
{
List
<
SystemParameter
>
list
=
systemParameterService
.
getListByType
(
67
);
List
<
SystemParameter
>
list
=
systemParameterService
.
getListByType
(
67
);
ComProjectDTO
dto
=
comProjectService
.
getProjectById
(
id
);
ComProjectDTO
dto
=
comProjectService
.
getProjectById
(
id
);
String
outputPath
=
"D:\\申请书和合同书.pdf"
;
ProjectInfoToPDF
.
generateProjectPDF
(
dto
,
outputPath
,
list
);
// 生成PDF文件字节数组
return
ResponseDataModel
.
ok
(
"项目信息导入成功!"
);
byte
[]
pdfBytes
=
ProjectInfoToPDF
.
generateProjectPDF
(
dto
,
list
);
// 设置响应头
response
.
setContentType
(
"application/pdf"
);
String
fileName
=
new
String
((
dto
.
getProjName
()
+
".pdf"
).
getBytes
(
"UTF-8"
),
"ISO-8859-1"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
fileName
);
response
.
setContentLength
(
pdfBytes
.
length
);
// 写入响应流
try
(
ServletOutputStream
out
=
response
.
getOutputStream
())
{
out
.
write
(
pdfBytes
);
out
.
flush
();
}
}
catch
(
Exception
e
)
{
response
.
setContentType
(
"text/plain;charset=UTF-8"
);
response
.
getWriter
().
write
(
"导出PDF失败:"
+
e
.
getMessage
());
}
}
}
}
}
\ No newline at end of file
science-admin/src/main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
View file @
401dd323
...
@@ -21,89 +21,97 @@ public class ProjectInfoToPDF {
...
@@ -21,89 +21,97 @@ public class ProjectInfoToPDF {
/**
/**
* 生成项目申请书和合同书PDF
* 生成项目申请书和合同书PDF
* @param project 项目信息
* @param project 项目信息
* @
param outputPath 输出路径
* @
return 生成的PDF文件字节数组
*/
*/
public
static
void
generateProjectPDF
(
ComProjectDTO
project
,
String
outputPath
,
List
<
SystemParameter
>
projAttributeList
)
throws
DocumentException
,
IOException
{
public
static
byte
[]
generateProjectPDF
(
ComProjectDTO
project
,
List
<
SystemParameter
>
projAttributeList
)
throws
DocumentException
,
IOException
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
Document
document
=
new
Document
(
PageSize
.
A4
);
Document
document
=
new
Document
(
PageSize
.
A4
);
PdfWriter
writer
=
PdfWriter
.
getInstance
(
document
,
new
FileOutputStream
(
outputPath
));
PdfWriter
writer
=
PdfWriter
.
getInstance
(
document
,
baos
);
// 文件水印
String
watermark
=
project
.
getAppNo
();
if
(
project
.
getProjState
()
>=
CommonEnum
.
projState
.
pass
.
getCode
())
{
watermark
=
project
.
getProjNo
();
}
// 宋体
try
{
BaseFont
bfChinese
=
loadChineseFont
(
"/fonts/simsun.ttc"
);
// 文件水印
// 仿宋
String
watermark
=
project
.
getAppNo
();
BaseFont
fsChinese
=
loadChineseFont
(
"/fonts/simfang.ttf"
);
if
(
project
.
getProjState
()
>=
CommonEnum
.
projState
.
pass
.
getCode
())
{
// WINGDNG2
watermark
=
project
.
getProjNo
();
BaseFont
WINGDNG2
=
loadChineseFont
(
"/fonts/WINGDNG2.ttf"
);
}
// 添加水印
// 宋体
writer
.
setPageEvent
(
new
WatermarkPageEvent
(
watermark
,
fsChinese
));
BaseFont
bfChinese
=
loadChineseFont
(
"/fonts/simsun.ttc"
);
// 仿宋
BaseFont
fsChinese
=
loadChineseFont
(
"/fonts/simfang.ttf"
);
// WINGDNG2
BaseFont
WINGDNG2
=
loadChineseFont
(
"/fonts/WINGDNG2.ttf"
);
document
.
open
();
// 添加水印
writer
.
setPageEvent
(
new
WatermarkPageEvent
(
watermark
,
fsChinese
));
document
.
open
();
Font
normalFont
=
new
Font
(
bfChinese
,
12
,
Font
.
NORMAL
);
Font
normalFont
=
new
Font
(
bfChinese
,
12
,
Font
.
NORMAL
);
Font
boldFont
=
new
Font
(
bfChinese
,
12
,
Font
.
BOLD
);
Font
boldFont
=
new
Font
(
bfChinese
,
12
,
Font
.
BOLD
);
//首页内容
//首页内容
FirstPageInfo
(
document
,
project
,
bfChinese
,
fsChinese
);
FirstPageInfo
(
document
,
project
,
bfChinese
,
fsChinese
);
// 添加新页面
// 添加新页面
document
.
newPage
();
document
.
newPage
();
// 添加项目内容章节
// 添加项目内容章节
addSection
(
document
,
"一、项目基本情况"
,
boldFont
);
addSection
(
document
,
"一、项目基本情况"
,
boldFont
);
addProjectBasicTable
(
document
,
project
,
bfChinese
,
fsChinese
);
// 添加项目基本信息表格
addProjectBasicTable
(
document
,
project
,
bfChinese
,
fsChinese
);
// 添加项目基本信息表格
// 添加横向页面
// 添加横向页面
document
.
setPageSize
(
PageSize
.
A4
.
rotate
());
document
.
setPageSize
(
PageSize
.
A4
.
rotate
());
document
.
newPage
();
document
.
newPage
();
// 添加项目组主要成员表格
// 添加项目组主要成员表格
addProjectMembersTable
(
document
,
project
,
bfChinese
,
fsChinese
);
addProjectMembersTable
(
document
,
project
,
bfChinese
,
fsChinese
);
document
.
newPage
();
document
.
newPage
();
// 添加项目绩效目标表
// 添加项目绩效目标表
addProjectKPITable
(
document
,
project
,
projAttributeList
,
bfChinese
,
fsChinese
,
WINGDNG2
);
addProjectKPITable
(
document
,
project
,
projAttributeList
,
bfChinese
,
fsChinese
,
WINGDNG2
);
// 恢复为纵向页面
// 恢复为纵向页面
document
.
setPageSize
(
PageSize
.
A4
);
document
.
setPageSize
(
PageSize
.
A4
);
document
.
newPage
();
document
.
newPage
();
// 项目经费预算表
// 项目经费预算表
addProjectBudgetTable
(
document
,
project
,
bfChinese
,
fsChinese
);
addProjectBudgetTable
(
document
,
project
,
bfChinese
,
fsChinese
);
// 插入申请书正文PDF
// 插入申请书正文PDF
if
(
project
.
getConvertUrl
()
!=
null
&&
!
project
.
getConvertUrl
().
trim
().
isEmpty
())
{
if
(
project
.
getConvertUrl
()
!=
null
&&
!
project
.
getConvertUrl
().
trim
().
isEmpty
())
{
insertPdfContent
(
document
,
System
.
getProperty
(
"user.dir"
)
+
project
.
getConvertUrl
(),
writer
);
insertPdfContent
(
document
,
System
.
getProperty
(
"user.dir"
)
+
project
.
getConvertUrl
(),
writer
);
}
}
// 添加新页面
// 添加新页面
document
.
newPage
();
document
.
newPage
();
addSection
(
document
,
"二、主要技术指标"
,
boldFont
);
addSection
(
document
,
"二、主要技术指标"
,
boldFont
);
addContent
(
document
,
project
.
getTechnologyTarget
(),
normalFont
);
addContent
(
document
,
project
.
getTechnologyTarget
(),
normalFont
);
addSection
(
document
,
"三、主要经济指标"
,
boldFont
);
addSection
(
document
,
"三、主要经济指标"
,
boldFont
);
addContent
(
document
,
project
.
getEconomyTarget
(),
normalFont
);
addContent
(
document
,
project
.
getEconomyTarget
(),
normalFont
);
addSection
(
document
,
"四、项目实施中形成的示范基地、中试线、生产线及其规模等"
,
boldFont
);
addSection
(
document
,
"四、项目实施中形成的示范基地、中试线、生产线及其规模等"
,
boldFont
);
addContent
(
document
,
project
.
getAchievementTarget
(),
normalFont
);
addContent
(
document
,
project
.
getAchievementTarget
(),
normalFont
);
addSection
(
document
,
"五、科技报告考核指标"
,
boldFont
);
addSection
(
document
,
"五、科技报告考核指标"
,
boldFont
);
addContent
(
document
,
project
.
getTechnologyReportsTarget
(),
normalFont
);
addContent
(
document
,
project
.
getTechnologyReportsTarget
(),
normalFont
);
addSection
(
document
,
"六、其他应考核的指标"
,
boldFont
);
addSection
(
document
,
"六、其他应考核的指标"
,
boldFont
);
addContent
(
document
,
project
.
getOtherTarget
(),
normalFont
);
addContent
(
document
,
project
.
getOtherTarget
(),
normalFont
);
// 添加签字栏
// 添加签字栏
addSignatureSection
(
document
,
normalFont
);
addSignatureSection
(
document
,
normalFont
);
document
.
close
();
document
.
close
();
return
baos
.
toByteArray
();
}
finally
{
if
(
document
.
isOpen
())
{
document
.
close
();
}
baos
.
close
();
}
}
}
/**
/**
...
...
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