Ver código fonte

增加第三方导入任务状态获取接口

欧阳劲驰 2 meses atrás
pai
commit
fd319b0896

+ 6 - 1
src/main/java/com/shkpr/service/alambizplugin/apiparam/GisSurveyThirdImportParams.java

@@ -22,7 +22,7 @@ public class GisSurveyThirdImportParams {
     /**
     /**
      * 文件列表
      * 文件列表
      */
      */
-    private final List<MultipartFile> files;
+    private List<MultipartFile> files;
     /**
     /**
      * 操作人
      * 操作人
      */
      */
@@ -43,4 +43,9 @@ public class GisSurveyThirdImportParams {
      * 忽略失败
      * 忽略失败
      */
      */
     private Boolean ignoreFail;
     private Boolean ignoreFail;
+
+    public GisSurveyThirdImportParams(String jobId, Boolean ignoreFail) {
+        this.jobId = jobId;
+        this.ignoreFail = ignoreFail;
+    }
 }
 }

+ 28 - 17
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyThirdImportBizService.java

@@ -66,9 +66,34 @@ public class GisSurveyThirdImportBizService {
      * @return 导入状态
      * @return 导入状态
      */
      */
     public GisSurveyThirdImportResult thirdImport(GisSurveyThirdImportParams params) {
     public GisSurveyThirdImportResult thirdImport(GisSurveyThirdImportParams params) {
+        //获取结果
+        GisSurveyThirdImportResult result = getResult(params);
+        if (result != null) return result;
+
+        //获取文件流
+        List<InputStream> inputStreams = new ArrayList<>();
+        for (MultipartFile file : params.getFiles()) {
+            try {
+                inputStreams.add(file.getInputStream());
+            } catch (IOException e) {
+                return GisSurveyThirdImportResult.fail(params);
+            }
+        }
+        //启动检查任务
+        startTask(params, inputStreams);
+        //返回进行中
+        return GisSurveyThirdImportResult.inProgress(params, SUBTASK_CACHE.get(params.getJobId()), LocalDateTime.now());
+    }
+
+    /**
+     * 获取结果
+     *
+     * @param params 第三方导入参数
+     * @return 导入结果
+     */
+    public GisSurveyThirdImportResult getResult(GisSurveyThirdImportParams params) {
         //获取已存在的任务
         //获取已存在的任务
         ListenableFuture<GisSurveyThirdImportResult> previousFuture = TASK_CACHE.get(params.getJobId());
         ListenableFuture<GisSurveyThirdImportResult> previousFuture = TASK_CACHE.get(params.getJobId());
-
         //判断完成
         //判断完成
         if (previousFuture != null && previousFuture.isDone()) {
         if (previousFuture != null && previousFuture.isDone()) {
             try {
             try {
@@ -92,25 +117,11 @@ public class GisSurveyThirdImportBizService {
             }
             }
         }
         }
 
 
-        //系统检查子任务
-        GisSurveyThirdImportSubtask importSubtask = SUBTASK_CACHE.get(params.getJobId());
         //进行中判断(未完成且未清除)
         //进行中判断(未完成且未清除)
         if (previousFuture != null && !previousFuture.isDone() && !previousFuture.isCancelled())
         if (previousFuture != null && !previousFuture.isDone() && !previousFuture.isCancelled())
-            return GisSurveyThirdImportResult.inProgress(params, importSubtask, TIME_CACHE.get(params.getJobId()));
+            return GisSurveyThirdImportResult.inProgress(params, SUBTASK_CACHE.get(params.getJobId()), TIME_CACHE.get(params.getJobId()));
 
 
-        //获取文件流
-        List<InputStream> inputStreams = new ArrayList<>();
-        for (MultipartFile file : params.getFiles()) {
-            try {
-                inputStreams.add(file.getInputStream());
-            } catch (IOException e) {
-                return GisSurveyThirdImportResult.fail(params);
-            }
-        }
-        //启动检查任务
-        startTask(params, inputStreams);
-        //返回进行中
-        return GisSurveyThirdImportResult.inProgress(params, importSubtask, LocalDateTime.now());
+        return null;
     }
     }
 
 
     /**
     /**

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

@@ -29,6 +29,7 @@ public class ApiURI {
     public static final String URI_XXX_SYS_CHECK_CANCEL = "sys-check-cancel";
     public static final String URI_XXX_SYS_CHECK_CANCEL = "sys-check-cancel";
     public static final String URI_XXX_SYS_CHECK_RESULTS = "sys-check-results";
     public static final String URI_XXX_SYS_CHECK_RESULTS = "sys-check-results";
     public static final String URI_XXX_THIRD_IMPORT = "third-import";
     public static final String URI_XXX_THIRD_IMPORT = "third-import";
+    public static final String URI_XXX_THIRD_IMPORT_GET = "third-import-get";
     public static final String URI_XXX_THIRD_IMPORT_CANCEL = "third-import-cancel";
     public static final String URI_XXX_THIRD_IMPORT_CANCEL = "third-import-cancel";
     public static final String URI_XXX_THIRD_IMPORT_PREVIEW = "third-import-preview";
     public static final String URI_XXX_THIRD_IMPORT_PREVIEW = "third-import-preview";
     public static final String URI_XXX_THIRD_IMPORT_COMMIT = "third-import-commit";
     public static final String URI_XXX_THIRD_IMPORT_COMMIT = "third-import-commit";

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

@@ -100,10 +100,6 @@ public enum ResponseCode {
     RESULT_SYSTEM_CHECK_CANCEL_FAILED(40002, "System check cancel failed."),
     RESULT_SYSTEM_CHECK_CANCEL_FAILED(40002, "System check cancel failed."),
     RESULT_SYSTEM_CHECK_RESULT_NOT_FOUND(40003, "System check result not found."),
     RESULT_SYSTEM_CHECK_RESULT_NOT_FOUND(40003, "System check result not found."),
 
 
-    RESULT_THIRD_IMPORT_FAILED(40010, "Third import failed."),
-    RESULT_THIRD_IMPORT_NOT_FOUND(40011, "Third import not found."),
-    RESULT_THIRD_IMPORT_CANCEL_FAILED(40012, "Third import cancel failed."),
-
     RESULT_ASYNC_TASK_FAILED(40010, "Async task failed."),
     RESULT_ASYNC_TASK_FAILED(40010, "Async task failed."),
     RESULT_ASYNC_TASK_NOT_FOUND(40011, "Async task not found."),
     RESULT_ASYNC_TASK_NOT_FOUND(40011, "Async task not found."),
     RESULT_ASYNC_TASK_CANCEL_FAILED(40012, "Async task cancel failed."),
     RESULT_ASYNC_TASK_CANCEL_FAILED(40012, "Async task cancel failed."),

+ 95 - 16
src/main/java/com/shkpr/service/alambizplugin/controller/ApiGisSurveyController.java

@@ -56,11 +56,12 @@ public class ApiGisSurveyController {
     private final AtomicInteger mSeqSysCheckReq;
     private final AtomicInteger mSeqSysCheckReq;
     private final AtomicInteger mSeqSysCheckCancelReq;
     private final AtomicInteger mSeqSysCheckCancelReq;
     private final AtomicInteger mSeqThirdImportReq;
     private final AtomicInteger mSeqThirdImportReq;
+    private final AtomicInteger mSeqThirdImportGetReq;
     private final AtomicInteger mSeqThirdImportCancelReq;
     private final AtomicInteger mSeqThirdImportCancelReq;
     private final AtomicInteger mSeqThirdImportPreviewReq;
     private final AtomicInteger mSeqThirdImportPreviewReq;
     private final AtomicInteger mSeqThirdImportCommitReq;
     private final AtomicInteger mSeqThirdImportCommitReq;
     private final AtomicInteger mSeqCadConvertReq;
     private final AtomicInteger mSeqCadConvertReq;
-    private final AtomicInteger mSeqCadConvertResultReq;
+    private final AtomicInteger mSeqCadConvertGetReq;
 
 
     private final GisSurveySystemCheckBizService systemCheckBizService;
     private final GisSurveySystemCheckBizService systemCheckBizService;
     private final GisSurveyThirdImportBizService thirdImportBizService;
     private final GisSurveyThirdImportBizService thirdImportBizService;
@@ -77,11 +78,12 @@ public class ApiGisSurveyController {
         mSeqSysCheckReq = new AtomicInteger(0);
         mSeqSysCheckReq = new AtomicInteger(0);
         mSeqSysCheckCancelReq = new AtomicInteger(0);
         mSeqSysCheckCancelReq = new AtomicInteger(0);
         mSeqThirdImportReq = new AtomicInteger(0);
         mSeqThirdImportReq = new AtomicInteger(0);
+        mSeqThirdImportGetReq = new AtomicInteger(0);
         mSeqThirdImportCancelReq = new AtomicInteger(0);
         mSeqThirdImportCancelReq = new AtomicInteger(0);
         mSeqThirdImportPreviewReq = new AtomicInteger(0);
         mSeqThirdImportPreviewReq = new AtomicInteger(0);
         mSeqThirdImportCommitReq = new AtomicInteger(0);
         mSeqThirdImportCommitReq = new AtomicInteger(0);
         mSeqCadConvertReq = new AtomicInteger(0);
         mSeqCadConvertReq = new AtomicInteger(0);
-        mSeqCadConvertResultReq = new AtomicInteger(0);
+        mSeqCadConvertGetReq = new AtomicInteger(0);
         this.systemCheckBizService = systemCheckBizService;
         this.systemCheckBizService = systemCheckBizService;
         this.thirdImportBizService = thirdImportBizService;
         this.thirdImportBizService = thirdImportBizService;
         this.cadConvertBizService = cadConvertBizService;
         this.cadConvertBizService = cadConvertBizService;
@@ -278,8 +280,8 @@ public class ApiGisSurveyController {
                         , params));
                         , params));
         //构建result
         //构建result
         ResponseRes<GisSurveyThirdImportResult> resResult = new ResponseRes<>();
         ResponseRes<GisSurveyThirdImportResult> resResult = new ResponseRes<>();
-        resResult.setRescode(ResponseCode.RESULT_THIRD_IMPORT_FAILED.toStrCode());
-        resResult.setResmsg(ResponseCode.RESULT_THIRD_IMPORT_FAILED.toStrMsg());
+        resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrCode());
+        resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrMsg());
 
 
         //执行第三方导入
         //执行第三方导入
         GisSurveyThirdImportResult result = thirdImportBizService.thirdImport(params);
         GisSurveyThirdImportResult result = thirdImportBizService.thirdImport(params);
@@ -296,8 +298,85 @@ public class ApiGisSurveyController {
         }
         }
         //结果为空
         //结果为空
         if (result == null) {
         if (result == null) {
-            resResult.setRescode(ResponseCode.RESULT_THIRD_IMPORT_NOT_FOUND.toStrCode());
-            resResult.setResmsg(ResponseCode.RESULT_THIRD_IMPORT_NOT_FOUND.toStrMsg());
+            resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_NOT_FOUND.toStrCode());
+            resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_NOT_FOUND.toStrMsg());
+        }
+
+        //end
+        resResult.setTimestamp(System.currentTimeMillis());
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
+                , String.format("%s:%s seq:{%s} rescode:{%s} resmsg:{%s} time:{%d ms} end<===="
+                        , strPlatform
+                        , URI_PATH
+                        , strRunSeq
+                        , resResult.getRescode()
+                        , resResult.getResmsg()
+                        , resResult.getTimestamp() - llReqBefore));
+        return resResult;
+    }
+
+    /**
+     * 获取第三方导入结果
+     *
+     * @param request       request
+     * @param strClientType 客户端类型
+     * @param strUserAgent  用户信息
+     * @param jobId         任务id
+     * @param ignoreFail    是否忽略错误
+     * @return 第三方导入结果
+     */
+    @GetMapping(value = ApiURI.URI_XXX_THIRD_IMPORT_GET)
+    public ResponseRes<GisSurveyThirdImportResult> thirdImportGet(HttpServletRequest request
+            , @RequestHeader(value = ApiURI.HEADER_CLIENT_TYPE, required = false) String strClientType
+            , @RequestHeader(value = ApiURI.HEADER_USER_AGENT, required = false) String strUserAgent
+            , @RequestParam(value = "jobId", required = false) String jobId
+            , @RequestParam(value = "ignoreFail", required = false, defaultValue = "false") String ignoreFail) throws SelfException {
+        //入参校验
+        final String URI_PATH = request.getRequestURI();
+        final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
+        final String strUserId = (String) request.getAttribute(TokenAuthenticationService.HEADER_USERID);
+        if (StringUtils.isAnyBlank(jobId) || StringUtils.length(jobId) > 64) {
+            throw new SelfException(ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrCode()
+                    , String.format(ApiURI.EXCEPTION_FORMAT
+                    , strPlatform
+                    , URI_PATH
+                    , ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrMsg()));
+        }
+
+        //构建入参数
+        GisSurveyThirdImportParams params = new GisSurveyThirdImportParams(jobId, Boolean.parseBoolean(ignoreFail));
+        //begin
+        long llReqBefore = System.currentTimeMillis();
+        String strRunSeq = String.format("%d-%d", llReqBefore, mSeqThirdImportGetReq.incrementAndGet());
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
+                , String.format("%s:%s seq:{%s} param:%s begin====>"
+                        , strPlatform
+                        , URI_PATH
+                        , strRunSeq
+                        , jobId));
+
+        //构建result
+        ResponseRes<GisSurveyThirdImportResult> resResult = new ResponseRes<>();
+        resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrCode());
+        resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrMsg());
+
+        //执行cad转换
+        GisSurveyThirdImportResult result = thirdImportBizService.getResult(params);
+
+        //执行成功
+        if (result != null && !Objects.equals(result.getImportStatus(), GisSurveConvertStatusEnum.FAIL.getCode())) {
+            resResult.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
+            resResult.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
+            resResult.setResdata(result);
+        }
+        //执行失败
+        if (result != null && Objects.equals(result.getImportStatus(), GisSurveConvertStatusEnum.FAIL.getCode())) {
+            resResult.setResdata(result);
+        }
+        //不存在
+        if (result == null) {
+            resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_NOT_FOUND.toStrCode());
+            resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_NOT_FOUND.toStrMsg());
         }
         }
 
 
         //end
         //end
