Browse Source

增加通用异步结果管理,第三方导出增加根据元素刷新状态判断是否启动

欧阳劲驰 1 month ago
parent
commit
5aaf7edc72

+ 33 - 5
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyThirdExportBizService.java

@@ -1,19 +1,23 @@
 package com.shkpr.service.alambizplugin.bizservice;
 
+import com.fasterxml.jackson.core.type.TypeReference;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.commproperties.AsyncTaskProperties;
+import com.shkpr.service.alambizplugin.components.AsyncResultManager;
 import com.shkpr.service.alambizplugin.components.GisSurveyThirdExporter;
 import com.shkpr.service.alambizplugin.constants.CommAsyncStatusEnum;
 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.CommAsyncResult;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
 import org.springframework.stereotype.Component;
 import org.springframework.util.concurrent.ListenableFuture;
 
+import java.time.Duration;
 import java.time.Instant;
 import java.time.LocalDateTime;
 import java.util.Map;
@@ -44,18 +48,22 @@ public class GisSurveyThirdExportBizService {
     private final String mBizType;
 
     private final AsyncTaskProperties asyncTaskProperties;
+    private final AsyncResultManager asyncResultManager;
     private final ThreadPoolTaskScheduler taskScheduler;
     private final GisSurveyThirdExporter thirdExporter;
+    private final GisSurveyJobInfoService jobInfoService;
 
 
-    public GisSurveyThirdExportBizService(AsyncTaskProperties asyncTaskProperties
+    public GisSurveyThirdExportBizService(AsyncTaskProperties asyncTaskProperties, AsyncResultManager asyncResultManager
             , @Qualifier("timeThreadPoolTaskScheduler") ThreadPoolTaskScheduler taskScheduler
-            , GisSurveyThirdExporter thirdExporter) {
+            , GisSurveyThirdExporter thirdExporter, GisSurveyJobInfoService jobInfoService) {
         mStrClassName = "GisSurveyThirdExportBizService";
         mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
         this.asyncTaskProperties = asyncTaskProperties;
+        this.asyncResultManager = asyncResultManager;
         this.taskScheduler = taskScheduler;
         this.thirdExporter = thirdExporter;
+        this.jobInfoService = jobInfoService;
     }
 
     /**
@@ -66,9 +74,29 @@ public class GisSurveyThirdExportBizService {
      * @return 转换结果
      */
     public CommAsyncResult<String> thirdExport(String jobId, FileTypeEnum fileType) {
-        //如已有结果,则直接返回
-        CommAsyncResult<String> result = getResult(jobId);
-        if (result != null) return result;
+        //获取上次结果
+        CommAsyncResult<String> lastResult = getResult(jobId);
+
+        //失败/进行中处理
+        if (lastResult != null && !Objects.equals(CommAsyncStatusEnum.SUCCESS.getCode(), lastResult.getStatus()))
+            return lastResult;
+
+        //文件结果flag
+        final String FLAG = GisSurveyThirdExporter.RESULT_PREFIX + fileType.getName() + "-" + jobId;
+        //获取文件结果
+        CommAsyncResult<String> fileResult = asyncResultManager.getResult(FLAG, new TypeReference<CommAsyncResult<String>>() {
+        });
+        //获取数据更新时间
+        LocalDateTime refreshTime = jobInfoService.findRefreshTimeByUid(jobId);
+        //判断文件结果落后时间
+        if (fileResult != null && fileResult.getRefreshTime() != null && refreshTime != null) {
+            //文件结果落后数据间隔
+            Duration lags = Duration.between(fileResult.getRefreshTime(), refreshTime);
+            //超出间隔,直接返回
+            if (asyncTaskProperties.getThirdExportResultLag().compareTo(lags) >= 0) {
+                return fileResult;
+            }
+        }
 
         //启动任务
         startTask(jobId, fileType);

+ 11 - 0
src/main/java/com/shkpr/service/alambizplugin/commproperties/AsyncTaskProperties.java

@@ -4,6 +4,7 @@ import lombok.Getter;
 import lombok.Setter;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 
+import java.nio.file.Path;
 import java.time.Duration;
 
 /**
@@ -32,7 +33,17 @@ public class AsyncTaskProperties {
     private Duration thirdExportTimeout;
 
     /**
+     * 第三方导出结果落后时间
+     */
+    private Duration thirdExportResultLag;
+
+    /**
      * cad转换超时时间
      */
     private Duration cadConvertTimeout;
+
+    /**
+     * 结果路径
+     */
+    private Path resultPath;
 }

+ 351 - 0
src/main/java/com/shkpr/service/alambizplugin/components/AsyncResultManager.java

@@ -0,0 +1,351 @@
+package com.shkpr.service.alambizplugin.components;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.global.base.log.LogLevelFlag;
+import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.alambizplugin.commproperties.AsyncTaskProperties;
+import com.shkpr.service.alambizplugin.commproperties.TempFileProperties;
+import com.shkpr.service.alambizplugin.commtools.CompressorUtils;
+import com.shkpr.service.alambizplugin.commtools.ExcelUtils;
+import com.shkpr.service.alambizplugin.commtools.ShapeUtils;
+import com.shkpr.service.alambizplugin.constants.ExcelEnum;
+import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
+import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
+import org.apache.commons.compress.archivers.ArchiveException;
+import org.apache.commons.io.FileUtils;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * 异步结果管理器
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Component
+public class AsyncResultManager {
+    /**
+     * 结果文件名
+     */
+    public final static String RESULT_FILE_NAME = "result.json";
+    /**
+     * 临时文件夹缓存
+     */
+    private final static Map<String, Path> TEMP_DIR_CACHE = new ConcurrentHashMap<>();
+    /**
+     * 文件分片大小
+     */
+    private final static Integer BUFFER_SIZE = 4 * 1024;
+
+    /**
+     * log
+     */
+    private final String mStrClassName;
+    private final String mBizType;
+    private final AsyncTaskProperties asyncTaskProperties;
+    private final TempFileProperties tempFileProperties;
+    private final ObjectMapper objectMapper;
+
+    public AsyncResultManager(AsyncTaskProperties asyncTaskProperties, TempFileProperties tempFileProperties, ObjectMapper objectMapper) {
+        mStrClassName = "AsyncResultManager";
+        mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
+        this.asyncTaskProperties = asyncTaskProperties;
+        this.tempFileProperties = tempFileProperties;
+        this.objectMapper = objectMapper;
+    }
+
+    /**
+     * 获取结果
+     *
+     * @param flag 结果标识
+     * @return 检查结果
+     */
+    public <T> T getResult(String flag, TypeReference<T> type) {
+        //创建文件输入流
+        File file = Paths.get(getResultDirPath(flag).toString(), RESULT_FILE_NAME).toFile();
+        if (!file.exists()) return null;
+        try (FileInputStream fileInputStream = new FileInputStream(file)) {
+            //获取文件通道
+            FileChannel channel = fileInputStream.getChannel();
+            //创建缓冲区
+            ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());
+            //读取通道
+            int read = channel.read(byteBuffer);
+            //输入读取信息
+            if (read > 0) return objectMapper.readValue(byteBuffer.array(), type);
+        } catch (IOException e) {
+            //打印报错信息
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format(
+                            "监测到io异常 结果标识:%s error:%s"
+                            , flag
+                            , e
+                    )
+            );
+            return null;
+        }
+        return null;
+    }
+
+    /**
+     * 获取结果文件夹路径
+     *
+     * @param flag 结果标识
+     * @return 结果文件夹路径
+     */
+    private Path getResultDirPath(String flag) {
+        return Paths.get(asyncTaskProperties.getResultPath().toString(), flag);
+    }
+
+    /**
+     * 创建临时文件夹
+     *
+     * @param flag 结果标识
+     */
+    public Boolean createTempDirectory(String flag) {
+        try {
+            //创建临时文件夹,并缓存路径
+            Path tempDirectory = Files.createTempDirectory(tempFileProperties.getResourcePath(), flag);
+            TEMP_DIR_CACHE.put(flag, tempDirectory);
+            return tempDirectory.toFile().exists();
+        } catch (IOException e) {
+            //打印报错信息
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format(
+                            "监测到io异常 结果标识:%s error:%s"
+                            , flag
+                            , e
+                    )
+            );
+            return false;
+        }
+    }
+
+    /**
+     * 写入json文件
+     *
+     * @param data     数据
+     * @param flag     结果标识
+     * @param fileName 文件名
+     */
+    public Path writeJson(Object data, String flag, String fileName) {
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                , String.format(
+                        "开始执行写入结果文件,结果标识:%s,文件名:%s========>"
+                        , flag
+                        , fileName
+                )
+        );
+        long begin = System.currentTimeMillis();
+
+        //写入文件
+        Path path = Paths.get(TEMP_DIR_CACHE.get(flag).toString(), fileName);
+        try {
+            //序列化数据
+            final byte[] bytes = objectMapper.writeValueAsBytes(data);
+            //写入文件
+            int total = writeFile(bytes, path);
+            if (total > 0) {
+                long end = System.currentTimeMillis();
+                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                        , String.format(
+                                "结束执行写入结果文件,结果标识:%s,文件名:%s,用时(毫秒):%d"
+                                , flag
+                                , fileName
+                                , (end - begin)
+                        )
+                );
+                return path;
+            }
+        } catch (IOException e) {
+            //打印报错信息
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format(
+                            "监测到io异常 结果标识:%s error:%s"
+                            , flag
+                            , e
+                    )
+            );
+        }
+        return null;
+    }
+
+    /**
+     * 写入excel文件
+     *
+     * @param heads    表头
+     * @param datas    数据
+     * @param flag     结果标识
+     * @param fileName 文件名
+     */
+    public Path writeExcel(Map<String, Map<String, String>> heads, Map<String, List<Map<String, Object>>> datas, String flag, String fileName) {
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                , String.format(
+                        "开始执行写入excel文件,结果标识:%s,文件名:%s========>"
+                        , flag
+                        , fileName
+                )
+        );
+        long begin = System.currentTimeMillis();
+
+        //写入文件
+        Path path = Paths.get(TEMP_DIR_CACHE.get(flag).toString(), fileName);
+        try {
+            ExcelUtils.writeFile(heads, datas, Files.newOutputStream(path), ExcelEnum.XLSX
+                    , GisSurveyExcelDefine.FILE_HANDLE.HEADER_ROW_NUM, GisSurveyExcelDefine.FILE_HANDLE.DATA_ROW_NUM);
+
+            long end = System.currentTimeMillis();
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                    , String.format(
+                            "结束执行写入excel文件,结果标识:%s,文件名:%s,用时(毫秒):%d"
+                            , flag
+                            , fileName
+                            , (end - begin)
+                    )
+            );
+
+            return path;
+        } catch (IOException e) {
+            //打印报错信息
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format(
+                            "监测到io异常 结果标识:%s error:%s"
+                            , flag
+                            , e
+                    )
+            );
+            return null;
+        }
+    }
+
+    /**
+     * 写入shape文件
+     *
+     * @param data     数据
+     * @param flag     结果标识
+     * @param fileName 文件名
+     */
+    public Path writeShape(Map<SimpleFeatureType, List<Map<String, Object>>> data, String flag, String fileName) {
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                , String.format(
+                        "开始执行写入shape文件,结果标识:%s,文件名:%s========>"
+                        , flag
+                        , fileName
+                )
+        );
+        long begin = System.currentTimeMillis();
+
+        //写入文件
+        Path path = Paths.get(TEMP_DIR_CACHE.get(flag).toString(), fileName);
+        try {
+            //创建临时文件夹
+            Path tempDirectory = Files.createTempDirectory(tempFileProperties.getResourcePath(), flag);
+            //导出到shape
+            ShapeUtils.writeShape(data, tempDirectory);
+            //压缩文件夹
+            Path zipPath = CompressorUtils.archivalZip(tempDirectory);
+            //移动文件
+            FileUtils.moveFile(zipPath.toFile(), path.toFile());
+
+            long end = System.currentTimeMillis();
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
+                    , String.format(
+                            "结束执行写入shape文件,结果标识:%s,文件名:%s,用时(毫秒):%d"
+                            , flag
+                            , fileName
+                            , (end - begin)
+                    )
+            );
+
+            return path;
+        } catch (IOException | ArchiveException e) {
+            //打印报错信息
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format(
+                            "监测到io异常 结果标识:%s error:%s"
+                            , flag
+                            , e
+                    )
+            );
+            return null;
+        }
+    }
+
+
+    /**
+     * 写文件
+     *
+     * @param data 数据
+     * @param path 文件路径
+     * @return 写入数量
+     * @throws IOException io异常
+     */
+    private int writeFile(final byte[] data, final Path path) throws IOException {
+        //创建文件输出流(此处会创建文件)
+        try (FileOutputStream fileOutputStream = new FileOutputStream(path.toFile())) {
+            //获取文件通道
+            FileChannel channel = fileOutputStream.getChannel();
+            //创建缓冲区
+            ByteBuffer byteBuffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
+            //偏移量
+            int offset = 0;
+            //写入总数
+            int total = 0;
+            while (offset < data.length) {
+                //分片大小
+                int chunkSize = Math.min(BUFFER_SIZE, data.length - offset);
+                //重置缓冲区,存入缓冲区,翻转
+                byteBuffer.clear();
+                byteBuffer.put(data, offset, chunkSize);
+                byteBuffer.flip();
+                //写入当前块
+                total += channel.write(byteBuffer);
+                offset += chunkSize;
+            }
+            //强制写入
+            channel.force(true);
+            return total;
+        }
+    }
+
+    /**
+     * 替换结果
+     *
+     * @param flag 结果标识
+     * @return 替换状态
+     */
+    public boolean replaceResult(String flag) {
+        //临时文件路径
+        Path path = TEMP_DIR_CACHE.get(flag);
+        try {
+            //替换结果目录
+            FileUtils.copyDirectory(path.toFile(), getResultDirPath(flag).toFile());
+
+            return true;
+        } catch (IOException e) {
+            //打印报错信息
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format(
+                            "监测到io异常 结果标识:%s error:%s"
+                            , flag
+                            , e
+                    )
+            );
+        }
+        return false;
+    }
+}

