Bladeren bron

增加忽略失败入参

欧阳劲驰 2 maanden geleden
bovenliggende
commit
d48d99b9ff

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

@@ -45,6 +45,11 @@ public class GisSurveyCheckParams {
     private String operator;
 
     /**
+     * 忽略失败
+     */
+    private Boolean ignoreFail = false;
+
+    /**
      * 返回上次结果
      */
     private Boolean returnLastResult = false;

+ 26 - 6
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyBizService.java

@@ -6,6 +6,7 @@ import com.shkpr.service.alambizplugin.apiparam.GisSurveyCheckParams;
 import com.shkpr.service.alambizplugin.commproperties.GisSurveySystemCheckProperties;
 import com.shkpr.service.alambizplugin.components.GisSurveySystemCheckResultManager;
 import com.shkpr.service.alambizplugin.components.GisSurveySystemChecker;
+import com.shkpr.service.alambizplugin.constants.GisSurveyCheckStatusEnum;
 import com.shkpr.service.alambizplugin.constants.GisSurveyCheckTypeEnum;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyJobInfoService;
@@ -20,7 +21,9 @@ import java.time.Duration;
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 
 /**
@@ -79,6 +82,22 @@ public class GisSurveyBizService {
         if (systemCheckId == null) return GisSurveySystemCheckResult.notExists(params);
         //获取已存在的任务
         ListenableFuture<GisSurveySystemCheckResult> previousFuture = TASK_CACHE.get(systemCheckId);
+        //如任务已完成,则检查历史失败
+        if (!params.getIgnoreFail() && previousFuture != null && previousFuture.isDone()) {
+            try {
+                //获取结果,并检查失败
+                GisSurveySystemCheckResult gisSurveySystemCheckResult = previousFuture.get();
+                if (Objects.equals(gisSurveySystemCheckResult.getCheckStatus(), GisSurveyCheckStatusEnum.FAIL.getCode()))
+                    return gisSurveySystemCheckResult;
+            } catch (InterruptedException | ExecutionException e) {
+                //打印报错信息(不太可能走到这)
+                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                        , String.format("检查历史失败异常 系统检查id:%s msg:%s", systemCheckId, e.getMessage())
+                );
+            }
+
+        }
+
         //获取已存在的结果
         GisSurveySystemCheckResult result = systemCheckFileManager.getResult(systemCheckId);
         //获取元素更新时间
@@ -97,6 +116,7 @@ public class GisSurveyBizService {
                 }
             }
         }
+
         //系统检查子任务
         GisSurveySystemCheckSubtask checkSubtask = SUBTASK_CACHE.get(systemCheckId);
         //进行中判断(未完成且未清除)
@@ -138,25 +158,25 @@ public class GisSurveyBizService {
      */
     public void expireResult(Duration ttl) {
         //获取超时的id
-        List<GisSurveySystemCheckId> taskIds = TIME_CACHE.entrySet().stream()
+        List<GisSurveySystemCheckId> systemCheckIds = TIME_CACHE.entrySet().stream()
                 .filter(entry ->
                         Duration.between(entry.getValue(), LocalDateTime.now()).compareTo(ttl) > 0
                 )
                 .map(Map.Entry::getKey)
                 .collect(Collectors.toList());
         //停止超时的任务并删除任务缓存
-        for (GisSurveySystemCheckId taskId : taskIds) {
+        for (GisSurveySystemCheckId systemCheckId : systemCheckIds) {
             //如任务不存在,则删除时间缓存
-            if (!TASK_CACHE.containsKey(taskId)) TIME_CACHE.remove(taskId);
+            if (!TASK_CACHE.containsKey(systemCheckId)) TIME_CACHE.remove(systemCheckId);
             //停用缓存
-            if (stopTask(taskId)) TIME_CACHE.remove(taskId);
+            if (stopTask(systemCheckId)) TIME_CACHE.remove(systemCheckId);
             else {
                 //打印报错信息
                 LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
                         , String.format(
-                                "过期任务停止失败 ttl:%s taskId:%s"
+                                "过期任务停止失败 ttl:%s 系统检查id:%s"
                                 , ttl
-                                , taskId
+                                , systemCheckId
                         )
                 );
             }

+ 4 - 0
src/main/java/com/shkpr/service/alambizplugin/controller/ApiGisSurveyController.java

@@ -97,6 +97,10 @@ public class ApiGisSurveyController {
             resResult.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
             resResult.setResdata(result);
         }
+        //执行失败
+        if (result != null && Objects.equals(result.getCheckStatus(), GisSurveyCheckStatusEnum.FAIL.getCode())) {
+            resResult.setResdata(result);
+        }
         //结果为空
         if (result == null) {
             resResult.setRescode(ResponseCode.RESULT_SYSTEM_CHECK_RESULT_NOT_FOUND.toStrCode());