@@ -350,8 +429,8 @@ public class ApiGisSurveyController {
                         , jobId));
                         , jobId));
         //构建result
         //构建result
         ResponseRes<Boolean> resResult = new ResponseRes<>();
         ResponseRes<Boolean> resResult = new ResponseRes<>();
-        resResult.setRescode(ResponseCode.RESULT_THIRD_IMPORT_CANCEL_FAILED.toStrCode());
-        resResult.setResmsg(ResponseCode.RESULT_THIRD_IMPORT_CANCEL_FAILED.toStrMsg());
+        resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrCode());
+        resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrMsg());
         //清除导入
         //清除导入
         Integer cancelCheck = thirdImportBizService.cancelImport(jobId);
         Integer cancelCheck = thirdImportBizService.cancelImport(jobId);
         //成功
         //成功
@@ -361,8 +440,8 @@ public class ApiGisSurveyController {
         }
         }
         //不存在
         //不存在
         else if (Objects.equals(cancelCheck, GisSurveyCheckStatusEnum.NOT_EXISTS.getCode())) {
         else if (Objects.equals(cancelCheck, GisSurveyCheckStatusEnum.NOT_EXISTS.getCode())) {
-            resResult.setRescode(ResponseCode.RESULT_THIRD_IMPORT_NOT_FOUND.toStrCode());
-            resResult.setResmsg(ResponseCode.RESULT_THIRD_IMPORT_NOT_FOUND.toStrMsg());
+            resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_NOT_FOUND.toStrCode());
+            resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_NOT_FOUND.toStrMsg());
         }
         }
         //end
         //end
         resResult.setTimestamp(System.currentTimeMillis());
         resResult.setTimestamp(System.currentTimeMillis());
