Browse Source

Merge remote-tracking branch 'origin/test-merge-02' into test-merge-02

chenr 3 months ago
parent
commit
fe7a24d493

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeMapper.xml

@@ -468,7 +468,7 @@
             and e_name like concat('%',#{eName},'%')
         </if>
         <if test="eType != null and eType != '' ">
-            and e_type like concat('%',#{eType},'%')
+            and e_type = #{eType}
         </if>
 
     </select>

+ 165 - 14
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -83,6 +83,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.math.MathContext;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Function;
@@ -1673,7 +1675,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
             //负值+0/1 正值-0/1
             String difference = "差值";
             //差值X + 差值Y 的开平方
-            String deviation = "偏";
+            String deviation = "偏";
             //指定表单和指定字段
             Map<String, Map<String, String>> dataMaps = new HashMap<>();
 
@@ -1734,7 +1736,9 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
 
             //构造表数据
             List<InsertDataVO> resultData = new LinkedList<>();
-            this.syncTabDataImpl(sgTabMaps, jlTabMaps, resultData);
+            //坐标
+            Map<String,Set<String>> coordinateMap = new HashMap<>();
+            this.syncTabDataImpl(sgTabMaps, jlTabMaps, resultData,coordinateMap);
 
             //入库处理
             if (resultData.size() > 0) {
@@ -1825,10 +1829,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                         if(levelingTableName.equals(initTabName)){
                             //设计标高
                             String designedElevationNew = stringStringMap.get(designedElevation);
-                            HashMap<Integer, Double> designedElevationNewMap = new HashMap<>();
+                            HashMap<Integer, BigDecimal> designedElevationNewMap = new HashMap<>();
                             //偏差
                             String heightDeviationNew = stringStringMap.get(heightDeviation);
-                            HashMap<Integer, Double> heightDeviationNewMap = new HashMap<>();
+                            HashMap<Integer, BigDecimal> heightDeviationNewMap = new HashMap<>();
                             //实际标高
                             String actualElevationNew = stringStringMap.get(actualElevation);
 
@@ -1865,12 +1869,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
 
                                     if (keys.get(i).equals(designedElevationNew)) {
                                         //设计标高
-                                        designedElevationNewMap.put(rowNum, Double.parseDouble(split2[0]));
+                                        designedElevationNewMap.put(rowNum, new BigDecimal(split2[0]));
                                     } else if (keys.get(i).equals(heightDeviationNew)){
                                         double v = Double.parseDouble(split2[0]);
-                                        //高度偏差
-                                        heightDeviationNewMap.put(rowNum, v);
-
+                                        //随机+ - 0/1
                                         Random random = new Random();
                                         int adjustment = random.nextInt(2);
                                         if(v > 0){
@@ -1878,6 +1880,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                         }else{
                                             v = v + adjustment;
                                         }
+
+                                        //高度偏差
+                                        heightDeviationNewMap.put(rowNum, BigDecimal.valueOf(v));
+
                                         heightDeviationList.add(v + "_^_"+ split2[1]);
                                     }
                                 }
@@ -1890,23 +1896,126 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                 continue;
                             }
                             List<String> list = new ArrayList<>();
+
+                            //获取当前key对应的坐标
+                            Set<String> strings = coordinateMap.get(initTabName);
+                            String index = null;
+                            for (String string : strings) {
+                                String[] split = string.split("__");
+                                if(Objects.equals(split[0],actualElevationNew)){
+                                    index = split[1];
+                                }
+                            }
                             //按照最小行数来计算
                             for (int i = rowMin; i <= rowMax; i++) {
-                                Double designed = designedElevationNewMap.get(i);
-                                Double height = heightDeviationNewMap.get(i);
+                                BigDecimal designed = designedElevationNewMap.get(i);
+                                BigDecimal height = heightDeviationNewMap.get(i);
+
                                 if(designed == null || height == null){
                                     continue;
                                 }
-                                double v = designed + (height / 100);
-
+                                BigDecimal v = designed.add(height.divide(new BigDecimal(100)));
                                 //第5列,索引为4
-                                list.add(v + "_^_"+ i + "_4");
+                                list.add(v.doubleValue() + "_^_"+ i + "_" + index);
+                            }
+                            //未获取到当前key的坐标就不设置值
+                            if(index == null){
+                                continue;
                             }
                             //设置实际标高的值
                             values.set(keys.indexOf(actualElevationNew), String.join("☆",list));
                         }else if(planePositionTableName.equals(initTabName)){
                             //CL10平面位置检测记录表(监理)
+                            //差值
+                            String differenceNewX = stringStringMap.get(difference + "X");
+                            HashMap<Integer, BigDecimal> differenceNewXMap = new HashMap<>();
+
+                            String differenceNewY = stringStringMap.get(difference + "Y");
+                            HashMap<Integer, BigDecimal> differenceNewYMap = new HashMap<>();
+
 
+                            String deviationNew = stringStringMap.get(deviation);
+                            //记录数量
+                            Integer rowMin = null;
+                            Integer rowMax = null;
+                            for (int i = 0; i < keys.size(); i++) {
+                                if(!Objects.equals(keys.get(i),differenceNewX) && !Objects.equals(keys.get(i),differenceNewY)){
+                                    continue;
+                                }
+
+                                String value = values.get(i);
+                                //拆分数据
+                                String[] split1 = value.split("☆");
+
+                                List<String> list = new ArrayList<>();
+
+                                for (String s : split1) {
+                                    String[] split2 = s.split("_\\^_");
+                                    int rowNum = Integer.parseInt(split2[1].split("_")[0]);
+                                    //获取最大行数
+                                    if(rowMax == null){
+                                        rowMax = rowNum;
+                                    }else if(rowMax < rowNum){
+                                        rowMax = rowNum;
+                                    }
+                                    //获取最小行数
+                                    if(rowMin == null){
+                                        rowMin = rowNum;
+                                    }else if(rowMin > rowNum){
+                                        rowMin = rowNum;
+                                    }
+                                    Integer v = Integer.parseInt(split2[0]);
+                                    //随机+ - 0/1
+                                    Random random = new Random();
+                                    int adjustment = random.nextInt(2);
+                                    if(v > 0){
+                                        v = v - adjustment;
+                                    }else{
+                                        v = v + adjustment;
+                                    }
+                                    if (keys.get(i).equals(differenceNewX)) {
+                                        //偏差X
+                                        differenceNewXMap.put(rowNum, new BigDecimal(split2[0]));
+                                    } else if (keys.get(i).equals(differenceNewY)){
+                                        //偏差Y
+                                        differenceNewYMap.put(rowNum, BigDecimal.valueOf(v));
+                                    }
+                                    list.add(v + "_^_"+ split2[1]);
+                                }
+                                values.set(i, String.join("☆",list));
+                            }
+                            if(rowMin==null){
+                                continue;
+                            }
+                            List<String> list = new ArrayList<>();
+                            //获取当前key对应的坐标
+                            Set<String> strings = coordinateMap.get(initTabName);
+                            String index = null;
+                            for (String string : strings) {
+                                String[] split = string.split("__");
+                                if(Objects.equals(split[0],deviationNew)){
+                                    index = split[1];
+                                }
+                            }
+                            //按照最小行数来计算
+                            for (int i = rowMin; i <= rowMax; i++) {
+                                BigDecimal x = differenceNewXMap.get(i);
+                                BigDecimal y = differenceNewYMap.get(i);
+
+                                if(x == null || y == null){
+                                    continue;
+                                }
+                                BigDecimal sqrt = sqrt(x.multiply(x).add(y.multiply(y)), 0);
+
+                                //第9列,索引为8
+                                list.add(sqrt.intValue() + "_^_"+ i + "_" + index);
+                            }
+                            //未获取到当前key的坐标就不设置值
+                            if(index == null){
+                                continue;
+                            }
+                            //设置实际标高的值
+                            values.set(keys.indexOf(deviationNew), String.join("☆",list));
                         }
 
 
@@ -2016,6 +2125,32 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         }
     }
 
