Explorar o código

公式相关:G8优化,兼容倒尺

yangyj %!s(int64=2) %!d(string=hai) anos
pai
achega
7f2b0a4ded

+ 34 - 158
blade-service/blade-manager/src/main/java/com/mixsmart/utils/FormulaUtils.java

@@ -44,6 +44,9 @@ import java.awt.Shape;
 import java.awt.geom.Ellipse2D;
 import java.awt.geom.Ellipse2D;
 import java.io.*;
 import java.io.*;
 
 
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.*;
 import java.util.*;
 import java.util.List;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -222,155 +225,7 @@ public class FormulaUtils {
             e.printStackTrace();
             e.printStackTrace();
         }
         }
     }
     }
-    /*public static  List<TableInfo> getTableInfoList(JSONArray dataArray) {
-        if (dataArray != null && !dataArray.isEmpty()) {
-            List<TableInfo> result = new ArrayList<>();
-            for (int m = 0; m < dataArray.size(); m++) {
-                TableInfo tableInfo = new TableInfo();
-                JSONObject dataInfo2 = dataArray.getJSONObject(m);
-                //
-                tableInfo.setContractId(dataInfo2.getString("contractId"));
-                tableInfo.setPkeyId(dataInfo2.getString("pkeyId"));
-                tableInfo.setProjectId(dataInfo2.getString("projectId"));
-                //huangjn 填报的类型,施工或监理
-                tableInfo.setClassify(dataInfo2.getString("classify"));
-
-                //设置首件信息
-                setFirstData(dataInfo2, tableInfo);
-//                //设置日志信息
-                setTheLogData(dataInfo2, tableInfo);
-
-                dataInfo2.fluentRemove("contractId")
-                        .fluentRemove("pkeyId")
-                        .fluentRemove("p_key_id")
-                        .fluentRemove("projectId")
-                        .fluentRemove("classify")
-                        .fluentRemove("pickerKey")
-                        .fluentRemove("id")
-                        .fluentRemove("isFirst")
-                        .fluentRemove("firstNodeId")
-                        .fluentRemove("isTheLog")
-                        .fluentRemove("theLogId")
-                        .fluentRemove("linkTabIds")
-                        .fluentRemove("recordTime")
-                        .fluentRemove("businessId")
-                        .fluentRemove("sourceUrl")
-                        .fluentRemove("pdfUrl")
-                        .fluentRemove("firstFileName")
-                        .fluentRemove("");
-                // 计算数据
-                LinkedHashMap<String, List<String>> dataMap = dataInfo2.keySet().stream().filter(e -> e.contains("__")).collect(Collectors.groupingBy(e -> e.split("__")[0], LinkedHashMap<String, List<String>>::new, Collectors.toList()));
-                LinkedHashMap<String, String> dataMap2 = new LinkedHashMap<>();
-                // 字段组合
-                for (String k : dataMap.keySet()) {
-                    if (dataMap.get(k).size() > 1 && !dataMap.get(k).contains("000Z")) {
-                        String[] ziduan = dataMap.get(k).toArray(new String[]{});
-                        String temp = "";
-                        for (int i = 0; i < ziduan.length - 1; i++) {
-                            for (int j = 0; j < ziduan.length - i - 1; j++) {
-                                Integer tr = Integer.parseInt((ziduan[j].split("__")[1]).split("_")[0]);
-                                Integer td = Integer.parseInt(ziduan[j].split("__")[1].split("_")[1]);
-
-                                Integer tr_1 = Integer.parseInt(ziduan[j + 1].split("__")[1].split("_")[0]);
-                                Integer td_1 = Integer.parseInt(ziduan[j + 1].split("__")[1].split("_")[1]);
-
-                                if (tr > tr_1 && td == td_1) { //纵向排序
-                                    temp = ziduan[j];
-                                    ziduan[j] = ziduan[j + 1];
-                                    ziduan[j + 1] = temp;
-                                }
-                            }
-                        }
 
 
-                        String lastStr = dataInfo2.getString(ziduan[0]) + "_^_" + ziduan[0].split("__")[1];
-                        for (int i = 1; i < ziduan.length; i++) {
-                            String keyData = dataInfo2.getString(ziduan[i]);
-                            if (!keyData.equals("")) {
-                                lastStr += "☆" + dataInfo2.getString(ziduan[i]) + "_^_" + ziduan[i].split("__")[1];
-                            }
-
-                        }
-                        dataMap2.put(k, lastStr);
-                    } else {
-                        String dataVal = dataInfo2.getString(dataMap.get(k).get(0));
-                        dataMap2.put(k, dataVal + "_^_" + dataMap.get(k).get(0).split("__")[1]);
-                    }
-                }
-                dataMap2.put("p_key_id", tableInfo.getPkeyId());
-                tableInfo.setDataMap(dataMap2);
-                result.add(tableInfo);
-            }
-            return result;
-        }
-        return null;
-    }*/
-/*
-    public static void setFirstData(JSONObject dataInfo2, TableInfo tableInfo) {
-        //huangjn 判断是否是首件
-        if (dataInfo2.containsKey("isFirst")) {
-            tableInfo.setIsFirst(dataInfo2.getString("isFirst"));
-        }
-        //huangjn 判断是否是首件
-
-        //首件资料绑定的节点
-        if (dataInfo2.containsKey("firstNodeId")) {
-            tableInfo.setFirstNodeId(dataInfo2.getString("firstNodeId"));
-        }
-        //首件ID(编辑时有值,新增时为空)
-        if (dataInfo2.containsKey("firstId")) {
-            tableInfo.setFirstId(dataInfo2.getString("firstId"));
-        }
-        //源文件
-        if (dataInfo2.containsKey("sourceUrl")) {
-            tableInfo.setSourceUrl(dataInfo2.getString("sourceUrl"));
-        }
-        //pdfUrl
-        if (dataInfo2.containsKey("pdfUrl")) {
-            tableInfo.setPdfUrl(dataInfo2.getString("pdfUrl"));
-        }
-        //文件名称
-        if (dataInfo2.containsKey("firstFileName")) {
-            tableInfo.setFirstFileName(dataInfo2.getString("firstFileName"));
-        }
-        //关联的信息
-        if (dataInfo2.containsKey("linkProcessList")) {
-            tableInfo.setLinkProcessList(dataInfo2.getJSONArray("linkProcessList"));
-        }
-    }
-
-    *//**
-     * 设置日志信息
-     *//*
-    public static void setTheLogData(JSONObject dataInfo2, TableInfo tableInfo) {
-        //huangjn 判断是否是日志
-        if (dataInfo2.containsKey("isTheLog")) {
-            tableInfo.setIsTheLog(dataInfo2.getString("isTheLog"));
-        }
-        //huangjn 判断是否是日志
-
-        //huangjn 日志ID
-        if (dataInfo2.containsKey("theLogId")) {
-            tableInfo.setTheLogId(dataInfo2.getString("theLogId"));
-        }
-        //huangjn 日志ID
-
-        //huangjn 日志勾选的工序
-        if (dataInfo2.containsKey("linkTabIds")) {
-            tableInfo.setLinkTabIds(dataInfo2.getJSONArray("linkTabIds"));
-        }
-        //huangjn 日志勾选的工序
-
-        //huangjn 日志所选时间
-        if (dataInfo2.containsKey("recordTime")) {
-            tableInfo.setRecordTime(dataInfo2.getString("recordTime"));
-        }
-        //huangjn 日志所选时间
-        //huangjn 每份填报数据的id,目前日志专用
-        if (dataInfo2.containsKey("id")) {
-            tableInfo.setBusinessId(dataInfo2.getString("id"));
-        }
-        //huangjn 每份填报数据的id,目前日志专用
-    }*/
 
 
     /**从元素名称中解析项目名称,细化项目匹配用*/
     /**从元素名称中解析项目名称,细化项目匹配用*/
     public static  String parseItemName(String eName){
     public static  String parseItemName(String eName){
@@ -423,6 +278,7 @@ public class FormulaUtils {
         return keywords.stream().anyMatch(s::contains);
         return keywords.stream().anyMatch(s::contains);
     }
     }
 
 
+    /*回归·测试变量*/
     public static List<String> itemNames =Arrays.asList(
     public static List<String> itemNames =Arrays.asList(
             ""
             ""
             ,"压 实 度 (%)下路床 特重、极重交通荷载等级 设计值"
             ,"压 实 度 (%)下路床 特重、极重交通荷载等级 设计值"
@@ -864,17 +720,37 @@ public class FormulaUtils {
 
 
     }
     }
 
 
-/*    public static void main(String[] args) {
-        JSONObject job = new JSONObject();
-        JSONObject job2 = new JSONObject();
-        job2.put("K","K");
-        job.fluentPut("A",1).fluentPut("B",2).fluentPut("C","bird").fluentPut("job",job2);
-        job.forEach((k,v)->{
-           // System.out.println(k);
-            System.out.println(v);
-        });
+    /**字符串sha256映射*/
+    public static String sha256(String input) {
+        try {
+            MessageDigest digest = MessageDigest.getInstance("SHA-256");
+            byte[] encodedHash = digest.digest(input.getBytes(StandardCharsets.UTF_8));
+            StringBuilder hexString = new StringBuilder();
+            for (byte b : encodedHash) {
+                String hex = Integer.toHexString(0xff & b);
+                if (hex.length() == 1) {
+                    hexString.append('0');
+                }
+                hexString.append(hex);
+            }
+            return hexString.toString();
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+    /**根据步长获取字符*/
+    public static String getEveryNthChar(String input, int step) {
+        StringBuilder result = new StringBuilder();
+        for (int i = 0; i < input.length(); i += step) {
+            result.append(input.charAt(i));
+        }
+        return result.toString();
+    }
+
+
 
 
-    }*/
 
 
 
 
 }
 }

+ 248 - 53
blade-service/blade-manager/src/main/java/org/springblade/manager/formula/ITurnPointCalculator.java

@@ -20,49 +20,38 @@ import static org.springblade.manager.formula.TurnPoint.*;
  */
  */
 public interface ITurnPointCalculator {
 public interface ITurnPointCalculator {
 
 
-
+     String ZD_REG="(?i)zd\\d+";
     static List<TurnPoint> create(List<Map<String, Object>> data, LinkedHashMap<String, String> configMap,String g8pcfw) {
     static List<TurnPoint> create(List<Map<String, Object>> data, LinkedHashMap<String, String> configMap,String g8pcfw) {
+        /*1.验证数据的合理性,如果已经合理则不需要计算,直接返回
+        * 2.尝试补充数据,如果不合理则重新生成转点,并用正尺方式生成
+        * 3.合理性定义(测点前视不存在或者非负数则视线高-测点实测高程在【0.5~4.8】范围,如果前视为负数则视线高-实际高程在【-0.5~-4.8】范围)*/
         if (Func.isNotEmpty(data) && configMap != null) {
         if (Func.isNotEmpty(data) && configMap != null) {
             LevelInfo levelInfo = new LevelInfo();
             LevelInfo levelInfo = new LevelInfo();
             levelInfo.setDx(g8pcfw);
             levelInfo.setDx(g8pcfw);
             List<TurnPoint> tmp = new ArrayList<>();
             List<TurnPoint> tmp = new ArrayList<>();
+            /*是否尝试初步补充数据*/
+            boolean ckecked=true;
             for (int i = 0; i < data.size(); i++) {
             for (int i = 0; i < data.size(); i++) {
                 Map<String, Object> dm = data.get(i);
                 Map<String, Object> dm = data.get(i);
                 Map<String, Object> dataMap = new HashMap<>(configMap.size() * 2);
                 Map<String, Object> dataMap = new HashMap<>(configMap.size() * 2);
                 TurnPoint tp = new TurnPoint(levelInfo, dataMap);
                 TurnPoint tp = new TurnPoint(levelInfo, dataMap);
                 /*V判断*/
                 /*V判断*/
                 tp.setVertical(StringUtils.isEquals(1, dm.get("vertical")));
                 tp.setVertical(StringUtils.isEquals(1, dm.get("vertical")));
-                for (Map.Entry<String, String> kv : configMap.entrySet()) {
-                    String key = kv.getKey();
-                    String field = kv.getValue();
-                    String value = StringUtils.handleNull(dm.get(field));
-                    switch (key) {
-                        case CD:
-                            tp.setName(value);
-                            break;
-                        case YG:
-                            tp.setBmd(value);
-                            break;
-                        case HS:
-                            tp.setH(value);
-                            break;
-                        case QS:
-                            tp.setQ(value);
-                            break;
-                        case SC:
-                            tp.setSc(value);
-                            break;
-                        case SJ:
-                            tp.setSj(value);
-                            break;
-                        case GC:
-                            tp.setDx(value);
-                            break;
-                        default:
-                            dataMap.put(key, value);
+                /*属性赋值*/
+                property(configMap,dataMap,dm,tp);
+                if(ckecked) {
+                    boolean isHead = (i == 0);
+                    boolean isTail = (i == data.size() - 1);
+                    /*检验水准点数据合法性&节点定性&补充缺失闭合点*/
+                    ckecked = identifying(levelInfo, tmp, tp, isHead, isTail);
+                    if(!ckecked){
+                        /*ckecked失败需要主动加入tmp,后续不执行identifying直接add*/
+                        tmp.add(tp);
                     }
                     }
+                }else{
+                    tmp.add(tp);
                 }
                 }
-                if (i == 0) {
+/*                if (i == 0) {
                     if (tp.checkBmd()) {
                     if (tp.checkBmd()) {
                         tp.setType(TurnPoint.BMD);
                         tp.setType(TurnPoint.BMD);
                         tp.setBmd(tp.getSj0L() + tp.getH0L());
                         tp.setBmd(tp.getSj0L() + tp.getH0L());
@@ -91,7 +80,7 @@ public interface ITurnPointCalculator {
                         TurnPoint close = new TurnPoint(levelInfo, new HashMap<>());
                         TurnPoint close = new TurnPoint(levelInfo, new HashMap<>());
                         close.setName(levelInfo.getBmdName());
                         close.setName(levelInfo.getBmdName());
                         close.setSj(levelInfo.getBmdSj());
                         close.setSj(levelInfo.getBmdSj());
-                        /*闭合点的偏差范围是±3mm*/
+                        *//*闭合点的偏差范围是±3mm*//*
                         double ldx=Arrays.asList(-0.003,-0.002,-0.001,0.001,0.002,0.003).get(ThreadLocalRandom.current().nextInt(6));
                         double ldx=Arrays.asList(-0.003,-0.002,-0.001,0.001,0.002,0.003).get(ThreadLocalRandom.current().nextInt(6));
                         close.setSc(close.getSj0L() + ldx);
                         close.setSc(close.getSj0L() + ldx);
                         close.setDx(ldx);
                         close.setDx(ldx);
@@ -105,11 +94,14 @@ public interface ITurnPointCalculator {
                     }
                     }
                 } else {
                 } else {
                     tp.setType(TurnPoint.CE);
                     tp.setType(TurnPoint.CE);
-                }
-                tmp.add(tp);
+                }*/
+            }
+            if(!ckecked){
+                tmp.forEach(ITurnPointCalculator::putCache);
+                return tmp;
             }
             }
             /*根据黄飞扬反馈情况,暂时去掉手填转点的可能性,每次重新生成20230803*/
             /*根据黄飞扬反馈情况,暂时去掉手填转点的可能性,每次重新生成20230803*/
-            tmp.removeIf(e-> ZD.equals(e.getType()));
+            //tmp.removeIf(e-> ZD.equals(e.getType()));
             List<TurnPoint> result = fill(tmp);
             List<TurnPoint> result = fill(tmp);
             if (ListUtils.isNotEmpty(result)) {
             if (ListUtils.isNotEmpty(result)) {
                 return  result;
                 return  result;
@@ -118,23 +110,106 @@ public interface ITurnPointCalculator {
         return Collections.emptyList();
         return Collections.emptyList();
     }
     }
 
 
+    static boolean identifying(LevelInfo levelInfo, List<TurnPoint> tmp,TurnPoint tp,boolean isHead,boolean isTail ){
+        if (isHead) {
+            if (tp.checkBmd()) {
+                tp.setType(TurnPoint.BMD);
+                tp.setBmd(tp.getSj0L() + tp.getH0L());
+                levelInfo.setBmdName(tp.getName());
+                levelInfo.setBmdSj(tp.getSj0L());
+                levelInfo.setSightHeight(tp.getBmd0L());
+            } else {
+                return false;
+            }
+        } else if (tp.getName().matches(ZD_REG)) {
+            tp.setType(TurnPoint.ZD);
+        } else if (isTail) {
+            if (StringUtils.isEquals(tp.getName(), levelInfo.getBmdName())) {
+                if (tp.getSj() == null) {
+                    tp.setSj(levelInfo.getBmdSj());
+                }
+                if (tp.getSc() == null && tp.getQ() == null) {
+                    double ldx = Double.parseDouble(rangeList(1, 0, levelInfo.getDx(), 0.001, 3, 1).get(0).toString());
+                    tp.setSc(tp.getSj0L() + ldx);
+                    tp.setDx(ldx);
+                }
+                tp.setType(TurnPoint.CLOSE);
+            } else {
+                tp.setType(TurnPoint.CE);
+                tmp.add(tp);
+                TurnPoint close = new TurnPoint(levelInfo, new HashMap<>());
+                close.setName(levelInfo.getBmdName());
+                close.setSj(levelInfo.getBmdSj());
+                /*闭合点的偏差范围是±3mm*/
+                double ldx=Arrays.asList(-0.003,-0.002,-0.001,0.001,0.002,0.003).get(ThreadLocalRandom.current().nextInt(6));
+                close.setSc(close.getSj0L() + ldx);
+                close.setDx(ldx);
+                close.setType(TurnPoint.CLOSE);
+                close.getDataMap().put(CD, close.getName());
+                close.getDataMap().put(YG, close.getBmd());
+                close.getDataMap().put(QS, close.getQ());
+                close.getDataMap().put(HS, close.getH());
+                tmp.add(close);
+                return true;
+            }
+        } else {
+            tp.setType(TurnPoint.CE);
+        }
+        tmp.add(tp);
+        return true;
+    }
 
 
+    static void  property(LinkedHashMap<String, String> configMap,Map<String, Object> dataMap,Map<String, Object> dm ,TurnPoint tp){
+         for (Map.Entry<String, String> kv : configMap.entrySet()) {
+             String key = kv.getKey();
+             String field = kv.getValue();
+             String value = StringUtils.handleNull(dm.get(field));
+             switch (key) {
+                 case CD:
+                     tp.setName(value);
+                     break;
+                 case YG:
+                     tp.setBmd(value);
+                     break;
+                 case HS:
+                     tp.setH(value);
+                     break;
+                 case QS:
+                     tp.setQ(value);
+                     break;
+                 case SC:
+                     tp.setSc(value);
+                     break;
+                 case SJ:
+                     tp.setSj(value);
+                     break;
+                 case GC:
+                     tp.setDx(value);
+                     break;
+                 default:
+                     dataMap.put(key, value);
+             }
+         }
+     }
 
 
     static List<TurnPoint> fill(List<TurnPoint> turnPointList) {
     static List<TurnPoint> fill(List<TurnPoint> turnPointList) {
         if (ListUtils.isNotEmpty(turnPointList)) {
         if (ListUtils.isNotEmpty(turnPointList)) {
-            Random rd = new Random();
+            /*Random rd = new Random();*/
             LevelInfo info = turnPointList.get(0).getLevelInfo();
             LevelInfo info = turnPointList.get(0).getLevelInfo();
             List<TurnPoint> result = new ArrayList<>();
             List<TurnPoint> result = new ArrayList<>();
             TurnPoint lastCd = turnPointList.stream().filter(TurnPoint::isCe).reduce((a, b) -> b).orElse(null);
             TurnPoint lastCd = turnPointList.stream().filter(TurnPoint::isCe).reduce((a, b) -> b).orElse(null);
+            /*checked==false的情况下不再计算个点数据,但需要把已有数据放回输出缓存,否则改组数据会被置空*/
+            boolean checked=true;
             for (TurnPoint tp : turnPointList) {
             for (TurnPoint tp : turnPointList) {
                 try {
                 try {
                     if (tp.equals(lastCd)) {
                     if (tp.equals(lastCd)) {
                         /*已经是最后一个测点*/
                         /*已经是最后一个测点*/
                         tp.getLevelInfo().setHasCe(Boolean.FALSE);
                         tp.getLevelInfo().setHasCe(Boolean.FALSE);
                     }
                     }
-                    /*先判断是不是转点*/
-                    if (tp.getType().equals(TurnPoint.ZD)) {
-                        if (Func.isBlank(tp.getQ()) && Func.isBlank(tp.getH()) && Func.isNotBlank(tp.getBmd())) {
+                    if(checked) {
+                        /*先判断是不是转点*/
+                        if (tp.getType().equals(TurnPoint.ZD)) {
+                       /* if (Func.isBlank(tp.getQ()) && Func.isBlank(tp.getH()) && Func.isNotBlank(tp.getBmd())) {
                             double dh = Math.abs(tp.getLevelInfo().getSightHeight() - tp.getBmd0L());
                             double dh = Math.abs(tp.getLevelInfo().getSightHeight() - tp.getBmd0L());
                             double big = BigDecimal.valueOf(rd.nextDouble() * (info.getStep() - dh) + dh).setScale(info.getScale(), ROUND_HALF_UP).doubleValue();
                             double big = BigDecimal.valueOf(rd.nextDouble() * (info.getStep() - dh) + dh).setScale(info.getScale(), ROUND_HALF_UP).doubleValue();
                             double small = big - dh;
                             double small = big - dh;
@@ -145,7 +220,7 @@ public interface ITurnPointCalculator {
                                 tp.setH(small);
                                 tp.setH(small);
                                 tp.setQ(big);
                                 tp.setQ(big);
                             }
                             }
-                            /* 更新仪器高*/
+                            *//* 更新仪器高*//*
                             info.setSightHeight(tp.getBmd0L());
                             info.setSightHeight(tp.getBmd0L());
                         } else if (Func.isBlank(tp.getQ()) && Func.isNotBlank(tp.getH()) && Func.isNotBlank(tp.getBmd())) {
                         } else if (Func.isBlank(tp.getQ()) && Func.isNotBlank(tp.getH()) && Func.isNotBlank(tp.getBmd())) {
                             tp.setQ(info.getSightHeight() + tp.getH0L() - tp.getBmd0L());
                             tp.setQ(info.getSightHeight() + tp.getH0L() - tp.getBmd0L());
@@ -161,21 +236,25 @@ public interface ITurnPointCalculator {
                         } else {
                         } else {
                             return Collections.emptyList();
                             return Collections.emptyList();
                         }
                         }
-                        /*可能存在自动插入转点情况,所以每个转点的序号需要实时计算*/
+                        *//*可能存在自动插入转点情况,所以每个转点的序号需要实时计算*//*
                         if (tp.getLevelInfo().getHasCe()) {
                         if (tp.getLevelInfo().getHasCe()) {
                             tp.setName("ZD" + info.getCloseZd().size());
                             tp.setName("ZD" + info.getCloseZd().size());
                             tp.getLevelInfo().getCloseZd().add(tp.clone());
                             tp.getLevelInfo().getCloseZd().add(tp.clone());
                         } else {
                         } else {
                             tp.getLevelInfo().getCloseZd().remove(tp.getLevelInfo().getCloseZd().size() - 1);
                             tp.getLevelInfo().getCloseZd().remove(tp.getLevelInfo().getCloseZd().size() - 1);
-                        }
-                    } else if (tp.getType().equals(TurnPoint.CLOSE)) {
-                        /*闭合转点*/
-                        tp.setQ(info.getSightHeight() - tp.getSc0L());
+                        }*/
+                            /*转点处理,失败则直接返回空集合*/
+                            checked = tpHandlerZd(info, tp);
+                        } else if (tp.getType().equals(TurnPoint.CLOSE)) {
+                            /*闭合转点*/
+                       /* tp.setQ(info.getSightHeight() - tp.getSc0L());
                         if (tp.needClose()) {
                         if (tp.needClose()) {
                             result.addAll(tp.close());
                             result.addAll(tp.close());
-                        }
-                    } else if (tp.getType().equals(TurnPoint.CE)) {
-                        if (StringUtils.isNotEmpty(tp.getSc())) {
+                        }*/
+                            /*闭合点处理*/
+                            tpHandlerClose(result, info, tp);
+                        } else if (tp.getType().equals(TurnPoint.CE)) {
+                        /*if (StringUtils.isNotEmpty(tp.getSc())) {
                             if (StringUtils.isNotEmpty(tp.getSj())) {
                             if (StringUtils.isNotEmpty(tp.getSj())) {
                                 tp.setDx(tp.getSc0L() - tp.getSj0L());
                                 tp.setDx(tp.getSc0L() - tp.getSj0L());
                             }
                             }
@@ -193,22 +272,30 @@ public interface ITurnPointCalculator {
                         }
                         }
                         if (!tp.isVisible()) {
                         if (!tp.isVisible()) {
                             result.addAll(tp.limit());
                             result.addAll(tp.limit());
-                        }
-                    } else if (tp.getType().equals(TurnPoint.BMD)) {
-                        TurnPoint st = new TurnPoint(tp.getLevelInfo(), new HashMap<>());
+                        }*/
+                            /*测点处理*/
+                            tpHandlerCe(result, info, tp);
+                        } else if (tp.getType().equals(TurnPoint.BMD)) {
+                      /*  TurnPoint st = new TurnPoint(tp.getLevelInfo(), new HashMap<>());
                         st.setBmd(tp.getBmd());
                         st.setBmd(tp.getBmd());
                         st.setType(TurnPoint.ZD);
                         st.setType(TurnPoint.ZD);
-                        tp.getLevelInfo().getCloseZd().add(st);
+                        tp.getLevelInfo().getCloseZd().add(st);*/
+                            /*水准点处理*/
+                            tpHandlerBmd(tp);
+                        }
                     }
                     }
-                    tp.getDataMap().put(CD, tp.getName());
+                   /* tp.getDataMap().put(CD, tp.getName());
                     tp.getDataMap().put(YG, tp.getBmd());
                     tp.getDataMap().put(YG, tp.getBmd());
                     tp.getDataMap().put(QS, tp.getQ());
                     tp.getDataMap().put(QS, tp.getQ());
                     tp.getDataMap().put(HS, tp.getH());
                     tp.getDataMap().put(HS, tp.getH());
                     tp.getDataMap().put(SC, tp.getSc());
                     tp.getDataMap().put(SC, tp.getSc());
                     tp.getDataMap().put(SJ, tp.getSj());
                     tp.getDataMap().put(SJ, tp.getSj());
-                    tp.getDataMap().put(GC, StringUtils.number2StringZero(StringUtils.isNotEmpty(tp.getDx()) ? tp.getDx0L() * 1000 : "", 0));
+                    tp.getDataMap().put(GC, StringUtils.number2StringZero(StringUtils.isNotEmpty(tp.getDx()) ? tp.getDx0L() * 1000 : "", 0));*/
+                    /*把数据放到输出缓存*/
+                    putCache(tp);
                     result.add(tp);
                     result.add(tp);
                 } catch (Exception e) {
                 } catch (Exception e) {
+                    e.printStackTrace();
                     tp.getDataMap().put("数据异常", tp.getName());
                     tp.getDataMap().put("数据异常", tp.getName());
                     result.add(tp);
                     result.add(tp);
                     return result;
                     return result;
@@ -221,4 +308,112 @@ public interface ITurnPointCalculator {
     }
     }
 
 
 
 
+    static void tpHandlerBmd(TurnPoint tp){
+        TurnPoint st = new TurnPoint(tp.getLevelInfo(), new HashMap<>());
+        st.setBmd(tp.getBmd());
+        st.setType(TurnPoint.ZD);
+        tp.getLevelInfo().getCloseZd().add(st);
+    }
+    static boolean tpHandlerZd(LevelInfo info ,TurnPoint tp){
+        if(!finalizeZd(tp)) {
+            if (Func.isBlank(tp.getQ()) && Func.isBlank(tp.getH()) && Func.isNotBlank(tp.getBmd())) {
+                double dh = Math.abs(tp.getLevelInfo().getSightHeight() - tp.getBmd0L());
+                double big = BigDecimal.valueOf(ThreadLocalRandom.current().nextDouble() * (info.getStep() - dh) + dh).setScale(info.getScale(), ROUND_HALF_UP).doubleValue();
+                double small = big - dh;
+                if (tp.isHigher()) {
+                    tp.setH(big);
+                    tp.setQ(small);
+                } else {
+                    tp.setH(small);
+                    tp.setQ(big);
+                }
+                /* 更新仪器高*/
+                /*info.setSightHeight(tp.getBmd0L());*/
+            } else if (Func.isBlank(tp.getQ()) && Func.isNotBlank(tp.getH()) && Func.isNotBlank(tp.getBmd())) {
+                tp.setQ(info.getSightHeight() + tp.getH0L() - tp.getBmd0L());
+                /*info.setSightHeight(tp.getBmd0L());*/
+            } else if (Func.isNotBlank(tp.getQ()) && Func.isBlank(tp.getH()) && Func.isNotBlank(tp.getBmd())) {
+                tp.setH(info.getSightHeight() - tp.getQ0L() - tp.getBmd0L());
+               /* info.setSightHeight(tp.getBmd0L());*/
+            } else if (Func.isNotBlank(tp.getQ()) && Func.isNotBlank(tp.getH()) && Func.isBlank(tp.getBmd())) {
+                tp.setBmd(info.getSightHeight() + tp.getH0L() - tp.getQ0L());
+                /*info.setSightHeight(tp.getBmd0L());*/
+            }  else {
+                return false;
+            }
+        }
+        /*更新当前视线高*/
+        info.setSightHeight(tp.getBmd0L());
+        /*可能存在自动插入转点情况,所以每个转点的序号需要实时计算*/
+        if (tp.getLevelInfo().getHasCe()) {
+            tp.setName("ZD" + info.getCloseZd().size());
+            tp.getLevelInfo().getCloseZd().add(tp.clone());
+        } else {
+            tp.getLevelInfo().getCloseZd().remove(tp.getLevelInfo().getCloseZd().size() - 1);
+        }
+        return true;
+    }
+    static void tpHandlerCe(List<TurnPoint> result,LevelInfo info ,TurnPoint tp){
+        if(!finalizeCe(tp)) {
+            if (StringUtils.isNotEmpty(tp.getSc())) {
+                if (StringUtils.isNotEmpty(tp.getSj())) {
+                    tp.setDx(tp.getSc0L() - tp.getSj0L());
+                }
+                tp.setQ(info.getSightHeight() - tp.getSc0L());
+            } else if (StringUtils.isNotEmpty(tp.getSj())) {
+                String dx = rangeList(1, 0, info.getDx(), 1, 0, 1).get(0).toString();
+                tp.setDx(dx);
+                tp.setSc(tp.getSj0L() + tp.getDx0L());
+                tp.setQ(info.getSightHeight() - tp.getSc0L());
+            } else if (StringUtils.isNotEmpty(tp.getQ())) {
+                tp.setSc(info.getSightHeight() - tp.getQ0L());
+                if (tp.getSj() != null) {
+                    tp.setDx(tp.getSj0L() - tp.getSj0L());
+                }
+            }
+        }
+        if (!tp.isVisible()) {
+            result.addAll(tp.limit());
+        }
+    }
+
+    /**验证当前测点数据的合理性*/
+    static boolean finalizeCe(TurnPoint tp){
+        if(Func.isNotBlank(tp.getSc())&&Func.isNotBlank(tp.getSj())&&Func.isNotBlank(tp.getQ())&&Func.isNotBlank(tp.getDx())){
+            /*实测高程=视线高-前视*/
+            boolean f1= tp.getSc0L()==tp.getLevelInfo().getSightHeight()-tp.getQ0L();
+            /*实测高程-设计值高程=偏差值*/
+            boolean f2=tp.getSc0L()-tp.getSj0L()==tp.getDx0L();
+            return f1&&f2;
+        }
+        return false;
+    }
+    /**验证当前转点数据的合理性*/
+    static boolean finalizeZd(TurnPoint tp){
+        if(Func.isNotBlank(tp.getQ()) && Func.isNotBlank(tp.getH()) && Func.isNotBlank(tp.getBmd())){
+            /*仪器高pre+后视cur-前视cur=仪器高cur*/
+            return tp.getLevelInfo().getSightHeight()+tp.getH0L()-tp.getQ0L()==tp.getBmd0L();
+        }
+        return false;
+    }
+
+    static void tpHandlerClose(List<TurnPoint> result,LevelInfo info ,TurnPoint tp){
+        /*闭合转点*/
+        tp.setQ(info.getSightHeight() - tp.getSc0L());
+        if (tp.needClose()) {
+            result.addAll(tp.close());
+        }
+    }
+
+    static void putCache(TurnPoint tp){
+        tp.getDataMap().put(CD, tp.getName());
+        tp.getDataMap().put(YG, tp.getBmd());
+        tp.getDataMap().put(QS, tp.getQ());
+        tp.getDataMap().put(HS, tp.getH());
+        tp.getDataMap().put(SC, tp.getSc());
+        tp.getDataMap().put(SJ, tp.getSj());
+        tp.getDataMap().put(GC, StringUtils.number2StringZero(StringUtils.isNotEmpty(tp.getDx()) ? tp.getDx0L() * 1000 : "", 0));
+    }
+
+
 }
 }

+ 5 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/formula/TurnPoint.java

@@ -229,8 +229,11 @@ public class TurnPoint {
     }
     }
 
 
     public Boolean isVisible() {
     public Boolean isVisible() {
-        /*只有测点落在0.5到step之间才有效*/
+        /*只有测点落在0.5到step之间才有效,负数前视取绝对值*/
         double d = getQ0L();
         double d = getQ0L();
+        if(d<0){
+            d=  Math.abs(d);
+        }
         return d >= levelInfo.getMin() && d <= levelInfo.getStep();
         return d >= levelInfo.getMin() && d <= levelInfo.getStep();
     }
     }
 
 
@@ -250,7 +253,7 @@ public class TurnPoint {
     }
     }
 
 
     public static Random r = new Random();
     public static Random r = new Random();
-
+    /*转点的核心处理算法,当测点不在测量范围会触发*/
     public List<TurnPoint> limit() {
     public List<TurnPoint> limit() {
         List<TurnPoint> result = new ArrayList<>();
         List<TurnPoint> result = new ArrayList<>();
         double step = levelInfo.getStep();
         double step = levelInfo.getStep();

+ 0 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/formula/impl/FormulaTurnPoint.java

@@ -33,9 +33,7 @@ import static org.springblade.manager.formula.TurnPoint.*;
 @Data
 @Data
 public class FormulaTurnPoint implements FormulaStrategy {
 public class FormulaTurnPoint implements FormulaStrategy {
     public static final String TURN_REG = "(?<=T\\(com.mixsmart.utils.CustomFunction\\).TURNPOINT\\()([^)]+)(?=\\))";
     public static final String TURN_REG = "(?<=T\\(com.mixsmart.utils.CustomFunction\\).TURNPOINT\\()([^)]+)(?=\\))";
-//    private FormData cur;
     static final List<String> KEYS;
     static final List<String> KEYS;
-//    private List<String> args;
     /**从节点参数获取G8偏差范围的公式脚本*/
     /**从节点参数获取G8偏差范围的公式脚本*/
     static final String F_DEV="WP['g8pcfw']";
     static final String F_DEV="WP['g8pcfw']";