@@ -417,8 +496,8 @@ public class ApiGisSurveyController {
 
 
         //构建result
         //构建result
         ResponseRes<PageResponse<GisSurveyLayerApplyThirdCopy>> resResult = new ResponseRes<>();
         ResponseRes<PageResponse<GisSurveyLayerApplyThirdCopy>> resResult = new ResponseRes<>();
-        resResult.setRescode(ResponseCode.RESULT_THIRD_IMPORT_FAILED.toStrCode());
-        resResult.setResmsg(ResponseCode.RESULT_THIRD_IMPORT_FAILED.toStrMsg());
+        resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrCode());
+        resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrMsg());
 
 
         //查询
         //查询
         PageResponse<GisSurveyLayerApplyThirdCopy> pageResponse = layerApplyThirdCopyService.findByJobId(jobId, pageable);
         PageResponse<GisSurveyLayerApplyThirdCopy> pageResponse = layerApplyThirdCopyService.findByJobId(jobId, pageable);
@@ -479,8 +558,8 @@ public class ApiGisSurveyController {
                         , jobId));
                         , jobId));
         //构建result
         //构建result
         ResponseRes<Boolean> resResult = new ResponseRes<>();
         ResponseRes<Boolean> resResult = new ResponseRes<>();
-        resResult.setRescode(ResponseCode.RESULT_THIRD_IMPORT_FAILED.toStrCode());
-        resResult.setResmsg(ResponseCode.RESULT_THIRD_IMPORT_FAILED.toStrMsg());
+        resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrCode());
+        resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrMsg());
 
 
         //提交导入
         //提交导入
         Boolean commitStatus = layerApplyService.mergeCopy(jobId, operator);
         Boolean commitStatus = layerApplyService.mergeCopy(jobId, operator);