+ 48 - 30
src/main/java/com/shkpr/service/alambizplugin/components/GisSurveyThirdExporter.java

@@ -2,18 +2,14 @@ package com.shkpr.service.alambizplugin.components;
 
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
-import com.shkpr.service.alambizplugin.commproperties.TempFileProperties;
-import com.shkpr.service.alambizplugin.commtools.CompressorUtils;
-import com.shkpr.service.alambizplugin.commtools.ExcelUtils;
-import com.shkpr.service.alambizplugin.commtools.ShapeUtils;
 import com.shkpr.service.alambizplugin.commtools.ThirdImportTemplateUtils;
 import com.shkpr.service.alambizplugin.constants.CommAsyncStatusEnum;
-import com.shkpr.service.alambizplugin.constants.ExcelEnum;
 import com.shkpr.service.alambizplugin.constants.FileTypeEnum;
 import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
 import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dbdao.services.intef.GisMetadataLayerTemplateService;
+import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyJobInfoService;
 import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyLayerApplyService;
 import com.shkpr.service.alambizplugin.dto.CommAsyncResult;
 import com.shkpr.service.alambizplugin.dto.GisMetadataLayerTemplate;
@@ -52,20 +48,27 @@ import java.util.stream.Collectors;
 @Component
 public class GisSurveyThirdExporter {
     /**
+     * 结果前缀
+     */
+    public final static String RESULT_PREFIX = "third-export-";
+    /**
      * log
      */
     private final String mStrClassName;
     private final String mBizType;
-    private final TempFileProperties tempFileProperties;
+
+    private final AsyncResultManager asyncResultManager;
+    private final GisSurveyJobInfoService jobInfoService;
     private final GisMetadataLayerTemplateService layerTemplateService;
     private final GisSurveyLayerApplyService gisSurveyLayerApplyService;
 
 
-    public GisSurveyThirdExporter(TempFileProperties tempFileProperties
+    public GisSurveyThirdExporter(AsyncResultManager asyncResultManager, GisSurveyJobInfoService jobInfoService
             , GisMetadataLayerTemplateService layerTemplateService, GisSurveyLayerApplyService gisSurveyLayerApplyService) {
         mStrClassName = "GisSurveyThirdExporter";
         mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
-        this.tempFileProperties = tempFileProperties;
+        this.asyncResultManager = asyncResultManager;
+        this.jobInfoService = jobInfoService;
         this.layerTemplateService = layerTemplateService;
         this.gisSurveyLayerApplyService = gisSurveyLayerApplyService;
     }
@@ -89,6 +92,8 @@ public class GisSurveyThirdExporter {
                     )
             );
 
+            //查询元素更新时间
+            LocalDateTime refreshTime = jobInfoService.findRefreshTimeByUid(jobId);
             //查询点线数据
             List<GisSurveyLayerApply> points = gisSurveyLayerApplyService.findAllByJobIdAndKind(jobId, GisMetadataDefine.TYPE_KINE.POINT);
             List<GisSurveyLayerApply> lines = gisSurveyLayerApplyService.findAllByJobIdAndKind(jobId, GisMetadataDefine.TYPE_KINE.LINE);
@@ -101,15 +106,20 @@ public class GisSurveyThirdExporter {
             //查询线图层模版
             List<GisMetadataLayerTemplate> lineLayerTemplates = layerTemplateService.findByKeyIn(lineLayer);
 
+            //结果flag
+            final String FLAG = RESULT_PREFIX + fileType.getName() + "-" + jobId;
+
+            //创建临时文件夹
+            if (!asyncResultManager.createTempDirectory(FLAG))
+                return new AsyncResult<>(result);
+
             //根据文件类型导出
-            Path resultPath = null;
+            Path outputPath = null;
             if (fileType == FileTypeEnum.EXCEL)
-                resultPath = exportExcel(points, lines, pointLayerTemplates, lineLayerTemplates);
+                outputPath = exportExcel(points, lines, pointLayerTemplates, lineLayerTemplates, FLAG);
             if (fileType == FileTypeEnum.SHAPE_FILE)
-                resultPath = exportShape(points, lines, pointLayerTemplates, lineLayerTemplates);
-
-            //导出文件判断
-            if (resultPath == null || !Files.exists(resultPath)) {
+                outputPath = exportShape(points, lines, pointLayerTemplates, lineLayerTemplates, FLAG);
+            if (outputPath == null || !Files.exists(outputPath)) {
                 //打印报错信息
                 LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
                         , String.format("第三方导出文件写入失败, 任务id:%s", jobId)
@@ -120,7 +130,22 @@ public class GisSurveyThirdExporter {
             //导出完成
             result.setStatus(CommAsyncStatusEnum.SUCCESS.getCode());
             result.setCompleteTime(LocalDateTime.now());
-            result.setData(resultPath.getFileName().toString());
+            result.setData(FLAG + "/" + outputPath.getFileName().toString());
+            result.setRefreshTime(refreshTime);
+
+            //写入结果
+            Path resultPath = asyncResultManager.writeJson(result, FLAG, AsyncResultManager.RESULT_FILE_NAME);
+            if (resultPath == null || !Files.exists(resultPath)) {
+                //打印报错信息
+                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                        , String.format("第三方导出文件写入失败, 任务id:%s", jobId)
+                );
+                return new AsyncResult<>(CommAsyncResult.fail(jobId));
+            }
+
+            //替换结果
+            if (!asyncResultManager.replaceResult(FLAG)) return new AsyncResult<>(CommAsyncResult.fail(jobId));
+
 
             LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
                     , String.format(
@@ -136,7 +161,7 @@ public class GisSurveyThirdExporter {
             LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
                     , String.format("第三方导出异常 任务id:%s error:%s", jobId, e)
             );
-            return new AsyncResult<>(result);
+            return new AsyncResult<>(CommAsyncResult.fail(jobId));
         }
     }
 
@@ -147,20 +172,18 @@ public class GisSurveyThirdExporter {
      * @param lines               线
      * @param pointLayerTemplates 点图层模版
      * @param lineLayerTemplates  线图层模版
+     * @param FLAG                结果flag
      * @return excel路径
      * @throws IOException io异常
      */
-    private Path exportExcel(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines, List<GisMetadataLayerTemplate> pointLayerTemplates, List<GisMetadataLayerTemplate> lineLayerTemplates) throws IOException {
+    private Path exportExcel(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines, List<GisMetadataLayerTemplate> pointLayerTemplates, List<GisMetadataLayerTemplate> lineLayerTemplates, String FLAG) throws IOException {
         //构建excel头
         Map<String, Map<String, String>> excelHeader = buildExcelHeader(pointLayerTemplates, lineLayerTemplates);
         //构建excel数据
         Map<String, List<Map<String, Object>>> excelData = buildExcelData(points, lines, pointLayerTemplates, lineLayerTemplates);
-        //导出excel
-        Path excelPath = Files.createTempFile(tempFileProperties.getResourcePath(), "third-export-", ".xlsx");
-        ExcelUtils.writeFile(excelHeader, excelData, Files.newOutputStream(excelPath), ExcelEnum.XLSX
-                , GisSurveyExcelDefine.FILE_HANDLE.HEADER_ROW_NUM, GisSurveyExcelDefine.FILE_HANDLE.DATA_ROW_NUM);
 
-        return excelPath;
+        //导出excel
+        return asyncResultManager.writeExcel(excelHeader, excelData, FLAG, "third-export.xlsx");
     }
 
     /**
@@ -170,22 +193,17 @@ public class GisSurveyThirdExporter {
      * @param lines               线
      * @param pointLayerTemplates 点图层模版
      * @param lineLayerTemplates  线图层模版
+     * @param FLAG                结果flag
      * @return shape路径
      * @throws IOException      io异常
      * @throws ArchiveException 压缩异常
      */
-    private Path exportShape(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines, List<GisMetadataLayerTemplate> pointLayerTemplates, List<GisMetadataLayerTemplate> lineLayerTemplates) throws IOException, ArchiveException, SchemaException {
+    private Path exportShape(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines, List<GisMetadataLayerTemplate> pointLayerTemplates, List<GisMetadataLayerTemplate> lineLayerTemplates, String FLAG) throws IOException, ArchiveException, SchemaException {
         //构建shape数据
         Map<SimpleFeatureType, List<Map<String, Object>>> shapeData = buildShapeData(points, lines, pointLayerTemplates, lineLayerTemplates);
 
-        //创建临时文件夹
-        Path directory = Files.createTempDirectory(tempFileProperties.getResourcePath(), "third-export-");
-
         //导出shape
-        ShapeUtils.writeShape(shapeData, directory);
-
-        //压缩文件夹
-        return CompressorUtils.archivalZip(directory);
+        return asyncResultManager.writeShape(shapeData, FLAG, "third-export.zip");
     }
 
 

+ 7 - 2
src/main/java/com/shkpr/service/alambizplugin/configuration/WebMvcConfiguration.java

@@ -1,7 +1,7 @@
 package com.shkpr.service.alambizplugin.configuration;
 
 import com.shkpr.service.alambizplugin.SpringContextUtil;
-import com.shkpr.service.alambizplugin.commproperties.GisSurveyCadConvertProperties;
+import com.shkpr.service.alambizplugin.commproperties.AsyncTaskProperties;
 import com.shkpr.service.alambizplugin.commproperties.GisSurveySystemCheckProperties;
 import com.shkpr.service.alambizplugin.commproperties.TempFileProperties;
 import com.shkpr.service.alambizplugin.constants.ApiURI;
@@ -34,11 +34,13 @@ import java.util.TreeMap;
 public class WebMvcConfiguration implements WebMvcConfigurer {
     private final GisSurveySystemCheckProperties systemCheckProperties;
     private final TempFileProperties tempFileProperties;
+    private final AsyncTaskProperties asyncTaskProperties;
 
     public WebMvcConfiguration(GisSurveySystemCheckProperties systemCheckProperties
-    , TempFileProperties tempFileProperties) {
+    , TempFileProperties tempFileProperties , AsyncTaskProperties asyncTaskProperties) {
         this.systemCheckProperties = systemCheckProperties;
         this.tempFileProperties = tempFileProperties;
+        this.asyncTaskProperties = asyncTaskProperties;
     }
 
     /**
@@ -52,6 +54,9 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
         //临时文件映射
         registry.addResourceHandler(ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_TEMP_FILES + "/**")
                 .addResourceLocations("file:" + tempFileProperties.getResourcePath() + "/");
+        //异步结果映射
+        registry.addResourceHandler(ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_ASYNC_RESULTS + "/**")
+                .addResourceLocations("file:" + asyncTaskProperties.getResultPath() + "/");
     }
 
     @Override

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

@@ -37,6 +37,7 @@ public class ApiURI {
     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";
+    public static final String URI_XXX_ASYNC_RESULTS = "async-results";
 
     public static final String URI_ACCESS_TOKEN_CHECK = "/kpr-plugin/apply/access-token-check";
     public static final String URI_FILE_BUSI_XXX = "/files/**";

+ 3 - 0
src/main/java/com/shkpr/service/alambizplugin/controllerfilter/JWTAuthenticationFilter.java

@@ -70,6 +70,9 @@ public class JWTAuthenticationFilter extends BasicAuthenticationFilter {
                 || this.mPathMatcher.match(
                 String.format("%s%s", request.getContextPath(), ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_TEMP_FILES + "/**"),
                 request.getRequestURI())
+                || this.mPathMatcher.match(
+                String.format("%s%s", request.getContextPath(), ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_ASYNC_RESULTS + "/**"),
+                request.getRequestURI())
         )) {
             chain.doFilter(request, response);
             return;

+ 17 - 7
src/main/java/com/shkpr/service/alambizplugin/dto/CommAsyncResult.java

@@ -9,7 +9,7 @@ import org.springframework.format.annotation.DateTimeFormat;
 import java.time.LocalDateTime;
 
 /**
- * 通用异步结
+ * 通用异步结
  *
  * @author 欧阳劲驰
  * @since 1.0.0
@@ -25,6 +25,10 @@ public class CommAsyncResult<T> {
      */
     private Integer status;
     /**
+     * 请求入参
+     */
+    private Object param;
+    /**
      * 结果数据
      */
     private T data;
@@ -40,13 +44,19 @@ public class CommAsyncResult<T> {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh_CN", timezone = "Asia/Shanghai")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime completeTime;
+    /**
+     * 数据更新时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh_CN", timezone = "Asia/Shanghai")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime refreshTime;
 
     /**
      * 进行中
      */
-    public static <T> CommAsyncResult<T> inProgress(String convertId, LocalDateTime requestTime) {
+    public static <T> CommAsyncResult<T> inProgress(String id, LocalDateTime requestTime) {
         CommAsyncResult<T> result = new CommAsyncResult<>();
-        result.setId(convertId);
+        result.setId(id);
         result.setStatus(GisSurveyImportStatusEnum.IN_PROGRESS.getCode());
         result.setRequestTime(requestTime);
         return result;
@@ -55,9 +65,9 @@ public class CommAsyncResult<T> {
     /**
      * 成功
      */
-    public static <T> CommAsyncResult<T> success(String convertId) {
+    public static <T> CommAsyncResult<T> success(String id) {
         CommAsyncResult<T> result = new CommAsyncResult<>();
-        result.setId(convertId);
+        result.setId(id);
         result.setStatus(GisSurveConvertStatusEnum.SUCCESS.getCode());
         result.setRequestTime(LocalDateTime.now());
         return result;
@@ -66,9 +76,9 @@ public class CommAsyncResult<T> {
     /**
      * 失败
      */
-    public static <T> CommAsyncResult<T> fail(String convertId) {
+    public static <T> CommAsyncResult<T> fail(String id) {
         CommAsyncResult<T> result = new CommAsyncResult<>();
-        result.setId(convertId);
+        result.setId(id);
         result.setStatus(GisSurveConvertStatusEnum.FAIL.getCode());
         result.setRequestTime(LocalDateTime.now());
         return result;

+ 2 - 0
src/main/resources/application.properties

@@ -152,7 +152,9 @@ cad-convert.rasterization-min-height=800
 async-task.system-check-timeout=PT1H
 async-task.third-import-timeout=PT30M
 async-task.third-export-timeout=PT30M
+async-task.third-export-result-lag=PT5M
 async-task.cad-convert-timeout=PT10M
+async-task.result-path=/home/kprCloud/alam_dma_kpr_plugin/async-results/
 #=============临时文件========================
 temp-file.check-cycle=PT1M
 temp-file.resource-path=/home/kprCloud/alam_dma_kpr_plugin/temp-files/