ソースを参照

系统检查增加无效点检查

欧阳劲驰 3 週間 前
コミット
1022bb20fe

+ 33 - 23
src/main/java/com/shkpr/service/alambizplugin/components/GisSurveySystemChecker.java

@@ -4,26 +4,14 @@ import com.fasterxml.jackson.core.type.TypeReference;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.apiparam.GisSurveyCheckParams;
-import com.shkpr.service.alambizplugin.components.checker.CrossLinesFinder;
-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;
+import com.shkpr.service.alambizplugin.components.checker.*;
 import com.shkpr.service.alambizplugin.constants.CommAsyncStatusEnum;
 import com.shkpr.service.alambizplugin.constants.GisSurveyCheckTypeEnum;
 import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckKeys;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyLayerApplyService;
 import com.shkpr.service.alambizplugin.dbdao.services.intef.TypeDefineService;
-import com.shkpr.service.alambizplugin.dto.CommAsyncResult;
-import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine;
-import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyPoint;
-import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckDefine;
-import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckId;
-import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckResultDetail;
-import com.shkpr.service.alambizplugin.dto.TypeDefine;
+import com.shkpr.service.alambizplugin.dto.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.AsyncResult;
@@ -59,6 +47,7 @@ public class GisSurveySystemChecker {
     private final AsyncResultManager asyncResultManager;
     private final GisSurveyLayerApplyService gisSurveyLayerApplyService;
     private final TypeDefineService typeDefineService;
+    private final InvalidPointsFinder invalidPointsFinder;
     private final IsolatedPointsFinder isolatedPointsFinder;
     private final IsolatedLinesFinder isolatedLinesFinder;
     private final DuplicatePointsFinder duplicatePointsFinder;
@@ -69,15 +58,16 @@ public class GisSurveySystemChecker {
 
     public GisSurveySystemChecker(AsyncResultManager asyncResultManager
             , GisSurveyLayerApplyService gisSurveyLayerApplyService, TypeDefineService typeDefineService
-            , IsolatedPointsFinder isolatedPointsFinder, IsolatedLinesFinder isolatedLinesFinder
-            , DuplicatePointsFinder duplicatePointsFinder, InvalidLinesFinder invalidLinesFinder
-            , OverlapLinesFinder overlapLinesFinder, CrossLinesFinder crossLinesFinder
-            , ElevationDiffFinder elevationDiffFinder) {
+            , InvalidPointsFinder invalidPointsFinder, IsolatedPointsFinder isolatedPointsFinder
+            , IsolatedLinesFinder isolatedLinesFinder, DuplicatePointsFinder duplicatePointsFinder
+            , InvalidLinesFinder invalidLinesFinder, OverlapLinesFinder overlapLinesFinder
+            , CrossLinesFinder crossLinesFinder, ElevationDiffFinder elevationDiffFinder) {
         mStrClassName = "GisSurveySystemChecker";
         mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
         this.asyncResultManager = asyncResultManager;
         this.gisSurveyLayerApplyService = gisSurveyLayerApplyService;
         this.typeDefineService = typeDefineService;
+        this.invalidPointsFinder = invalidPointsFinder;
         this.isolatedPointsFinder = isolatedPointsFinder;
         this.isolatedLinesFinder = isolatedLinesFinder;
         this.duplicatePointsFinder = duplicatePointsFinder;
@@ -109,6 +99,8 @@ public class GisSurveySystemChecker {
         CommAsyncResult<Map<String, GisSurveySystemCheckResultDetail>> result = CommAsyncResult.fail(systemCheckId.toString());
         result.setOperator(params.getOperator());
 
+        //无效点任务
+        ListenableFuture<GisSurveySystemCheckResultDetail> invalidPointsFuture = null;
         //孤立点任务
         ListenableFuture<GisSurveySystemCheckResultDetail> isolatedPointsFuture = null;
         //孤立线任务
@@ -173,6 +165,13 @@ public class GisSurveySystemChecker {
             //子任务
             HashMap<String, ListenableFuture<GisSurveySystemCheckResultDetail>> subtask = new HashMap<>();
 
+            //无效点检查
+            if (points != null) {
+                if (params.getStartSubitemKeys().contains(GisSurveySystemCheckKeys.INVALID_POINTS)) {
+                    invalidPointsFuture = invalidPointsFinder.finderInvalidPoints(points, systemCheckId);
+                    subtask.put(GisSurveySystemCheckKeys.INVALID_POINTS, invalidPointsFuture);
+                }
+            }
             //孤立点检查
             if (points != null && lines != null) {
                 if (params.getStartSubitemKeys().contains(GisSurveySystemCheckKeys.ISOLATED_POINTS)) {
@@ -231,13 +230,21 @@ public class GisSurveySystemChecker {
             if (lastResult != null && lastResult.getRefreshTimes() != null) refreshTimes = lastResult.getRefreshTimes();
 
             //等待结果,并存入返回,优先监听点相关(执行速度快且只需要点集合,优先释放点集合内存)
+            if (invalidPointsFuture != null) {
+                //监听无效点
+                final GisSurveySystemCheckResultDetail invalidPointsResult = invalidPointsFuture.get();
+                data.put(GisSurveySystemCheckKeys.INVALID_POINTS, invalidPointsResult);
+                refreshTimes.put(GisSurveySystemCheckKeys.INVALID_POINTS, params.getRefreshTime());
+                //释放点缓存
+                clearPoints(points, invalidPointsFuture, isolatedPointsFuture, duplicatePointsFuture, invalidLinesFuture);
+            }
             if (isolatedPointsFuture != null) {
                 //监听孤立点
                 final GisSurveySystemCheckResultDetail isolatedPointsResult = isolatedPointsFuture.get();
                 data.put(GisSurveySystemCheckKeys.ISOLATED_POINTS, isolatedPointsResult);
                 refreshTimes.put(GisSurveySystemCheckKeys.ISOLATED_POINTS, params.getRefreshTime());
                 //释放点缓存
-                clearPoints(points, isolatedPointsFuture, duplicatePointsFuture, invalidLinesFuture);
+                clearPoints(points, invalidPointsFuture, isolatedPointsFuture, duplicatePointsFuture, invalidLinesFuture);
             }
             if (duplicatePointsFuture != null) {
                 //监听重复点
@@ -245,7 +252,7 @@ public class GisSurveySystemChecker {
                 data.put(GisSurveySystemCheckKeys.DUPLICATE_POINTS, duplicatePointsResult);
                 refreshTimes.put(GisSurveySystemCheckKeys.DUPLICATE_POINTS, params.getRefreshTime());
                 //释放点缓存
-                clearPoints(points, isolatedPointsFuture, duplicatePointsFuture, invalidLinesFuture);
+                clearPoints(points, invalidPointsFuture, isolatedPointsFuture, duplicatePointsFuture, invalidLinesFuture);
             }
             if (isolatedLinesFuture != null) {
                 //监听孤立线
@@ -259,7 +266,7 @@ public class GisSurveySystemChecker {
                 data.put(GisSurveySystemCheckKeys.INVALID_LINES, invalidLinesResult);
                 refreshTimes.put(GisSurveySystemCheckKeys.INVALID_LINES, params.getRefreshTime());
                 //释放点缓存
-                clearPoints(points, isolatedPointsFuture, duplicatePointsFuture, invalidLinesFuture);
+                clearPoints(points, invalidPointsFuture, isolatedPointsFuture, duplicatePointsFuture, invalidLinesFuture);
             }
             if (overlapLinesFuture != null) {
                 //监听重叠线
@@ -329,6 +336,7 @@ public class GisSurveySystemChecker {
             log.error("StackTrac:", e);
 
             //清除子任务
+            if (invalidPointsFuture != null) invalidPointsFuture.cancel(true);
             if (isolatedPointsFuture != null) isolatedPointsFuture.cancel(true);
             if (isolatedLinesFuture != null) isolatedLinesFuture.cancel(true);
             if (duplicatePointsFuture != null) duplicatePointsFuture.cancel(true);
@@ -351,16 +359,18 @@ public class GisSurveySystemChecker {
      * 清除点缓存
      *
      * @param points                点集合
+     * @param invalidPointsFuture   无效点任务
      * @param isolatedPointsFuture  孤立点任务
      * @param duplicatePointsFuture 重复点任务
      * @param invalidLinesFuture    无效线任务
      */
     public void clearPoints(List<GisSurveyLayerApplyPoint> points
-            , ListenableFuture<GisSurveySystemCheckResultDetail> isolatedPointsFuture
+            , ListenableFuture<GisSurveySystemCheckResultDetail> invalidPointsFuture, ListenableFuture<GisSurveySystemCheckResultDetail> isolatedPointsFuture
             , ListenableFuture<GisSurveySystemCheckResultDetail> duplicatePointsFuture
             , ListenableFuture<GisSurveySystemCheckResultDetail> invalidLinesFuture) {
         //点相关任务都完成,则清除缓存
-        if (isolatedPointsFuture != null && isolatedPointsFuture.isDone() &&
+        if (invalidPointsFuture != null && invalidPointsFuture.isDone() &&
+                isolatedPointsFuture != null && isolatedPointsFuture.isDone() &&
                 duplicatePointsFuture != null && duplicatePointsFuture.isDone() &&
                 invalidLinesFuture != null && invalidLinesFuture.isDone()) points.clear();
     }

+ 155 - 0
src/main/java/com/shkpr/service/alambizplugin/components/checker/InvalidPointsFinder.java

@@ -0,0 +1,155 @@
+package com.shkpr.service.alambizplugin.components.checker;
+
+import com.global.base.log.LogLevelFlag;
+import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.alambizplugin.commtools.BeanUtil;
+import com.shkpr.service.alambizplugin.components.AsyncResultManager;
+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.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.exception.UncheckedInterruptedException;
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.Point;
+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.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 无效点查找器
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Component
+public class InvalidPointsFinder {
+    /**
+     * 中国经纬度范围
+     */
+    private static final Double MIN_LNG = 73.62;
+    private static final Double MAX_LNG = 134.77;
+    private static final Double MIN_LAT = 16.7;
+    private static final Double MAX_LAT = 53.56;
+    /**
+     * log
+     */
+    private final String mStrClassName;
+    private final String mBizType;
+    private final AsyncResultManager asyncResultManager;
+
+    public InvalidPointsFinder(AsyncResultManager asyncResultManager) {
+        mStrClassName = "InvalidPointsFinder";
+        mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
+        this.asyncResultManager = asyncResultManager;
+    }
+
+
+    /**
+     * 寻找无效点
+     *
+     * @param points        点集合
+     * @param systemCheckId 系统检查id
+     * @return 无效点
+     * @throws InterruptedException 中断异常
+     */
+    @Async
+    public ListenableFuture<GisSurveySystemCheckResultDetail> finderInvalidPoints(List<GisSurveyLayerApplyPoint> points
+            , GisSurveySystemCheckId systemCheckId) throws InterruptedException {
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行寻找无效点   ======>");
+        long begin = System.currentTimeMillis();
+
+        try {
+            //并行流寻找无效线
+            List<GisSurveySystemCheckElement> elements = points.parallelStream()
+                    //响应中断
+                    .peek(line -> {
+                        if (Thread.currentThread().isInterrupted())
+                            throw new UncheckedInterruptedException(new InterruptedException());
+                    })
+                    //过滤无效点
+                    .filter(point -> checkCoordinate(point.getGis()))
+                    .map(line -> BeanUtil.copy(line, GisSurveySystemCheckElement.class))
+                    .collect(Collectors.toList());
+
+            return new AsyncResult<>(createSystemCheckResult(elements, systemCheckId, begin));
+        } catch (UncheckedInterruptedException e) {
+            throw e.getCause();
+        }
+    }
+
+    /**
+     * 检查坐标
+     *
+     * @param point 点
+     * @return 超出范围昨状态
+     */
+    private boolean checkCoordinate(Point point) {
+        //获取坐标
+        if (point == null || point.getCoordinate() == null) return false;
+        Coordinate coordinate = point.getCoordinate();
+        //解析
+        double lng = coordinate.getX();
+        double lat = coordinate.getY();
+        //判断是否在范围
+        return MIN_LNG >= lng || lng >= MAX_LNG || MIN_LAT >= lat || lat >= MAX_LAT;
+    }
+
+    /**
+     * 创建系统检查结果
+     *
+     * @param data          数据
+     * @param systemCheckId 系统检查id
+     * @param begin         开始时间
+     * @return 结果
+     */
+    private GisSurveySystemCheckResultDetail createSystemCheckResult(List<GisSurveySystemCheckElement> data, GisSurveySystemCheckId systemCheckId, long begin) {
+        long end = System.currentTimeMillis();
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                , String.format(
+                        "结束执行寻找无效线,用时(毫秒):%d"
+                        , (end - begin)
+                )
+        );
+
+        //数据大小
+        final int size = data.size();
+        //结果flag
+        final String FLAG = systemCheckId.getFlag();
+        //写入json和excel结果
+        Path jsonPath = asyncResultManager.writeJson(data, FLAG, GisSurveySystemCheckKeys.INVALID_POINTS + ".json");
+        Path excelPath = asyncResultManager.writeExcel(GisSurveySystemCheckResultHead.INVALID_POINTS,
+                buildSystemCheckExcel(data), FLAG, GisSurveySystemCheckKeys.INVALID_POINTS + ".xlsx");
+
+        //构建结果
+        return new GisSurveySystemCheckResultDetail(true
+                , FLAG + "/" + jsonPath.getFileName()
+                , FLAG + "/" + excelPath.getFileName()
+                , size);
+    }
+
+    /**
+     * 构建excel数据
+     *
+     * @param data 数据
+     * @return excel数据
+     */
+    private List<Map<String, Object>> buildSystemCheckExcel(List<GisSurveySystemCheckElement> data) {
+        return data.stream().map(element -> {
+            Map<String, Object> map = new HashMap<>();
+            map.put(GisSurveySystemCheckResultHead.KEYS.NO, element.getNo());
+            map.put(GisSurveySystemCheckResultHead.KEYS.CODE, element.getCode());
+            map.put(GisSurveySystemCheckResultHead.KEYS.NAME, element.getName());
+            return map;
+        }).collect(Collectors.toList());
+    }
+}

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

@@ -8,6 +8,10 @@ package com.shkpr.service.alambizplugin.constants;
  */
 public interface GisSurveySystemCheckKeys {
     /**
+     * 无效点
+     */
+    String INVALID_POINTS = "invalidPoints";
+    /**
      * 孤立点
      */
     String ISOLATED_POINTS = "isolatedPoints";

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

@@ -11,6 +11,14 @@ import java.util.Map;
  */
 public class GisSurveySystemCheckResultHead {
     /**
+     * 无效点
+     */
+    public final static Map<String, String> INVALID_POINTS = new LinkedHashMap<String, String>() {{
+        put(KEYS.NO, "点号");
+        put(KEYS.CODE, "编码");
+        put(KEYS.NAME, "类型");
+    }};
+    /**
      * 孤立点
      */
     public final static Map<String, String> ISOLATED_POINTS = new LinkedHashMap<String, String>() {{