소스 검색

第三方导出增加目标坐标系处理

欧阳劲驰 2 주 전
부모
커밋
675f5bc05c

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

@@ -1,5 +1,7 @@
 package com.shkpr.service.alambizplugin.apiparam;
 
+import com.shkpr.service.alambizplugin.constants.CommCRSDefine;
+import com.shkpr.service.alambizplugin.constants.FileTypeEnum;
 import com.shkpr.service.alambizplugin.controllervalid.CommonParamValidSK;
 import lombok.Data;
 
@@ -27,6 +29,14 @@ public class GisSurveyThirdExportParams {
     @Size(max = 64, groups = {CommonParamValidSK.class})
     private String fileType;
     /**
+     * 文件类型枚举(内部用)
+     */
+    private FileTypeEnum fileTypeEnum;
+    /**
+     * 目标坐标系code
+     */
+    private String targetCRSCode = CommCRSDefine.CGCS2000;
+    /**
      * 操作人
      */
     @NotNull(groups = {CommonParamValidSK.class})

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

@@ -3,11 +3,11 @@ 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.apiparam.GisSurveyThirdExportParams;
 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.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyJobInfoService;
 import com.shkpr.service.alambizplugin.dto.CommAsyncCache;
@@ -69,42 +69,40 @@ public class GisSurveyThirdExportBizService {
     /**
      * 第三方导出
      *
-     * @param jobId    任务id
-     * @param fileType 导出文件类型
-     * @param operator 操作人
+     * @param params 导出参数
      * @return 转换结果
      */
-    public CommAsyncResult<Map<String, String>> thirdExport(String jobId, FileTypeEnum fileType, String operator) {
+    public CommAsyncResult<Map<String, String>> thirdExport(GisSurveyThirdExportParams params) {
         //获取上次结果
-        CommAsyncResult<Map<String, String>> lastResult = getTempResult(jobId);
+        CommAsyncResult<Map<String, String>> lastResult = getTempResult(params.getJobId());
         //失败/进行中处理
         if (lastResult != null && !Objects.equals(CommAsyncStatusEnum.SUCCESS.getCode(), lastResult.getStatus()))
             return lastResult;
 
         //文件结果flag
-        final String FLAG = GisSurveyThirdExporter.RESULT_PREFIX + jobId;
+        final String FLAG = GisSurveyThirdExporter.RESULT_PREFIX + params.getJobId();
         //获取文件结果
         CommAsyncResult<Map<String, String>> fileResult = asyncResultManager.getResult(FLAG, new TypeReference<CommAsyncResult<Map<String, String>>>() {
         });
         //获取数据更新时间
-        LocalDateTime refreshTime = jobInfoService.findRefreshTime(jobId);
+        LocalDateTime refreshTime = jobInfoService.findRefreshTime(params.getJobId());
         //直接返回文件结果判断:结果\刷新时间\数据不为空,结果数据包含当前项,文件结果落后数据库
         if (fileResult != null && refreshTime != null
                 //文件结果包含数据库时间
-                && fileResult.getRefreshTimes() != null && fileResult.getRefreshTimes().containsKey(fileType.getName())
+                && fileResult.getRefreshTimes() != null && fileResult.getRefreshTimes().containsKey(params.getFileTypeEnum().getName())
                 //文件结果数据包含当前项
-                && fileResult.getData() != null && fileResult.getData().containsKey(fileType.getName())) {
+                && fileResult.getData() != null && fileResult.getData().containsKey(params.getFileTypeEnum().getName())) {
 
             //文件结果落后数据间隔
-            Duration lags = Duration.between(fileResult.getRefreshTimes().get(fileType.getName()), refreshTime);
+            Duration lags = Duration.between(fileResult.getRefreshTimes().get(params.getFileTypeEnum().getName()), refreshTime);
             //规定落后时间大于落后数据间隔(数据未落后),直接返回
             if (asyncTaskProperties.getThirdExportResultLag().compareTo(lags) >= 0) return fileResult;
         }
 
         //启动任务
-        startTask(jobId, fileType, operator);
+        startTask(params);
         //返回进行中
-        return CommAsyncResult.inProgress(jobId, LocalDateTime.now(), operator);
+        return CommAsyncResult.inProgress(params.getJobId(), LocalDateTime.now(), params.getOperator());
 
     }
 
@@ -174,33 +172,32 @@ public class GisSurveyThirdExportBizService {
     /**
      * 启动任务
      *
-     * @param jobId    任务id
-     * @param fileType 导出文件类型
-     * @param operator 操作人
+     * @param params 导出参数
      */
-    private void startTask(String jobId, FileTypeEnum fileType, String operator) {
+    private void startTask(GisSurveyThirdExportParams params) {
         //获取已存在的任务
-        ListenableFuture<CommAsyncResult<Map<String, String>>> previousFuture = TASK_CACHE.get(jobId);
+        ListenableFuture<CommAsyncResult<Map<String, String>>> previousFuture = TASK_CACHE.get(params.getJobId());
         //已结束判断,删除缓存
-        if (previousFuture != null && (previousFuture.isDone() || previousFuture.isCancelled())) removeCache(jobId);
+        if (previousFuture != null && (previousFuture.isDone() || previousFuture.isCancelled()))
+            removeCache(params.getJobId());
         //执行异步任务
-        ListenableFuture<CommAsyncResult<Map<String, String>>> future = thirdExporter.thirdExportTask(jobId, fileType, operator);
+        ListenableFuture<CommAsyncResult<Map<String, String>>> future = thirdExporter.thirdExportTask(params);
         //任务超时
         taskScheduler.schedule(() -> {
             if (!future.isCancelled() && !future.isDone() && stopTask(future)) {
-                removeCache(jobId);
+                removeCache(params.getJobId());
                 LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
                         , String.format(
                                 "第三方导出超时,成功停止任务;任务id: %s"
-                                , jobId
+                                , params.getJobId()
                         )
                 );
             }
         }, Instant.now().plusMillis(asyncTaskProperties.getThirdExportTimeout().toMillis()));
         //缓存任务句柄
-        TASK_CACHE.put(jobId, future);
+        TASK_CACHE.put(params.getJobId(), future);
         //缓存时间
-        INFO_CACHE.put(jobId, new CommAsyncCache(LocalDateTime.now(), operator));
+        INFO_CACHE.put(params.getJobId(), new CommAsyncCache(LocalDateTime.now(), params.getOperator()));
     }
 
     /**

+ 61 - 5
src/main/java/com/shkpr/service/alambizplugin/components/GisSurveyThirdExporter.java

@@ -3,8 +3,11 @@ package com.shkpr.service.alambizplugin.components;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.alambizplugin.apiparam.GisSurveyThirdExportParams;
+import com.shkpr.service.alambizplugin.commtools.CRSUtil;
 import com.shkpr.service.alambizplugin.commtools.ThirdImportTemplateUtils;
 import com.shkpr.service.alambizplugin.constants.CommAsyncStatusEnum;
+import com.shkpr.service.alambizplugin.constants.CommCRSDefine;
 import com.shkpr.service.alambizplugin.constants.FileTypeEnum;
 import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
 import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
@@ -21,6 +24,8 @@ import org.apache.commons.compress.archivers.ArchiveException;
 import org.apache.commons.lang3.StringUtils;
 import org.geotools.data.DataUtilities;
 import org.geotools.feature.SchemaException;
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.Geometry;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.AsyncResult;
@@ -28,6 +33,7 @@ import org.springframework.stereotype.Component;
 import org.springframework.util.concurrent.ListenableFuture;
 
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.time.Duration;
@@ -78,15 +84,18 @@ public class GisSurveyThirdExporter {
     /**
      * 第三方导出任务
      *
-     * @param jobId    任务id
-     * @param fileType 导出文件类型
-     * @param operator 操作人
+     * @param params 导出参数
      * @return 导出结果
      */
     @Async
-    public ListenableFuture<CommAsyncResult<Map<String, String>>> thirdExportTask(String jobId, FileTypeEnum fileType, String operator) {
+    public ListenableFuture<CommAsyncResult<Map<String, String>>> thirdExportTask(GisSurveyThirdExportParams params) {
+        //参数
+        String jobId = params.getJobId();
+        FileTypeEnum fileType = params.getFileTypeEnum();
+        String targetCRSCode = params.getTargetCRSCode();
+        String operator = params.getOperator();
         //构建返回
-        CommAsyncResult<Map<String, String>> result = CommAsyncResult.fail(jobId);
+        CommAsyncResult<Map<String, String>> result = CommAsyncResult.fail(params.getJobId());
         result.setOperator(operator);
         try {
             LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
@@ -102,6 +111,9 @@ public class GisSurveyThirdExporter {
             List<GisSurveyLayerApply> points = gisSurveyLayerApplyService.findAllByJobIdAndKind(jobId, GisMetadataDefine.TYPE_KINE.POINT);
             List<GisSurveyLayerApply> lines = gisSurveyLayerApplyService.findAllByJobIdAndKind(jobId, GisMetadataDefine.TYPE_KINE.LINE);
 
+            //处理坐标系
+            if (!Objects.equals(targetCRSCode, CommCRSDefine.CGCS2000)) transformGeom(targetCRSCode, points, lines);
+
             //获取图层key
             List<String> pointLayer = getLayerKeys(points);
             List<String> lineLayer = getLayerKeys(lines);
@@ -184,6 +196,50 @@ public class GisSurveyThirdExporter {
     }
 
     /**
+     * 转换geom
+     *
+     * @param targetCRSCode 目标坐标系
+     * @param points        点集合
+     * @param lines         线结合
+     */
+    private void transformGeom(String targetCRSCode, List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines) {
+        //处理点
+        points.parallelStream().forEach(point -> {
+            //获取geom
+            Geometry geometry = point.getGis();
+            if (geometry == null) return;
+            //转换geom
+            Geometry transform = CRSUtil.transform(geometry, CommCRSDefine.CGCS2000, targetCRSCode);
+            if (transform == null) return;
+            //回填元素
+            point.setGis(transform);
+            //获取解析后的经纬度
+            Coordinate coordinate = transform.getCoordinate();
+            String lngStr = BigDecimal.valueOf(coordinate.getX()).toPlainString();
+            String latStr = BigDecimal.valueOf(coordinate.getY()).toPlainString();
+            //回填经纬度属性
+            List<GisSurveyPropertyValue> propertyValues = point.getPropertyValues();
+            propertyValues.stream()
+                    .filter(it -> Objects.equals(it.getProperty(), GisSurveyExcelDefine.TEMPLATE.LAT))
+                    .forEach(it -> it.setValue(latStr));
+            propertyValues.stream()
+                    .filter(it -> Objects.equals(it.getProperty(), GisSurveyExcelDefine.TEMPLATE.LNG))
+                    .forEach(it -> it.setValue(lngStr));
+        });
+        //处理线
+        lines.parallelStream().forEach(line -> {
+            //获取geom
+            Geometry geometry = line.getGis();
+            if (geometry == null) return;
+            //转换geom
+            Geometry transform = CRSUtil.transform(geometry, CommCRSDefine.CGCS2000, targetCRSCode);
+            if (transform == null) return;
+            //回填元素
+            line.setGis(transform);
+        });
+    }
+
+    /**
      * 导出excel
      *
      * @param points              点

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

@@ -18,6 +18,7 @@ import com.shkpr.service.alambizplugin.commtools.CommTool;
 import com.shkpr.service.alambizplugin.constants.ApiURI;
 import com.shkpr.service.alambizplugin.constants.CadEnum;
 import com.shkpr.service.alambizplugin.constants.CommAsyncStatusEnum;
+import com.shkpr.service.alambizplugin.constants.CommCRSDefine;
 import com.shkpr.service.alambizplugin.constants.FileTypeEnum;
 import com.shkpr.service.alambizplugin.constants.GisSurveyImportStatusEnum;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
@@ -289,7 +290,7 @@ public class ApiGisSurveyController {
             , @RequestParam(value = "operator", required = false) String operator
             , @RequestParam(value = "jobId", required = false) String jobId
             , @RequestParam(value = "nature", required = false) String nature
-            , @RequestParam(value = "sourceCRSCode", required = false, defaultValue = "4490") String sourceCRSCode
+            , @RequestParam(value = "sourceCRSCode", required = false, defaultValue = CommCRSDefine.CGCS2000) String sourceCRSCode
             , @RequestParam(value = "resetNo", required = false) Boolean resetNo
             , @RequestParam(value = "checkConstraint", required = false, defaultValue = "false") Boolean checkConstraint
             , @RequestParam(value = "ignoreFail", required = false, defaultValue = "false") String ignoreFail) throws SelfException {
@@ -686,10 +687,10 @@ public class ApiGisSurveyController {
 
         //导出类型枚举
         FileTypeEnum fileTypeEnum = FileTypeEnum.getFileType(oJsonParam.getFileType());
-        if (fileTypeEnum == null) fileTypeEnum = FileTypeEnum.EXCEL;
+        oJsonParam.setFileTypeEnum(fileTypeEnum == null ? FileTypeEnum.EXCEL : fileTypeEnum);
 
         //执行第三方导出
-        CommAsyncResult<Map<String, String>> result = thirdExportBizService.thirdExport(oJsonParam.getJobId(), fileTypeEnum, oJsonParam.getOperator());
+        CommAsyncResult<Map<String, String>> result = thirdExportBizService.thirdExport(oJsonParam);
         String resultStr = null;
         try {
             if (result != null) resultStr = objectMapper.writeValueAsString(result);