소스 검색

增加第三方导出获取结果接口

欧阳劲驰 1 개월 전
부모
커밋
29a0c27d2c

+ 24 - 1
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyThirdExportBizService.java

@@ -75,7 +75,7 @@ public class GisSurveyThirdExportBizService {
      */
     public CommAsyncResult<Map<String, String>> thirdExport(String jobId, FileTypeEnum fileType) {
         //获取上次结果
-        CommAsyncResult<Map<String, String>> lastResult = getResult(jobId);
+        CommAsyncResult<Map<String, String>> lastResult = getTempResult(jobId);
 
         //失败/进行中处理
         if (lastResult != null && !Objects.equals(CommAsyncStatusEnum.SUCCESS.getCode(), lastResult.getStatus()))
@@ -115,6 +115,26 @@ public class GisSurveyThirdExportBizService {
      * @return 结果
      */
     public CommAsyncResult<Map<String, String>> getResult(String jobId) {
+        //获取上次结果
+        CommAsyncResult<Map<String, String>> lastResult = getTempResult(jobId);
+        //失败/进行中处理
+        if (lastResult != null && !Objects.equals(CommAsyncStatusEnum.SUCCESS.getCode(), lastResult.getStatus()))
+            return lastResult;
+
+        //文件结果flag
+        final String FLAG = GisSurveyThirdExporter.RESULT_PREFIX + jobId;
+        //获取文件结果
+        return asyncResultManager.getResult(FLAG, new TypeReference<CommAsyncResult<Map<String, String>>>() {
+        });
+    }
+
+    /**
+     * 获取缓存结果
+     *
+     * @param jobId 任务id
+     * @return 缓存结果
+     */
+    private CommAsyncResult<Map<String, String>> getTempResult(String jobId) {
         //获取已存在的任务
         ListenableFuture<CommAsyncResult<Map<String, String>>> previousFuture = TASK_CACHE.get(jobId);
 
@@ -141,6 +161,9 @@ public class GisSurveyThirdExportBizService {
         if (previousFuture != null && !previousFuture.isDone() && !previousFuture.isCancelled())
             return CommAsyncResult.inProgress(jobId, TIME_CACHE.get(jobId));
 
+        //取消判断
+        if (previousFuture != null && previousFuture.isCancelled()) removeCache(jobId);
+
         return null;
     }
 

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

@@ -34,6 +34,7 @@ public class ApiURI {
     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_EXPORT = "third-export";
+    public static final String URI_XXX_THIRD_EXPORT_GET = "third-export-get";
     public static final String URI_XXX_CAD_CONVERT = "cad-convert";
     public static final String URI_XXX_CAD_CONVERT_GET = "cad-convert-get";
     public static final String URI_XXX_TEMP_FILES = "temp-files";

+ 77 - 2
src/main/java/com/shkpr/service/alambizplugin/controller/ApiGisSurveyController.java

@@ -66,6 +66,7 @@ public class ApiGisSurveyController {
     private final AtomicInteger mSeqThirdImportCommitReq;
     private final AtomicInteger mSeqCadConvertReq;
     private final AtomicInteger mSeqThirdExportReq;
+    private final AtomicInteger mSeqThirdExportGetReq;
     private final AtomicInteger mSeqCadConvertGetReq;
 
     private final GisSurveySystemCheckBizService systemCheckBizService;
@@ -91,6 +92,7 @@ public class ApiGisSurveyController {
         mSeqThirdImportPreviewReq = new AtomicInteger(0);
         mSeqThirdImportCommitReq = new AtomicInteger(0);
         mSeqThirdExportReq = new AtomicInteger(0);
+        mSeqThirdExportGetReq = new AtomicInteger(0);
         mSeqCadConvertReq = new AtomicInteger(0);
         mSeqCadConvertGetReq = new AtomicInteger(0);
         this.systemCheckBizService = systemCheckBizService;
@@ -607,12 +609,12 @@ public class ApiGisSurveyController {
             , @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 = "fileType", required = false, defaultValue = "excel") String fileType) throws SelfException {
+            , @RequestParam(value = "fileType", required = false) String fileType) 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 || StringUtils.length(fileType) > 64) {
+        if (StringUtils.isAnyBlank(jobId,fileType) || StringUtils.length(jobId) > 64 || StringUtils.length(fileType) > 64) {
             throw new SelfException(ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrCode()
                     , String.format(ApiURI.EXCEPTION_FORMAT
                     , strPlatform
@@ -667,6 +669,79 @@ public class ApiGisSurveyController {
     }
 
     /**
+     * 获取第三方导出结果
+     *
+     * @param request       request
+     * @param strClientType 客户端类型
+     * @param strUserAgent  用户信息
+     * @param jobId         任务id
+     * @return cad转换结果
+     */
+    @GetMapping(value = ApiURI.URI_XXX_THIRD_EXPORT_GET)
+    public ResponseRes<CommAsyncResult<Map<String, String>>> thirdExportGet(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) 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()));
+        }
+
+        //begin
+        long llReqBefore = System.currentTimeMillis();
+        String strRunSeq = String.format("%d-%d", llReqBefore, mSeqThirdExportGetReq.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<CommAsyncResult<Map<String, String>>> resResult = new ResponseRes<>();
+        resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrCode());
+        resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrMsg());
+
+        //执行第三方导出
+        CommAsyncResult<Map<String, String>> result = thirdExportBizService.getResult(jobId);
+
+        //执行成功
+        if (result != null && !Objects.equals(result.getStatus(), CommAsyncStatusEnum.FAIL.getCode())) {
+            resResult.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
+            resResult.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
+            resResult.setResdata(result);
+        }
+        //执行失败
+        if (result != null && Objects.equals(result.getStatus(), CommAsyncStatusEnum.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
+        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;
+    }
+
+    /**
      * 执行cad转换
      *
      * @param request         request

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

@@ -28,6 +28,7 @@ public class ApiJWTGisSurveyBizFilter extends JWTAuthenticationFilter {
         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_EXPORT), "GET");
+        msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_EXPORT_GET), "GET");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_CAD_CONVERT), "POST");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_CAD_CONVERT_GET), "GET");
     }