|
@@ -2,18 +2,14 @@ package com.shkpr.service.alambizplugin.components;
|
|
|
|
|
|
import com.global.base.log.LogLevelFlag;
|
|
import com.global.base.log.LogLevelFlag;
|
|
import com.global.base.log.LogPrintMgr;
|
|
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.commtools.ThirdImportTemplateUtils;
|
|
import com.shkpr.service.alambizplugin.constants.CommAsyncStatusEnum;
|
|
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.FileTypeEnum;
|
|
import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
|
|
import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
|
|
import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
|
|
import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
|
|
import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
|
|
import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
|
|
import com.shkpr.service.alambizplugin.dbdao.services.intef.GisMetadataLayerTemplateService;
|
|
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.dbdao.services.intef.GisSurveyLayerApplyService;
|
|
import com.shkpr.service.alambizplugin.dto.CommAsyncResult;
|
|
import com.shkpr.service.alambizplugin.dto.CommAsyncResult;
|
|
import com.shkpr.service.alambizplugin.dto.GisMetadataLayerTemplate;
|
|
import com.shkpr.service.alambizplugin.dto.GisMetadataLayerTemplate;
|
|
@@ -52,20 +48,27 @@ import java.util.stream.Collectors;
|
|
@Component
|
|
@Component
|
|
public class GisSurveyThirdExporter {
|
|
public class GisSurveyThirdExporter {
|
|
/**
|
|
/**
|
|
|
|
+ * 结果前缀
|
|
|
|
+ */
|
|
|
|
+ public final static String RESULT_PREFIX = "third-export-";
|
|
|
|
+ /**
|
|
* log
|
|
* log
|
|
*/
|
|
*/
|
|
private final String mStrClassName;
|
|
private final String mStrClassName;
|
|
private final String mBizType;
|
|
private final String mBizType;
|
|
- private final TempFileProperties tempFileProperties;
|
|
|
|
|
|
+
|
|
|
|
+ private final AsyncResultManager asyncResultManager;
|
|
|
|
+ private final GisSurveyJobInfoService jobInfoService;
|
|
private final GisMetadataLayerTemplateService layerTemplateService;
|
|
private final GisMetadataLayerTemplateService layerTemplateService;
|
|
private final GisSurveyLayerApplyService gisSurveyLayerApplyService;
|
|
private final GisSurveyLayerApplyService gisSurveyLayerApplyService;
|
|
|
|
|
|
|
|
|
|
- public GisSurveyThirdExporter(TempFileProperties tempFileProperties
|
|
|
|
|
|
+ public GisSurveyThirdExporter(AsyncResultManager asyncResultManager, GisSurveyJobInfoService jobInfoService
|
|
, GisMetadataLayerTemplateService layerTemplateService, GisSurveyLayerApplyService gisSurveyLayerApplyService) {
|
|
, GisMetadataLayerTemplateService layerTemplateService, GisSurveyLayerApplyService gisSurveyLayerApplyService) {
|
|
mStrClassName = "GisSurveyThirdExporter";
|
|
mStrClassName = "GisSurveyThirdExporter";
|
|
mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
|
|
mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
|
|
- this.tempFileProperties = tempFileProperties;
|
|
|
|
|
|
+ this.asyncResultManager = asyncResultManager;
|
|
|
|
+ this.jobInfoService = jobInfoService;
|
|
this.layerTemplateService = layerTemplateService;
|
|
this.layerTemplateService = layerTemplateService;
|
|
this.gisSurveyLayerApplyService = gisSurveyLayerApplyService;
|
|
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> points = gisSurveyLayerApplyService.findAllByJobIdAndKind(jobId, GisMetadataDefine.TYPE_KINE.POINT);
|
|
List<GisSurveyLayerApply> lines = gisSurveyLayerApplyService.findAllByJobIdAndKind(jobId, GisMetadataDefine.TYPE_KINE.LINE);
|
|
List<GisSurveyLayerApply> lines = gisSurveyLayerApplyService.findAllByJobIdAndKind(jobId, GisMetadataDefine.TYPE_KINE.LINE);
|
|
@@ -101,15 +106,20 @@ public class GisSurveyThirdExporter {
|
|
//查询线图层模版
|
|
//查询线图层模版
|
|
List<GisMetadataLayerTemplate> lineLayerTemplates = layerTemplateService.findByKeyIn(lineLayer);
|
|
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)
|
|
if (fileType == FileTypeEnum.EXCEL)
|
|
- resultPath = exportExcel(points, lines, pointLayerTemplates, lineLayerTemplates);
|
|
|
|
|
|
+ outputPath = exportExcel(points, lines, pointLayerTemplates, lineLayerTemplates, FLAG);
|
|
if (fileType == FileTypeEnum.SHAPE_FILE)
|
|
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
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
|
|
, String.format("第三方导出文件写入失败, 任务id:%s", jobId)
|
|
, String.format("第三方导出文件写入失败, 任务id:%s", jobId)
|
|
@@ -120,7 +130,22 @@ public class GisSurveyThirdExporter {
|
|
//导出完成
|
|
//导出完成
|
|
result.setStatus(CommAsyncStatusEnum.SUCCESS.getCode());
|
|
result.setStatus(CommAsyncStatusEnum.SUCCESS.getCode());
|
|
result.setCompleteTime(LocalDateTime.now());
|
|
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
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
|
|
, String.format(
|
|
, String.format(
|
|
@@ -136,7 +161,7 @@ public class GisSurveyThirdExporter {
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
|
|
, String.format("第三方导出异常 任务id:%s error:%s", jobId, e)
|
|
, 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 lines 线
|
|
* @param pointLayerTemplates 点图层模版
|
|
* @param pointLayerTemplates 点图层模版
|
|
* @param lineLayerTemplates 线图层模版
|
|
* @param lineLayerTemplates 线图层模版
|
|
|
|
+ * @param FLAG 结果flag
|
|
* @return excel路径
|
|
* @return excel路径
|
|
* @throws IOException io异常
|
|
* @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头
|
|
//构建excel头
|
|
Map<String, Map<String, String>> excelHeader = buildExcelHeader(pointLayerTemplates, lineLayerTemplates);
|
|
Map<String, Map<String, String>> excelHeader = buildExcelHeader(pointLayerTemplates, lineLayerTemplates);
|
|
//构建excel数据
|
|
//构建excel数据
|
|
Map<String, List<Map<String, Object>>> excelData = buildExcelData(points, lines, pointLayerTemplates, lineLayerTemplates);
|
|
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 lines 线
|
|
* @param pointLayerTemplates 点图层模版
|
|
* @param pointLayerTemplates 点图层模版
|
|
* @param lineLayerTemplates 线图层模版
|
|
* @param lineLayerTemplates 线图层模版
|
|
|
|
+ * @param FLAG 结果flag
|
|
* @return shape路径
|
|
* @return shape路径
|
|
* @throws IOException io异常
|
|
* @throws IOException io异常
|
|
* @throws ArchiveException 压缩异常
|
|
* @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数据
|
|
//构建shape数据
|
|
Map<SimpleFeatureType, List<Map<String, Object>>> shapeData = buildShapeData(points, lines, pointLayerTemplates, lineLayerTemplates);
|
|
Map<SimpleFeatureType, List<Map<String, Object>>> shapeData = buildShapeData(points, lines, pointLayerTemplates, lineLayerTemplates);
|
|
|
|
|
|
- //创建临时文件夹
|
|
|
|
- Path directory = Files.createTempDirectory(tempFileProperties.getResourcePath(), "third-export-");
|
|
|
|
-
|
|
|
|
//导出shape
|
|
//导出shape
|
|
- ShapeUtils.writeShape(shapeData, directory);
|
|
|
|
-
|
|
|
|
- //压缩文件夹
|
|
|
|
- return CompressorUtils.archivalZip(directory);
|
|
|
|
|
|
+ return asyncResultManager.writeShape(shapeData, FLAG, "third-export.zip");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|