Sfoglia il codice sorgente

公式-换算值
1、 换算值开发(80%)

LHB 5 giorni fa
parent
commit
afa904a2e0

+ 144 - 0
blade-service/blade-manager/src/main/java/com/mixsmart/utils/CustomFunction.java

@@ -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;
@@ -1998,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
@@ -2237,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) {
@@ -3154,4 +3173,129 @@ public class CustomFunction {
         }
         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> 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)) {
+            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());
+            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 = obj2ListNe(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(h,1);
+                }else{
+                    List<Object> surveyDepthList = obj2ListNe(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(avg,1));
+                    });
+                    //结果再计算平均值
+                    h = doubleArrList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
+                    //在进行修正
+                    h = roundHalfEven(h,1);
+                }
+
+                //是否泵送
+                if ("是".equals(Pumping) || "1".equals(Pumping)) {
+
+                    //从数据库中获取数据
+                    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");
+                    }
+                } 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);
+                }
+            }
+        }
+        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 value 要修正的数字
+     * @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();
+    }
 }

+ 25 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/bean/SpringContextHolder.java

@@ -0,0 +1,25 @@
+package org.springblade.manager.bean;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SpringContextHolder implements ApplicationContextAware {
+
+    private static ApplicationContext applicationContext;
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        SpringContextHolder.applicationContext = applicationContext;
+    }
+
+    public static <T> T getBean(Class<T> clazz) {
+        return applicationContext.getBean(clazz);
+    }
+
+    public static Object getBean(String name) {
+        return applicationContext.getBean(name);
+    }
+}