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
00bf95bd
Commit
00bf95bd
authored
Feb 12, 2025
by
徐俊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xujun
parent
66734b50
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
220 additions
and
0 deletions
+220
-0
ComProjectController.java
...ava/com/yiboshi/science/rest/v1/ComProjectController.java
+13
-0
ProjectInfoToPDF.java
...main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
+207
-0
simsun.ttc
science-admin/src/main/resources/fonts/simsun.ttc
+0
-0
方正仿宋简体.ttf
science-admin/src/main/resources/fonts/方正仿宋简体.ttf
+0
-0
11a920ac-e337-4b0d-bfc6-c71480a92195.jpg
upload/files/2024/7/11a920ac-e337-4b0d-bfc6-c71480a92195.jpg
+0
-0
No files found.
science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectController.java
View file @
00bf95bd
package
com
.
yiboshi
.
science
.
rest
.
v1
;
package
com
.
yiboshi
.
science
.
rest
.
v1
;
import
com.itextpdf.text.DocumentException
;
import
com.yiboshi.arch.base.ResponseDataModel
;
import
com.yiboshi.arch.base.ResponseDataModel
;
import
com.yiboshi.science.base.Pagination
;
import
com.yiboshi.science.base.Pagination
;
import
com.yiboshi.science.config.annotation.Logs
;
import
com.yiboshi.science.config.annotation.Logs
;
...
@@ -15,6 +16,7 @@ import com.yiboshi.science.rest.BaseController;
...
@@ -15,6 +16,7 @@ import com.yiboshi.science.rest.BaseController;
import
com.yiboshi.science.service.ComFileService
;
import
com.yiboshi.science.service.ComFileService
;
import
com.yiboshi.science.service.ComProjectService
;
import
com.yiboshi.science.service.ComProjectService
;
import
com.yiboshi.science.service.ComProjectTaskService
;
import
com.yiboshi.science.service.ComProjectTaskService
;
import
com.yiboshi.science.utils.ProjectInfoToPDF
;
import
com.yiboshi.science.utils.StringUtil
;
import
com.yiboshi.science.utils.StringUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
...
@@ -207,4 +209,14 @@ public class ComProjectController extends BaseController<ComProjectService, ComP
...
@@ -207,4 +209,14 @@ public class ComProjectController extends BaseController<ComProjectService, ComP
(
@Validated
@RequestBody
List
<
ProjectImportDTO
>
list
)
throws
IOException
{
(
@Validated
@RequestBody
List
<
ProjectImportDTO
>
list
)
throws
IOException
{
return
ResponseDataModel
.
ok
(
comProjectService
.
projectImport
(
list
));
return
ResponseDataModel
.
ok
(
comProjectService
.
projectImport
(
list
));
}
}
@ApiOperation
(
value
=
"项目信息导出"
,
httpMethod
=
"POST"
,
notes
=
"项目信息导出"
)
@RequestMapping
(
"/projectExport/{id}"
)
@PostMapping
public
ResponseDataModel
<
String
>
projectExport
(
@PathVariable
String
id
)
throws
DocumentException
,
IOException
{
ComProjectDTO
dto
=
comProjectService
.
getProjectById
(
id
);
String
outputPath
=
"D:\\申请书和合同书.pdf"
;
ProjectInfoToPDF
.
generateProjectPDF
(
dto
,
outputPath
);
return
ResponseDataModel
.
ok
(
"项目信息导入成功!"
);
}
}
}
\ No newline at end of file
science-admin/src/main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
0 → 100644
View file @
00bf95bd
package
com
.
yiboshi
.
science
.
utils
;
import
com.itextpdf.text.*
;
import
com.itextpdf.text.pdf.*
;
import
com.yiboshi.science.param.dto.ComProjectDTO
;
import
org.springframework.core.io.ClassPathResource
;
import
java.io.*
;
import
java.util.Objects
;
public
class
ProjectInfoToPDF
{
/**
* 生成项目申请书和合同书PDF
* @param project 项目信息
* @param outputPath 输出路径
*/
public
static
void
generateProjectPDF
(
ComProjectDTO
project
,
String
outputPath
)
throws
DocumentException
,
IOException
{
Document
document
=
new
Document
(
PageSize
.
A4
);
PdfWriter
writer
=
PdfWriter
.
getInstance
(
document
,
new
FileOutputStream
(
outputPath
));
document
.
open
();
// 设置中文字体
BaseFont
bfChinese
;
try
{
// 从资源文件夹加载字体
InputStream
fontStream
=
ProjectInfoToPDF
.
class
.
getResourceAsStream
(
"/fonts/simsun.ttc"
);
if
(
fontStream
==
null
)
{
throw
new
FileNotFoundException
(
"在resources/fonts目录下未找到simsun.ttc字体文件"
);
}
// 将字体文件复制到临时文件
File
tempFile
=
File
.
createTempFile
(
"simsun"
,
".ttc"
);
tempFile
.
deleteOnExit
();
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
tempFile
))
{
byte
[]
buffer
=
new
byte
[
1024
];
int
length
;
while
((
length
=
fontStream
.
read
(
buffer
))
>
0
)
{
fos
.
write
(
buffer
,
0
,
length
);
}
}
bfChinese
=
BaseFont
.
createFont
(
tempFile
.
getAbsolutePath
()
+
",0"
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
EMBEDDED
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"加载字体文件失败,请确保resources/fonts目录下存在simsun.ttc文件:"
+
e
.
getMessage
(),
e
);
}
Font
labelFont
=
new
Font
(
bfChinese
,
16
,
Font
.
NORMAL
);
Font
valueFont
=
new
Font
(
bfChinese
,
16
,
Font
.
NORMAL
);
Font
normalFont
=
new
Font
(
bfChinese
,
12
,
Font
.
NORMAL
);
Font
boldFont
=
new
Font
(
bfChinese
,
12
,
Font
.
BOLD
);
//首页内容
FirstPageInfo
(
document
,
project
,
bfChinese
);
// 添加项目基本信息表格
PdfPTable
table
=
new
PdfPTable
(
2
);
table
.
setWidthPercentage
(
100
);
table
.
setSpacingBefore
(
10
f
);
table
.
setSpacingAfter
(
10
f
);
// 设置列宽度
float
[]
columnWidths
=
{
0.3f
,
0.7f
};
table
.
setWidths
(
columnWidths
);
// 添加表格内容
addTableRow
(
table
,
"项目名称:"
,
project
.
getProjName
(),
labelFont
,
valueFont
);
addTableRow
(
table
,
"项目申报单位:"
,
project
.
getProjNo
(),
labelFont
,
valueFont
);
addTableRow
(
table
,
"申请单位:"
,
project
.
getAppUnitName
(),
labelFont
,
valueFont
);
addTableRow
(
table
,
"项目负责人:"
,
project
.
getAppPersonName
(),
labelFont
,
valueFont
);
addTableRow
(
table
,
"联系电话:"
,
project
.
getMobile
(),
labelFont
,
valueFont
);
addTableRow
(
table
,
"电子邮箱:"
,
project
.
getEmail
(),
labelFont
,
valueFont
);
document
.
add
(
table
);
// 添加项目内容章节
addSection
(
document
,
"一、项目实施目标"
,
boldFont
);
addContent
(
document
,
project
.
getResearchContent
(),
normalFont
);
addSection
(
document
,
"二、主要技术指标"
,
boldFont
);
addContent
(
document
,
project
.
getTechnologyTarget
(),
normalFont
);
addSection
(
document
,
"三、主要经济指标"
,
boldFont
);
addContent
(
document
,
project
.
getEconomyTarget
(),
normalFont
);
addSection
(
document
,
"四、项目实施中形成的示范基地、中试线、生产线及其规模等"
,
boldFont
);
addContent
(
document
,
project
.
getAchievementTarget
(),
normalFont
);
addSection
(
document
,
"五、科技报告考核指标"
,
boldFont
);
addContent
(
document
,
project
.
getTechnologyReportsTarget
(),
normalFont
);
addSection
(
document
,
"六、其他应考核的指标"
,
boldFont
);
addContent
(
document
,
project
.
getOtherTarget
(),
normalFont
);
// 添加签字栏
addSignatureSection
(
document
,
normalFont
);
document
.
close
();
}
//首页
private
static
Document
FirstPageInfo
(
Document
document
,
ComProjectDTO
project
,
BaseFont
bfChinese
)
throws
DocumentException
{
Font
titleFont
=
new
Font
(
bfChinese
,
20
,
Font
.
BOLD
);
Font
normalFont
=
new
Font
(
bfChinese
,
12
,
Font
.
NORMAL
);
// 添加项目编号到左上角
Paragraph
projNo
;
if
(
Objects
.
nonNull
(
project
.
getProjNo
()))
{
Chunk
text
=
new
Chunk
(
"项目编号:"
,
normalFont
);
Chunk
number
=
new
Chunk
(
project
.
getProjNo
(),
normalFont
);
number
.
setUnderline
(
0.1f
,
-
2
f
);
// 设置下划线
projNo
=
new
Paragraph
();
projNo
.
add
(
text
);
projNo
.
add
(
number
);
projNo
.
add
(
Chunk
.
NEWLINE
);
projNo
.
add
(
Chunk
.
NEWLINE
);
projNo
.
add
(
Chunk
.
NEWLINE
);
projNo
.
add
(
Chunk
.
NEWLINE
);
}
else
{
Chunk
text
=
new
Chunk
(
"项目编号:"
,
normalFont
);
Chunk
underline
=
new
Chunk
(
" "
,
normalFont
);
underline
.
setUnderline
(
0.1f
,
-
2
f
);
// 设置下划线
projNo
=
new
Paragraph
();
projNo
.
add
(
text
);
projNo
.
add
(
underline
);
projNo
.
add
(
Chunk
.
NEWLINE
);
projNo
.
add
(
Chunk
.
NEWLINE
);
projNo
.
add
(
Chunk
.
NEWLINE
);
projNo
.
add
(
Chunk
.
NEWLINE
);
}
projNo
.
setAlignment
(
Element
.
ALIGN_LEFT
);
projNo
.
setSpacingAfter
(
10
);
document
.
add
(
projNo
);
// 添加标题
Paragraph
title
=
new
Paragraph
(
"省级临床医学中心科研项目申请书"
,
titleFont
);
title
.
setAlignment
(
Element
.
ALIGN_CENTER
);
title
.
setSpacingAfter
(
20
);
document
.
add
(
title
);
return
document
;
}
private
static
void
addTableRow
(
PdfPTable
table
,
String
label
,
String
value
,
Font
labelFont
,
Font
valueFont
)
{
PdfPCell
labelCell
=
new
PdfPCell
(
new
Phrase
(
label
,
labelFont
));
labelCell
.
setMinimumHeight
(
25
f
);
labelCell
.
setVerticalAlignment
(
Element
.
ALIGN_MIDDLE
);
labelCell
.
setHorizontalAlignment
(
Element
.
ALIGN_RIGHT
);
labelCell
.
setPaddingRight
(
5
f
);
labelCell
.
setBorder
(
Rectangle
.
NO_BORDER
);
// 创建带下划线的值
Chunk
valueChunk
;
if
(
value
!=
null
&&
!
value
.
trim
().
isEmpty
())
{
valueChunk
=
new
Chunk
(
value
,
valueFont
);
}
else
{
valueChunk
=
new
Chunk
(
" "
,
valueFont
);
}
valueChunk
.
setUnderline
(
0.1f
,
-
2
f
);
// 添加下划线
PdfPCell
valueCell
=
new
PdfPCell
(
new
Phrase
(
valueChunk
));
valueCell
.
setMinimumHeight
(
25
f
);
valueCell
.
setVerticalAlignment
(
Element
.
ALIGN_MIDDLE
);
valueCell
.
setPaddingLeft
(
5
f
);
valueCell
.
setBorder
(
Rectangle
.
NO_BORDER
);
table
.
addCell
(
labelCell
);
table
.
addCell
(
valueCell
);
}
private
static
void
addSection
(
Document
document
,
String
title
,
Font
font
)
throws
DocumentException
{
Paragraph
section
=
new
Paragraph
(
title
,
font
);
section
.
setSpacingBefore
(
15
);
section
.
setSpacingAfter
(
10
);
document
.
add
(
section
);
}
private
static
void
addContent
(
Document
document
,
String
content
,
Font
font
)
throws
DocumentException
{
if
(
content
!=
null
)
{
Paragraph
paragraph
=
new
Paragraph
(
content
,
font
);
paragraph
.
setIndentationLeft
(
20
);
paragraph
.
setSpacingAfter
(
10
);
document
.
add
(
paragraph
);
}
}
private
static
void
addSignatureSection
(
Document
document
,
Font
font
)
throws
DocumentException
{
Paragraph
signature
=
new
Paragraph
(
"\n\n"
,
font
);
signature
.
add
(
new
Chunk
(
"申请人签字:"
,
font
));
signature
.
add
(
new
Chunk
(
" "
,
font
));
signature
.
add
(
new
Chunk
(
"日期:"
,
font
));
signature
.
add
(
new
Chunk
(
" "
,
font
));
signature
.
setAlignment
(
Element
.
ALIGN_RIGHT
);
signature
.
setSpacingBefore
(
50
);
document
.
add
(
signature
);
Paragraph
unitSignature
=
new
Paragraph
(
"\n"
,
font
);
unitSignature
.
add
(
new
Chunk
(
"申请单位(盖章):"
,
font
));
unitSignature
.
add
(
new
Chunk
(
" "
,
font
));
unitSignature
.
add
(
new
Chunk
(
"日期:"
,
font
));
unitSignature
.
add
(
new
Chunk
(
" "
,
font
));
unitSignature
.
setAlignment
(
Element
.
ALIGN_RIGHT
);
unitSignature
.
setSpacingBefore
(
30
);
document
.
add
(
unitSignature
);
}
}
science-admin/src/main/resources/fonts/simsun.ttc
0 → 100644
View file @
00bf95bd
File added
science-admin/src/main/resources/fonts/方正仿宋简体.ttf
0 → 100644
View file @
00bf95bd
File added
upload/files/2024/7/11a920ac-e337-4b0d-bfc6-c71480a92195.jpg
deleted
100644 → 0
View file @
66734b50
77.8 KB
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