Pārlūkot izejas kodu

增加结果控制、启动控制、子任务控制

欧阳劲驰 2 mēneši atpakaļ
vecāks
revīzija
371627ce26

+ 31 - 0
src/main/java/com/shkpr/service/alambizplugin/apiparam/GisSurveyCheckParams.java

@@ -45,7 +45,38 @@ public class GisSurveyCheckParams {
     private String operator;
 
     /**
+     * 返回上次结果
+     */
+    private Boolean returnLastResult = false;
+
+    /**
+     * 是否启动检查(满足检查条件的情况下)
+     */
+    private Boolean checkStart = true;
+
+    /**
+     * 孤立点启动
+     */
+    private Boolean isolatedPointsStart = true;
+
+    /**
+     * 孤立线启动
+     */
+    private Boolean isolatedLinesStart = true;
+
+    /**
+     * 重复点启动
+     */
+    private Boolean duplicatePointsStart = true;
+
+    /**
+     * 重叠线启动
+     */
+    private Boolean overlapLinesStart = true;
+
+    /**
      * 元素/属性的变化时间
+     * <p>系统内部用</p>
      */
     private LocalDateTime refreshTime;
 

+ 14 - 5
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyBizService.java

@@ -103,10 +103,17 @@ public class GisSurveyBizService {
         if (previousFuture != null && !previousFuture.isDone() && !previousFuture.isCancelled())
             return GisSurveySystemCheckResult.inProgress(params, checkSubtask, TIME_CACHE.get(systemCheckId));
         //启动检查任务
-        startTask(systemCheckId, params);
-        //返回进行中
-        return GisSurveySystemCheckResult.inProgress(params, checkSubtask, LocalDateTime.now());
-
+        if (Boolean.TRUE.equals(params.getCheckStart())) {
+            startTask(systemCheckId, params);
+            //如需要返回上次结果,则直接返回结果
+            if (Boolean.TRUE.equals(params.getReturnLastResult())) {
+                return result;
+            }
+            //返回进行中
+            return GisSurveySystemCheckResult.inProgress(params, checkSubtask, LocalDateTime.now());
+        }
+        //未启动返回结果
+        return result;
     }
 
     /**
@@ -191,7 +198,9 @@ public class GisSurveyBizService {
         //异步执行系统检查任务
         ListenableFuture<GisSurveySystemCheckResult> checkFuture = systemChecker.systemCheckTask(params,
                 //缓存子任务句柄
-                subtask -> SUBTASK_CACHE.put(systemCheckId, subtask)
+                subtask -> SUBTASK_CACHE.put(systemCheckId, subtask),
+                //删除子任务句柄
+                subtaskSystemCheckId -> SUBTASK_CACHE.remove(systemCheckId)
         );
         //缓存任务句柄
         TASK_CACHE.put(systemCheckId, checkFuture);

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

@@ -68,11 +68,14 @@ public class GisSurveySystemChecker {
     /**
      * 系统检查任务
      *
-     * @param params 系统检查参数
+     * @param params              系统检查参数
+     * @param onStartSubtask      启动子任务
+     * @param onDeprecatedSubtask 弃用子任务(完成数据收集/取消)
      * @return 系统检查返回
      */
     @Async
-    public ListenableFuture<GisSurveySystemCheckResult> systemCheckTask(GisSurveyCheckParams params, Consumer<GisSurveySystemCheckSubtask> onStartSubtask) {
+    public ListenableFuture<GisSurveySystemCheckResult> systemCheckTask(GisSurveyCheckParams params
+            , Consumer<GisSurveySystemCheckSubtask> onStartSubtask, Consumer<GisSurveySystemCheckId> onDeprecatedSubtask) {
         //系统检查id
         GisSurveySystemCheckId systemCheckId = GisSurveySystemCheckId.generateId(params);
         if (systemCheckId == null) return new AsyncResult<>(GisSurveySystemCheckResult.fail(params));
@@ -117,16 +120,20 @@ public class GisSurveySystemChecker {
 
             //孤立点检查
             if (points != null && lines != null) {
-                isolatedPointsFuture = isolatedPointsFinder.findIsolatedPoints(points, lines, systemCheckId);
+                if (params.getIsolatedPointsStart())
+                    isolatedPointsFuture = isolatedPointsFinder.findIsolatedPoints(points, lines, systemCheckId);
             }
             //重复点检查
             if (points != null) {
-                duplicatePointsFuture = duplicatePointsFinder.findDuplicatePoints(points, typeDefines, systemCheckId);
+                if (params.getDuplicatePointsStart())
+                    duplicatePointsFuture = duplicatePointsFinder.findDuplicatePoints(points, typeDefines, systemCheckId);
             }
             //孤立线和重叠线检查
             if (lines != null) {
-                isolatedLinesFuture = isolatedLinesFinder.findIsolatedLines(lines, systemCheckId);
-                overlapLinesFuture = overlapLinesFinder.findDuplicateLines(lines, systemCheckId);
+                if (params.getIsolatedLinesStart())
+                    isolatedLinesFuture = isolatedLinesFinder.findIsolatedLines(lines, systemCheckId);
+                if (params.getOverlapLinesStart())
+                    overlapLinesFuture = overlapLinesFinder.findOverlapLines(lines, systemCheckId);
             }
 
             //返回子任务
@@ -167,8 +174,11 @@ public class GisSurveySystemChecker {
             //写入结果
             systemCheckResultManager.writeResult(result, systemCheckId, GisSurveySystemCheckResultPath.RESULT);
             //替换结果
-            if (!systemCheckResultManager.replaceResult(systemCheckId))
+            if (!systemCheckResultManager.replaceResult(systemCheckId)) {
+                //弃用子任务
+                onDeprecatedSubtask.accept(systemCheckId);
                 return new AsyncResult<>(GisSurveySystemCheckResult.fail(params));
+            }
 
             LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
                     , String.format(
@@ -178,6 +188,9 @@ public class GisSurveySystemChecker {
                             Duration.between(result.getRequestTime(), result.getCompleteTime()).toMillis()
                     )
             );
+
+            //弃用子任务
+            onDeprecatedSubtask.accept(systemCheckId);
             return new AsyncResult<>(result);
         } catch (InterruptedException | ExecutionException e) {
             LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
@@ -187,14 +200,19 @@ public class GisSurveySystemChecker {
                             systemCheckId.getCode()
                     )
             );
+
             //清除子任务
             if (isolatedPointsFuture != null) isolatedPointsFuture.cancel(true);
             if (isolatedLinesFuture != null) isolatedLinesFuture.cancel(true);
             if (duplicatePointsFuture != null) duplicatePointsFuture.cancel(true);
             if (overlapLinesFuture != null) overlapLinesFuture.cancel(true);
+
             //失败信息
             result.setCheckStatus(GisSurveyCheckStatusEnum.FAIL.getCode());
             result.setCompleteTime(LocalDateTime.now());
+
+            //弃用子任务
+            onDeprecatedSubtask.accept(systemCheckId);
             return new AsyncResult<>(result);
         }
     }

+ 11 - 11
src/main/java/com/shkpr/service/alambizplugin/components/checker/OverlapLinesFinder.java

@@ -23,7 +23,7 @@ import java.util.Arrays;
 import java.util.List;
 
 /**
- * 寻找重线
+ * 寻找重线
  *
  * @author 欧阳劲驰
  * @since 0.0.1
@@ -46,17 +46,17 @@ public class OverlapLinesFinder {
     }
 
     /**
-     * 寻找重线
-     * <p>返回的为重复线组,未重复的线不会出现在返回结果</p>
+     * 寻找重线
+     * <p>返回的为重叠线组,未重叠的线不会出现在返回结果</p>
      * <p>一组线,仅为两条重叠的线,长度固定为2</p>
      *
      * @param lines 线集合
-     * @return 重线分组
+     * @return 重线分组
      */
     @Async
-    public ListenableFuture<GisSurveySystemCheckResultDetail> findDuplicateLines(List<GisSurveyLayerApplyLine> lines
+    public ListenableFuture<GisSurveySystemCheckResultDetail> findOverlapLines(List<GisSurveyLayerApplyLine> lines
             , GisSurveySystemCheckId systemCheckId) throws InterruptedException {
-        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行寻找重线========>");
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行寻找重线========>");
         long begin = System.currentTimeMillis();
 
         //结果
@@ -70,9 +70,9 @@ public class OverlapLinesFinder {
                 GisSurveyLayerApplyLine line2 = lines.get(j);
                 //响应中断
                 if (Thread.interrupted()) throw new InterruptedException();
-                // 判断是否重
-                if (calcDuplicateLines(line1, line2)) {
-                    // 创建两两一组的重线对
+                // 判断是否重
+                if (calcOverlapLines(line1, line2)) {
+                    // 创建两两一组的重线对
                     groupElements.add(Arrays.asList(BeanUtil.copy(line1, GisSurveySystemCheckElement.class),
                             BeanUtil.copy(line2, GisSurveySystemCheckElement.class)));
                 }
@@ -89,7 +89,7 @@ public class OverlapLinesFinder {
      * @param line2 线段2
      * @return 重叠状态
      */
-    public boolean calcDuplicateLines(GisSurveyLayerApplyLine line1, GisSurveyLayerApplyLine line2) {
+    public boolean calcOverlapLines(GisSurveyLayerApplyLine line1, GisSurveyLayerApplyLine line2) {
         //取出四个点
         Coordinate a = line2.getGis().getCoordinateN(0);
         Coordinate b = line1.getGis().getCoordinateN(1);
@@ -136,7 +136,7 @@ public class OverlapLinesFinder {
         long end = System.currentTimeMillis();
         LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
                 , String.format(
-                        "结束执行寻找重线,用时(毫秒):%d"
+                        "结束执行寻找重线,用时(毫秒):%d"
                         , (end - begin)
                 )
         );

+ 1 - 0
src/main/java/com/shkpr/service/alambizplugin/constants/ResponseCode.java

@@ -98,6 +98,7 @@ public enum ResponseCode {
     RESULT_SYSTEM_CHECK_FAILED(40000, "System check failed."),
     RESULT_SYSTEM_CHECK_NOT_FOUND(40001, "System check not found."),
     RESULT_SYSTEM_CHECK_CANCEL_FAILED(40002, "System check cancel failed."),
+    RESULT_SYSTEM_CHECK_RESULT_NOT_FOUND(40003, "System check result not found."),
 
     BUSINESS_SYNC_FUN_FAILED(65529,"The Synch operation failed."),
     BUSINESS_DB_REQ_FAILED(65530,"The DB operation failed."),

+ 9 - 1
src/main/java/com/shkpr/service/alambizplugin/controller/ApiGisSurveyController.java

@@ -87,14 +87,22 @@ public class ApiGisSurveyController {
         ResponseRes<GisSurveySystemCheckResult> resResult = new ResponseRes<>();
         resResult.setRescode(ResponseCode.RESULT_SYSTEM_CHECK_FAILED.toStrCode());
         resResult.setResmsg(ResponseCode.RESULT_SYSTEM_CHECK_FAILED.toStrMsg());
+
         //执行系统检查
         GisSurveySystemCheckResult result = gisSurveyBizService.sysCheckFun(oJsonParam);
+
         //执行成功
-        if (!Objects.equals(result.getCheckStatus(), GisSurveyCheckStatusEnum.FAIL.getCode())) {
+        if (result != null && !Objects.equals(result.getCheckStatus(), GisSurveyCheckStatusEnum.FAIL.getCode())) {
             resResult.setRescode(ResponseCode.STATUS_SUCCESS.toStrCode());
             resResult.setResmsg(ResponseCode.STATUS_SUCCESS.toStrMsg());
             resResult.setResdata(result);
         }
+        //结果为空
+        if (result == null) {
+            resResult.setRescode(ResponseCode.RESULT_SYSTEM_CHECK_RESULT_NOT_FOUND.toStrCode());
+            resResult.setResmsg(ResponseCode.RESULT_SYSTEM_CHECK_RESULT_NOT_FOUND.toStrMsg());
+        }
+
         //end
         resResult.setTimestamp(System.currentTimeMillis());
         LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId

+ 1 - 1
src/main/java/com/shkpr/service/alambizplugin/dto/GisSurveySystemCheckResultDetail.java

@@ -19,7 +19,7 @@ public class GisSurveySystemCheckResultDetail {
     /**
      * 完成状态
      */
-    private boolean done = false;
+    private Boolean done;
     /**
      * 结果地址
      */