+    // 牛顿迭代法实现开平方
+    public  BigDecimal sqrt(BigDecimal value, int precision) {
+        // 检查负数输入
+        if (value.compareTo(BigDecimal.ZERO) < 0) {
+            throw new ArithmeticException("不能对负数开平方");
+        }
+
+        // 精度设置(保留小数位 + 额外2位保证精度)
+        MathContext mc = new MathContext(precision + 2, RoundingMode.HALF_EVEN);
+
+        // 初始值 = value / 2
+        BigDecimal guess = value.divide(BigDecimal.valueOf(2), mc);
+        BigDecimal lastGuess;
+
+        // 牛顿迭代公式:xₙ₊₁ = (xₙ + value/xₙ)/2
+        do {
+            lastGuess = guess;
+            guess = value.divide(guess, mc).add(guess)
+                    .divide(BigDecimal.valueOf(2), mc);
+        } while (guess.subtract(lastGuess).abs().compareTo(
+                BigDecimal.valueOf(1, precision + 1)) > 0); // 精度控制
+
+        // 返回最终结果(精确到指定小数位)
+        return guess.setScale(precision, RoundingMode.HALF_UP);
+    }
+
     /**
      * 构造数据
      *
@@ -2025,7 +2160,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
      * @throws Exception
      */
     private void syncTabDataImpl
-    (Map<String, String> sgData, Map<String, String> jlData, List<InsertDataVO> resultData) throws
+    (Map<String, String> sgData, Map<String, String> jlData, List<InsertDataVO> resultData, Map<String,Set<String>> coordinateMap) throws
             Exception {
         for (Map.Entry<String, String> sgTab : sgData.entrySet()) { //质检表
             String[] split = sgTab.getKey().split("---");
@@ -2044,6 +2179,22 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                 //表的代码名称相同,就复制数据,例如:G10=G10
                 if (nodeNameRe.equals(nodeNameReJL)) {
                     String htmlStringJL = this.getHtmlString(pKeyIdJL);
+
+                    //解析html坐标,生成key与keyName的映射关系
+                    if (StringUtils.isNotEmpty(htmlStringJL)) {
+                        Document doc = Jsoup.parse(htmlStringJL);
+                        Elements select = doc.select("[id]");
+                        HashSet<String> strings = new HashSet<>();
+                        for (Element element : select) {
+                            String id = element.id();
+                            String[] split1 = id.split("__");
+                            String s = split1[1].split("_")[1];
+
+                            strings.add(split1[0] + "__" + s);
+                        }
+                        coordinateMap.put(initTabNameJL, strings);
+                    }
+
                     //获取质检实体表对应数据
                     List<Map<String, Object>> mapsList = jdbcTemplate.queryForList("select * from " + initTabName + " where p_key_id = " + pKeyId);
                     if (mapsList.size() > 0) {