Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
patzn-cloud-service-soil
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-soil
Commits
fb91c167
Commit
fb91c167
authored
Dec 19, 2020
by
wangweidong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
土工平台修改
parent
9bd86238
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
138 additions
and
45 deletions
+138
-45
SoilExperimentServiceImpl.java
...ice/lims/soil/service/impl/SoilExperimentServiceImpl.java
+138
-45
No files found.
src/main/java/com/patzn/cloud/service/lims/soil/service/impl/SoilExperimentServiceImpl.java
View file @
fb91c167
...
@@ -38,8 +38,11 @@ import jcifs.smb.SmbFile;
...
@@ -38,8 +38,11 @@ import jcifs.smb.SmbFile;
import
net.coobird.thumbnailator.Thumbnails
;
import
net.coobird.thumbnailator.Thumbnails
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.ss.usermodel.CellType
;
import
org.apache.poi.ss.usermodel.CellType
;
import
org.apache.poi.ss.usermodel.DataValidation
;
import
org.apache.poi.ss.usermodel.DataValidationConstraint
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.ss.util.CellRangeAddressList
;
import
org.apache.poi.xssf.usermodel.*
;
import
org.apache.poi.xssf.usermodel.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -197,6 +200,7 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
...
@@ -197,6 +200,7 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
@Override
public
SoilOriginalRecord
saveExcelOriginalRecord
(
Long
[]
ids
,
Long
templateId
,
Account
account
)
{
public
SoilOriginalRecord
saveExcelOriginalRecord
(
Long
[]
ids
,
Long
templateId
,
Account
account
)
{
...
@@ -248,7 +252,11 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
...
@@ -248,7 +252,11 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
XSSFSheet
sheetOne
=
xssfWorkbook
.
getSheetAt
(
0
);
XSSFSheet
sheetOne
=
xssfWorkbook
.
getSheetAt
(
0
);
sheetOne
.
setForceFormulaRecalculation
(
true
);
sheetOne
.
setForceFormulaRecalculation
(
true
);
logger
.
error
(
"----------------------5"
);
logger
.
error
(
"----------------------5"
);
if
(
null
!=
template
.
getSampleBeginRow
()
Integer
beginRow
=
template
.
getSampleBeginRow
();
if
(
null
!=
beginRow
&&
null
!=
template
.
getSampleMergerNum
()
&&
null
!=
template
.
getSampleMergerNum
()
&&
null
!=
template
.
getTemplateSampleNum
()){
&&
null
!=
template
.
getTemplateSampleNum
()){
logger
.
error
(
"不为空"
);
logger
.
error
(
"不为空"
);
...
@@ -258,22 +266,71 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
...
@@ -258,22 +266,71 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
int
templateSampleNum
=
template
.
getTemplateSampleNum
();
int
templateSampleNum
=
template
.
getTemplateSampleNum
();
if
(
voList
.
size
()<
templateSampleNum
){
if
(
voList
.
size
()<
templateSampleNum
){
logger
.
error
(
"----------------------6"
);
logger
.
error
(
"----------------------6"
);
int
beginRow
=
template
.
getSampleBeginRow
();
int
sampleMergerNum
=
template
.
getSampleMergerNum
();
int
sampleMergerNum
=
template
.
getSampleMergerNum
();
int
sn
=
1
;
for
(
SoilExperimentVO
vo:
voList
)
{
for
(
SoilExperimentVO
vo:
voList
)
{
XSSFRow
xssfRow
=
sheetOne
.
getRow
(
beginRow
);
XSSFRow
xssfRow
=
sheetOne
.
getRow
(
beginRow
);
for
(
SoilOriginalTemplateConfig
config:
configList
)
{
for
(
SoilOriginalTemplateConfig
config:
configList
)
{
XSSFCell
cell
=
xssfRow
.
getCell
(
config
.
getColumnPlace
());
XSSFCell
cell
=
xssfRow
.
getCell
(
config
.
getColumnPlace
());
if
(
"sn"
.
equals
(
config
.
getDataAttribute
())){
continue
;
}
cell
.
setCellValue
(
StringHandleUtils
.
getFieldIfNummReturnBlankValueByFieldName
(
config
.
getDataAttribute
(),
vo
));
cell
.
setCellValue
(
StringHandleUtils
.
getFieldIfNummReturnBlankValueByFieldName
(
config
.
getDataAttribute
(),
vo
));
sn
++;
}
}
beginRow
+=
sampleMergerNum
;
beginRow
+=
sampleMergerNum
;
}
}
for
(
SoilOriginalTemplateConfig
config:
configList
)
{
if
(
StringUtils
.
isNotBlank
(
config
.
getFormula
())&&
null
!=
config
.
getColumnPlace
()
&&
null
!=
config
.
getMergeRowNum
()){
Integer
sampleBgMum
=
template
.
getSampleBeginRow
();
Integer
mergeRowNum
=
config
.
getMergeRowNum
();
int
formulaNum
=
template
.
getSampleBeginRow
()+
sampleMergerNum
*
voList
.
size
()-
1
;
for
(
int
i
=
sampleBgMum
;
i
<
formulaNum
;
i
+=
mergeRowNum
)
{
XSSFRow
row
=
sheetOne
.
getRow
(
i
);
XSSFCell
cell
=
row
.
getCell
(
config
.
getColumnPlace
());
String
formula
=
config
.
getFormula
();
formula
=
formula
.
replace
(
"#{sn}"
,(
i
+
1
)+
""
);
if
(
formula
.
contains
(
"#{sn+1}"
)){
formula
=
formula
.
replace
(
"#{sn+1}"
,(
i
+
2
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+2}"
)){
formula
=
formula
.
replace
(
"#{sn+2}"
,(
i
+
3
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+3}"
)){
formula
=
formula
.
replace
(
"#{sn+3}"
,(
i
+
4
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+4}"
)){
formula
=
formula
.
replace
(
"#{sn+4}"
,(
i
+
5
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+5}"
)){
formula
=
formula
.
replace
(
"#{sn+5}"
,(
i
+
6
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+6}"
)){
formula
=
formula
.
replace
(
"#{sn+6}"
,(
i
+
7
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+7}"
)){
formula
=
formula
.
replace
(
"#{sn+7}"
,(
i
+
8
)+
""
);
}
cell
.
setCellFormula
(
formula
);
}
}
}
logger
.
error
(
"----------------------7"
);
logger
.
error
(
"----------------------7"
);
}
else
{
}
else
{
logger
.
error
(
"----------------------8"
);
logger
.
error
(
"----------------------8"
);
int
beginRow
=
template
.
getSampleBeginRow
();
int
sampleMergerNum
=
template
.
getSampleMergerNum
();
int
sampleMergerNum
=
template
.
getSampleMergerNum
();
int
insertRow
=
beginRow
+
sampleMergerNum
*
templateSampleNum
;
int
insertRow
=
beginRow
+
sampleMergerNum
*
templateSampleNum
;
logger
.
error
(
"---------------------9"
);
logger
.
error
(
"---------------------9"
);
...
@@ -284,7 +341,7 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
...
@@ -284,7 +341,7 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
int
mergerB
=
insertRow
;
...
@@ -307,6 +364,8 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
...
@@ -307,6 +364,8 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
logger
.
error
(
"----------------------12"
);
logger
.
error
(
"----------------------12"
);
for
(
int
m
=
0
;
m
<
insertCount
;
m
++)
{
for
(
int
m
=
0
;
m
<
insertCount
;
m
++)
{
for
(
int
i
=
0
;
i
<
sampleMergerNum
;
i
++)
{
for
(
int
i
=
0
;
i
<
sampleMergerNum
;
i
++)
{
sheetOne
.
shiftRows
(
insertRow
,
sheetOne
.
getLastRowNum
(),
1
,
true
,
false
);
sheetOne
.
shiftRows
(
insertRow
,
sheetOne
.
getLastRowNum
(),
1
,
true
,
false
);
...
@@ -318,44 +377,10 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
...
@@ -318,44 +377,10 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
insertRow
++;
insertRow
++;
}
}
}
for
(
SoilOriginalTemplateConfig
config:
configList
)
{
if
(
null
!=
config
.
getMergeRowNum
()){
sheetOne
.
addMergedRegion
(
new
CellRangeAddress
(
mergerB
,
mergerB
+
sampleMergerNum
-
1
,
config
.
getMergeBegin
(),
config
.
getMergeEnd
()));
if
(
StringUtils
.
isNotBlank
(
config
.
getFormula
())){
XSSFRow
fRow
=
sheetOne
.
getRow
(
mergerB
);
XSSFCell
fCell
=
fRow
.
getCell
(
config
.
getColumnPlace
());
String
formula
=
config
.
getFormula
();
fCell
.
setCellType
(
CellType
.
FORMULA
);
formula
=
formula
.
replace
(
"#{sn}"
,
mergerB
+
""
);
fCell
.
setCellFormula
(
formula
);
}
}
else
{
for
(
int
i
=
0
;
i
<
sampleMergerNum
;
i
++)
{
if
(
config
.
getMergeBegin
()!=
null
&&
config
.
getMergeEnd
()!=
null
&&
config
.
getMergeEnd
()>
config
.
getMergeBegin
()){
sheetOne
.
addMergedRegion
(
new
CellRangeAddress
(
mergerB
+
i
,
mergerB
+
i
,
config
.
getMergeBegin
(),
config
.
getMergeEnd
()));
if
(
StringUtils
.
isNotBlank
(
config
.
getFormula
())){
XSSFRow
fRow
=
sheetOne
.
getRow
(
mergerB
+
i
);
XSSFCell
fCell
=
fRow
.
getCell
(
config
.
getColumnPlace
());
String
formula
=
config
.
getFormula
();
formula
=
formula
.
replace
(
"#{sn}"
,
mergerB
+
i
+
""
);
fCell
.
setCellFormula
(
formula
);
}
}
else
{
}
}
}
}
mergerB
=
mergerB
+
sampleMergerNum
;
}
logger
.
error
(
"----------------------14"
);
logger
.
error
(
"----------------------14"
);
int
sn
=
1
;
int
sn
=
1
;
for
(
SoilExperimentVO
vo:
voList
)
{
for
(
SoilExperimentVO
vo:
voList
)
{
...
@@ -371,22 +396,90 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
...
@@ -371,22 +396,90 @@ public class SoilExperimentServiceImpl extends BaseServiceImpl<SoilExperimentMap
}
else
{
}
else
{
cell
.
setCellValue
(
StringHandleUtils
.
getFieldIfNummReturnBlankValueByFieldName
(
config
.
getDataAttribute
(),
vo
));
cell
.
setCellValue
(
StringHandleUtils
.
getFieldIfNummReturnBlankValueByFieldName
(
config
.
getDataAttribute
(),
vo
));
}
}
if
(
StringUtils
.
isNotBlank
(
config
.
getFormula
())&&
null
!=
config
.
getColumnPlace
()){
}
beginRow
+=
sampleMergerNum
;
sn
++;
}
for
(
SoilOriginalTemplateConfig
config:
configList
)
{
if
(
null
==
config
.
getMergeRowNum
()){
config
.
setMergeRowNum
(
1
);
}
if
(
StringUtils
.
isNotBlank
(
config
.
getFormula
())&&
null
!=
config
.
getColumnPlace
()
&&
null
!=
config
.
getMergeRowNum
()){
Integer
sampleBgMum
=
template
.
getSampleBeginRow
();
Integer
mergeRowNum
=
config
.
getMergeRowNum
();
int
formulaNum
=
template
.
getSampleBeginRow
()+
sampleMergerNum
*
voList
.
size
()-
1
;
for
(
int
i
=
sampleBgMum
;
i
<
formulaNum
;
i
+=
mergeRowNum
)
{
XSSFRow
row
=
sheetOne
.
getRow
(
i
);
XSSFCell
cell
=
row
.
getCell
(
config
.
getColumnPlace
());
String
formula
=
config
.
getFormula
();
String
formula
=
config
.
getFormula
();
formula
=
formula
.
replace
(
"#{sn}"
,(
beginRow
+
1
)+
""
);
formula
=
formula
.
replace
(
"#{sn}"
,(
i
+
1
)+
""
);
if
(
formula
.
contains
(
"#{sn+1}"
)){
formula
=
formula
.
replace
(
"#{sn+1}"
,(
i
+
2
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+2}"
)){
formula
=
formula
.
replace
(
"#{sn+2}"
,(
i
+
3
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+3}"
)){
formula
=
formula
.
replace
(
"#{sn+3}"
,(
i
+
4
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+4}"
)){
formula
=
formula
.
replace
(
"#{sn+4}"
,(
i
+
5
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+5}"
)){
formula
=
formula
.
replace
(
"#{sn+5}"
,(
i
+
6
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+6}"
)){
formula
=
formula
.
replace
(
"#{sn+6}"
,(
i
+
7
)+
""
);
}
if
(
formula
.
contains
(
"#{sn+7}"
)){
formula
=
formula
.
replace
(
"#{sn+7}"
,(
i
+
8
)+
""
);
}
cell
.
setCellFormula
(
formula
);
cell
.
setCellFormula
(
formula
);
}
}
}
}
beginRow
+=
sampleMergerNum
;
}
sn
++;
for
(
SoilOriginalTemplateConfig
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
=
template
.
getSampleBeginRow
()+
templateSampleNum
*
sampleMergerNum
;
Integer
sampleEnMum
=
template
.
getSampleBeginRow
()+
voList
.
size
()*
sampleMergerNum
-
1
;
while
(
sampleBgMum
<=
sampleEnMum
)
{
sheetOne
.
addMergedRegion
(
new
CellRangeAddress
(
sampleBgMum
,
sampleBgMum
+
step
-
1
,
config
.
getMergeBegin
(),
config
.
getMergeEnd
()));
sampleBgMum
=
sampleBgMum
+
step
;
}
}
}
}
logger
.
error
(
"----------------------15"
);
logger
.
error
(
"----------------------15"
);
}
}
}
}
logger
.
error
(
"----------------------16"
);
// XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheetOne);
// DataValidationConstraint dvConstraint= dvHelper.createFormulaListConstraint("现用盒号盒重!$A$2:$A$567");
//
// CellRangeAddressList addressList = new CellRangeAddressList((short) beginRow.intValue(), (short) sheetOne.getLastRowNum(), (short) 3, (short)4);
// XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList);
// sheetOne.addValidationData(validation);
FileOutputStream
os
=
null
;
FileOutputStream
os
=
null
;
File
file
=
null
;
File
file
=
null
;
String
generated
=
"原始记录"
;
String
generated
=
"原始记录"
;
...
...
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