Commit f84ab852 authored by 李秀明's avatar 李秀明

fix: BUG#21612 设备管理>消防水池,正常占比数据应该保留2位小数

parent 5eb2f0ae
......@@ -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);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment