|
|
@@ -14,9 +14,11 @@ import org.springblade.common.utils.BaseUtils;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.redis.cache.BladeRedis;
|
|
|
import org.springblade.core.tool.utils.*;
|
|
|
+import org.springblade.manager.bean.SpringContextHolder;
|
|
|
import org.springblade.manager.dto.ParamElements;
|
|
|
import org.springblade.manager.entity.WbsTreeContract;
|
|
|
import org.springblade.manager.utils.RandomNumberHolder;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
@@ -24,6 +26,7 @@ import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
@@ -1188,7 +1191,7 @@ public class CustomFunction {
|
|
|
}else{
|
|
|
localDateTime= LocalDateTime.now();
|
|
|
}
|
|
|
- return localDateTime.atZone(java.time.ZoneOffset.UTC)
|
|
|
+ return localDateTime.atZone(ZoneOffset.UTC)
|
|
|
.toInstant()
|
|
|
.toEpochMilli();
|
|
|
}
|
|
|
@@ -1997,6 +2000,19 @@ public class CustomFunction {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+ public static List<Object> obj3List(Object obj) {
|
|
|
+ List<Object> result = new ArrayList<>();
|
|
|
+ if (obj != null) {
|
|
|
+ List<Object> datas = new ArrayList<>();
|
|
|
+ if (obj instanceof List) {
|
|
|
+ datas = (List<Object>) obj;
|
|
|
+ } else {
|
|
|
+ datas.add(obj);
|
|
|
+ }
|
|
|
+ return datas;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* @return java.lang.Object
|
|
|
@@ -2236,6 +2252,10 @@ public class CustomFunction {
|
|
|
List<Object> list = obj2List(obj);
|
|
|
return list.parallelStream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
|
|
}
|
|
|
+ public static List<Object> obj3ListNe(Object obj) {
|
|
|
+ List<Object> list = obj3List(obj);
|
|
|
+ return list.parallelStream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
|
|
+ }
|
|
|
|
|
|
/*obj2ListNe别名*/
|
|
|
public static List<Object> objToListNe(Object obj) {
|
|
|
@@ -3121,4 +3141,183 @@ public class CustomFunction {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 特征值计算
|
|
|
+ */
|
|
|
+ public static Object eigenvalue(Object data){
|
|
|
+
|
|
|
+ //默认只有10组数据
|
|
|
+ if (data != null ) {
|
|
|
+ List<Object> datas = obj2ListNe(data);
|
|
|
+ datas = datas.size() > 10 ? datas.subList(0, datas.size()/2) : datas;
|
|
|
+ int total = datas.size();
|
|
|
+ //换算系数
|
|
|
+ double conversionFactor;
|
|
|
+ //获取换算系数
|
|
|
+ if(total >= 10 && total <= 15){
|
|
|
+ conversionFactor = 1.695;
|
|
|
+ }else if(total >= 16 && total <= 24){
|
|
|
+ conversionFactor = 1.645;
|
|
|
+ }else if(total>=25){
|
|
|
+ conversionFactor = 1.595;
|
|
|
+ }else{
|
|
|
+ throw new ServiceException("数据组数小于10");
|
|
|
+ }
|
|
|
+ List<String> _datas = datas.stream().map(StringUtils::handleNull).collect(Collectors.toList());
|
|
|
+ //获取平均值
|
|
|
+ double avgVal = _datas.stream().mapToDouble(Double::parseDouble).average().orElse(0D);
|
|
|
+ //获取标准差
|
|
|
+ double sqrt = Math.sqrt(_datas.stream().mapToDouble(Double::parseDouble).map(e -> Math.pow(e - avgVal, 2)).sum() / (total-1));
|
|
|
+ return avgVal - (conversionFactor * sqrt);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 混凝土强度 “换算值”计算
|
|
|
+ * @param data 混凝土强度实测值
|
|
|
+ * @param angle 角度
|
|
|
+ * @param pouringSurface 浇筑面
|
|
|
+ * @param type 测区计算方式 1-单独测区深度,2-测区平均值
|
|
|
+ * @param surveyDepth 测区深度
|
|
|
+ * @param Pumping 是否泵送 1-是,2-否
|
|
|
+ */
|
|
|
+ public static Object concreteStrength(Object data, Object angle, Object pouringSurface, Object type, Object surveyDepth, Object Pumping){
|
|
|
+ List<Object> datas = obj2ListNe(data);
|
|
|
+ List<Object> data1 = obj2ListNe(angle);
|
|
|
+ List<Object> data2 = obj2ListNe(pouringSurface);
|
|
|
+ List<Object> data4 = obj2ListNe(Pumping);
|
|
|
+
|
|
|
+ //数据库查询对象
|
|
|
+ JdbcTemplate jdbcTemplateStatic = SpringContextHolder.getBean(JdbcTemplate.class);
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(datas) && CollectionUtil.isNotEmpty(data1) && CollectionUtil.isNotEmpty(data2) && surveyDepth != null && CollectionUtil.isNotEmpty(data4)) {
|
|
|
+ angle = data1.get(0);
|
|
|
+ pouringSurface = data2.get(0);
|
|
|
+ Pumping = data4.get(0);
|
|
|
+
|
|
|
+ List<Double> list = datas.stream().filter(StringUtils::isNumber).map(m -> Double.valueOf(m.toString())).collect(Collectors.toList());
|
|
|
+ list = removeThreeMinAndMaxEfficient(list);
|
|
|
+ //计算平均值
|
|
|
+ double asDouble = list.stream().filter(StringUtils::isNumber).map(StringUtils::handleNull).mapToDouble(Double::parseDouble).average().orElse(0.0);
|
|
|
+ if (StringUtils.isNotEmpty(angle) && StringUtils.isNotEmpty(pouringSurface)) {
|
|
|
+ //角度 根据平均值从数据库中查询对应的映射值
|
|
|
+ List<Map<String, Object>> angleList = jdbcTemplateStatic.queryForList("select data_value from coordinate_angle where r_value = " + asDouble + " and h_value = " + angle);
|
|
|
+ if (CollectionUtil.isNotEmpty(angleList)) {
|
|
|
+ Map<String, Object> stringObjectMap = angleList.get(0);
|
|
|
+ asDouble += Double.parseDouble(stringObjectMap.get("data_value").toString());
|
|
|
+ }
|
|
|
+ //角度 根据平均值从数据库中查询对应的映射值
|
|
|
+ List<Map<String, Object>> pouringSurfaceList = jdbcTemplateStatic.queryForList("select data_value from coordinate_pouring_urface where r_value = " + asDouble + " and h_value = '" + pouringSurface + "'");
|
|
|
+ if (CollectionUtil.isNotEmpty(pouringSurfaceList)) {
|
|
|
+ Map<String, Object> stringObjectMap = pouringSurfaceList.get(0);
|
|
|
+ asDouble += Double.parseDouble(stringObjectMap.get("data_value").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ //最终值 R H
|
|
|
+ double r = asDouble;
|
|
|
+ double h = 0;
|
|
|
+
|
|
|
+ //测区深度 第一种只取第一条数据
|
|
|
+ if(type == null || "1".equals(type.toString())){
|
|
|
+ String surveyDepthStr;
|
|
|
+ if(surveyDepth instanceof List){
|
|
|
+ List<Object> surveyDepthList = obj3ListNe(surveyDepth);
|
|
|
+ surveyDepthStr = surveyDepthList.get(0).toString();
|
|
|
+ }else{
|
|
|
+ surveyDepthStr = surveyDepth.toString();
|
|
|
+ }
|
|
|
+ //分割字符串
|
|
|
+ String[] split = surveyDepthStr.split(surveyDepthStr.contains(",") ? "," : "、");
|
|
|
+ //计算平均值
|
|
|
+ h = Arrays.stream(split).filter(StringUtils::isNumber).map(StringUtils::handleNull).mapToDouble(Double::parseDouble).average().orElse(0.0);
|
|
|
+ //进行0.5修正
|
|
|
+ h = roundHalfEven(new BigDecimal(h).setScale(1, RoundingMode.HALF_UP).doubleValue(),1);
|
|
|
+ }else{
|
|
|
+ List<Object> surveyDepthList = obj3ListNe(surveyDepth);
|
|
|
+ List<Double> doubleArrList = new ArrayList<>();
|
|
|
+ surveyDepthList.forEach(f -> {
|
|
|
+ String string = f.toString();
|
|
|
+ //分割字符串
|
|
|
+ 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(new BigDecimal(avg).setScale(1, RoundingMode.HALF_UP).doubleValue(),1));
|
|
|
+ });
|
|
|
+ //结果再计算平均值
|
|
|
+ h = doubleArrList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
|
|
|
+ //在进行修正
|
|
|
+ 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 new BigDecimal(stringObjectMap.get("data_value").toString()).setScale(1, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更高效的实现方式(一次性操作)
|
|
|
+ public static List<Double> removeThreeMinAndMaxEfficient(List<Double> list) {
|
|
|
+ if (list.size() <= 6) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建列表的副本
|
|
|
+ List<Double> sortedList = new ArrayList<>(list);
|
|
|
+
|
|
|
+ // 排序列表
|
|
|
+ Collections.sort(sortedList);
|
|
|
+
|
|
|
+ // 直接获取中间部分的元素(跳过前3个和后3个)
|
|
|
+ return sortedList.subList(3, sortedList.size() - 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 使用银行家舍入法进行0.5修正
|
|
|
+ * @param number 要修正的数字
|
|
|
+ * @param scale 保留的小数位数
|
|
|
+ * @return 修正后的结果
|
|
|
+ */
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|