Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
patzn-cloud-service-hmhj
Overview
Overview
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
wangweidong
patzn-cloud-service-hmhj
Commits
f98d2cc9
Commit
f98d2cc9
authored
Jun 11, 2021
by
wangweidong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
霍煤鸿骏系统
parent
f8866f2e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
254 additions
and
53 deletions
+254
-53
StringHandleUtils.java
...om/patzn/cloud/service/lims/common/StringHandleUtils.java
+21
-1
EntrustSampleServiceImpl.java
...vice/lims/hmhj/service/impl/EntrustSampleServiceImpl.java
+233
-52
No files found.
src/main/java/com/patzn/cloud/service/lims/common/StringHandleUtils.java
View file @
f98d2cc9
...
@@ -3,6 +3,8 @@ package com.patzn.cloud.service.lims.common;
...
@@ -3,6 +3,8 @@ package com.patzn.cloud.service.lims.common;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.patzn.cloud.commons.enums.IBaseEnum
;
import
com.patzn.cloud.commons.enums.IBaseEnum
;
import
com.patzn.cloud.commons.toolkit.DateUtils
;
import
com.patzn.cloud.commons.toolkit.DateUtils
;
import
com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO
;
import
com.patzn.cloud.service.hmhj.vo.EntrustSampleVO
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -609,5 +611,23 @@ public class StringHandleUtils {
...
@@ -609,5 +611,23 @@ public class StringHandleUtils {
}
}
public
static
String
getFieldValue
(
String
dataAttribute
,
EntrustSampleVO
vo
)
{
if
(
StringUtils
.
isBlank
(
dataAttribute
)){
return
""
;
}
if
(
StringHandleUtils
.
is_alpha
(
dataAttribute
)){
return
StringHandleUtils
.
getFieldIfNummReturnBlankValueByFieldName
(
dataAttribute
,
vo
);
}
else
{
List
<
EntrustSampleItemVO
>
sampleItemVOList
=
vo
.
getItemVOList
();
if
(
CollectionUtils
.
isEmpty
(
sampleItemVOList
)){
return
""
;
}
for
(
EntrustSampleItemVO
itemVO
:
sampleItemVOList
)
{
if
(
dataAttribute
.
equals
(
itemVO
.
getName
())){
return
itemVO
.
getTestValue
();
}
}
}
return
""
;
}
}
}
src/main/java/com/patzn/cloud/service/lims/hmhj/service/impl/EntrustSampleServiceImpl.java
View file @
f98d2cc9
...
@@ -16,12 +16,15 @@ import com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO;
...
@@ -16,12 +16,15 @@ import com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO;
import
com.patzn.cloud.service.hmhj.vo.EntrustSampleVO
;
import
com.patzn.cloud.service.hmhj.vo.EntrustSampleVO
;
import
com.patzn.cloud.service.lims.common.StringHandleUtils
;
import
com.patzn.cloud.service.lims.common.StringHandleUtils
;
import
com.patzn.cloud.service.lims.hmhj.mapper.EntrustSampleMapper
;
import
com.patzn.cloud.service.lims.hmhj.mapper.EntrustSampleMapper
;
import
com.patzn.cloud.service.lims.hmhj.original.OriginalUtil
;
import
com.patzn.cloud.service.lims.hmhj.service.*
;
import
com.patzn.cloud.service.lims.hmhj.service.*
;
import
com.patzn.cloud.commons.service.impl.BaseServiceImpl
;
import
com.patzn.cloud.commons.service.impl.BaseServiceImpl
;
import
com.patzn.poibox.xwpf.PoiUtil2007
;
import
com.patzn.poibox.xwpf.PoiUtil2007
;
import
com.patzn.poibox.xwpf.XWPFTemplate
;
import
com.patzn.poibox.xwpf.XWPFTemplate
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.xssf.usermodel.*
;
import
org.apache.poi.xwpf.usermodel.XWPFDocument
;
import
org.apache.poi.xwpf.usermodel.XWPFDocument
;
import
org.apache.poi.xwpf.usermodel.XWPFTable
;
import
org.apache.poi.xwpf.usermodel.XWPFTable
;
import
org.apache.poi.xwpf.usermodel.XWPFTableCell
;
import
org.apache.poi.xwpf.usermodel.XWPFTableCell
;
...
@@ -35,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
...
@@ -35,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -68,7 +72,8 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
...
@@ -68,7 +72,8 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
@Autowired
@Autowired
private
IEntrustReportService
entrustReportService
;
private
IEntrustReportService
entrustReportService
;
@Autowired
private
IOriginalTemplateConfigService
originalTemplateConfigService
;
@Autowired
@Autowired
private
IEntrustService
entrustService
;
private
IEntrustService
entrustService
;
...
@@ -269,10 +274,6 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
...
@@ -269,10 +274,6 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
Entrust
entrust
=
entrustService
.
getById
(
entrustId
);
Entrust
entrust
=
entrustService
.
getById
(
entrustId
);
EntrustReportTemplate
sysFileTemplate
=
entrustReportTemplateService
.
getById
(
templateId
);
EntrustReportTemplate
sysFileTemplate
=
entrustReportTemplateService
.
getById
(
templateId
);
RestAssert
.
fail
(
null
==
sysFileTemplate
,
"选择的报告模板不存在"
);
Set
<
String
>
sampleNameSet
=
new
HashSet
<>();
Set
<
String
>
sampleNameSet
=
new
HashSet
<>();
...
@@ -281,59 +282,239 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
...
@@ -281,59 +282,239 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
}
}
String
sampleName
=
StringHandleUtils
.
join
(
sampleNameSet
);
String
sampleName
=
StringHandleUtils
.
join
(
sampleNameSet
);
String
sampleShape
=
sampleList
.
get
(
0
).
getSampleShape
();
if
(
sysFileTemplate
.
getName
().
contains
(
".docx"
)){
RestAssert
.
fail
(
null
==
sysFileTemplate
,
"选择的报告模板不存在"
);
String
sampleShape
=
sampleList
.
get
(
0
).
getSampleShape
();
Map
<
String
,
Object
>
contractMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
contractMap
=
new
HashMap
<>();
contractMap
.
put
(
"s"
,
entrust
);
contractMap
.
put
(
"s"
,
entrust
);
contractMap
.
put
(
"sampleName"
,
sampleName
);
contractMap
.
put
(
"sampleName"
,
sampleName
);
contractMap
.
put
(
"sampleShape"
,
sampleShape
);
contractMap
.
put
(
"sampleShape"
,
sampleShape
);
InputStream
io
=
ossClient
.
download
(
sysFileTemplate
.
getObjectKey
());
InputStream
io
=
ossClient
.
download
(
sysFileTemplate
.
getObjectKey
());
XWPFTemplate
xwpfTemplate
=
null
;
XWPFTemplate
xwpfTemplate
=
null
;
try
{
try
{
xwpfTemplate
=
XWPFTemplate
.
compile
(
io
).
setDefaultValue
(
"/"
).
render
(
contractMap
);
xwpfTemplate
=
XWPFTemplate
.
compile
(
io
).
setDefaultValue
(
"/"
).
render
(
contractMap
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"生成报告失败"
,
e
);
logger
.
error
(
"生成报告失败"
,
e
);
RestAssert
.
fail
(
"报告生成失败:"
+
e
.
getMessage
());
RestAssert
.
fail
(
"报告生成失败:"
+
e
.
getMessage
());
}
}
XWPFDocument
baseDoc
=
xwpfTemplate
.
getXWPFDocument
();
XWPFDocument
baseDoc
=
xwpfTemplate
.
getXWPFDocument
();
List
<
EntrustSampleItemVO
>
sampleItemVOList
=
entrustSampleItemService
.
listBySampleIds
(
ids
);
List
<
XWPFTable
>
tableList
=
baseDoc
.
getTables
();
for
(
XWPFTable
xwpfTable
:
tableList
)
{
String
text
=
xwpfTable
.
getText
();
if
(
com
.
patzn
.
cloud
.
commons
.
toolkit
.
StringHandleUtils
.
containsString
(
text
,
"{name}"
,
"{sampleCode}"
,
"{agreedValue}"
,
"{testValue}"
))
{
//检测内容
reportMakeTestContent
(
xwpfTable
,
sampleItemVOList
.
size
(),
1
,
sampleItemVOList
);
}
}
String
generated
=
entrust
.
getCode
();
FileOutputStream
os
=
null
;
File
file
=
null
;
try
{
file
=
File
.
createTempFile
(
generated
,
".docx"
);
os
=
new
FileOutputStream
(
file
);
baseDoc
.
write
(
os
);
os
.
flush
();
entrustReportService
.
uploadReportGenerateDocx
(
entrust
,
ids
,
account
,
StringHandleUtils
.
join
(
sampleNameSet
),
"报告生成"
,
file
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
os
.
close
();
baseDoc
.
close
();
io
.
close
();
FileUtils
.
deleteFiles
(
file
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
else
if
(
sysFileTemplate
.
getName
().
contains
(
".xlsx"
)){
List
<
EntrustSampleItemVO
>
sampleItemVOList
=
entrustSampleItemService
.
listBySampleIds
(
ids
);
List
<
EntrustSampleVO
>
sampleVOList
=
new
ArrayList
<>();
for
(
EntrustSample
sample
:
sampleList
)
{
EntrustSampleVO
vo
=
sample
.
convert
(
EntrustSampleVO
.
class
);
List
<
EntrustSampleItemVO
>
sampleItemList
=
new
ArrayList
<>();
for
(
EntrustSampleItemVO
itemVO
:
sampleItemVOList
)
{
if
(
sample
.
getId
().
equals
(
itemVO
.
getEntrustSampleId
())){
sampleItemList
.
add
(
itemVO
);
}
}
vo
.
setItemVOList
(
sampleItemList
);
sampleVOList
.
add
(
vo
);
}
InputStream
io
=
ossClient
.
download
(
sysFileTemplate
.
getObjectKey
());
XSSFWorkbook
xssfWorkbook
=
null
;
try
{
xssfWorkbook
=
new
XSSFWorkbook
(
io
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
List
<
OriginalTemplateConfig
>
configList
=
originalTemplateConfigService
.
list
(
Condition
.
create
().
eq
(
"template_id"
,
templateId
));
OriginalUtil
.
doReplace
(
xssfWorkbook
,
entrust
);
XSSFSheet
sheetOne
=
xssfWorkbook
.
getSheetAt
(
0
);
String
sheetName
=
sheetOne
.
getSheetName
();
System
.
out
.
println
(
sheetName
);
sheetOne
.
setForceFormulaRecalculation
(
true
);
Integer
beginRow
=
sysFileTemplate
.
getSampleBeginRow
();
int
sampleMergerNum
=
sysFileTemplate
.
getSampleMergerNum
();
int
templateSampleNum
=
sysFileTemplate
.
getTemplateSampleNum
();
if
(
templateSampleNum
>=
sampleVOList
.
size
()){
for
(
EntrustSampleVO
vo:
sampleVOList
)
{
XSSFRow
xssfRow
=
sheetOne
.
getRow
(
beginRow
);
for
(
OriginalTemplateConfig
config:
configList
)
{
XSSFCell
cell
=
xssfRow
.
getCell
(
config
.
getColumnPlace
());
if
(
"sn"
.
equals
(
config
.
getDataAttribute
())){
continue
;
}
if
(
StringUtils
.
isBlank
(
config
.
getDataAttribute
())){
continue
;
}
String
value
=
StringHandleUtils
.
getFieldValue
(
config
.
getDataAttribute
(),
vo
);
cell
.
setCellValue
(
value
);
}
beginRow
+=
sampleMergerNum
;
}
String
generated
=
entrust
.
getCode
();
FileOutputStream
os
=
null
;
File
file
=
null
;
try
{
file
=
File
.
createTempFile
(
generated
,
".docx"
);
os
=
new
FileOutputStream
(
file
);
xssfWorkbook
.
write
(
os
);
os
.
flush
();
entrustReportService
.
uploadReportGenerateDocx
(
entrust
,
ids
,
account
,
StringHandleUtils
.
join
(
sampleNameSet
),
"报告生成"
,
file
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
xssfWorkbook
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
io
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
FileUtils
.
deleteFiles
(
file
);
}
}
else
{
int
insertRow
=
beginRow
+
sampleMergerNum
*
templateSampleNum
;
XSSFRow
zeroRow
=
sheetOne
.
getRow
(
beginRow
);
XSSFCellStyle
cellStyle
=
zeroRow
.
getCell
(
0
).
getCellStyle
();
int
lastCellNum
=
zeroRow
.
getLastCellNum
();
int
insertCount
=
sampleVOList
.
size
()-
templateSampleNum
;
for
(
int
m
=
0
;
m
<
insertCount
;
m
++)
{
for
(
int
i
=
0
;
i
<
sampleMergerNum
;
i
++)
{
sheetOne
.
shiftRows
(
insertRow
,
sheetOne
.
getLastRowNum
(),
1
,
true
,
false
);
XSSFRow
row
=
sheetOne
.
createRow
(
insertRow
);
row
.
setHeight
(
zeroRow
.
getHeight
());
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
XSSFCell
xssfCell
=
row
.
createCell
(
j
);
xssfCell
.
setCellStyle
(
cellStyle
);
}
insertRow
++;
}
}
int
sn
=
1
;
for
(
EntrustSampleVO
vo:
sampleVOList
)
{
XSSFRow
xssfRow
=
sheetOne
.
getRow
(
beginRow
);
for
(
OriginalTemplateConfig
config:
configList
)
{
if
(
null
==
config
.
getColumnPlace
()){
continue
;
}
XSSFCell
cell
=
xssfRow
.
getCell
(
config
.
getColumnPlace
());
if
(
"sn"
.
equals
(
config
.
getDataAttribute
())){
cell
.
setCellValue
(
sn
);
}
else
{
cell
.
setCellValue
(
StringHandleUtils
.
getFieldValue
(
config
.
getDataAttribute
(),
vo
));
}
}
beginRow
+=
sampleMergerNum
;
sn
++;
}
for
(
OriginalTemplateConfig
config:
configList
)
{
if
(
null
==
config
.
getMergeRowNum
()){
config
.
setMergeRowNum
(
1
);
}
if
(
null
==
config
.
getMergeBegin
()){
continue
;
}
if
(
null
==
config
.
getMergeEnd
()){
continue
;
}
int
step
=
config
.
getMergeRowNum
();
if
(
step
==
1
&&
config
.
getMergeEnd
()
==
config
.
getMergeBegin
()){
continue
;
}
if
(
null
!=
config
.
getColumnPlace
()
&&
null
!=
config
.
getMergeRowNum
()){
Integer
sampleBgMum
=
sysFileTemplate
.
getSampleBeginRow
()+
templateSampleNum
*
sampleMergerNum
;
Integer
sampleEnMum
=
sysFileTemplate
.
getSampleBeginRow
()+
sampleVOList
.
size
()*
sampleMergerNum
-
1
;
while
(
sampleBgMum
<=
sampleEnMum
)
{
sheetOne
.
addMergedRegion
(
new
CellRangeAddress
(
sampleBgMum
,
sampleBgMum
+
step
-
1
,
config
.
getMergeBegin
(),
config
.
getMergeEnd
()));
sampleBgMum
=
sampleBgMum
+
step
;
}
}
}
}
String
generated
=
entrust
.
getCode
();
FileOutputStream
os
=
null
;
File
file
=
null
;
try
{
file
=
File
.
createTempFile
(
generated
,
".docx"
);
os
=
new
FileOutputStream
(
file
);
xssfWorkbook
.
write
(
os
);
os
.
flush
();
entrustReportService
.
uploadReportGenerateDocx
(
entrust
,
ids
,
account
,
StringHandleUtils
.
join
(
sampleNameSet
),
"报告生成"
,
file
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
xssfWorkbook
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
io
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
FileUtils
.
deleteFiles
(
file
);
}
List
<
EntrustSampleItemVO
>
sampleItemVOList
=
entrustSampleItemService
.
listBySampleIds
(
ids
);
}
List
<
XWPFTable
>
tableList
=
baseDoc
.
getTables
();
for
(
XWPFTable
xwpfTable
:
tableList
)
{
String
text
=
xwpfTable
.
getText
();
if
(
com
.
patzn
.
cloud
.
commons
.
toolkit
.
StringHandleUtils
.
containsString
(
text
,
"{name}"
,
"{sampleCode}"
,
"{agreedValue}"
,
"{testValue}"
))
{
//检测内容
reportMakeTestContent
(
xwpfTable
,
sampleItemVOList
.
size
(),
1
,
sampleItemVOList
);
}
}
String
generated
=
entrust
.
getCode
();
FileOutputStream
os
=
null
;
File
file
=
null
;
try
{
file
=
File
.
createTempFile
(
generated
,
".docx"
);
os
=
new
FileOutputStream
(
file
);
baseDoc
.
write
(
os
);
os
.
flush
();
entrustReportService
.
uploadReportGenerateDocx
(
entrust
,
ids
,
account
,
StringHandleUtils
.
join
(
sampleNameSet
),
"报告生成"
,
file
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
os
.
close
();
baseDoc
.
close
();
io
.
close
();
FileUtils
.
deleteFiles
(
file
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
true
;
return
true
;
}
}
...
...
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