|
@@ -8,6 +8,7 @@ import com.shkpr.service.alambizplugin.commtools.ExcelUtils;
|
|
|
import com.shkpr.service.alambizplugin.commtools.ShapeUtils;
|
|
|
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;
|
|
@@ -26,7 +27,6 @@ import org.springframework.scheduling.annotation.AsyncResult;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.concurrent.ListenableFuture;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
@@ -70,11 +70,12 @@ public class GisSurveyThirdExporter {
|
|
|
/**
|
|
|
* 第三方导出任务
|
|
|
*
|
|
|
- * @param jobId 任务id
|
|
|
+ * @param jobId 任务id
|
|
|
+ * @param fileType 导出文件类型
|
|
|
* @return 导出结果
|
|
|
*/
|
|
|
@Async
|
|
|
- public ListenableFuture<CommAsyncResult<String>> thirdExportTask(String jobId) {
|
|
|
+ public ListenableFuture<CommAsyncResult<String>> thirdExportTask(String jobId, FileTypeEnum fileType) {
|
|
|
//构建返回
|
|
|
CommAsyncResult<String> result = CommAsyncResult.fail(jobId);
|
|
|
try {
|
|
@@ -88,45 +89,27 @@ public class GisSurveyThirdExporter {
|
|
|
//查询点线数据
|
|
|
List<GisSurveyLayerApply> points = gisSurveyLayerApplyService.findAllByJobIdAndKind(jobId, GisMetadataDefine.TYPE_KINE.POINT);
|
|
|
List<GisSurveyLayerApply> lines = gisSurveyLayerApplyService.findAllByJobIdAndKind(jobId, GisMetadataDefine.TYPE_KINE.LINE);
|
|
|
- //获取图层key
|
|
|
- List<String> pointLayer = getLayerKeys(points);
|
|
|
- List<String> lineLayer = getLayerKeys(lines);
|
|
|
- //查询点图层模版
|
|
|
- List<GisMetadataLayerTemplate> pointLayerTemplates = layerTemplateService.findByKeyIn(pointLayer);
|
|
|
- //查询线图层模版
|
|
|
- List<GisMetadataLayerTemplate> lineLayerTemplates = layerTemplateService.findByKeyIn(lineLayer);
|
|
|
-
|
|
|
- //构建excel头
|
|
|
- Map<String, Map<String, String>> excelHeader = buildExcelHeader(pointLayerTemplates, lineLayerTemplates);
|
|
|
-
|
|
|
- //构建excel数据
|
|
|
- Map<String, List<Map<String, Object>>> excelData = buildExcelData(points, lines, pointLayerTemplates, lineLayerTemplates);
|
|
|
- //构建shape数据
|
|
|
- Map<String, List<Geometry>> shapeData = buildShapeData(points, lines);
|
|
|
-
|
|
|
- //创建临时文件夹
|
|
|
- Path directory = Files.createTempDirectory(tempFileProperties.getResourcePath(), "third-export-");
|
|
|
-
|
|
|
- //导出excel
|
|
|
- File excelFile = new File(directory + "/" + "output.xlsx");
|
|
|
- ExcelUtils.writeFile(excelHeader, excelData, Files.newOutputStream(excelFile.toPath()), ExcelEnum.XLSX);
|
|
|
- //导出shape
|
|
|
- ShapeUtils.writeShape(shapeData, directory);
|
|
|
-
|
|
|
- //压缩文件夹
|
|
|
- Path zipPath = CompressorUtils.archivalZip(directory);
|
|
|
- if (!Files.exists(zipPath)) {
|
|
|
+
|
|
|
+ //根据文件类型导出
|
|
|
+ Path resultPath = null;
|
|
|
+ if (fileType == FileTypeEnum.EXCEL)
|
|
|
+ resultPath = exportExcel(points, lines);
|
|
|
+ if (fileType == FileTypeEnum.SHAPE_FILE)
|
|
|
+ resultPath = exportShape(points, lines);
|
|
|
+
|
|
|
+ //导出文件判断
|
|
|
+ if (resultPath == null || !Files.exists(resultPath)) {
|
|
|
//打印报错信息
|
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
|
|
|
- , String.format("第三方导出zip压缩失败 任务id:%s", jobId)
|
|
|
+ , String.format("第三方导出文件写入失败, 任务id:%s", jobId)
|
|
|
);
|
|
|
return new AsyncResult<>(result);
|
|
|
}
|
|
|
|
|
|
- //导出
|
|
|
+ //导出完成
|
|
|
result.setStatus(CommAsyncStatusEnum.SUCCESS.getCode());
|
|
|
result.setCompleteTime(LocalDateTime.now());
|
|
|
- result.setData(zipPath.getFileName().toString());
|
|
|
+ result.setData(resultPath.getFileName().toString());
|
|
|
|
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
|
|
|
, String.format(
|
|
@@ -147,6 +130,58 @@ public class GisSurveyThirdExporter {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param points 点
|
|
|
+ * @param lines 线
|
|
|
+ * @return excel路径
|
|
|
+ * @throws IOException io异常
|
|
|
+ */
|
|
|
+ private Path exportExcel(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines) throws IOException {
|
|
|
+ //获取图层key
|
|
|
+ List<String> pointLayer = getLayerKeys(points);
|
|
|
+ List<String> lineLayer = getLayerKeys(lines);
|
|
|
+ //查询点图层模版
|
|
|
+ List<GisMetadataLayerTemplate> pointLayerTemplates = layerTemplateService.findByKeyIn(pointLayer);
|
|
|
+ //查询线图层模版
|
|
|
+ List<GisMetadataLayerTemplate> lineLayerTemplates = layerTemplateService.findByKeyIn(lineLayer);
|
|
|
+
|
|
|
+ //构建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);
|
|
|
+
|
|
|
+ return excelPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出shape
|
|
|
+ *
|
|
|
+ * @param points 点
|
|
|
+ * @param lines 线
|
|
|
+ * @return shape路径
|
|
|
+ * @throws IOException io异常
|
|
|
+ * @throws ArchiveException 压缩异常
|
|
|
+ */
|
|
|
+ private Path exportShape(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines) throws IOException, ArchiveException {
|
|
|
+ //构建shape数据
|
|
|
+ Map<String, List<Geometry>> shapeData = buildShapeData(points, lines);
|
|
|
+
|
|
|
+ //创建临时文件夹
|
|
|
+ Path directory = Files.createTempDirectory(tempFileProperties.getResourcePath(), "third-export-");
|
|
|
+
|
|
|
+ //导出shape
|
|
|
+ ShapeUtils.writeShape(shapeData, directory);
|
|
|
+
|
|
|
+ //压缩文件夹
|
|
|
+ return CompressorUtils.archivalZip(directory);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取图层key
|
|
|
*
|
|
|
* @param datas 数据
|