Explorar o código

第三方导出改为post接口,结果增加操作人字段

欧阳劲驰 hai 1 mes
pai
achega
2854cfca7c

+ 35 - 0
src/main/java/com/shkpr/service/alambizplugin/apiparam/GisSurveyThirdExportParams.java

@@ -0,0 +1,35 @@
+package com.shkpr.service.alambizplugin.apiparam;
+
+import com.shkpr.service.alambizplugin.controllervalid.CommonParamValidSK;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * 第三方导入入参
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Data
+public class GisSurveyThirdExportParams {
+    /**
+     * 任务id
+     */
+    @NotNull(groups = {CommonParamValidSK.class})
+    @Size(max = 64, groups = {CommonParamValidSK.class})
+    private String jobId;
+    /**
+     * 文件类型
+     */
+    @NotNull(groups = {CommonParamValidSK.class})
+    @Size(max = 64, groups = {CommonParamValidSK.class})
+    private String fileType;
+    /**
+     * 操作人
+     */
+    @NotNull(groups = {CommonParamValidSK.class})
+    @Size(max = 64, groups = {CommonParamValidSK.class})
+    private String operator;
+}

+ 17 - 10
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyCadConvertBizService.java

@@ -8,6 +8,7 @@ import com.shkpr.service.alambizplugin.components.GisSurveyCadConverter;
 import com.shkpr.service.alambizplugin.constants.CadEnum;
 import com.shkpr.service.alambizplugin.constants.GisSurveConvertStatusEnum;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
