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
17c34644
Commit
17c34644
authored
Jul 19, 2021
by
ghxdhr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
原始记录修约;新增字段sql
parent
8dea0f87
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
239 additions
and
4 deletions
+239
-4
SingleSheetMoreItemOperation.java
...vice/lims/hmhj/original/SingleSheetMoreItemOperation.java
+116
-1
SingleSheetMoreOperation.java
.../service/lims/hmhj/original/SingleSheetMoreOperation.java
+116
-3
20210719新增字段.sql
src/test/java/resources/db_sql/hmhj/v147/20210719新增字段.sql
+7
-0
No files found.
src/main/java/com/patzn/cloud/service/lims/hmhj/original/SingleSheetMoreItemOperation.java
View file @
17c34644
...
@@ -6,9 +6,14 @@ import com.patzn.cloud.service.hmhj.entity.OriginalTemplateConfig;
...
@@ -6,9 +6,14 @@ import com.patzn.cloud.service.hmhj.entity.OriginalTemplateConfig;
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
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.math.NumberUtils
;
import
org.apache.poi.ss.formula.FormulaParseException
;
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.ss.util.CellRangeAddress
;
import
org.apache.poi.xssf.usermodel.*
;
import
org.apache.poi.xssf.usermodel.*
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -22,7 +27,9 @@ public class SingleSheetMoreItemOperation implements Operation {
...
@@ -22,7 +27,9 @@ public class SingleSheetMoreItemOperation implements Operation {
private
List
<
OriginalTemplateConfig
>
configList
;
private
List
<
OriginalTemplateConfig
>
configList
;
private
XSSFWorkbook
xssfWorkbook
;
private
XSSFWorkbook
xssfWorkbook
;
private
String
collectionDatePrefix
=
"clc."
;
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
;
public
SingleSheetMoreItemOperation
(
OriginalTemplate
template
,
List
<
EntrustSampleVO
>
voList
,
Entrust
entrust
,
List
<
OriginalTemplateConfig
>
configList
,
XSSFWorkbook
xssfWorkbook
)
{
public
SingleSheetMoreItemOperation
(
OriginalTemplate
template
,
List
<
EntrustSampleVO
>
voList
,
Entrust
entrust
,
List
<
OriginalTemplateConfig
>
configList
,
XSSFWorkbook
xssfWorkbook
)
{
this
.
template
=
template
;
this
.
template
=
template
;
this
.
voList
=
voList
;
this
.
voList
=
voList
;
...
@@ -30,6 +37,16 @@ public class SingleSheetMoreItemOperation implements Operation {
...
@@ -30,6 +37,16 @@ public class SingleSheetMoreItemOperation implements Operation {
this
.
configList
=
configList
;
this
.
configList
=
configList
;
this
.
xssfWorkbook
=
xssfWorkbook
;
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"
);
}
}
private
void
dealCollectionData
(
List
<
EntrustSampleVO
>
voList
,
List
<
OriginalTemplateConfig
>
configList
)
{
private
void
dealCollectionData
(
List
<
EntrustSampleVO
>
voList
,
List
<
OriginalTemplateConfig
>
configList
)
{
...
@@ -126,6 +143,34 @@ public class SingleSheetMoreItemOperation implements Operation {
...
@@ -126,6 +143,34 @@ public class SingleSheetMoreItemOperation implements Operation {
if
(
sampleIdMap
.
size
()
!=
0
&&
config
.
getDataAttribute
().
startsWith
(
collectionDatePrefix
))
{
if
(
sampleIdMap
.
size
()
!=
0
&&
config
.
getDataAttribute
().
startsWith
(
collectionDatePrefix
))
{
String
mapKey
=
config
.
getDataAttribute
().
substring
(
4
);
String
mapKey
=
config
.
getDataAttribute
().
substring
(
4
);
if
(
sampleIdMap
.
get
(
vo
.
getId
()).
size
()
>
0
)
{
if
(
sampleIdMap
.
get
(
vo
.
getId
()).
size
()
>
0
)
{
if
(
null
!=
config
.
getRoundNum
())
{
// 需要修约
// ROUND(A,小数位数)-(MOD(A*10^(小数位数+1),20)=5)*10^(-小数位数)
String
formula
=
"ROUND(%s,%s)-(MOD(%s*10^(%s+1),20)=5)*10^(-%s)"
;
String
s
=
sampleIdMap
.
get
(
vo
.
getId
()).
get
(
mapKey
);
if
(
needUseFormula
(
cell
,
s
,
config
.
getRoundNum
()))
{
roundingValueUseFormula
(
cell
,
s
,
formula
,
config
.
getRoundNum
());
}
if
(
null
!=
cell2
&&
vo
.
getCollectionDataList
().
size
()
>=
2
)
{
String
s1
=
vo
.
getCollectionDataList
().
get
(
1
).
get
(
mapKey
);
if
(
needUseFormula
(
cell2
,
s1
,
config
.
getRoundNum
()))
{
roundingValueUseFormula
(
cell2
,
s1
,
formula
,
config
.
getRoundNum
());
}
}
if
(
null
!=
cell3
&&
vo
.
getCollectionDataList
().
size
()
>=
3
)
{
String
s2
=
vo
.
getCollectionDataList
().
get
(
2
).
get
(
mapKey
);
if
(
needUseFormula
(
cell2
,
s2
,
config
.
getRoundNum
()))
{
roundingValueUseFormula
(
cell3
,
s2
,
formula
,
config
.
getRoundNum
());
}
}
if
(
null
!=
cell4
&&
vo
.
getCollectionDataList
().
size
()
>=
4
)
{
String
s3
=
vo
.
getCollectionDataList
().
get
(
3
).
get
(
mapKey
);
if
(
needUseFormula
(
cell4
,
s3
,
config
.
getRoundNum
()))
{
roundingValueUseFormula
(
cell4
,
s3
,
formula
,
config
.
getRoundNum
());
}
}
continue
;
}
// 不需要修约
cell
.
setCellValue
(
sampleIdMap
.
get
(
vo
.
getId
()).
get
(
mapKey
));
cell
.
setCellValue
(
sampleIdMap
.
get
(
vo
.
getId
()).
get
(
mapKey
));
if
(
null
!=
cell2
&&
vo
.
getCollectionDataList
().
size
()
>=
2
)
{
if
(
null
!=
cell2
&&
vo
.
getCollectionDataList
().
size
()
>=
2
)
{
...
@@ -201,4 +246,73 @@ public class SingleSheetMoreItemOperation implements Operation {
...
@@ -201,4 +246,73 @@ public class SingleSheetMoreItemOperation implements Operation {
}
}
}
}
}
}
/**
*
* @param cell
* @param value
* @param roundNum 保留几位小数
* @return
*/
// 是否需要使用公式修约
private
boolean
needUseFormula
(
Cell
cell
,
String
value
,
Integer
roundNum
)
{
if
(
StringUtils
.
isEmpty
(
value
))
{
return
false
;
}
if
(!
NumberUtils
.
isDigits
(
value
))
{
cell
.
setCellValue
(
""
);
return
false
;
}
if
(!
value
.
contains
(
"."
))
{
cell
.
setCellValue
(
value
);
return
false
;
}
int
point
=
value
.
indexOf
(
"."
);
// 小数点后的数字
String
stringAfterPoint
=
value
.
substring
(
point
+
1
);
if
(
stringAfterPoint
.
length
()
<
roundNum
)
{
// 少的位数补0
for
(
int
i
=
0
;
i
<
roundNum
-
stringAfterPoint
.
length
();
i
++)
{
value
=
value
+
"0"
;
}
cell
.
setCellValue
(
value
);
return
false
;
}
if
(
stringAfterPoint
.
length
()
==
roundNum
)
{
cell
.
setCellValue
(
value
);
return
false
;
}
char
c
=
value
.
charAt
(
point
+
roundNum
+
1
);
char
[]
chars
=
{
c
};
int
i
=
Integer
.
parseInt
(
new
String
(
chars
));
String
afterPointRoundNum
=
value
.
substring
(
0
,
point
+
roundNum
+
1
);
if
(
i
>=
6
)
{
BigDecimal
bigDecimal
=
new
BigDecimal
(
afterPointRoundNum
).
add
(
new
BigDecimal
(
valueMap
.
get
(
roundNum
)));
cell
.
setCellValue
(
bigDecimal
.
toString
());
return
false
;
}
if
(
i
<=
4
)
{
cell
.
setCellValue
(
afterPointRoundNum
);
return
false
;
}
String
substring
=
value
.
substring
(
point
+
roundNum
+
1
);
if
(
Integer
.
parseInt
(
substring
)
>
0
)
{
return
true
;
}
else
{
BigDecimal
bigDecimal
=
new
BigDecimal
(
afterPointRoundNum
).
add
(
new
BigDecimal
(
valueMap
.
get
(
roundNum
)));
cell
.
setCellValue
(
bigDecimal
.
toString
());
return
false
;
}
}
// 使用公式进行修约
private
void
roundingValueUseFormula
(
Cell
cell
,
String
value
,
String
formula
,
Integer
roundNum
)
{
String
format
=
String
.
format
(
formula
,
value
,
roundNum
,
value
,
roundNum
,
roundNum
);
try
{
cell
.
setCellFormula
(
format
);
formulaEvaluator
.
evaluate
(
cell
).
getNumberValue
();
}
catch
(
FormulaParseException
e
)
{
System
.
out
.
println
(
"excel公式解析出错!"
);
}
}
}
}
\ No newline at end of file
src/main/java/com/patzn/cloud/service/lims/hmhj/original/SingleSheetMoreOperation.java
View file @
17c34644
...
@@ -6,12 +6,16 @@ import com.patzn.cloud.service.hmhj.entity.OriginalTemplate;
...
@@ -6,12 +6,16 @@ import com.patzn.cloud.service.hmhj.entity.OriginalTemplate;
import
com.patzn.cloud.service.hmhj.entity.OriginalTemplateConfig
;
import
com.patzn.cloud.service.hmhj.entity.OriginalTemplateConfig
;
import
com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO
;
import
com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO
;
import
com.patzn.cloud.service.lims.common.StringHandleUtils
;
import
com.patzn.cloud.service.lims.common.StringHandleUtils
;
import
com.patzn.cloud.service.lims.hmhj.common.HSSFWorkbookUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.math.NumberUtils
;
import
org.apache.poi.ss.formula.FormulaParseException
;
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.ss.util.CellRangeAddress
;
import
org.apache.poi.xssf.usermodel.*
;
import
org.apache.poi.xssf.usermodel.*
;
import
org.aspectj.weaver.ast.Var
;
import
java.
util.ArrayList
;
import
java.
math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -23,13 +27,25 @@ public class SingleSheetMoreOperation implements Operation {
...
@@ -23,13 +27,25 @@ public class SingleSheetMoreOperation implements Operation {
private
List
<
OriginalTemplateConfig
>
configList
;
private
List
<
OriginalTemplateConfig
>
configList
;
private
XSSFWorkbook
xssfWorkbook
;
private
XSSFWorkbook
xssfWorkbook
;
private
String
collectionDataPrefix
=
"clc."
;
private
String
collectionDataPrefix
=
"clc."
;
private
FormulaEvaluator
formulaEvaluator
;
private
Map
<
Integer
,
String
>
valueMap
;
public
SingleSheetMoreOperation
(
OriginalTemplate
template
,
List
<
EntrustSampleItemVO
>
voList
,
Entrust
entrust
,
List
<
OriginalTemplateConfig
>
configList
,
XSSFWorkbook
xssfWorkbook
)
{
public
SingleSheetMoreOperation
(
OriginalTemplate
template
,
List
<
EntrustSampleItemVO
>
voList
,
Entrust
entrust
,
List
<
OriginalTemplateConfig
>
configList
,
XSSFWorkbook
xssfWorkbook
)
{
this
.
template
=
template
;
this
.
template
=
template
;
this
.
voList
=
voList
;
this
.
voList
=
voList
;
this
.
entrust
=
entrust
;
this
.
entrust
=
entrust
;
this
.
configList
=
configList
;
this
.
configList
=
configList
;
this
.
xssfWorkbook
=
xssfWorkbook
;
this
.
xssfWorkbook
=
xssfWorkbook
;
this
.
formulaEvaluator
=
new
XSSFFormulaEvaluator
(
xssfWorkbook
);
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"
);
}
}
@Override
@Override
...
@@ -106,6 +122,35 @@ public class SingleSheetMoreOperation implements Operation {
...
@@ -106,6 +122,35 @@ public class SingleSheetMoreOperation implements Operation {
}
else
if
(
config
.
getDataAttribute
().
startsWith
(
"clc."
))
{
}
else
if
(
config
.
getDataAttribute
().
startsWith
(
"clc."
))
{
String
mapKey
=
config
.
getDataAttribute
().
substring
(
4
);
String
mapKey
=
config
.
getDataAttribute
().
substring
(
4
);
if
(
CollectionUtils
.
isNotEmpty
(
vo
.
getCollectionDataList
()))
{
if
(
CollectionUtils
.
isNotEmpty
(
vo
.
getCollectionDataList
()))
{
String
s
=
vo
.
getCollectionDataList
().
get
(
0
).
get
(
mapKey
);
if
(
null
!=
config
.
getRoundNum
())
{
// 需要修约
// ROUND(A,小数位数)-(MOD(A*10^(小数位数+1),20)=5)*10^(-小数位数)
String
formula
=
"ROUND(%s,%s)-(MOD(%s*10^(%s+1),20)=5)*10^(-%s)"
;
if
(
needUseFormula
(
cell
,
s
,
config
.
getRoundNum
()))
{
roundingValueUseFormula
(
cell
,
s
,
formula
,
config
.
getRoundNum
());
}
/* 下面为冗余代码,可能要删掉 */
if
(
null
!=
cell2
&&
vo
.
getCollectionDataList
().
size
()
>=
2
)
{
String
s1
=
vo
.
getCollectionDataList
().
get
(
1
).
get
(
mapKey
);
if
(
needUseFormula
(
cell2
,
s1
,
config
.
getRoundNum
()))
{
roundingValueUseFormula
(
cell2
,
s1
,
formula
,
config
.
getRoundNum
());
}
}
if
(
null
!=
cell3
&&
vo
.
getCollectionDataList
().
size
()
>=
3
)
{
String
s2
=
vo
.
getCollectionDataList
().
get
(
2
).
get
(
mapKey
);
if
(
needUseFormula
(
cell2
,
s2
,
config
.
getRoundNum
()))
{
roundingValueUseFormula
(
cell3
,
s2
,
formula
,
config
.
getRoundNum
());
}
}
if
(
null
!=
cell4
&&
vo
.
getCollectionDataList
().
size
()
>=
4
)
{
String
s3
=
vo
.
getCollectionDataList
().
get
(
3
).
get
(
mapKey
);
if
(
needUseFormula
(
cell4
,
s3
,
config
.
getRoundNum
()))
{
roundingValueUseFormula
(
cell4
,
s3
,
formula
,
config
.
getRoundNum
());
}
}
continue
;
}
// 不需要修约
cell
.
setCellValue
(
vo
.
getCollectionDataList
().
get
(
0
).
get
(
mapKey
));
cell
.
setCellValue
(
vo
.
getCollectionDataList
().
get
(
0
).
get
(
mapKey
));
if
(
null
!=
cell2
&&
vo
.
getCollectionDataList
().
size
()
>=
2
)
{
if
(
null
!=
cell2
&&
vo
.
getCollectionDataList
().
size
()
>=
2
)
{
...
@@ -223,4 +268,72 @@ public class SingleSheetMoreOperation implements Operation {
...
@@ -223,4 +268,72 @@ public class SingleSheetMoreOperation implements Operation {
}
}
}
}
}
}
/**
*
* @param cell
* @param value
* @param roundNum 保留几位小数
* @return
*/
// 是否需要使用公式修约
private
boolean
needUseFormula
(
Cell
cell
,
String
value
,
Integer
roundNum
)
{
if
(
StringUtils
.
isEmpty
(
value
))
{
return
false
;
}
if
(!
NumberUtils
.
isDigits
(
value
))
{
cell
.
setCellValue
(
""
);
return
false
;
}
if
(!
value
.
contains
(
"."
))
{
cell
.
setCellValue
(
value
);
return
false
;
}
int
point
=
value
.
indexOf
(
"."
);
// 小数点后的数字
String
stringAfterPoint
=
value
.
substring
(
point
+
1
);
if
(
stringAfterPoint
.
length
()
<
roundNum
)
{
// 少的位数补0
for
(
int
i
=
0
;
i
<
roundNum
-
stringAfterPoint
.
length
();
i
++)
{
value
=
value
+
"0"
;
}
cell
.
setCellValue
(
value
);
return
false
;
}
if
(
stringAfterPoint
.
length
()
==
roundNum
)
{
cell
.
setCellValue
(
value
);
return
false
;
}
char
c
=
value
.
charAt
(
point
+
roundNum
+
1
);
char
[]
chars
=
{
c
};
int
i
=
Integer
.
parseInt
(
new
String
(
chars
));
String
afterPointRoundNum
=
value
.
substring
(
0
,
point
+
roundNum
+
1
);
if
(
i
>=
6
)
{
BigDecimal
bigDecimal
=
new
BigDecimal
(
afterPointRoundNum
).
add
(
new
BigDecimal
(
valueMap
.
get
(
roundNum
)));
cell
.
setCellValue
(
bigDecimal
.
toString
());
return
false
;
}
if
(
i
<=
4
)
{
cell
.
setCellValue
(
afterPointRoundNum
);
return
false
;
}
String
substring
=
value
.
substring
(
point
+
roundNum
+
1
);
if
(
Integer
.
parseInt
(
substring
)
>
0
)
{
return
true
;
}
else
{
BigDecimal
bigDecimal
=
new
BigDecimal
(
afterPointRoundNum
).
add
(
new
BigDecimal
(
valueMap
.
get
(
roundNum
)));
cell
.
setCellValue
(
bigDecimal
.
toString
());
return
false
;
}
}
// 使用公式进行修约
private
void
roundingValueUseFormula
(
Cell
cell
,
String
value
,
String
formula
,
Integer
roundNum
)
{
String
format
=
String
.
format
(
formula
,
value
,
roundNum
,
value
,
roundNum
,
roundNum
);
try
{
cell
.
setCellFormula
(
format
);
formulaEvaluator
.
evaluate
(
cell
).
getNumberValue
();
}
catch
(
FormulaParseException
e
)
{
System
.
out
.
println
(
"excel公式解析出错!"
);
}
}
}
}
src/test/java/resources/db_sql/hmhj/v147/20210719新增字段.sql
0 → 100644
View file @
17c34644
-- ghx
-- ghx
ALTER
TABLE
"public"
.
"original_template_config"
ADD
COLUMN
"round_num"
int2
;
COMMENT
ON
COLUMN
"public"
.
"original_template_config"
.
"round_num"
IS
'修约保留位数'
;
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