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
Show 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;
...
@@ -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.core.util.WordUtils
;
import
com.inet.dcs.document.entity.po.ExtFiles
;
import
com.inet.dcs.document.entity.po.ExtFiles
;
import
com.yonde.dcs.document.common.entity.vo.DxDocumentVO
;
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.SearchItem
;
import
com.yonde.dex.basedata.data.search.SearchItems
;
import
com.yonde.dex.basedata.data.search.SearchItems
;
import
com.yonde.dex.basedata.data.search.SearchQueryBuilder
;
import
com.yonde.dex.basedata.data.search.SearchQueryBuilder
;
...
@@ -340,19 +340,29 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
...
@@ -340,19 +340,29 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
return
pdfFile2
.
getAbsolutePath
();
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/"
;
String
targetPath
=
System
.
getProperty
(
"user.dir"
)
+
"/TEMP/"
;
File
wordFile
=
new
File
(
targetPath
+
modelName
);
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
{
try
{
InputStream
tempStream2
=
Files
.
newInputStream
(
wordFile
.
toPath
());
tempStream
=
Files
.
newInputStream
(
wordFile
.
toPath
());
OutputStream
outputStream
=
Files
.
newOutputStream
(
pdfFile2
.
toPath
());
outputStream
=
Files
.
newOutputStream
(
pdfFile2
.
toPath
());
byte
[]
bytes2
=
WordUtils
.
fillWord
(
dataMap
,
tempStream
2
);
byte
[]
bytes2
=
WordUtils
.
fillWord
(
dataMap
,
tempStream
);
ByteArrayInputStream
byteArrayInputStream
=
new
ByteArrayInputStream
(
bytes2
);
byteArrayInputStream
=
new
ByteArrayInputStream
(
bytes2
);
WordUtils
.
wordToPDF
(
byteArrayInputStream
,
outputStream
);
WordUtils
.
wordToPDF
(
byteArrayInputStream
,
outputStream
);
byteArrayInputStream
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
try
{
byteArrayInputStream
.
close
();
tempStream
.
close
();
outputStream
.
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
return
pdfFile2
.
getAbsolutePath
();
return
pdfFile2
.
getAbsolutePath
();
}
}
...
@@ -382,24 +392,33 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
...
@@ -382,24 +392,33 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
//查询项目群下所有案卷
//查询项目群下所有案卷
SearchQueryCondition
searchProgram
=
SearchUtil
.
buildQuery
(
"dxContextId"
,
SearchItem
.
Operator
.
EQ
,
id
);
SearchQueryCondition
searchProgram
=
SearchUtil
.
buildQuery
(
"dxContextId"
,
SearchItem
.
Operator
.
EQ
,
id
);
List
<
V
>
content
=
this
.
findRecursion
(
searchProgram
).
getContent
();
List
<
V
>
content
=
this
.
findRecursion
(
searchProgram
).
getContent
();
//临时文件目录
String
tempDir
=
ResourceHelper
.
createTemDir
().
getPath
();
List
<
Long
>
extFilesIdList
=
content
.
stream
().
map
(
v
->
v
.
getId
()).
collect
(
Collectors
.
toList
());
List
<
Long
>
extFilesIdList
=
content
.
stream
().
map
(
v
->
v
.
getId
()).
collect
(
Collectors
.
toList
());
//查询案卷下文件清单
//查询案卷下文件清单
for
(
Long
filesId
:
extFilesIdList
)
{
for
(
Long
filesId
:
extFilesIdList
)
{
SearchQueryCondition
searchQueryCondition
=
SearchQueryBuilder
.
openBuild
().
openFilterBuilder
()
.
setItem
(
"targetId"
,
SearchItem
.
Operator
.
EQ
,
filesId
).
closeFilterBuilder
()
//查询案卷的附件信息及link中的doc
.
setPropName
(
"target"
).
setPropName
(
"source"
).
build
();
SearchQueryCondition
query
=
SearchQueryCondition
.
builder
()
List
<
ExtFilesDocLinkVO
>
extFilesDocLinkVOList
=
extFilesDocLinkService
.
findRecursion
(
searchQueryCondition
).
getContent
();
.
openProp
(
SearchQueryCondition
.
builder
().
name
(
"objFileLinks"
).
build
())
if
(
CollectionUtils
.
isNotEmpty
(
extFilesDocLinkVOList
))
{
.
openProp
(
SearchQueryCondition
.
builder
().
name
(
"extFilesDocLinks"
)
ExtFilesVO
extFilesVO
=
extFilesDocLinkVOList
.
get
(
0
).
getTarget
();
.
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模型)数据并填充到模板中
//1.获取案卷下所有的档案(doc模型)数据并填充到模板中
Map
<
String
,
Object
>
wordFillDataForJN
=
getJNDirectoryFillData
(
extFilesDocLinkVOList
,
extFilesVO
);
Map
<
String
,
Object
>
wordFillDataForJN
=
getJNDirectoryFillData
(
extFilesDocLinkVOList
,
extFilesVO
);
String
JNDirectoryPdfPath
=
fillWordAndConvertPdf
(
"卷内目录模板.docx"
,
wordFillDataForJN
,
getJNMLFileName
(
extFilesVO
));
String
JNDirectoryPdfPath
=
fillWordAndConvertPdf
(
"卷内目录模板.docx"
,
wordFillDataForJN
,
getJNMLFileName
(
extFilesVO
)
,
tempDir
);
//2.获取备考表需要填充的数据并填充数据到模板中
//2.获取备考表需要填充的数据并填充数据到模板中
Map
<
String
,
Object
>
wordFillDataForBK
=
getJNBKTableFillData
(
extFilesDocLinkVOList
,
extFilesVO
);
Map
<
String
,
Object
>
wordFillDataForBK
=
getJNBKTableFillData
(
extFilesDocLinkVOList
,
extFilesVO
);
String
BKPdfPath
=
fillWordAndConvertPdf
(
"卷内备考表模板.docx"
,
wordFillDataForBK
,
getBKFileName
(
extFilesVO
));
String
BKPdfPath
=
fillWordAndConvertPdf
(
"卷内备考表模板.docx"
,
wordFillDataForBK
,
getBKFileName
(
extFilesVO
)
,
tempDir
);
//3.上传卷内文档目录文件
//3.上传卷内文档目录文件
MultipartFile
multipartFileForJN
=
DxObjFileUtils
.
createFile
(
JNDirectoryPdfPath
);
MultipartFile
multipartFileForJN
=
DxObjFileUtils
.
createFile
(
JNDirectoryPdfPath
);
...
@@ -423,7 +442,7 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
...
@@ -423,7 +442,7 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
extFilesVO
.
setOperator
(
OperatorType
.
MODIFY
);
extFilesVO
.
setOperator
(
OperatorType
.
MODIFY
);
this
.
saveRecursion
((
V
)
extFilesVO
);
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
...
@@ -616,7 +635,7 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
throw
new
DxBusinessException
(
"500"
,
"必须要选中一条案卷"
);
throw
new
DxBusinessException
(
"500"
,
"必须要选中一条案卷"
);
}
}
//临时文件目录
//临时文件目录
String
tempDir
=
ResourceHelper
.
createTem
p
Dir
().
getPath
();
String
tempDir
=
ResourceHelper
.
createTemDir
().
getPath
();
//文件id集合
//文件id集合
List
<
Long
>
fileIds
=
new
ArrayList
<>();
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 {
...
@@ -162,16 +162,14 @@ public class ResourceHelper {
public
static
String
getBaseHomeDir
()
{
public
static
String
getBaseHomeDir
()
{
if
(
StringUtils
.
isEmpty
(
baseHomeDir
))
{
if
(
StringUtils
.
isEmpty
(
baseHomeDir
))
{
ApplicationHome
home
=
new
ApplicationHome
(
PDFUtil
.
class
);
ApplicationHome
home
=
new
ApplicationHome
(
PDFUtil
.
class
);
baseHomeDir
=
home
.
getSource
().
getParentFile
().
getPath
();
baseHomeDir
=
home
.
getSource
().
getParentFile
().
getPa
rentFile
().
getPa
th
();
}
}
return
baseHomeDir
;
return
baseHomeDir
;
}
}
public
static
File
createTemDir
()
{
public
static
File
createTemDir
()
{
String
uuid
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
String
uuid
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
String
temDir
=
getBaseHomeDir
()
+
File
.
separator
+
String
temDir
=
getBaseHomeDir
()
+
File
.
separator
+
"fileTempDir"
+
File
.
separator
+
uuid
;
"tem"
+
File
.
separator
+
uuid
;
return
FileUtil
.
mkdir
(
temDir
);
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