+import com.shkpr.service.alambizplugin.dto.CommAsyncCache;
 import com.shkpr.service.alambizplugin.dto.CommAsyncResult;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -39,9 +40,9 @@ public class GisSurveyCadConvertBizService {
      */
     private final static Map<String, ListenableFuture<CommAsyncResult<String>>> TASK_CACHE = new ConcurrentHashMap<>();
     /**
-     * 开始时间缓存
+     * 信息缓存
      */
-    private final static Map<String, LocalDateTime> TIME_CACHE = new ConcurrentHashMap<>();
+    private final static Map<String, CommAsyncCache> INFO_CACHE = new ConcurrentHashMap<>();
     /**
      * log
      */
@@ -69,9 +70,10 @@ public class GisSurveyCadConvertBizService {
      * @param file       文件
      * @param convertId  转换id
      * @param outCadEnum 输出cad类型
+     * @param operator   操作人
      * @return 转换结果
      */
-    public CommAsyncResult<String> cadConvert(MultipartFile file, String convertId, CadEnum outCadEnum) {
+    public CommAsyncResult<String> cadConvert(MultipartFile file, String convertId, CadEnum outCadEnum, String operator) {
         //如已有结果,则直接返回
         CommAsyncResult<String> result = getResult(convertId);
         if (result != null) return result;
@@ -81,9 +83,9 @@ public class GisSurveyCadConvertBizService {
             InputStream inputStream = file.getInputStream();
 
             //启动转换
-            startTask(convertId, inputStream, outCadEnum);
+            startTask(convertId, inputStream, outCadEnum, operator);
             //返回进行中
-            return CommAsyncResult.inProgress(convertId, LocalDateTime.now());
+            return CommAsyncResult.inProgress(convertId, LocalDateTime.now(), operator);
         } catch (IOException e) {
             //打印报错信息
             LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
@@ -123,8 +125,12 @@ public class GisSurveyCadConvertBizService {
         }
 
         //进行中判断(未完成且未清除)
-        if (previousFuture != null && !previousFuture.isDone() && !previousFuture.isCancelled())
-            return CommAsyncResult.inProgress(convertId, TIME_CACHE.get(convertId));
+        if (previousFuture != null && !previousFuture.isDone() && !previousFuture.isCancelled()) {
+            //获取缓存信息
+            CommAsyncCache asyncCache = INFO_CACHE.get(convertId);
+            if (asyncCache != null)
+                return CommAsyncResult.inProgress(convertId, asyncCache.getStartTime(), asyncCache.getOperator());
+        }
 
         return null;
     }
@@ -135,8 +141,9 @@ public class GisSurveyCadConvertBizService {
      * @param convertId   转换id
      * @param inputStream 文件输入流
      * @param cadEnum     cad类型
+     * @param operator    操作人
      */
-    private void startTask(String convertId, InputStream inputStream, CadEnum cadEnum) {
+    private void startTask(String convertId, InputStream inputStream, CadEnum cadEnum, String operator) {
         //获取已存在的任务
         ListenableFuture<CommAsyncResult<String>> previousFuture = TASK_CACHE.get(convertId);
         //已结束判断,删除缓存
@@ -160,7 +167,7 @@ public class GisSurveyCadConvertBizService {
         //缓存任务句柄
         TASK_CACHE.put(convertId, future);
         //缓存时间
-        TIME_CACHE.put(convertId, LocalDateTime.now());
+        INFO_CACHE.put(convertId, new CommAsyncCache(LocalDateTime.now(), operator));
     }
 
     /**
@@ -183,6 +190,6 @@ public class GisSurveyCadConvertBizService {
      */
     private void removeCache(String convertId) {
         TASK_CACHE.remove(convertId);
-        TIME_CACHE.remove(convertId);
+        INFO_CACHE.remove(convertId);
     }
 }

+ 18 - 11
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyThirdExportBizService.java

@@ -11,6 +11,7 @@ import com.shkpr.service.alambizplugin.constants.FileTypeEnum;
 import com.shkpr.service.alambizplugin.constants.GisSurveConvertStatusEnum;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyJobInfoService;
+import com.shkpr.service.alambizplugin.dto.CommAsyncCache;
 import com.shkpr.service.alambizplugin.dto.CommAsyncResult;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@@ -38,9 +39,9 @@ public class GisSurveyThirdExportBizService {
      */
     private final static Map<String, ListenableFuture<CommAsyncResult<Map<String, String>>>> TASK_CACHE = new ConcurrentHashMap<>();
     /**
-     * 开始时间缓存
+     * 信息缓存
      */
-    private final static Map<String, LocalDateTime> TIME_CACHE = new ConcurrentHashMap<>();
+    private final static Map<String, CommAsyncCache> INFO_CACHE = new ConcurrentHashMap<>();
     /**
      * log
      */
@@ -71,9 +72,10 @@ public class GisSurveyThirdExportBizService {
      *
      * @param jobId    任务id
      * @param fileType 导出文件类型
+     * @param operator 操作人
      * @return 转换结果
      */
-    public CommAsyncResult<Map<String, String>> thirdExport(String jobId, FileTypeEnum fileType) {
+    public CommAsyncResult<Map<String, String>> thirdExport(String jobId, FileTypeEnum fileType, String operator) {
         //获取上次结果
         CommAsyncResult<Map<String, String>> lastResult = getTempResult(jobId);
 
@@ -102,9 +104,9 @@ public class GisSurveyThirdExportBizService {
         }
 
         //启动任务
-        startTask(jobId, fileType);
+        startTask(jobId, fileType, operator);
         //返回进行中
-        return CommAsyncResult.inProgress(jobId, LocalDateTime.now());
+        return CommAsyncResult.inProgress(jobId, LocalDateTime.now(),operator);
 
     }
 
@@ -158,8 +160,12 @@ public class GisSurveyThirdExportBizService {
         }
 
         //进行中判断(未完成且未清除)
-        if (previousFuture != null && !previousFuture.isDone() && !previousFuture.isCancelled())
-            return CommAsyncResult.inProgress(jobId, TIME_CACHE.get(jobId));
+        if (previousFuture != null && !previousFuture.isDone() && !previousFuture.isCancelled()) {
+            //获取缓存信息
+            CommAsyncCache asyncCache = INFO_CACHE.get(jobId);
+            if (asyncCache != null)
+                return CommAsyncResult.inProgress(jobId, asyncCache.getStartTime(), asyncCache.getOperator());
+        }
 
         //取消判断
         if (previousFuture != null && previousFuture.isCancelled()) removeCache(jobId);
@@ -172,14 +178,15 @@ public class GisSurveyThirdExportBizService {
      *
      * @param jobId    任务id
      * @param fileType 导出文件类型
+     * @param operator 操作人
      */
-    private void startTask(String jobId, FileTypeEnum fileType) {
+    private void startTask(String jobId, FileTypeEnum fileType, String operator) {
         //获取已存在的任务
         ListenableFuture<CommAsyncResult<Map<String, String>>> previousFuture = TASK_CACHE.get(jobId);
         //已结束判断,删除缓存
         if (previousFuture != null && (previousFuture.isDone() || previousFuture.isCancelled())) removeCache(jobId);
         //执行异步任务
-        ListenableFuture<CommAsyncResult<Map<String, String>>> future = thirdExporter.thirdExportTask(jobId, fileType);
+        ListenableFuture<CommAsyncResult<Map<String, String>>> future = thirdExporter.thirdExportTask(jobId, fileType, operator);
         //任务超时
         taskScheduler.schedule(() -> {
             if (!future.isCancelled() && !future.isDone() && stopTask(future)) {
@@ -195,7 +202,7 @@ public class GisSurveyThirdExportBizService {
         //缓存任务句柄
         TASK_CACHE.put(jobId, future);
         //缓存时间
-        TIME_CACHE.put(jobId, LocalDateTime.now());
+        INFO_CACHE.put(jobId, new CommAsyncCache(LocalDateTime.now(),operator));
     }
 
     /**
@@ -218,6 +225,6 @@ public class GisSurveyThirdExportBizService {
      */
     private void removeCache(String jobId) {
         TASK_CACHE.remove(jobId);
-        TIME_CACHE.remove(jobId);
+        INFO_CACHE.remove(jobId);
     }
 }

+ 3 - 1
src/main/java/com/shkpr/service/alambizplugin/components/GisSurveyThirdExporter.java

@@ -80,12 +80,14 @@ public class GisSurveyThirdExporter {
      *
      * @param jobId    任务id
      * @param fileType 导出文件类型
+     * @param operator 操作人
      * @return 导出结果
      */
     @Async
-    public ListenableFuture<CommAsyncResult<Map<String, String>>> thirdExportTask(String jobId, FileTypeEnum fileType) {
+    public ListenableFuture<CommAsyncResult<Map<String, String>>> thirdExportTask(String jobId, FileTypeEnum fileType, String operator) {
         //构建返回
         CommAsyncResult<Map<String, String>> result = CommAsyncResult.fail(jobId);
+        result.setOperator(operator);
         try {
             LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
                     , String.format(

+ 15 - 13
src/main/java/com/shkpr/service/alambizplugin/controller/ApiGisSurveyController.java

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.apiparam.GisSurveyCheckParams;
+import com.shkpr.service.alambizplugin.apiparam.GisSurveyThirdExportParams;
 import com.shkpr.service.alambizplugin.apiparam.GisSurveyThirdImportParams;
 import com.shkpr.service.alambizplugin.bizservice.GisSurveyCadConvertBizService;
 import com.shkpr.service.alambizplugin.bizservice.GisSurveySystemCheckBizService;
@@ -634,26 +635,25 @@ public class ApiGisSurveyController {
      * @param request       request
      * @param strClientType 客户端类型
      * @param strUserAgent  用户信息
-     * @param jobId         任务id
-     * @param fileType      导出文件类型
+     * @param oJsonParam    入参
      * @return cad转换结果
      */
-    @GetMapping(value = ApiURI.URI_XXX_THIRD_EXPORT)
+    @PostMapping(value = ApiURI.URI_XXX_THIRD_EXPORT)
     public ResponseRes<String> thirdExport(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 = "fileType", required = false) String fileType) throws SelfException {
+            , @RequestBody(required = false) @Validated(value = {CommonParamValidSK.class}) GisSurveyThirdExportParams oJsonParam
+            , BindingResult bindRes) 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, fileType) || StringUtils.length(jobId) > 64 || StringUtils.length(fileType) > 64) {
-            throw new SelfException(ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrCode()
+        if (oJsonParam == null || bindRes.hasErrors()) {
+            throw new SelfException(ResponseCode.STATUS_ERROR_JSON_FORMAT.toStrCode()
                     , String.format(ApiURI.EXCEPTION_FORMAT
                     , strPlatform
                     , URI_PATH
-                    , ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrMsg()));
+                    , ResponseCode.STATUS_ERROR_JSON_FORMAT.toStrMsg()));
         }
 
         //begin
@@ -664,7 +664,7 @@ public class ApiGisSurveyController {
                         , strPlatform
                         , URI_PATH
                         , strRunSeq
-                        , jobId));
+                        , oJsonParam));
 
         //构建result
         ResponseRes<String> resResult = new ResponseRes<>();
@@ -672,11 +672,11 @@ public class ApiGisSurveyController {
         resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrMsg());
 
         //导出类型枚举
-        FileTypeEnum fileTypeEnum = FileTypeEnum.getFileType(fileType);
+        FileTypeEnum fileTypeEnum = FileTypeEnum.getFileType(oJsonParam.getFileType());
         if (fileTypeEnum == null) fileTypeEnum = FileTypeEnum.EXCEL;
 
         //执行第三方导出
-        CommAsyncResult<Map<String, String>> result = thirdExportBizService.thirdExport(jobId, fileTypeEnum);
+        CommAsyncResult<Map<String, String>> result = thirdExportBizService.thirdExport(oJsonParam.getJobId(), fileTypeEnum, oJsonParam.getOperator());
         String resultStr = null;
         try {
             if (result != null) resultStr = objectMapper.writeValueAsString(result);
@@ -798,6 +798,7 @@ public class ApiGisSurveyController {
      * @param file            文件
      * @param convertId       转换id
      * @param outputExtension 输出扩展名
+     * @param operator        操作人
      * @return cad转换结果
      */
     @PostMapping(value = ApiURI.URI_XXX_CAD_CONVERT)
@@ -806,7 +807,8 @@ public class ApiGisSurveyController {
             , @RequestHeader(value = ApiURI.HEADER_USER_AGENT, required = false) String strUserAgent
             , @RequestParam(value = "file", required = false) MultipartFile file
             , @RequestParam(value = "convertId", required = false) String convertId
-            , @RequestParam(value = "outputExtension", required = false) String outputExtension) throws SelfException {
+            , @RequestParam(value = "outputExtension", required = false) String outputExtension
+            , @RequestParam(value = "operator", required = false, defaultValue = "") String operator) throws SelfException {
         //入参校验
         final String URI_PATH = request.getRequestURI();
         final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
@@ -866,7 +868,7 @@ public class ApiGisSurveyController {
         resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrMsg());
 
         //执行cad转换
-        CommAsyncResult<String> result = cadConvertBizService.cadConvert(file, convertId, outCadEnum);
+        CommAsyncResult<String> result = cadConvertBizService.cadConvert(file, convertId, outCadEnum, operator);
         String resultStr = null;
         try {
             if (result != null) resultStr = objectMapper.writeValueAsString(result);

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

@@ -27,7 +27,7 @@ public class ApiJWTGisSurveyBizFilter extends JWTAuthenticationFilter {
         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_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), "POST");
         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");

+ 30 - 0
src/main/java/com/shkpr/service/alambizplugin/dto/CommAsyncCache.java

@@ -0,0 +1,30 @@
+package com.shkpr.service.alambizplugin.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.time.LocalDateTime;
+
+/**
+ * 通用异步缓存
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Data
+@AllArgsConstructor
+public class CommAsyncCache {
+    /**
+     * 启动时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh_CN", timezone = "Asia/Shanghai")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime startTime;
+
+    /**
+     * 操作人
+     */
+    private String operator;
+}

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

@@ -27,6 +27,10 @@ public class CommAsyncResult<T> {
      */
     private Integer status;
     /**
+     * 操作人
+     */
+    private String operator;
+    /**
      * 启动的子项key
      */
     private List<String> subitemKeys;
@@ -56,11 +60,12 @@ public class CommAsyncResult<T> {
     /**
      * 进行中
      */
-    public static <T> CommAsyncResult<T> inProgress(String id, LocalDateTime requestTime) {
+    public static <T> CommAsyncResult<T> inProgress(String id, LocalDateTime requestTime,String operator) {
         CommAsyncResult<T> result = new CommAsyncResult<>();
         result.setId(id);
         result.setStatus(GisSurveyImportStatusEnum.IN_PROGRESS.getCode());
         result.setRequestTime(requestTime);
+        result.setOperator(operator);
         return result;
     }