Prechádzať zdrojové kódy

无效线检查增加中断异常捕获

欧阳劲驰 3 týždňov pred
rodič
commit
e9e3cb15a7

+ 55 - 62
src/main/java/com/shkpr/service/alambizplugin/components/checker/InvalidLinesFinder.java

@@ -8,14 +8,7 @@ import com.shkpr.service.alambizplugin.commtools.GeomUtil;
 import com.shkpr.service.alambizplugin.commtools.ThirdImportTemplateUtils;
 import com.shkpr.service.alambizplugin.components.AsyncResultManager;
 import com.shkpr.service.alambizplugin.components.GisSurveyThirdImporter;
-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.GisSurveyTemplateDefine;
-import com.shkpr.service.alambizplugin.constants.GisSurveyThirdImportKeys;
-import com.shkpr.service.alambizplugin.constants.GisSurveyThirdImportResultHead;
-import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
+import com.shkpr.service.alambizplugin.constants.*;
 import com.shkpr.service.alambizplugin.dto.*;
 import com.shkpr.service.alambizplugin.exception.UncheckedInterruptedException;
 import org.apache.commons.lang3.StringUtils;
@@ -26,12 +19,7 @@ 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;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -174,11 +162,12 @@ public class InvalidLinesFinder {
      * @param points 点集合
      * @param lines  线集合
      * @return 线分组
+     * @throws InterruptedException 中断异常
      */
     @Async
     public ListenableFuture<GisSurveySystemCheckResultDetail> finderInvalidLines(
             List<GisSurveyLayerApplyPoint> points, List<GisSurveyLayerApplyLine> lines,
-            GisSurveySystemCheckDefine define, GisSurveySystemCheckId systemCheckId) {
+            GisSurveySystemCheckDefine define, GisSurveySystemCheckId systemCheckId) throws InterruptedException {
         //经纬度公差
         double lngTolerance = GeomUtil.getTolerance(define, GisSurveyTemplateDefine.LNG);
         double latTolerance = GeomUtil.getTolerance(define, GisSurveyTemplateDefine.LAT);
@@ -186,63 +175,67 @@ public class InvalidLinesFinder {
         LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行寻找无效线   ======>");
         long begin = System.currentTimeMillis();
 
-        //如点为空,则全是无效线
-        if (points.isEmpty()) {
+        try {
+            //如点为空,则全是无效线
+            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<>(createSystemCheckResult(elements, systemCheckId, begin));
+            }
+            //如线为空,则无无效线
+            if (lines.isEmpty())
+                return new AsyncResult<>(createSystemCheckResult(Lists.newArrayList(), systemCheckId, begin));
+            //联通点
+            Map<String, GisSurveyLayerApplyPoint> connectedPoints = points.parallelStream()
+                    //响应中断
+                    .peek(line -> {
+                        if (Thread.currentThread().isInterrupted())
+                            throw new UncheckedInterruptedException(new InterruptedException());
+                    })
+                    .filter(point -> Objects.nonNull(point) && Objects.nonNull(point.getCode()))
+                    //获取点编码
+                    .collect(Collectors.toMap(GisSurveyLayerApplyPoint::getCode, point -> point));
+            //并行流寻找无效线
             List<GisSurveySystemCheckElement> elements = lines.parallelStream()
                     //响应中断
                     .peek(line -> {
                         if (Thread.currentThread().isInterrupted())
                             throw new UncheckedInterruptedException(new InterruptedException());
                     })
-                    //转为返回元素
+                    //过滤无效线
+                    .filter(line -> {
+                        //线格式判断
+                        if (line.getGis() == null || line.getGis().getCoordinates().length < 2 ||
+                                StringUtils.isAnyBlank(line.getUpNode(), line.getDownNode())) return true;
+                        //判断下游节点不存在
+                        if (!connectedPoints.containsKey(line.getUpNode()) || !connectedPoints.containsKey(line.getDownNode()))
+                            return true;
+                        //判断上游节点gis包含
+                        GisSurveyLayerApplyPoint upPoint = connectedPoints.get(line.getUpNode());
+                        if (!GeomUtil.calcContain(line, upPoint, lngTolerance, latTolerance)) return true;
+                        //判断下游节点gis包含
+                        GisSurveyLayerApplyPoint downPoint = connectedPoints.get(line.getDownNode());
+                        if (!GeomUtil.calcContain(line, downPoint, lngTolerance, latTolerance)) return true;
+                        //线坐标
+                        Coordinate[] coordinates = line.getGis().getCoordinates();
+                        //判断线长度小于误差
+                        return Math.sqrt(lngTolerance * lngTolerance + latTolerance * latTolerance) >=
+                                GeomUtil.calcLength(coordinates[0], coordinates[coordinates.length - 1]);
+                    })
                     .map(line -> BeanUtil.copy(line, GisSurveySystemCheckElement.class))
                     .collect(Collectors.toList());
+
             return new AsyncResult<>(createSystemCheckResult(elements, systemCheckId, begin));
+        } catch (UncheckedInterruptedException e) {
+            throw e.getCause();
         }
-        //如线为空,则无无效线
-        if (lines.isEmpty())
-            return new AsyncResult<>(createSystemCheckResult(Lists.newArrayList(), systemCheckId, begin));
-        //联通点
-        Map<String, GisSurveyLayerApplyPoint> connectedPoints = points.parallelStream()
-                //响应中断
-                .peek(line -> {
-                    if (Thread.currentThread().isInterrupted())
-                        throw new UncheckedInterruptedException(new InterruptedException());
-                })
-                .filter(point -> Objects.nonNull(point) && Objects.nonNull(point.getCode()))
-                //获取点编码
-                .collect(Collectors.toMap(GisSurveyLayerApplyPoint::getCode, point -> point));
-        //并行流寻找无效线
-        List<GisSurveySystemCheckElement> elements = lines.parallelStream()
-                //响应中断
-                .peek(line -> {
-                    if (Thread.currentThread().isInterrupted())
-                        throw new UncheckedInterruptedException(new InterruptedException());
-                })
-                //过滤无效线
-                .filter(line -> {
-                    //线格式判断
-                    if (line.getGis() == null || line.getGis().getCoordinates().length < 2 ||
-                            StringUtils.isAnyBlank(line.getUpNode(), line.getDownNode())) return true;
-                    //判断下游节点不存在
-                    if (!connectedPoints.containsKey(line.getUpNode()) || !connectedPoints.containsKey(line.getDownNode()))
-                        return true;
-                    //判断上游节点gis包含
-                    GisSurveyLayerApplyPoint upPoint = connectedPoints.get(line.getUpNode());
-                    if (!GeomUtil.calcContain(line, upPoint, lngTolerance, latTolerance)) return true;
-                    //判断下游节点gis包含
-                    GisSurveyLayerApplyPoint downPoint = connectedPoints.get(line.getDownNode());
-                    if (!GeomUtil.calcContain(line, downPoint, lngTolerance, latTolerance)) return true;
-                    //线坐标
-                    Coordinate[] coordinates = line.getGis().getCoordinates();
-                    //判断线长度小于误差
-                    return Math.sqrt(lngTolerance * lngTolerance + latTolerance * latTolerance) >=
-                            GeomUtil.calcLength(coordinates[0], coordinates[coordinates.length - 1]);
-                })
-                .map(line -> BeanUtil.copy(line, GisSurveySystemCheckElement.class))
-                .collect(Collectors.toList());
-
-        return new AsyncResult<>(createSystemCheckResult(elements, systemCheckId, begin));
     }
 
     /**