Browse Source

系统检查增加无效线检查

欧阳劲驰 1 month ago
parent
commit
7d7fc2d641

+ 46 - 7
src/main/java/com/shkpr/service/alambizplugin/components/GisSurveySystemChecker.java

@@ -6,6 +6,7 @@ import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.apiparam.GisSurveyCheckParams;
 import com.shkpr.service.alambizplugin.components.checker.DuplicatePointsFinder;
 import com.shkpr.service.alambizplugin.components.checker.ElevationDiffFinder;
+import com.shkpr.service.alambizplugin.components.checker.InvalidLinesFinder;
 import com.shkpr.service.alambizplugin.components.checker.IsolatedLinesFinder;
 import com.shkpr.service.alambizplugin.components.checker.IsolatedPointsFinder;
 import com.shkpr.service.alambizplugin.components.checker.OverlapLinesFinder;
@@ -56,14 +57,15 @@ public class GisSurveySystemChecker {
     private final IsolatedPointsFinder isolatedPointsFinder;
     private final IsolatedLinesFinder isolatedLinesFinder;
     private final DuplicatePointsFinder duplicatePointsFinder;
+    private final InvalidLinesFinder invalidLinesFinder;
     private final OverlapLinesFinder overlapLinesFinder;
     private final ElevationDiffFinder elevationDiffFinder;
 
     public GisSurveySystemChecker(AsyncResultManager asyncResultManager
             , GisSurveyLayerApplyService gisSurveyLayerApplyService, TypeDefineService typeDefineService
             , IsolatedPointsFinder isolatedPointsFinder, IsolatedLinesFinder isolatedLinesFinder
-            , DuplicatePointsFinder duplicatePointsFinder, OverlapLinesFinder overlapLinesFinder
-            , ElevationDiffFinder elevationDiffFinder) {
+            , DuplicatePointsFinder duplicatePointsFinder, InvalidLinesFinder invalidLinesFinder
+            , OverlapLinesFinder overlapLinesFinder, ElevationDiffFinder elevationDiffFinder) {
         mStrClassName = "GisSurveySystemChecker";
         mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
         this.asyncResultManager = asyncResultManager;
@@ -72,6 +74,7 @@ public class GisSurveySystemChecker {
         this.isolatedPointsFinder = isolatedPointsFinder;
         this.isolatedLinesFinder = isolatedLinesFinder;
         this.duplicatePointsFinder = duplicatePointsFinder;
+        this.invalidLinesFinder = invalidLinesFinder;
         this.overlapLinesFinder = overlapLinesFinder;
         this.elevationDiffFinder = elevationDiffFinder;
     }
@@ -103,6 +106,8 @@ public class GisSurveySystemChecker {
         ListenableFuture<GisSurveySystemCheckResultDetail> isolatedLinesFuture = null;
         //重复点任务
         ListenableFuture<GisSurveySystemCheckResultDetail> duplicatePointsFuture = null;
+        //无效线任务
+        ListenableFuture<GisSurveySystemCheckResultDetail> invalidLinesFuture = null;
         //重叠线任务
         ListenableFuture<GisSurveySystemCheckResultDetail> overlapLinesFuture = null;
         //高程差任务
@@ -152,6 +157,13 @@ public class GisSurveySystemChecker {
                     subtask.put(GisSurveySystemCheckKeys.ISOLATED_POINTS, isolatedPointsFuture);
                 }
             }
+            //无效线检查
+            if (points != null && lines != null) {
+                if (params.getSubitemKeys().contains(GisSurveySystemCheckKeys.INVALID_LINES)) {
+                    invalidLinesFuture = invalidLinesFinder.finderInvalidLines(points, lines, systemCheckId);
+                    subtask.put(GisSurveySystemCheckKeys.INVALID_LINES, invalidLinesFuture);
+                }
+            }
             //重复点检查
             if (points != null) {
                 if (params.getSubitemKeys().contains(GisSurveySystemCheckKeys.DUPLICATE_POINTS)) {
@@ -182,7 +194,7 @@ public class GisSurveySystemChecker {
             CommAsyncResult<Map<String, GisSurveySystemCheckResultDetail>> lastResult = asyncResultManager.getResult(FLAG, new TypeReference<CommAsyncResult<Map<String, GisSurveySystemCheckResultDetail>>>() {
             });
             //设置数据
-            Map<String, GisSurveySystemCheckResultDetail>  data = new HashMap<>();
+            Map<String, GisSurveySystemCheckResultDetail> data = new HashMap<>();
             if (lastResult != null && lastResult.getData() != null) data = lastResult.getData();
             //设置数据时间
             Map<String, LocalDateTime> refreshTimes = new HashMap<>();
@@ -194,16 +206,16 @@ public class GisSurveySystemChecker {
                 final GisSurveySystemCheckResultDetail isolatedPointsResult = isolatedPointsFuture.get();
                 data.put(GisSurveySystemCheckKeys.ISOLATED_POINTS, isolatedPointsResult);
                 refreshTimes.put(GisSurveySystemCheckKeys.ISOLATED_POINTS, params.getRefreshTime());
-                //释放点缓存(孤立点和重复点都完成时,后续不需要点数据,释放缓存节省内存)
-                if (duplicatePointsFuture != null && duplicatePointsFuture.isDone()) points.clear();
+                //释放点缓存
+                clearPoints(points, isolatedPointsFuture, duplicatePointsFuture, invalidLinesFuture);
             }
             if (duplicatePointsFuture != null) {
                 //监听重复点
                 final GisSurveySystemCheckResultDetail duplicatePointsResult = duplicatePointsFuture.get();
                 data.put(GisSurveySystemCheckKeys.DUPLICATE_POINTS, duplicatePointsResult);
                 refreshTimes.put(GisSurveySystemCheckKeys.DUPLICATE_POINTS, params.getRefreshTime());
-                //释放点缓存(孤立点和重复点都完成时,后续不需要点数据,释放缓存节省内存)
-                if (isolatedPointsFuture != null && isolatedPointsFuture.isDone()) points.clear();
+                //释放点缓存
+                clearPoints(points, isolatedPointsFuture, duplicatePointsFuture, invalidLinesFuture);
             }
             if (isolatedLinesFuture != null) {
                 //监听孤立线
@@ -211,6 +223,14 @@ public class GisSurveySystemChecker {
                 data.put(GisSurveySystemCheckKeys.ISOLATED_LINES, isolatedLinesResult);
                 refreshTimes.put(GisSurveySystemCheckKeys.ISOLATED_LINES, params.getRefreshTime());
             }
+            if (invalidLinesFuture != null) {
+                //监听无效线
+                final GisSurveySystemCheckResultDetail invalidLinesResult = invalidLinesFuture.get();
+                data.put(GisSurveySystemCheckKeys.INVALID_LINES, invalidLinesResult);
+                refreshTimes.put(GisSurveySystemCheckKeys.INVALID_LINES, params.getRefreshTime());
+                //释放点缓存
+                clearPoints(points, isolatedPointsFuture, duplicatePointsFuture, invalidLinesFuture);
+            }
             if (overlapLinesFuture != null) {
                 //监听重叠线
                 final GisSurveySystemCheckResultDetail overlapLinesResult = overlapLinesFuture.get();
@@ -275,6 +295,7 @@ public class GisSurveySystemChecker {
             if (isolatedPointsFuture != null) isolatedPointsFuture.cancel(true);
             if (isolatedLinesFuture != null) isolatedLinesFuture.cancel(true);
             if (duplicatePointsFuture != null) duplicatePointsFuture.cancel(true);
+            if (invalidLinesFuture != null) invalidLinesFuture.cancel(true);
             if (overlapLinesFuture != null) overlapLinesFuture.cancel(true);
             if (elevationDiffFuture != null) elevationDiffFuture.cancel(true);
 
@@ -287,4 +308,22 @@ public class GisSurveySystemChecker {
             return new AsyncResult<>(result);
         }
     }
+
+    /**
+     * 清除点缓存
+     *
+     * @param points                点集合
+     * @param isolatedPointsFuture  孤立点任务
+     * @param duplicatePointsFuture 重复点任务
+     * @param invalidLinesFuture    无效线任务
+     */
+    public void clearPoints(List<GisSurveyLayerApplyPoint> points
+            , ListenableFuture<GisSurveySystemCheckResultDetail> isolatedPointsFuture
+            , ListenableFuture<GisSurveySystemCheckResultDetail> duplicatePointsFuture
+            , ListenableFuture<GisSurveySystemCheckResultDetail> invalidLinesFuture) {
+        //点相关任务都完成,则清除缓存
+        if (isolatedPointsFuture != null && isolatedPointsFuture.isDone() &&
+                duplicatePointsFuture != null && duplicatePointsFuture.isDone() &&
+                invalidLinesFuture != null && invalidLinesFuture.isDone()) points.clear();
+    }
 }

+ 132 - 1
src/main/java/com/shkpr/service/alambizplugin/components/checker/InvalidLinesFinder.java

@@ -3,21 +3,33 @@ package com.shkpr.service.alambizplugin.components.checker;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.google.common.collect.Lists;
+import com.shkpr.service.alambizplugin.commtools.BeanUtil;
 import com.shkpr.service.alambizplugin.commtools.ThirdImportTemplateUtils;
+import com.shkpr.service.alambizplugin.components.AsyncResultManager;
 import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
 import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
+import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckKeys;
+import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckResultHead;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dto.GisMetadataLayerTemplate;
 import com.shkpr.service.alambizplugin.dto.GisMetadataPropertyTemplate;
+import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine;
+import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyPoint;
+import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckElement;
+import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckId;
+import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckResultDetail;
 import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportElement;
 import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportResultDetail;
+import com.shkpr.service.alambizplugin.exception.UncheckedInterruptedException;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.AsyncResult;
 import org.springframework.stereotype.Component;
 import org.springframework.util.concurrent.ListenableFuture;
 
+import java.nio.file.Path;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -37,10 +49,12 @@ public class InvalidLinesFinder {
      */
     private final String mStrClassName;
     private final String mBizType;
+    private final AsyncResultManager asyncResultManager;
 
-    public InvalidLinesFinder() {
+    public InvalidLinesFinder(AsyncResultManager asyncResultManager) {
         mStrClassName = "InvalidLinesFinder";
         mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
+        this.asyncResultManager = asyncResultManager;
     }
 
     /**
@@ -156,4 +170,121 @@ public class InvalidLinesFinder {
         );
         return new AsyncResult<>(new GisSurveyThirdImportResultDetail<>(true, results));
     }
+
+    /**
+     * 寻找无效线
+     *
+     * @param points 点集合
+     * @param lines  线集合
+     * @return 线分组
+     */
+    @Async
+    public ListenableFuture<GisSurveySystemCheckResultDetail> finderInvalidLines(
+            List<GisSurveyLayerApplyPoint> points, List<GisSurveyLayerApplyLine> lines, GisSurveySystemCheckId systemCheckId) {
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行寻找无效线   ======>");
+        long begin = System.currentTimeMillis();
+
+        //如点为空,则全是无效线
+        if (points.isEmpty()) {
+            List<GisSurveySystemCheckElement> elements = lines.parallelStream()
+                    //响应中断
+                    .peek(line -> {
+                        if (Thread.currentThread().isInterrupted())
+                            throw new UncheckedInterruptedException(new InterruptedException());
+                    })
+                    //转为返回元素
+                    .map(line -> BeanUtil.copy(line, GisSurveySystemCheckElement.class))
+                    .collect(Collectors.toList());
+            return new AsyncResult<>(createResult(elements, systemCheckId, begin));
+        }
+        //如线为空,则无无效线
+        if (lines.isEmpty()) return new AsyncResult<>(createResult(Lists.newArrayList(), systemCheckId, begin));
+
+        //点编码集合
+        Set<String> pointCodes = points.parallelStream()
+                //响应中断
+                .peek(line -> {
+                    if (Thread.currentThread().isInterrupted())
+                        throw new UncheckedInterruptedException(new InterruptedException());
+                })
+                //获取点号,并去重
+                .map(GisSurveyLayerApplyPoint::getCode)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+
+        //并行流寻找重复点号
+        List<GisSurveySystemCheckElement> elements = lines.parallelStream()
+                //响应中断
+                .peek(line -> {
+                    if (Thread.currentThread().isInterrupted())
+                        throw new UncheckedInterruptedException(new InterruptedException());
+                })
+                //过滤上下游节点都不在点集合中
+                .filter(line -> !pointCodes.contains(line.getUpNode())
+                        || !pointCodes.contains(line.getDownNode()))
+                .map(line -> BeanUtil.copy(line, GisSurveySystemCheckElement.class))
+                .collect(Collectors.toList());
+
+        long end = System.currentTimeMillis();
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                , String.format(
+                        "结束执行寻找无效线,用时(毫秒):%d"
+                        , (end - begin)
+                )
+        );
+        return new AsyncResult<>(createResult(elements, systemCheckId, begin));
+    }
+
+    /**
+     * 创建结果
+     *
+     * @param data          数据
+     * @param systemCheckId 系统检查id
+     * @param begin         开始时间
+     * @return 结果
+     */
+    private GisSurveySystemCheckResultDetail createResult(List<GisSurveySystemCheckElement> data
+            , GisSurveySystemCheckId systemCheckId, long begin) {
+        //数据大小
+        final int size = data.size();
+        //结果flag
+        final String FLAG = systemCheckId.getFlag();
+        //写入json和excel结果
+        Path jsonPath = asyncResultManager.writeJson(data, FLAG, GisSurveySystemCheckKeys.INVALID_LINES + ".json");
+        Path excelPath = asyncResultManager.writeExcel(GisSurveySystemCheckResultHead.INVALID_LINES,
+                buildExcel(data), FLAG, GisSurveySystemCheckKeys.INVALID_LINES + ".xlsx");
+
+        long end = System.currentTimeMillis();
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                , String.format(
+                        "结束执行寻找无效线,用时(毫秒):%d"
+                        , (end - begin)
+                )
+        );
+
+        //构建结果
+        return new GisSurveySystemCheckResultDetail(true
+                , FLAG + "/" + jsonPath.getFileName()
+                , FLAG + "/" + excelPath.getFileName()
+                , size);
+    }
+
+    /**
+     * 构建excel数据
+     *
+     * @param data 数据
+     * @return excel数据
+     */
+    private List<Map<String, Object>> buildExcel(List<GisSurveySystemCheckElement> data) {
+        return data.stream().map(element -> {
+            Map<String, Object> map = new HashMap<>();
+            map.put(GisSurveySystemCheckResultHead.KEYS.UP_NO, element.getUpNo());
+            map.put(GisSurveySystemCheckResultHead.KEYS.DOWN_NO, element.getDownNo());
+            map.put(GisSurveySystemCheckResultHead.KEYS.CODE, element.getCode());
+            map.put(GisSurveySystemCheckResultHead.KEYS.UP_NODE, element.getUpNode());
+            map.put(GisSurveySystemCheckResultHead.KEYS.DOWN_NODE, element.getDownNode());
+            map.put(GisSurveySystemCheckResultHead.KEYS.NAME, element.getName());
+            return map;
+        }).collect(Collectors.toList());
+    }
 }

+ 4 - 0
src/main/java/com/shkpr/service/alambizplugin/constants/GisSurveySystemCheckKeys.java

@@ -20,6 +20,10 @@ public interface GisSurveySystemCheckKeys {
      */
     String DUPLICATE_POINTS = "duplicatePoints";
     /**
+     * 无效线
+     */
+    String INVALID_LINES = "invalidLines";
+    /**
      * 重叠线
      */
     String OVERLAP_LINES = "overlapLines";

+ 11 - 0
src/main/java/com/shkpr/service/alambizplugin/constants/GisSurveySystemCheckResultHead.java

@@ -40,6 +40,17 @@ public class GisSurveySystemCheckResultHead {
         put(KEYS.NAME, "类型");
     }};
     /**
+     * 无效线
+     */
+    public final static Map<String, String> INVALID_LINES = new LinkedHashMap<String, String>() {{
+        put(KEYS.UP_NO, "起点号");
+        put(KEYS.DOWN_NO, "终点号");
+        put(KEYS.CODE, "编码");
+        put(KEYS.UP_NODE, "起点编码");
+        put(KEYS.DOWN_NODE, "终点编码");
+        put(KEYS.NAME, "类型");
+    }};
+    /**
      * 重叠线
      */
     public final static Map<String, String> OVERLAP_LINES = new LinkedHashMap<String, String>() {{