Commit 042906a7 authored by KeYong's avatar KeYong

更新后端液位转换

parent a262e8d1
...@@ -17,7 +17,8 @@ public enum UnitEnum { ...@@ -17,7 +17,8 @@ public enum UnitEnum {
M("m", "米", ""), M("m", "米", ""),
DM("dm", "分米", ""), DM("dm", "分米", ""),
CM("cm", "厘米", ""); CM("cm", "厘米", ""),
MM("mm", "毫米", "");
private String key; private String key;
......
...@@ -20,7 +20,37 @@ public class UnitTransformUtil { ...@@ -20,7 +20,37 @@ public class UnitTransformUtil {
public static Map<String, Object> transformValues(String currentValue, String currentUnit, String minValue, String maxValue) { public static Map<String, Object> transformValues(String currentValue, String currentUnit, String minValue, String maxValue) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
if (UnitEnum.CM.getKey().equalsIgnoreCase(currentUnit) || UnitEnum.CM.getName().equals(currentUnit)){ if (UnitEnum.MM.getKey().equalsIgnoreCase(currentUnit) || UnitEnum.MM.getName().equals(currentUnit)){
BigDecimal divide = new BigDecimal(1000);
if (StringUtil.isNotEmpty(currentValue) && !"--".equals(currentValue)){
BigDecimal nowLevel = new BigDecimal(currentValue);
map.put("nowValue", nowLevel.divide(divide,2,BigDecimal.ROUND_HALF_UP));
BigDecimal nowVal = new BigDecimal(currentValue).divide(divide,2,BigDecimal.ROUND_HALF_UP);
// status 中 0 表示过低;1 表示正常;2 表示过高
if (StringUtil.isNotEmpty(minValue) && !"--".equals(minValue) && StringUtil.isNotEmpty(maxValue)
&& !"--".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));
} else if (nowVal.compareTo(new BigDecimal(maxValue)) == 1) {
map.put("status", "2");
map.put("abs", 100);
} else {
map.put("status", "1");
map.put("abs", nowVal.divide(new BigDecimal(maxValue),2,BigDecimal.ROUND_HALF_UP).movePointRight(2));
}
} else {
map.put("status", "--");
map.put("abs", "--");
}
} else {
map.put("nowValue", "--");
map.put("status", "--");
map.put("abs", "--");
}
} else if (UnitEnum.CM.getKey().equalsIgnoreCase(currentUnit) || UnitEnum.CM.getName().equals(currentUnit)){
BigDecimal divide = new BigDecimal(100); BigDecimal divide = new BigDecimal(100);
if (StringUtil.isNotEmpty(currentValue) && !"--".equals(currentValue)){ if (StringUtil.isNotEmpty(currentValue) && !"--".equals(currentValue)){
BigDecimal nowLevel = new BigDecimal(currentValue); BigDecimal nowLevel = new BigDecimal(currentValue);
...@@ -81,7 +111,7 @@ public class UnitTransformUtil { ...@@ -81,7 +111,7 @@ public class UnitTransformUtil {
} }
} else { } else {
BigDecimal nowVal = new BigDecimal(0); BigDecimal nowVal = new BigDecimal(0);
if (StringUtil.isNotEmpty(currentValue)) { if (StringUtil.isNotEmpty(currentValue) && !"--".equals(currentValue)) {
nowVal = new BigDecimal(currentValue); nowVal = new BigDecimal(currentValue);
map.put("nowValue", nowVal); map.put("nowValue", nowVal);
} else { } else {
......
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