|
@@ -1,13 +1,16 @@
|
|
|
package com.persagy.apm.energy.report.common.utils;
|
|
package com.persagy.apm.energy.report.common.utils;
|
|
|
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.nfunk.jep.JEP;
|
|
import org.nfunk.jep.JEP;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
+@Slf4j
|
|
|
public class DataUtils {
|
|
public class DataUtils {
|
|
|
/**
|
|
/**
|
|
|
* 对象转Double类型
|
|
* 对象转Double类型
|
|
@@ -123,15 +126,17 @@ public class DataUtils {
|
|
|
// 结果保留的位数
|
|
// 结果保留的位数
|
|
|
int scale = 4;
|
|
int scale = 4;
|
|
|
if (d1 == null || d2 == null) {
|
|
if (d1 == null || d2 == null) {
|
|
|
- throw new IllegalArgumentException("两个double做除法,其中一个为空或两个都为空");
|
|
|
|
|
|
|
+ log.error("两个double做除法,其中一个为空或两个都为空, d1: {}, d2: {}", d1, d2);
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
if (d2.equals(0d)) {
|
|
if (d2.equals(0d)) {
|
|
|
- throw new IllegalArgumentException("double做除法,被除数不能为0");
|
|
|
|
|
|
|
+ log.error("double做除法,被除数不能为0");
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
BigDecimal bigDecimal1 = new BigDecimal(d1);
|
|
BigDecimal bigDecimal1 = new BigDecimal(d1);
|
|
|
BigDecimal bigDecimal2 = new BigDecimal(d2);
|
|
BigDecimal bigDecimal2 = new BigDecimal(d2);
|
|
|
return bigDecimal1.divide(
|
|
return bigDecimal1.divide(
|
|
|
- bigDecimal2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
|
|
|
+ bigDecimal2, scale, RoundingMode.HALF_UP).doubleValue();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|