|
|
@@ -3187,16 +3187,14 @@ public class CustomFunction {
|
|
|
List<Object> datas = obj2ListNe(data);
|
|
|
List<Object> data1 = obj2ListNe(angle);
|
|
|
List<Object> data2 = obj2ListNe(pouringSurface);
|
|
|
- List<Object> data3 = obj3ListNe(surveyDepth);
|
|
|
List<Object> data4 = obj2ListNe(Pumping);
|
|
|
|
|
|
//数据库查询对象
|
|
|
JdbcTemplate jdbcTemplateStatic = SpringContextHolder.getBean(JdbcTemplate.class);
|
|
|
|
|
|
- if (CollectionUtil.isNotEmpty(datas) && CollectionUtil.isNotEmpty(data1) && CollectionUtil.isNotEmpty(data2) && CollectionUtil.isNotEmpty(data3) && CollectionUtil.isNotEmpty(data4)) {
|
|
|
+ if (CollectionUtil.isNotEmpty(datas) && CollectionUtil.isNotEmpty(data1) && CollectionUtil.isNotEmpty(data2) && surveyDepth != null && CollectionUtil.isNotEmpty(data4)) {
|
|
|
angle = data1.get(0);
|
|
|
pouringSurface = data2.get(0);
|
|
|
- surveyDepth = data3.get(0);
|
|
|
Pumping = data4.get(0);
|
|
|
|
|
|
List<Double> list = datas.stream().filter(StringUtils::isNumber).map(m -> Double.valueOf(m.toString())).collect(Collectors.toList());
|
|
|
@@ -3225,7 +3223,7 @@ public class CustomFunction {
|
|
|
if(type == null || "1".equals(type.toString())){
|
|
|
String surveyDepthStr;
|
|
|
if(surveyDepth instanceof List){
|
|
|
- List<Object> surveyDepthList = obj2ListNe(surveyDepth);
|
|
|
+ List<Object> surveyDepthList = obj3ListNe(surveyDepth);
|
|
|
surveyDepthStr = surveyDepthList.get(0).toString();
|
|
|
}else{
|
|
|
surveyDepthStr = surveyDepth.toString();
|
|
|
@@ -3235,9 +3233,9 @@ public class CustomFunction {
|
|
|
//计算平均值
|
|
|
h = Arrays.stream(split).filter(StringUtils::isNumber).map(StringUtils::handleNull).mapToDouble(Double::parseDouble).average().orElse(0.0);
|
|
|
//进行0.5修正
|
|
|
- h = roundHalfEven(h,1);
|
|
|
+ h = roundHalfEven(new BigDecimal(h).setScale(1, RoundingMode.HALF_UP).doubleValue(),1);
|
|
|
}else{
|
|
|
- List<Object> surveyDepthList = obj2ListNe(surveyDepth);
|
|
|
+ List<Object> surveyDepthList = obj3ListNe(surveyDepth);
|
|
|
List<Double> doubleArrList = new ArrayList<>();
|
|
|
surveyDepthList.forEach(f -> {
|
|
|
String string = f.toString();
|
|
|
@@ -3245,26 +3243,26 @@ public class CustomFunction {
|
|
|
String[] split = string.split(string.contains(",") ? "," : "、");
|
|
|
//计算平均值
|
|
|
double avg = Arrays.stream(split).filter(StringUtils::isNumber).map(StringUtils::handleNull).mapToDouble(Double::parseDouble).average().orElse(0.0);
|
|
|
- doubleArrList.add(roundHalfEven(avg,1));
|
|
|
+ doubleArrList.add(roundHalfEven(new BigDecimal(avg).setScale(1, RoundingMode.HALF_UP).doubleValue(),1));
|
|
|
});
|
|
|
//结果再计算平均值
|
|
|
h = doubleArrList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
|
|
|
//在进行修正
|
|
|
- h = roundHalfEven(h,1);
|
|
|
+ h = roundHalfEven(new BigDecimal(h).setScale(1, RoundingMode.HALF_UP).doubleValue(),1);
|
|
|
}
|
|
|
|
|
|
//是否泵送
|
|
|
if ("是".equals(Pumping) || "1".equals(Pumping)) {
|
|
|
-
|
|
|
+ //计算公式:f = 0.034488 * (R^1.9400) * 10^(-0.0173 * dm)
|
|
|
+ double v = 0.034488 * Math.pow(r, 1.9400) * Math.pow(10, -0.0173 * h);
|
|
|
+ return new BigDecimal(v).setScale(1, RoundingMode.HALF_UP);
|
|
|
+ } else {
|
|
|
//从数据库中获取数据
|
|
|
List<Map<String, Object>> list1 = jdbcTemplateStatic.queryForList("select data_value from coordinate_data where r_value = " + r + " and h_value = " + h);
|
|
|
if (CollectionUtil.isNotEmpty(list1)) {
|
|
|
Map<String, Object> stringObjectMap = list1.get(0);
|
|
|
- return stringObjectMap.get("data_value");
|
|
|
+ return new BigDecimal(stringObjectMap.get("data_value").toString()).setScale(1, RoundingMode.HALF_UP);
|
|
|
}
|
|
|
- } else {
|
|
|
- //计算公式:f = 0.034488 * (R^1.9400) * 10^(-0.0173 * dm)
|
|
|
- return 0.034488 * Math.pow(r, 1.9400) * Math.pow(10, -0.0173 * h);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -3289,13 +3287,37 @@ public class CustomFunction {
|
|
|
|
|
|
/**
|
|
|
* 使用银行家舍入法进行0.5修正
|
|
|
- * @param value 要修正的数字
|
|
|
+ * @param number 要修正的数字
|
|
|
* @param scale 保留的小数位数
|
|
|
* @return 修正后的结果
|
|
|
*/
|
|
|
- public static double roundHalfEven(double value, int scale) {
|
|
|
- BigDecimal bd = BigDecimal.valueOf(value);
|
|
|
- bd = bd.setScale(scale, RoundingMode.HALF_EVEN);
|
|
|
- return bd.doubleValue();
|
|
|
+ public static double roundHalfEven(double number, int scale) {
|
|
|
+ BigDecimal bd = BigDecimal.valueOf(number);
|
|
|
+
|
|
|
+ // 获取小数部分
|
|
|
+ BigDecimal integerPart = new BigDecimal(bd.toBigInteger().toString());
|
|
|
+ BigDecimal decimalPart = bd.subtract(integerPart);
|
|
|
+
|
|
|
+ // 如果小数部分为0,直接返回
|
|
|
+ if (decimalPart.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return number;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将小数部分乘以10,获取第一位小数
|
|
|
+ BigDecimal firstDecimal = decimalPart.multiply(BigDecimal.TEN)
|
|
|
+ .setScale(0, RoundingMode.DOWN);
|
|
|
+
|
|
|
+ int firstDigit = firstDecimal.intValue();
|
|
|
+
|
|
|
+ if (firstDigit < 5) {
|
|
|
+ // 小数位数小于5,改成5
|
|
|
+ return integerPart.add(new BigDecimal("0.5")).doubleValue();
|
|
|
+ } else if (firstDigit > 5) {
|
|
|
+ // 小数位数大于5,四舍五入到整数
|
|
|
+ return bd.setScale(0, RoundingMode.HALF_UP).doubleValue();
|
|
|
+ } else {
|
|
|
+ // 等于5,不变
|
|
|
+ return number;
|
|
|
+ }
|
|
|
}
|
|
|
}
|