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
a7fe5e1d
Commit
a7fe5e1d
authored
Nov 18, 2021
by
lijingjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
霍煤需求修改;
parent
56639177
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
272 additions
and
144 deletions
+272
-144
Operation.java
...com/patzn/cloud/service/lims/hmhj/original/Operation.java
+77
-0
SingleSheetMoreItemOperation.java
...vice/lims/hmhj/original/SingleSheetMoreItemOperation.java
+52
-73
SingleSheetMoreOperation.java
.../service/lims/hmhj/original/SingleSheetMoreOperation.java
+40
-64
EntrustSampleItemServiceImpl.java
.../lims/hmhj/service/impl/EntrustSampleItemServiceImpl.java
+14
-3
Test.java
src/test/java/com/patzn/cloud/service/lims/test/Test.java
+89
-4
No files found.
src/main/java/com/patzn/cloud/service/lims/hmhj/original/Operation.java
View file @
a7fe5e1d
package
com
.
patzn
.
cloud
.
service
.
lims
.
hmhj
.
original
;
import
com.patzn.cloud.service.lims.common.StringHandleUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.ss.usermodel.Cell
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
public
interface
Operation
{
void
doMakeOriginal
();
/**
* 对从直读光谱中抓取过来的原铝分析结果,进行修约
* @param cell
* @param value
* @param roundNum
*/
default
void
rounding
(
Cell
cell
,
String
value
,
Integer
roundNum
)
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(!
StringHandleUtils
.
validateNumber
(
value
))
{
if
(
value
.
startsWith
(
"!"
))
{
value
=
value
.
substring
(
1
);
}
else
{
cell
.
setCellValue
(
value
);
return
;
}
}
// IF(ABS(TRUNC(A1,B1+5)*10^B1-TRUNC(A1,B1+5)*10^B1)<0.499999,ROUND(A1,B1),
// IF(ABS(TRUNC(A1,B1+5)*10^B1-TRUNC(A1,B1+5)*10^B1)>0.500001,ROUND(A1,B1),
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1)))
int
beginIndex
=
value
.
lastIndexOf
(
"."
)
+
1
,
valueLength
=
value
.
length
();
int
remindLength
=
valueLength
-
beginIndex
;
String
truncValue
=
""
,
zeroStr
=
"000000000"
;
// bdA = TRUNC(A1,B1+5)*10^B1
if
(
remindLength
>=
roundNum
+
5
)
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
+
5
);
}
else
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
+
5
-
remindLength
);
}
BigDecimal
bdDiff
=
new
BigDecimal
(
truncValue
).
scaleByPowerOfTen
(
roundNum
);
// bdB = TRUNC(A1,B1+5)*10^B1
if
(
remindLength
>=
roundNum
)
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
);
}
else
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
-
remindLength
);
}
bdDiff
=
bdDiff
.
subtract
(
new
BigDecimal
(
truncValue
).
scaleByPowerOfTen
(
roundNum
)).
abs
();
// 若 < 0.499999 或 大于 0.500001
if
(
bdDiff
.
compareTo
(
new
BigDecimal
(
"0.499999"
))
<
0
||
bdDiff
.
compareTo
(
new
BigDecimal
(
"0.500001"
))
>
0
)
{
cell
.
setCellValue
(
new
BigDecimal
(
value
).
setScale
(
roundNum
,
RoundingMode
.
HALF_EVEN
).
toPlainString
());
return
;
}
// 处理第三种情况
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1))
if
(
remindLength
>=
roundNum
+
1
)
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
+
1
);
}
else
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
+
1
-
remindLength
);
}
bdDiff
=
new
BigDecimal
(
truncValue
);
bdDiff
=
bdDiff
.
subtract
(
new
BigDecimal
(
"0.5"
).
scaleByPowerOfTen
(-
roundNum
)).
abs
();
int
signValue
=
Integer
.
valueOf
(
value
).
compareTo
(
0
);
BigDecimal
significance
=
new
BigDecimal
(
"2"
).
scaleByPowerOfTen
(-
roundNum
).
multiply
(
BigDecimal
.
valueOf
(
signValue
)).
abs
();
// ceiling
BigDecimal
[]
result
=
bdDiff
.
divideAndRemainder
(
significance
);
if
(
result
[
1
].
compareTo
(
BigDecimal
.
ZERO
)
==
0
)
{
cell
.
setCellValue
(
bdDiff
.
toPlainString
());
}
else
{
cell
.
setCellValue
(
result
[
0
].
add
(
BigDecimal
.
ONE
).
multiply
(
significance
).
setScale
(
roundNum
).
toPlainString
());
}
}
}
}
src/main/java/com/patzn/cloud/service/lims/hmhj/original/SingleSheetMoreItemOperation.java
View file @
a7fe5e1d
...
...
@@ -6,12 +6,10 @@ import com.patzn.cloud.service.hmhj.entity.OriginalTemplateConfig;
import
com.patzn.cloud.service.hmhj.vo.EntrustSampleVO
;
import
com.patzn.cloud.service.lims.common.StringHandleUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.FormulaEvaluator
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.xssf.usermodel.*
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -21,30 +19,31 @@ public class SingleSheetMoreItemOperation implements Operation {
private
OriginalTemplate
template
;
private
List
<
EntrustSampleVO
>
voList
;
private
Entrust
entrust
;
private
Entrust
entrust
;
private
List
<
OriginalTemplateConfig
>
configList
;
private
XSSFWorkbook
xssfWorkbook
;
private
String
collectionDatePrefix
=
"clc."
;
private
HashMap
<
Long
,
Map
<
String
,
String
>>
sampleIdMap
=
new
HashMap
<>();
private
HashMap
<
Long
,
Map
<
String
,
String
>>
sampleIdMap
=
new
HashMap
<>();
private
FormulaEvaluator
formulaEvaluator
;
private
Map
<
Integer
,
String
>
valueMap
;
private
Map
<
Integer
,
String
>
valueMap
;
public
SingleSheetMoreItemOperation
(
OriginalTemplate
template
,
List
<
EntrustSampleVO
>
voList
,
Entrust
entrust
,
List
<
OriginalTemplateConfig
>
configList
,
XSSFWorkbook
xssfWorkbook
)
{
this
.
template
=
template
;
this
.
voList
=
voList
;
this
.
entrust
=
entrust
;
this
.
configList
=
configList
;
this
.
xssfWorkbook
=
xssfWorkbook
;
dealCollectionData
(
voList
,
configList
);
dealCollectionData
(
voList
,
configList
);
valueMap
=
new
HashMap
<>();
valueMap
.
put
(
1
,
"0.1"
);
valueMap
.
put
(
2
,
"0.01"
);
valueMap
.
put
(
3
,
"0.001"
);
valueMap
.
put
(
4
,
"0.0001"
);
valueMap
.
put
(
5
,
"0.00001"
);
valueMap
.
put
(
6
,
"0.000001"
);
valueMap
.
put
(
7
,
"0.0000001"
);
valueMap
.
put
(
8
,
"0.00000001"
);
valueMap
.
put
(
9
,
"0.000000001"
);
valueMap
.
put
(
1
,
"0.1"
);
valueMap
.
put
(
2
,
"0.01"
);
valueMap
.
put
(
3
,
"0.001"
);
valueMap
.
put
(
4
,
"0.0001"
);
valueMap
.
put
(
5
,
"0.00001"
);
valueMap
.
put
(
6
,
"0.000001"
);
valueMap
.
put
(
7
,
"0.0000001"
);
valueMap
.
put
(
8
,
"0.00000001"
);
valueMap
.
put
(
9
,
"0.000000001"
);
}
private
void
dealCollectionData
(
List
<
EntrustSampleVO
>
voList
,
List
<
OriginalTemplateConfig
>
configList
)
{
...
...
@@ -58,11 +57,11 @@ public class SingleSheetMoreItemOperation implements Operation {
for
(
Map
.
Entry
<
String
,
String
>
entry
:
map
.
entrySet
())
{
if
(
dataAtrrs
.
contains
(
entry
.
getKey
()))
{
HashMap
<
String
,
String
>
dataMap
=
new
HashMap
<>();
dataMap
.
put
(
entry
.
getKey
(),
entry
.
getValue
());
dataMap
.
put
(
entry
.
getKey
(),
entry
.
getValue
());
if
(
sampleIdMap
.
containsKey
(
vo
.
getId
()))
{
sampleIdMap
.
get
(
vo
.
getId
()).
put
(
entry
.
getKey
(),
entry
.
getValue
());
sampleIdMap
.
get
(
vo
.
getId
()).
put
(
entry
.
getKey
(),
entry
.
getValue
());
}
else
{
sampleIdMap
.
put
(
vo
.
getId
(),
dataMap
);
sampleIdMap
.
put
(
vo
.
getId
(),
dataMap
);
}
}
}
...
...
@@ -73,20 +72,20 @@ public class SingleSheetMoreItemOperation implements Operation {
@Override
public
void
doMakeOriginal
()
{
OriginalUtil
.
doReplace
(
xssfWorkbook
,
entrust
);
OriginalUtil
.
doReplace
(
xssfWorkbook
,
entrust
);
XSSFSheet
sheetOne
=
xssfWorkbook
.
getSheetAt
(
0
);
sheetOne
.
setForceFormulaRecalculation
(
true
);
Integer
beginRow
=
template
.
getSampleBeginRow
();
int
sampleMergerNum
=
template
.
getSampleMergerNum
();
int
templateSampleNum
=
template
.
getTemplateSampleNum
();
int
insertRow
=
beginRow
+
sampleMergerNum
*
templateSampleNum
;
int
insertRow
=
beginRow
+
sampleMergerNum
*
templateSampleNum
;
XSSFRow
zeroRow
=
sheetOne
.
getRow
(
beginRow
);
int
lastCellNum
=
zeroRow
.
getLastCellNum
();
int
insertCount
=
voList
.
size
()
-
templateSampleNum
;
for
(
int
m
=
0
;
m
<
insertCount
;
m
++)
{
int
insertCount
=
voList
.
size
()
-
templateSampleNum
;
for
(
int
m
=
0
;
m
<
insertCount
;
m
++)
{
for
(
int
i
=
0
;
i
<
sampleMergerNum
;
i
++)
{
sheetOne
.
shiftRows
(
insertRow
,
sheetOne
.
getLastRowNum
(),
1
,
true
,
false
);
sheetOne
.
shiftRows
(
insertRow
,
sheetOne
.
getLastRowNum
(),
1
,
true
,
false
);
XSSFRow
row
=
sheetOne
.
createRow
(
insertRow
);
row
.
setHeight
(
zeroRow
.
getHeight
());
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
...
...
@@ -101,7 +100,7 @@ public class SingleSheetMoreItemOperation implements Operation {
int
sn
=
1
;
for
(
EntrustSampleVO
vo
:
voList
)
{
for
(
EntrustSampleVO
vo
:
voList
)
{
XSSFRow
xssfRow
=
sheetOne
.
getRow
(
beginRow
);
XSSFRow
xssfRowTwo
=
null
;
XSSFRow
xssfRowThree
=
null
;
...
...
@@ -118,7 +117,7 @@ public class SingleSheetMoreItemOperation implements Operation {
xssfRowThree
=
sheetOne
.
getRow
(
beginRow
+
2
);
xssfRow4
=
sheetOne
.
getRow
(
beginRow
+
3
);
}
for
(
OriginalTemplateConfig
config
:
configList
)
{
for
(
OriginalTemplateConfig
config
:
configList
)
{
XSSFCell
cell
=
xssfRow
.
getCell
(
config
.
getColumnPlace
());
XSSFCell
cell2
=
null
;
XSSFCell
cell3
=
null
;
...
...
@@ -132,10 +131,10 @@ public class SingleSheetMoreItemOperation implements Operation {
if
(
null
!=
xssfRow4
)
{
cell4
=
xssfRow4
.
getCell
(
config
.
getColumnPlace
());
}
if
(
"sn"
.
equals
(
config
.
getDataAttribute
())){
if
(
"sn"
.
equals
(
config
.
getDataAttribute
()))
{
continue
;
}
if
(
StringUtils
.
isBlank
(
config
.
getDataAttribute
())){
if
(
StringUtils
.
isBlank
(
config
.
getDataAttribute
()))
{
continue
;
}
if
(
sampleIdMap
.
size
()
!=
0
&&
config
.
getDataAttribute
().
startsWith
(
collectionDatePrefix
))
{
...
...
@@ -143,18 +142,18 @@ public class SingleSheetMoreItemOperation implements Operation {
if
(
sampleIdMap
.
get
(
vo
.
getId
())
!=
null
&&
sampleIdMap
.
get
(
vo
.
getId
()).
size
()
>
0
)
{
if
(
null
!=
config
.
getRoundNum
())
{
// 需要修约
String
s
=
sampleIdMap
.
get
(
vo
.
getId
()).
get
(
mapKey
);
rounding
(
cell
,
s
,
config
.
getRoundNum
());
rounding
(
cell
,
s
,
config
.
getRoundNum
());
if
(
null
!=
cell2
&&
vo
.
getCollectionDataList
().
size
()
>=
2
)
{
String
s1
=
vo
.
getCollectionDataList
().
get
(
1
).
get
(
mapKey
);
rounding
(
cell2
,
s1
,
config
.
getRoundNum
());
rounding
(
cell2
,
s1
,
config
.
getRoundNum
());
}
if
(
null
!=
cell3
&&
vo
.
getCollectionDataList
().
size
()
>=
3
)
{
String
s2
=
vo
.
getCollectionDataList
().
get
(
2
).
get
(
mapKey
);
rounding
(
cell3
,
s2
,
config
.
getRoundNum
());
rounding
(
cell3
,
s2
,
config
.
getRoundNum
());
}
if
(
null
!=
cell4
&&
vo
.
getCollectionDataList
().
size
()
>=
4
)
{
String
s3
=
vo
.
getCollectionDataList
().
get
(
3
).
get
(
mapKey
);
rounding
(
cell4
,
s3
,
config
.
getRoundNum
());
rounding
(
cell4
,
s3
,
config
.
getRoundNum
());
}
continue
;
}
...
...
@@ -173,84 +172,65 @@ public class SingleSheetMoreItemOperation implements Operation {
}
continue
;
}
String
value
=
StringHandleUtils
.
getFieldIfNummReturnBlankValueByFieldName
(
config
.
getDataAttribute
(),
vo
);
String
value
=
StringHandleUtils
.
getFieldIfNummReturnBlankValueByFieldName
(
config
.
getDataAttribute
(),
vo
);
cell
.
setCellValue
(
value
);
}
beginRow
+=
sampleMergerNum
;
beginRow
+=
sampleMergerNum
;
sn
++;
}
// 公式
Integer
sampleBgMum
=
template
.
getSampleBeginRow
();
for
(
OriginalTemplateConfig
config
:
configList
)
{
if
(
null
==
config
.
getMergeRowNum
()){
for
(
OriginalTemplateConfig
config
:
configList
)
{
if
(
null
==
config
.
getMergeRowNum
())
{
config
.
setMergeRowNum
(
1
);
}
String
formula
=
config
.
getFormula
();
if
(
StringUtils
.
isBlank
(
formula
)){
if
(
StringUtils
.
isBlank
(
formula
))
{
continue
;
}
Integer
columnPlace
=
config
.
getColumnPlace
();
if
(
null
==
config
.
getColumnPlace
()){
if
(
null
==
config
.
getColumnPlace
())
{
continue
;
}
if
(
null
==
config
.
getMergeRowNum
())
{
if
(
null
==
config
.
getMergeRowNum
())
{
continue
;
}
Integer
mergeRowNum
=
config
.
getMergeRowNum
();
int
formulaNum
=
template
.
getSampleBeginRow
()
+
sampleMergerNum
*
templateSampleNum
-
1
;
int
formulaNum
=
template
.
getSampleBeginRow
()
+
sampleMergerNum
*
templateSampleNum
-
1
;
for
(
int
i
=
sampleBgMum
;
i
<=
formulaNum
;
i
+=
mergeRowNum
)
{
for
(
int
i
=
sampleBgMum
;
i
<=
formulaNum
;
i
+=
mergeRowNum
)
{
XSSFRow
row
=
sheetOne
.
getRow
(
i
);
XSSFCell
cell
=
row
.
getCell
(
columnPlace
);
cell
.
setCellFormula
(
OriginalUtil
.
initFormula
(
formula
,
i
));
cell
.
setCellFormula
(
OriginalUtil
.
initFormula
(
formula
,
i
));
}
}
// 合并单元格
for
(
OriginalTemplateConfig
config
:
configList
)
{
if
(
null
==
config
.
getMergeRowNum
())
{
for
(
OriginalTemplateConfig
config
:
configList
)
{
if
(
null
==
config
.
getMergeRowNum
())
{
config
.
setMergeRowNum
(
1
);
}
if
(
null
==
config
.
getMergeBegin
()){
if
(
null
==
config
.
getMergeBegin
())
{
continue
;
}
if
(
null
==
config
.
getMergeEnd
()){
if
(
null
==
config
.
getMergeEnd
())
{
continue
;
}
int
step
=
config
.
getMergeRowNum
();
if
(
step
==
1
&&
config
.
getMergeEnd
()
==
config
.
getMergeBegin
())
{
int
step
=
config
.
getMergeRowNum
();
if
(
step
==
1
&&
config
.
getMergeEnd
()
==
config
.
getMergeBegin
())
{
continue
;
}
if
(
null
!=
config
.
getColumnPlace
()
&&
null
!=
config
.
getMergeRowNum
()){
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
;
}
if
(
null
!=
config
.
getColumnPlace
()
&&
null
!=
config
.
getMergeRowNum
())
{
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
;
}
}
}
// 四舍六入五成双
private
static
void
rounding
(
Cell
cell
,
String
value
,
Integer
roundNum
)
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(!
StringHandleUtils
.
validateNumber
(
value
))
{
if
(
value
.
startsWith
(
"!"
))
{
value
=
value
.
substring
(
1
);
}
else
{
cell
.
setCellValue
(
value
);
return
;
}
}
BigDecimal
bd1
=
new
BigDecimal
(
value
);
BigDecimal
bd2
=
bd1
.
setScale
(
roundNum
,
BigDecimal
.
ROUND_HALF_EVEN
);
cell
.
setCellValue
(
bd2
.
toPlainString
());
}
}
}
\ No newline at end of file
src/main/java/com/patzn/cloud/service/lims/hmhj/original/SingleSheetMoreOperation.java
View file @
a7fe5e1d
...
...
@@ -7,20 +7,17 @@ import com.patzn.cloud.service.hmhj.entity.OriginalTemplateConfig;
import
com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO
;
import
com.patzn.cloud.service.lims.common.StringHandleUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.FormulaEvaluator
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.xssf.usermodel.*
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
SingleSheetMoreOperation
implements
Operation
{
private
OriginalTemplate
template
;
private
List
<
EntrustSampleItemVO
>
voList
;
private
Entrust
entrust
;
private
Entrust
entrust
;
private
List
<
OriginalTemplateConfig
>
configList
;
private
XSSFWorkbook
xssfWorkbook
;
private
String
collectionDataPrefix
=
"clc."
;
...
...
@@ -39,20 +36,20 @@ public class SingleSheetMoreOperation implements Operation {
@Override
public
void
doMakeOriginal
()
{
OriginalUtil
.
doReplace
(
xssfWorkbook
,
entrust
);
OriginalUtil
.
doReplace
(
xssfWorkbook
,
entrust
);
XSSFSheet
sheetOne
=
xssfWorkbook
.
getSheetAt
(
0
);
sheetOne
.
setForceFormulaRecalculation
(
true
);
Integer
beginRow
=
template
.
getSampleBeginRow
();
int
sampleMergerNum
=
template
.
getSampleMergerNum
();
int
templateSampleNum
=
template
.
getTemplateSampleNum
();
int
insertRow
=
beginRow
+
sampleMergerNum
*
templateSampleNum
;
int
insertRow
=
beginRow
+
sampleMergerNum
*
templateSampleNum
;
XSSFRow
zeroRow
=
sheetOne
.
getRow
(
beginRow
);
int
lastCellNum
=
zeroRow
.
getLastCellNum
();
int
insertCount
=
voList
.
size
()
-
templateSampleNum
;
for
(
int
m
=
0
;
m
<
insertCount
;
m
++)
{
int
insertCount
=
voList
.
size
()
-
templateSampleNum
;
for
(
int
m
=
0
;
m
<
insertCount
;
m
++)
{
for
(
int
i
=
0
;
i
<
sampleMergerNum
;
i
++)
{
sheetOne
.
shiftRows
(
insertRow
,
sheetOne
.
getLastRowNum
(),
1
,
true
,
false
);
sheetOne
.
shiftRows
(
insertRow
,
sheetOne
.
getLastRowNum
(),
1
,
true
,
false
);
XSSFRow
row
=
sheetOne
.
createRow
(
insertRow
);
row
.
setHeight
(
zeroRow
.
getHeight
());
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
...
...
@@ -67,7 +64,7 @@ public class SingleSheetMoreOperation implements Operation {
int
sn
=
1
;
for
(
EntrustSampleItemVO
vo
:
voList
)
{
for
(
EntrustSampleItemVO
vo
:
voList
)
{
XSSFRow
xssfRow
=
sheetOne
.
getRow
(
beginRow
);
XSSFRow
xssfRowTwo
=
null
;
XSSFRow
xssfRowThree
=
null
;
...
...
@@ -85,8 +82,8 @@ public class SingleSheetMoreOperation implements Operation {
xssfRow4
=
sheetOne
.
getRow
(
beginRow
+
3
);
}
for
(
OriginalTemplateConfig
config
:
configList
)
{
if
(
null
==
config
.
getColumnPlace
()){
for
(
OriginalTemplateConfig
config
:
configList
)
{
if
(
null
==
config
.
getColumnPlace
())
{
continue
;
}
XSSFCell
cell
=
xssfRow
.
getCell
(
config
.
getColumnPlace
());
...
...
@@ -105,26 +102,26 @@ public class SingleSheetMoreOperation implements Operation {
if
(
null
==
config
.
getDataAttribute
())
{
continue
;
}
if
(
"sn"
.
equals
(
config
.
getDataAttribute
())){
if
(
"sn"
.
equals
(
config
.
getDataAttribute
()))
{
cell
.
setCellValue
(
sn
);
}
else
if
(
config
.
getDataAttribute
().
startsWith
(
"clc."
))
{
String
mapKey
=
config
.
getDataAttribute
().
substring
(
4
);
if
(
CollectionUtils
.
isNotEmpty
(
vo
.
getCollectionDataList
()))
{
String
s
=
vo
.
getCollectionDataList
().
get
(
0
).
get
(
mapKey
);
if
(
null
!=
config
.
getRoundNum
())
{
// 需要修约
rounding
(
cell
,
s
,
config
.
getRoundNum
());
rounding
(
cell
,
s
,
config
.
getRoundNum
());
/* 下面为冗余代码,可能要删掉 */
if
(
null
!=
cell2
&&
vo
.
getCollectionDataList
().
size
()
>=
2
)
{
String
s1
=
vo
.
getCollectionDataList
().
get
(
1
).
get
(
mapKey
);
rounding
(
cell2
,
s1
,
config
.
getRoundNum
());
rounding
(
cell2
,
s1
,
config
.
getRoundNum
());
}
if
(
null
!=
cell3
&&
vo
.
getCollectionDataList
().
size
()
>=
3
)
{
String
s2
=
vo
.
getCollectionDataList
().
get
(
2
).
get
(
mapKey
);
rounding
(
cell3
,
s2
,
config
.
getRoundNum
());
rounding
(
cell3
,
s2
,
config
.
getRoundNum
());
}
if
(
null
!=
cell4
&&
vo
.
getCollectionDataList
().
size
()
>=
4
)
{
String
s3
=
vo
.
getCollectionDataList
().
get
(
3
).
get
(
mapKey
);
rounding
(
cell4
,
s3
,
config
.
getRoundNum
());
rounding
(
cell4
,
s3
,
config
.
getRoundNum
());
}
continue
;
}
...
...
@@ -142,72 +139,70 @@ public class SingleSheetMoreOperation implements Operation {
}
}
continue
;
}
else
{
cell
.
setCellValue
(
StringHandleUtils
.
getFieldIfNummReturnBlankValueByFieldName
(
config
.
getDataAttribute
(),
vo
));
}
else
{
cell
.
setCellValue
(
StringHandleUtils
.
getFieldIfNummReturnBlankValueByFieldName
(
config
.
getDataAttribute
(),
vo
));
}
}
beginRow
+=
sampleMergerNum
;
beginRow
+=
sampleMergerNum
;
sn
++;
}
for
(
OriginalTemplateConfig
config
:
configList
)
{
if
(
null
==
config
.
getMergeRowNum
())
{
for
(
OriginalTemplateConfig
config
:
configList
)
{
if
(
null
==
config
.
getMergeRowNum
())
{
config
.
setMergeRowNum
(
1
);
}
if
(
StringUtils
.
isNotBlank
(
config
.
getFormula
())
&&
null
!=
config
.
getColumnPlace
()
&&
null
!=
config
.
getMergeRowNum
())
{
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
)
{
int
formulaNum
=
template
.
getSampleBeginRow
()
+
sampleMergerNum
*
voList
.
size
()
-
1
;
for
(
int
i
=
sampleBgMum
;
i
<=
formulaNum
;
i
+=
mergeRowNum
)
{
XSSFRow
row
=
sheetOne
.
getRow
(
i
);
if
(
null
==
row
){
if
(
null
==
row
)
{
continue
;
}
XSSFCell
cell
=
row
.
getCell
(
config
.
getColumnPlace
());
if
(
null
==
cell
){
if
(
null
==
cell
)
{
continue
;
}
String
formula
=
config
.
getFormula
();
cell
.
setCellFormula
(
OriginalUtil
.
initFormula
(
formula
,
i
));
cell
.
setCellFormula
(
OriginalUtil
.
initFormula
(
formula
,
i
));
}
}
}
for
(
OriginalTemplateConfig
config:
configList
)
{
if
(
null
==
config
.
getMergeRowNum
()){
for
(
OriginalTemplateConfig
config
:
configList
)
{
if
(
null
==
config
.
getMergeRowNum
())
{
config
.
setMergeRowNum
(
1
);
}
if
(
null
==
config
.
getMergeBegin
()){
if
(
null
==
config
.
getMergeBegin
())
{
continue
;
}
if
(
null
==
config
.
getMergeEnd
()){
if
(
null
==
config
.
getMergeEnd
())
{
continue
;
}
int
step
=
config
.
getMergeRowNum
();
if
(
step
==
1
&&
config
.
getMergeEnd
()
==
config
.
getMergeBegin
())
{
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
;
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
;
}
}
}
// 处理曲线和空白
dealCurveAndBlank
(
configList
,
voList
,
template
,
xssfWorkbook
);
dealCurveAndBlank
(
configList
,
voList
,
template
,
xssfWorkbook
);
}
private
void
dealCurveAndBlank
(
List
<
OriginalTemplateConfig
>
configList
,
List
<
EntrustSampleItemVO
>
voList
,
OriginalTemplate
template
,
XSSFWorkbook
xssfWorkbook
)
{
Integer
curveBeginNum
=
template
.
getCurveBeginNum
();
Integer
blankBeginNum
=
template
.
getBlankBeginNum
();
List
<
Map
<
String
,
String
>>
curveDataList
=
null
;
Map
<
String
,
String
>
blankDataMap
=
null
;
List
<
Map
<
String
,
String
>>
curveDataList
=
null
;
Map
<
String
,
String
>
blankDataMap
=
null
;
XSSFSheet
sheet
=
xssfWorkbook
.
getSheetAt
(
0
);
if
(
CollectionUtils
.
isNotEmpty
(
voList
))
{
curveDataList
=
voList
.
get
(
0
).
getCurveDataList
();
...
...
@@ -230,7 +225,6 @@ public class SingleSheetMoreOperation implements Operation {
}
index
++;
}
}
// 填充空白
if
(
blankBeginNum
!=
null
&&
blankDataMap
!=
null
&&
blankDataMap
.
size
()
>
0
)
{
...
...
@@ -247,22 +241,4 @@ public class SingleSheetMoreOperation implements Operation {
}
}
}
// 四舍六入五成双
private
static
void
rounding
(
Cell
cell
,
String
value
,
Integer
roundNum
)
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(!
StringHandleUtils
.
validateNumber
(
value
))
{
if
(
value
.
startsWith
(
"!"
))
{
value
=
value
.
substring
(
1
);
}
else
{
cell
.
setCellValue
(
value
);
return
;
}
}
BigDecimal
bd1
=
new
BigDecimal
(
value
);
BigDecimal
bd2
=
bd1
.
setScale
(
roundNum
,
BigDecimal
.
ROUND_HALF_EVEN
);
cell
.
setCellValue
(
bd2
.
toPlainString
());
}
}
}
src/main/java/com/patzn/cloud/service/lims/hmhj/service/impl/EntrustSampleItemServiceImpl.java
View file @
a7fe5e1d
...
...
@@ -1199,9 +1199,20 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
String
objectKey
=
entry
.
getKey
();
Long
reportId
=
entry
.
getValue
();
entrustReport
.
setId
(
reportId
);
Map
<
String
,
String
>
sampleMap
=
reportSampleList
.
stream
().
filter
(
t
->
t
.
getObjectKey
().
equals
(
objectKey
)).
collect
(
Collectors
.
toMap
(
t
->
{
return
finalIsOther
?
t
.
getFirstCode
()
:
t
.
getSampleCode
();
Map
<
String
,
String
>
sampleMap
=
null
;
// 根据是否一级编码确定使用得objectKey
if
(
finalIsOther
)
{
sampleMap
=
reportSampleList
.
stream
().
filter
(
t
->
t
.
getOtherObjectKey
().
equals
(
objectKey
)).
collect
(
Collectors
.
toMap
(
ReportSampleVO:
:
getFirstCode
,
ReportSampleVO:
:
getSampleGrading
));
}
else
{
sampleMap
=
reportSampleList
.
stream
().
filter
(
t
->
t
.
getObjectKey
().
equals
(
objectKey
)).
collect
(
Collectors
.
toMap
(
t
->
{
if
(
StringUtils
.
isNotBlank
(
t
.
getThirdCode
()))
{
return
t
.
getThirdCode
();
}
else
if
(
StringUtils
.
isNotBlank
(
t
.
getSecondCode
()))
{
return
t
.
getSecondCode
();
}
return
t
.
getFirstCode
();
},
ReportSampleVO:
:
getSampleGrading
));
}
if
(
StringUtils
.
isBlank
(
objectKey
))
{
continue
;
...
...
@@ -1306,7 +1317,7 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
private
void
updateJudgeNoPass
(
EntrustSample
sample
,
Account
account
,
List
<
EntrustSample
>
sampleList
)
{
sampleList
.
add
(
sample
.
setOkJudge
(
"不合格"
).
setJudger
(
account
.
getUserName
()).
setJudgerId
(
account
.
getUserId
())
.
setJudgeTime
(
new
Date
()).
setJudgeStatus
(
0
).
setJudgeProgress
(
0
)
.
setSampleGrading
(
"
-
"
));
.
setSampleGrading
(
"
等外
"
));
}
...
...
src/test/java/com/patzn/cloud/service/lims/test/Test.java
View file @
a7fe5e1d
package
com
.
patzn
.
cloud
.
service
.
lims
.
test
;
import
com.patzn.cloud.service.lims.common.DateKit
;
import
com.patzn.cloud.service.lims.common.StringHandleUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.List
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
public
class
Test
{
public
static
void
main
(
String
[]
args
)
{
List
<
String
>
dateList
=
DateKit
.
dateInMonth
(
"2021-09"
);
dateList
.
stream
().
forEach
(
System
.
out
::
print
);
System
.
out
.
println
(
getTestValue
(
"0.1841"
,
2
));
System
.
out
.
println
(
getTestValue
(
"0.1952"
,
2
));
System
.
out
.
println
(
getTestValue
(
"0.2056"
,
2
));
}
private
static
String
getTestValue
(
String
value
,
int
roundNum
)
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(!
StringHandleUtils
.
validateNumber
(
value
))
{
if
(
value
.
startsWith
(
"!"
))
{
value
=
value
.
substring
(
1
);
}
else
{
return
value
;
}
}
// IF(ABS(TRUNC(A1,B1+5)*10^B1-TRUNC(A1,B1+5)*10^B1)<0.499999,ROUND(A1,B1),
// IF(ABS(TRUNC(A1,B1+5)*10^B1-TRUNC(A1,B1+5)*10^B1)>0.500001,ROUND(A1,B1),
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1)))
int
beginIndex
=
value
.
lastIndexOf
(
"."
)
+
1
,
valueLength
=
value
.
length
();
int
remindLength
=
valueLength
-
beginIndex
;
String
truncValue
=
""
,
zeroStr
=
"000000000"
;
// bdA = TRUNC(A1,B1+5)*10^B1
if
(
remindLength
>=
roundNum
+
5
)
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
+
5
);
}
else
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
+
5
-
remindLength
);
}
BigDecimal
bdDiff
=
new
BigDecimal
(
truncValue
).
scaleByPowerOfTen
(
roundNum
);
// bdB = TRUNC(A1,B1+5)*10^B1
if
(
remindLength
>=
roundNum
)
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
);
}
else
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
-
remindLength
);
}
bdDiff
=
bdDiff
.
subtract
(
new
BigDecimal
(
truncValue
).
scaleByPowerOfTen
(
roundNum
)).
abs
();
// 若 < 0.499999 或 大于 0.500001
if
(
bdDiff
.
compareTo
(
new
BigDecimal
(
"0.499999"
))
<
0
||
bdDiff
.
compareTo
(
new
BigDecimal
(
"0.500001"
))
>
0
)
{
return
new
BigDecimal
(
value
).
setScale
(
roundNum
,
RoundingMode
.
HALF_EVEN
).
toPlainString
();
}
// 处理第三种情况
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1))
if
(
remindLength
>=
roundNum
+
1
)
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
+
1
);
}
else
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
+
1
-
remindLength
);
}
bdDiff
=
new
BigDecimal
(
truncValue
);
bdDiff
=
bdDiff
.
subtract
(
new
BigDecimal
(
"0.5"
).
scaleByPowerOfTen
(-
roundNum
)).
abs
();
int
signValue
=
Double
.
valueOf
(
value
).
compareTo
(
0.0
);
BigDecimal
significance
=
new
BigDecimal
(
"2"
).
scaleByPowerOfTen
(-
roundNum
).
multiply
(
BigDecimal
.
valueOf
(
signValue
)).
abs
();
// ceiling
BigDecimal
[]
result
=
bdDiff
.
divideAndRemainder
(
significance
);
if
(
result
[
1
].
compareTo
(
BigDecimal
.
ZERO
)
==
0
)
{
return
bdDiff
.
setScale
(
roundNum
).
toPlainString
();
}
else
{
return
result
[
0
].
add
(
BigDecimal
.
ONE
).
multiply
(
significance
).
setScale
(
roundNum
).
toPlainString
();
}
}
return
value
;
}
private
static
String
rounding
(
String
value
,
Integer
roundNum
)
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(!
StringHandleUtils
.
validateNumber
(
value
))
{
if
(
value
.
startsWith
(
"!"
))
{
value
=
value
.
substring
(
1
);
}
else
{
return
value
;
}
}
BigDecimal
bd1
=
new
BigDecimal
(
value
);
BigDecimal
bd2
=
bd1
.
setScale
(
roundNum
,
BigDecimal
.
ROUND_HALF_EVEN
);
return
bd2
.
toPlainString
();
}
return
""
;
}
}
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