Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dcs-doc-expand
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
INET-TWO
server
dcs-doc-expand
Commits
a2a8e48a
Commit
a2a8e48a
authored
Nov 20, 2024
by
wangqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
卷内目录生成pdf文件后,将临时目录及文件删除
parent
88baa04d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
22 deletions
+39
-22
ExtFilesServiceImpl.java
...t/dcs/document/core/service/impl/ExtFilesServiceImpl.java
+37
-18
ResourceHelper.java
.../java/com/inet/dcs/document/core/util/ResourceHelper.java
+2
-4
No files found.
inet-doc-expand-core/src/main/java/com/inet/dcs/document/core/service/impl/ExtFilesServiceImpl.java
View file @
a2a8e48a
...
...
@@ -19,7 +19,7 @@ import com.inet.dcs.document.core.util.SearchUtil;
import
com.inet.dcs.document.core.util.WordUtils
;
import
com.inet.dcs.document.entity.po.ExtFiles
;
import
com.yonde.dcs.document.common.entity.vo.DxDocumentVO
;
import
com.
yonde.dcs.plan.common.utils
.ResourceHelper
;
import
com.
inet.dcs.document.core.util
.ResourceHelper
;
import
com.yonde.dex.basedata.data.search.SearchItem
;
import
com.yonde.dex.basedata.data.search.SearchItems
;
import
com.yonde.dex.basedata.data.search.SearchQueryBuilder
;
...
...
@@ -340,19 +340,29 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
return
pdfFile2
.
getAbsolutePath
();
}
public
String
fillWordAndConvertPdf
(
String
modelName
,
Map
<
String
,
Object
>
dataMap
,
String
pdfFileName
)
{
public
String
fillWordAndConvertPdf
(
String
modelName
,
Map
<
String
,
Object
>
dataMap
,
String
pdfFileName
,
String
tempDir
)
{
String
targetPath
=
System
.
getProperty
(
"user.dir"
)
+
"/TEMP/"
;
File
wordFile
=
new
File
(
targetPath
+
modelName
);
File
pdfFile2
=
new
File
(
"TEMP/JNDir/"
+
pdfFileName
+
".pdf"
);
File
pdfFile2
=
new
File
(
tempDir
+
File
.
separator
+
pdfFileName
+
".pdf"
);
InputStream
tempStream
=
null
;
OutputStream
outputStream
=
null
;
ByteArrayInputStream
byteArrayInputStream
=
null
;
try
{
InputStream
tempStream2
=
Files
.
newInputStream
(
wordFile
.
toPath
());
OutputStream
outputStream
=
Files
.
newOutputStream
(
pdfFile2
.
toPath
());
byte
[]
bytes2
=
WordUtils
.
fillWord
(
dataMap
,
tempStream
2
);
ByteArrayInputStream
byteArrayInputStream
=
new
ByteArrayInputStream
(
bytes2
);
tempStream
=
Files
.
newInputStream
(
wordFile
.
toPath
());
outputStream
=
Files
.
newOutputStream
(
pdfFile2
.
toPath
());
byte
[]
bytes2
=
WordUtils
.
fillWord
(
dataMap
,
tempStream
);
byteArrayInputStream
=
new
ByteArrayInputStream
(
bytes2
);
WordUtils
.
wordToPDF
(
byteArrayInputStream
,
outputStream
);
byteArrayInputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
byteArrayInputStream
.
close
();
tempStream
.
close
();
outputStream
.
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
return
pdfFile2
.
getAbsolutePath
();
}
...
...
@@ -382,24 +392,33 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
//查询项目群下所有案卷
SearchQueryCondition
searchProgram
=
SearchUtil
.
buildQuery
(
"dxContextId"
,
SearchItem
.
Operator
.
EQ
,
id
);
List
<
V
>
content
=
this
.
findRecursion
(
searchProgram
).
getContent
();
//临时文件目录
String
tempDir
=
ResourceHelper
.
createTemDir
().
getPath
();
List
<
Long
>
extFilesIdList
=
content
.
stream
().
map
(
v
->
v
.
getId
()).
collect
(
Collectors
.
toList
());
//查询案卷下文件清单
for
(
Long
filesId
:
extFilesIdList
)
{
SearchQueryCondition
searchQueryCondition
=
SearchQueryBuilder
.
openBuild
().
openFilterBuilder
()
.
setItem
(
"targetId"
,
SearchItem
.
Operator
.
EQ
,
filesId
).
closeFilterBuilder
()
.
setPropName
(
"target"
).
setPropName
(
"source"
).
build
();
List
<
ExtFilesDocLinkVO
>
extFilesDocLinkVOList
=
extFilesDocLinkService
.
findRecursion
(
searchQueryCondition
).
getContent
();
if
(
CollectionUtils
.
isNotEmpty
(
extFilesDocLinkVOList
))
{
ExtFilesVO
extFilesVO
=
extFilesDocLinkVOList
.
get
(
0
).
getTarget
();
//查询案卷的附件信息及link中的doc
SearchQueryCondition
query
=
SearchQueryCondition
.
builder
()
.
openProp
(
SearchQueryCondition
.
builder
().
name
(
"objFileLinks"
).
build
())
.
openProp
(
SearchQueryCondition
.
builder
().
name
(
"extFilesDocLinks"
)
.
openProp
(
SearchQueryCondition
.
builder
().
name
(
"source"
).
build
()).
build
())
.
searchItems
(
SearchItems
.
builder
()
.
item
(
new
SearchItem
(
"id"
,
SearchItem
.
Operator
.
EQ
,
filesId
,
null
))
.
build
()).
build
();
ExtFilesVO
extFilesVO
=
this
.
findRecursion
(
query
).
getContent
().
get
(
0
);
//link(source=doc)
List
<
ExtFilesDocLinkVO
>
extFilesDocLinkVOList
=
extFilesVO
.
getExtFilesDocLinks
();
if
(
CollectionUtils
.
isNotEmpty
(
extFilesVO
.
getExtFilesDocLinks
()))
{
//1.获取案卷下所有的档案(doc模型)数据并填充到模板中
Map
<
String
,
Object
>
wordFillDataForJN
=
getJNDirectoryFillData
(
extFilesDocLinkVOList
,
extFilesVO
);
String
JNDirectoryPdfPath
=
fillWordAndConvertPdf
(
"卷内目录模板.docx"
,
wordFillDataForJN
,
getJNMLFileName
(
extFilesVO
));
String
JNDirectoryPdfPath
=
fillWordAndConvertPdf
(
"卷内目录模板.docx"
,
wordFillDataForJN
,
getJNMLFileName
(
extFilesVO
)
,
tempDir
);
//2.获取备考表需要填充的数据并填充数据到模板中
Map
<
String
,
Object
>
wordFillDataForBK
=
getJNBKTableFillData
(
extFilesDocLinkVOList
,
extFilesVO
);
String
BKPdfPath
=
fillWordAndConvertPdf
(
"卷内备考表模板.docx"
,
wordFillDataForBK
,
getBKFileName
(
extFilesVO
));
String
BKPdfPath
=
fillWordAndConvertPdf
(
"卷内备考表模板.docx"
,
wordFillDataForBK
,
getBKFileName
(
extFilesVO
)
,
tempDir
);
//3.上传卷内文档目录文件
MultipartFile
multipartFileForJN
=
DxObjFileUtils
.
createFile
(
JNDirectoryPdfPath
);
...
...
@@ -423,7 +442,7 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
extFilesVO
.
setOperator
(
OperatorType
.
MODIFY
);
this
.
saveRecursion
((
V
)
extFilesVO
);
//删除目录下所有的文件
FileUtils
.
deleteFilesInDirectory
(
System
.
getProperty
(
"user.dir"
)
+
"/TEMP/JNDir/"
);
FileUtils
.
deleteDirectory
(
tempDir
);
}
}
...
...
@@ -616,7 +635,7 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
throw
new
DxBusinessException
(
"500"
,
"必须要选中一条案卷"
);
}
//临时文件目录
String
tempDir
=
ResourceHelper
.
createTem
p
Dir
().
getPath
();
String
tempDir
=
ResourceHelper
.
createTemDir
().
getPath
();
//文件id集合
List
<
Long
>
fileIds
=
new
ArrayList
<>();
...
...
inet-doc-expand-core/src/main/java/com/inet/dcs/document/core/util/ResourceHelper.java
View file @
a2a8e48a
...
...
@@ -162,16 +162,14 @@ public class ResourceHelper {
public
static
String
getBaseHomeDir
()
{
if
(
StringUtils
.
isEmpty
(
baseHomeDir
))
{
ApplicationHome
home
=
new
ApplicationHome
(
PDFUtil
.
class
);
baseHomeDir
=
home
.
getSource
().
getParentFile
().
getPath
();
baseHomeDir
=
home
.
getSource
().
getParentFile
().
getPa
rentFile
().
getPa
th
();
}
return
baseHomeDir
;
}
public
static
File
createTemDir
()
{
String
uuid
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
String
temDir
=
getBaseHomeDir
()
+
File
.
separator
+
"tem"
+
File
.
separator
+
uuid
;
String
temDir
=
getBaseHomeDir
()
+
File
.
separator
+
"fileTempDir"
+
File
.
separator
+
uuid
;
return
FileUtil
.
mkdir
(
temDir
);
}
...
...
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