Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
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
项目统一框架
amos-boot-biz
Commits
f84ab852
Commit
f84ab852
authored
Aug 16, 2024
by
李秀明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: BUG#21612 设备管理>消防水池,正常占比数据应该保留2位小数
parent
5eb2f0ae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
8 deletions
+17
-8
UnitTransformUtil.java
...m/yeejoin/equipmanage/common/utils/UnitTransformUtil.java
+17
-8
No files found.
amos-boot-module/amos-boot-module-api/amos-boot-module-equip-api/src/main/java/com/yeejoin/equipmanage/common/utils/UnitTransformUtil.java
View file @
f84ab852
...
...
@@ -4,6 +4,7 @@ import com.yeejoin.equipmanage.common.enums.UnitEnum;
import
lombok.extern.slf4j.Slf4j
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -32,7 +33,7 @@ public class UnitTransformUtil {
&&
!
"--"
.
equals
(
maxValue
)
&&
!
"null"
.
equalsIgnoreCase
(
minValue
)&&
!
"--"
.
equals
(
maxValue
)
&&
!
"null"
.
equalsIgnoreCase
(
maxValue
))
{
if
(
nowVal
.
compareTo
(
new
BigDecimal
(
minValue
))
<
0
)
{
map
.
put
(
"status"
,
"0"
);
map
.
put
(
"abs"
,
nowVal
.
divide
(
new
BigDecimal
(
maxValue
),
2
,
BigDecimal
.
ROUND_HALF_UP
).
movePointRight
(
2
));
map
.
put
(
"abs"
,
getPercent
(
nowVal
,
new
BigDecimal
(
maxValue
)
));
}
else
if
(
nowVal
.
compareTo
(
new
BigDecimal
(
maxValue
))
>
0
)
{
// 当前值大于最大值
map
.
put
(
"status"
,
"2"
);
map
.
put
(
"abs"
,
100
);
...
...
@@ -41,7 +42,7 @@ public class UnitTransformUtil {
map
.
put
(
"abs"
,
100
);
}
else
{
map
.
put
(
"status"
,
"1"
);
map
.
put
(
"abs"
,
nowVal
.
divide
(
new
BigDecimal
(
maxValue
),
2
,
BigDecimal
.
ROUND_HALF_UP
).
movePointRight
(
2
));
map
.
put
(
"abs"
,
getPercent
(
nowVal
,
new
BigDecimal
(
maxValue
)
));
}
}
else
{
map
.
put
(
"status"
,
"--"
);
...
...
@@ -65,7 +66,7 @@ public class UnitTransformUtil {
&&
!
"--"
.
equals
(
maxValue
)
&&
!
"null"
.
equalsIgnoreCase
(
minValue
)&&
!
"--"
.
equals
(
maxValue
)
&&
!
"null"
.
equalsIgnoreCase
(
maxValue
))
{
if
(
nowVal
.
compareTo
(
new
BigDecimal
(
minValue
))
<
0
)
{
map
.
put
(
"status"
,
"0"
);
map
.
put
(
"abs"
,
nowVal
.
divide
(
new
BigDecimal
(
maxValue
),
2
,
BigDecimal
.
ROUND_HALF_UP
).
movePointRight
(
2
));
map
.
put
(
"abs"
,
getPercent
(
nowVal
,
new
BigDecimal
(
maxValue
)
));
}
else
if
(
nowVal
.
compareTo
(
new
BigDecimal
(
maxValue
))
==
1
)
{
map
.
put
(
"status"
,
"2"
);
map
.
put
(
"abs"
,
100
);
...
...
@@ -74,7 +75,7 @@ public class UnitTransformUtil {
map
.
put
(
"abs"
,
100
);
}
else
{
map
.
put
(
"status"
,
"1"
);
map
.
put
(
"abs"
,
nowVal
.
divide
(
new
BigDecimal
(
maxValue
),
2
,
BigDecimal
.
ROUND_HALF_UP
).
movePointRight
(
2
));
map
.
put
(
"abs"
,
getPercent
(
nowVal
,
new
BigDecimal
(
maxValue
)
));
}
}
else
{
map
.
put
(
"status"
,
"--"
);
...
...
@@ -98,7 +99,7 @@ public class UnitTransformUtil {
&&
!
"--"
.
equals
(
maxValue
)
&&
!
"null"
.
equalsIgnoreCase
(
minValue
)&&
!
"--"
.
equals
(
maxValue
)
&&
!
"null"
.
equalsIgnoreCase
(
maxValue
))
{
if
(
nowVal
.
compareTo
(
new
BigDecimal
(
minValue
))
<
0
)
{
map
.
put
(
"status"
,
"0"
);
map
.
put
(
"abs"
,
nowVal
.
divide
(
new
BigDecimal
(
maxValue
),
2
,
BigDecimal
.
ROUND_HALF_UP
).
movePointRight
(
2
));
map
.
put
(
"abs"
,
getPercent
(
nowVal
,
new
BigDecimal
(
maxValue
)
));
}
else
if
(
nowVal
.
compareTo
(
new
BigDecimal
(
maxValue
))
==
1
)
{
map
.
put
(
"status"
,
"2"
);
map
.
put
(
"abs"
,
100
);
...
...
@@ -107,7 +108,7 @@ public class UnitTransformUtil {
map
.
put
(
"abs"
,
100
);
}
else
{
map
.
put
(
"status"
,
"1"
);
map
.
put
(
"abs"
,
nowVal
.
divide
(
new
BigDecimal
(
maxValue
),
2
,
BigDecimal
.
ROUND_HALF_UP
).
movePointRight
(
2
));
map
.
put
(
"abs"
,
getPercent
(
nowVal
,
new
BigDecimal
(
maxValue
)
));
}
}
else
{
map
.
put
(
"status"
,
"--"
);
...
...
@@ -133,7 +134,7 @@ public class UnitTransformUtil {
&&
!
"null"
.
equalsIgnoreCase
(
minValue
)&&
!
"--"
.
equals
(
maxValue
)
&&
!
"null"
.
equalsIgnoreCase
(
maxValue
))
{
if
(
nowVal
.
compareTo
(
new
BigDecimal
(
minValue
))
<
0
)
{
map
.
put
(
"status"
,
"0"
);
map
.
put
(
"abs"
,
nowVal
.
divide
(
new
BigDecimal
(
maxValue
),
2
,
BigDecimal
.
ROUND_HALF_UP
).
movePointRight
(
2
));
map
.
put
(
"abs"
,
getPercent
(
nowVal
,
new
BigDecimal
(
maxValue
)
));
}
else
if
(
nowVal
.
compareTo
(
new
BigDecimal
(
maxValue
))
==
1
)
{
map
.
put
(
"status"
,
"2"
);
map
.
put
(
"abs"
,
100
);
...
...
@@ -142,7 +143,7 @@ public class UnitTransformUtil {
map
.
put
(
"abs"
,
100
);
}
else
{
map
.
put
(
"status"
,
"1"
);
map
.
put
(
"abs"
,
nowVal
.
divide
(
new
BigDecimal
(
maxValue
),
2
,
BigDecimal
.
ROUND_HALF_UP
).
movePointRight
(
2
));
map
.
put
(
"abs"
,
getPercent
(
nowVal
,
new
BigDecimal
(
maxValue
)
));
}
}
else
{
map
.
put
(
"status"
,
"--"
);
...
...
@@ -152,4 +153,12 @@ public class UnitTransformUtil {
map
.
put
(
"unit"
,
"M"
);
return
map
;
}
private
static
BigDecimal
getPercent
(
BigDecimal
num1
,
BigDecimal
num2
)
{
if
(
num2
.
compareTo
(
BigDecimal
.
ZERO
)
==
0
)
{
return
BigDecimal
.
ZERO
;
}
else
{
return
num1
.
divide
(
num2
,
4
,
RoundingMode
.
HALF_UP
).
multiply
(
new
BigDecimal
(
100
)).
setScale
(
2
,
RoundingMode
.
HALF_UP
);
}
}
}
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