@@ -616,7 +695,7 @@ public class ApiGisSurveyController {
      * @return cad转换结果
      * @return cad转换结果
      */
      */
     @GetMapping(value = ApiURI.URI_XXX_CAD_CONVERT_GET)
     @GetMapping(value = ApiURI.URI_XXX_CAD_CONVERT_GET)
-    public ResponseRes<GisSurveyCadConvertResult> cadConvertResult(HttpServletRequest request
+    public ResponseRes<GisSurveyCadConvertResult> cadConvertGet(HttpServletRequest request
             , @RequestHeader(value = ApiURI.HEADER_CLIENT_TYPE, required = false) String strClientType
             , @RequestHeader(value = ApiURI.HEADER_CLIENT_TYPE, required = false) String strClientType
             , @RequestHeader(value = ApiURI.HEADER_USER_AGENT, required = false) String strUserAgent
             , @RequestHeader(value = ApiURI.HEADER_USER_AGENT, required = false) String strUserAgent
             , @RequestParam(value = "convertId", required = false) String convertId) throws SelfException {
             , @RequestParam(value = "convertId", required = false) String convertId) throws SelfException {
@@ -634,7 +713,7 @@ public class ApiGisSurveyController {
 
 
         //begin
         //begin
         long llReqBefore = System.currentTimeMillis();
         long llReqBefore = System.currentTimeMillis();
-        String strRunSeq = String.format("%d-%d", llReqBefore, mSeqCadConvertResultReq.incrementAndGet());
+        String strRunSeq = String.format("%d-%d", llReqBefore, mSeqCadConvertGetReq.incrementAndGet());
         LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
         LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
                 , String.format("%s:%s seq:{%s} param:%s begin====>"
                 , String.format("%s:%s seq:{%s} param:%s begin====>"
                         , strPlatform
                         , strPlatform

+ 1 - 0
src/main/java/com/shkpr/service/alambizplugin/controllerfilter/third/ApiJWTGisSurveyBizFilter.java

@@ -23,6 +23,7 @@ public class ApiJWTGisSurveyBizFilter extends JWTAuthenticationFilter {
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_SYS_CHECK_CANCEL), "POST");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_SYS_CHECK_CANCEL), "POST");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_SYS_CHECK_RESULTS), "GET");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_SYS_CHECK_RESULTS), "GET");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_IMPORT), "POST");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_IMPORT), "POST");
+        msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_IMPORT_GET), "GET");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_IMPORT_CANCEL), "GET");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_IMPORT_CANCEL), "GET");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_IMPORT_PREVIEW), "GET");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_IMPORT_PREVIEW), "GET");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_IMPORT_COMMIT), "GET");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_IMPORT_COMMIT), "GET");