|
@@ -21,7 +21,9 @@ import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApply;
|
|
import com.shkpr.service.alambizplugin.dto.GisSurveyPropertyValue;
|
|
import com.shkpr.service.alambizplugin.dto.GisSurveyPropertyValue;
|
|
import org.apache.commons.compress.archivers.ArchiveException;
|
|
import org.apache.commons.compress.archivers.ArchiveException;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
-import org.locationtech.jts.geom.Geometry;
|
|
|
|
|
|
+import org.geotools.data.DataUtilities;
|
|
|
|
+import org.geotools.feature.SchemaException;
|
|
|
|
+import org.opengis.feature.simple.SimpleFeatureType;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.AsyncResult;
|
|
import org.springframework.scheduling.annotation.AsyncResult;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -90,12 +92,20 @@ public class GisSurveyThirdExporter {
|
|
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);
|
|
|
|
|
|
|
|
+ //获取图层key
|
|
|
|
+ List<String> pointLayer = getLayerKeys(points);
|
|
|
|
+ List<String> lineLayer = getLayerKeys(lines);
|
|
|
|
+ //查询点图层模版
|
|
|
|
+ List<GisMetadataLayerTemplate> pointLayerTemplates = layerTemplateService.findByKeyIn(pointLayer);
|
|
|
|
+ //查询线图层模版
|
|
|
|
+ List<GisMetadataLayerTemplate> lineLayerTemplates = layerTemplateService.findByKeyIn(lineLayer);
|
|
|
|
+
|
|
//根据文件类型导出
|
|
//根据文件类型导出
|
|
Path resultPath = null;
|
|
Path resultPath = null;
|
|
if (fileType == FileTypeEnum.EXCEL)
|
|
if (fileType == FileTypeEnum.EXCEL)
|
|
- resultPath = exportExcel(points, lines);
|
|
|
|
|
|
+ resultPath = exportExcel(points, lines, pointLayerTemplates, lineLayerTemplates);
|
|
if (fileType == FileTypeEnum.SHAPE_FILE)
|
|
if (fileType == FileTypeEnum.SHAPE_FILE)
|
|
- resultPath = exportShape(points, lines);
|
|
|
|
|
|
+ resultPath = exportShape(points, lines, pointLayerTemplates, lineLayerTemplates);
|
|
|
|
|
|
//导出文件判断
|
|
//导出文件判断
|
|
if (resultPath == null || !Files.exists(resultPath)) {
|
|
if (resultPath == null || !Files.exists(resultPath)) {
|
|
@@ -120,7 +130,7 @@ public class GisSurveyThirdExporter {
|
|
);
|
|
);
|
|
|
|
|
|
return new AsyncResult<>(result);
|
|
return new AsyncResult<>(result);
|
|
- } catch (InterruptedException | IOException | ArchiveException e) {
|
|
|
|
|
|
+ } catch (InterruptedException | IOException | ArchiveException | SchemaException e) {
|
|
//打印报错信息
|
|
//打印报错信息
|
|
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)
|
|
@@ -132,20 +142,14 @@ public class GisSurveyThirdExporter {
|
|
/**
|
|
/**
|
|
* 导出excel
|
|
* 导出excel
|
|
*
|
|
*
|
|
- * @param points 点
|
|
|
|
- * @param lines 线
|
|
|
|
|
|
+ * @param points 点
|
|
|
|
+ * @param lines 线
|
|
|
|
+ * @param pointLayerTemplates 点图层模版
|
|
|
|
+ * @param lineLayerTemplates 线图层模版
|
|
* @return excel路径
|
|
* @return excel路径
|
|
* @throws IOException io异常
|
|
* @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);
|
|
|
|
-
|
|
|
|
|
|
+ private Path exportExcel(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines, List<GisMetadataLayerTemplate> pointLayerTemplates, List<GisMetadataLayerTemplate> lineLayerTemplates) throws IOException {
|
|
//构建excel头
|
|
//构建excel头
|
|
Map<String, Map<String, String>> excelHeader = buildExcelHeader(pointLayerTemplates, lineLayerTemplates);
|
|
Map<String, Map<String, String>> excelHeader = buildExcelHeader(pointLayerTemplates, lineLayerTemplates);
|
|
//构建excel数据
|
|
//构建excel数据
|
|
@@ -161,15 +165,17 @@ public class GisSurveyThirdExporter {
|
|
/**
|
|
/**
|
|
* 导出shape
|
|
* 导出shape
|
|
*
|
|
*
|
|
- * @param points 点
|
|
|
|
- * @param lines 线
|
|
|
|
|
|
+ * @param points 点
|
|
|
|
+ * @param lines 线
|
|
|
|
+ * @param pointLayerTemplates 点图层模版
|
|
|
|
+ * @param lineLayerTemplates 线图层模版
|
|
* @return shape路径
|
|
* @return shape路径
|
|
* @throws IOException io异常
|
|
* @throws IOException io异常
|
|
* @throws ArchiveException 压缩异常
|
|
* @throws ArchiveException 压缩异常
|
|
*/
|
|
*/
|
|
- private Path exportShape(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines) throws IOException, ArchiveException {
|
|
|
|
|
|
+ private Path exportShape(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines, List<GisMetadataLayerTemplate> pointLayerTemplates, List<GisMetadataLayerTemplate> lineLayerTemplates) throws IOException, ArchiveException, SchemaException {
|
|
//构建shape数据
|
|
//构建shape数据
|
|
- Map<String, List<Geometry>> shapeData = buildShapeData(points, lines);
|
|
|
|
|
|
+ Map<SimpleFeatureType, List<Map<String, Object>>> shapeData = buildShapeData(points, lines, pointLayerTemplates, lineLayerTemplates);
|
|
|
|
|
|
//创建临时文件夹
|
|
//创建临时文件夹
|
|
Path directory = Files.createTempDirectory(tempFileProperties.getResourcePath(), "third-export-");
|
|
Path directory = Files.createTempDirectory(tempFileProperties.getResourcePath(), "third-export-");
|
|
@@ -280,7 +286,8 @@ public class GisSurveyThirdExporter {
|
|
//处理模版数据
|
|
//处理模版数据
|
|
Map<String, Object> rowData = it.getPropertyValues().stream()
|
|
Map<String, Object> rowData = it.getPropertyValues().stream()
|
|
.filter(it1 -> !StringUtils.isAnyBlank(it1.getProperty(), it1.getValue()))
|
|
.filter(it1 -> !StringUtils.isAnyBlank(it1.getProperty(), it1.getValue()))
|
|
- .collect(Collectors.toMap(GisSurveyPropertyValue::getProperty, GisSurveyPropertyValue::getValue));
|
|
|
|
|
|
+ .collect(Collectors.toMap(GisSurveyPropertyValue::getProperty, GisSurveyPropertyValue::getValue
|
|
|
|
+ , (i1, i2) -> i1));
|
|
//处理图层数据
|
|
//处理图层数据
|
|
if (StringUtils.isNotBlank(it.getLayer())) {
|
|
if (StringUtils.isNotBlank(it.getLayer())) {
|
|
//获取模版
|
|
//获取模版
|
|
@@ -298,37 +305,96 @@ public class GisSurveyThirdExporter {
|
|
/**
|
|
/**
|
|
* 构建shape数据
|
|
* 构建shape数据
|
|
*
|
|
*
|
|
- * @param points 点元素
|
|
|
|
- * @param lines 线元素
|
|
|
|
|
|
+ * @param points 点元素
|
|
|
|
+ * @param lines 线元素
|
|
|
|
+ * @param pointLayerTemplates 点图层模版
|
|
|
|
+ * @param lineLayerTemplates 线图层模版
|
|
* @return excel数据
|
|
* @return excel数据
|
|
*/
|
|
*/
|
|
- private Map<String, List<Geometry>> buildShapeData(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines) {
|
|
|
|
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始构建shape数据 ======>");
|
|
|
|
|
|
+ private Map<SimpleFeatureType, List<Map<String, Object>>> buildShapeData(List<GisSurveyLayerApply> points, List<GisSurveyLayerApply> lines
|
|
|
|
+ , List<GisMetadataLayerTemplate> pointLayerTemplates, List<GisMetadataLayerTemplate> lineLayerTemplates) throws SchemaException {
|
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始构建shape属性头和数据 ======>");
|
|
long begin = System.currentTimeMillis();
|
|
long begin = System.currentTimeMillis();
|
|
|
|
|
|
- //点excel数据
|
|
|
|
- List<Geometry> pointExcelData = points.parallelStream()
|
|
|
|
- .map(GisSurveyLayerApply::getGis)
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- //线excel数据
|
|
|
|
- List<Geometry> lineExcelData = lines.parallelStream()
|
|
|
|
- .map(GisSurveyLayerApply::getGis)
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
|
+ //点模版规格
|
|
|
|
+ String pointTemplateSpec = pointLayerTemplates.stream()
|
|
|
|
+ .flatMap(it -> it.getPropertyTemplates().stream())
|
|
|
|
+ .sorted(Comparator.comparing(GisMetadataPropertyTemplate::getOrdering))
|
|
|
|
+ .map(it ->
|
|
|
|
+ StringUtils.substring(it.getKey(), 0, 10) + ":"
|
|
|
|
+ + (StringUtils.isBlank(it.getType()) ? "string" : it.getType())
|
|
|
|
+ )
|
|
|
|
+ .distinct()
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
+ //线模版规格
|
|
|
|
+ String lineTemplateSpec = lineLayerTemplates.stream()
|
|
|
|
+ .flatMap(it -> it.getPropertyTemplates().stream())
|
|
|
|
+ .sorted(Comparator.comparing(GisMetadataPropertyTemplate::getOrdering))
|
|
|
|
+ .map(it ->
|
|
|
|
+ StringUtils.substring(it.getKey(), 0, 10) + ":"
|
|
|
|
+ + (StringUtils.isBlank(it.getType()) ? "string" : it.getType())
|
|
|
|
+ )
|
|
|
|
+ .distinct()
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
|
|
- //excel数据
|
|
|
|
- Map<String, List<Geometry>> shapeData = new HashMap<>();
|
|
|
|
- shapeData.put(GisMetadataDefine.TYPE_KINE.POINT, pointExcelData);
|
|
|
|
- shapeData.put(GisMetadataDefine.TYPE_KINE.LINE, lineExcelData);
|
|
|
|
|
|
+
|
|
|
|
+ //创建点类型
|
|
|
|
+ final SimpleFeatureType POINT_TYPE = DataUtilities.createType(
|
|
|
|
+ "point",
|
|
|
|
+ GisSurveyExcelDefine.FILE_HANDLE.POINT_SPEC + pointTemplateSpec
|
|
|
|
+ );
|
|
|
|
+ //创建线类型
|
|
|
|
+ final SimpleFeatureType LINE_TYPE = DataUtilities.createType(
|
|
|
|
+ "line",
|
|
|
|
+ GisSurveyExcelDefine.FILE_HANDLE.LINE_SPEC + lineTemplateSpec
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ //shape数据
|
|
|
|
+ Map<SimpleFeatureType, List<Map<String, Object>>> shapeData = new HashMap<>();
|
|
|
|
+ shapeData.put(POINT_TYPE, buildShapeItemData(points, pointLayerTemplates));
|
|
|
|
+ shapeData.put(LINE_TYPE, buildShapeItemData(lines, lineLayerTemplates));
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
long end = System.currentTimeMillis();
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
|
|
, String.format(
|
|
, String.format(
|
|
- "结束构建shape数据,用时(毫秒):%d"
|
|
|
|
|
|
+ "结束构建shape属性头和数据,用时(毫秒):%d"
|
|
, (end - begin)
|
|
, (end - begin)
|
|
)
|
|
)
|
|
);
|
|
);
|
|
return shapeData;
|
|
return shapeData;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 构建shape项数据
|
|
|
|
+ *
|
|
|
|
+ * @param layerApplies 采集元素集合
|
|
|
|
+ * @param layerTemplates 图层模版
|
|
|
|
+ * @return excel数据
|
|
|
|
+ */
|
|
|
|
+ private List<Map<String, Object>> buildShapeItemData(List<GisSurveyLayerApply> layerApplies, List<GisMetadataLayerTemplate> layerTemplates) {
|
|
|
|
+ return layerApplies.parallelStream()
|
|
|
|
+ .map(it -> {
|
|
|
|
+ //处理模版数据
|
|
|
|
+ Map<String, Object> rowData = it.getPropertyValues().stream()
|
|
|
|
+ .filter(it1 -> !StringUtils.isAnyBlank(it1.getProperty(), it1.getValue()))
|
|
|
|
+ .collect(Collectors.toMap(gisSurveyPropertyValue ->
|
|
|
|
+ StringUtils.substring(gisSurveyPropertyValue.getProperty(), 0, 10)
|
|
|
|
+ , GisSurveyPropertyValue::getValue
|
|
|
|
+ , (i1, i2) -> i1)
|
|
|
|
+ );
|
|
|
|
+ //处理图层数据
|
|
|
|
+ if (StringUtils.isNotBlank(it.getLayer())) {
|
|
|
|
+ //获取模版
|
|
|
|
+ GisMetadataLayerTemplate gisMetadataLayerTemplate = layerTemplates.stream()
|
|
|
|
+ .filter(it1 -> Objects.equals(it1.getKey(), it.getLayer()))
|
|
|
|
+ .findFirst().orElse(null);
|
|
|
|
+ //存入图层
|
|
|
|
+ if (gisMetadataLayerTemplate != null)
|
|
|
|
+ rowData.put(GisSurveyExcelDefine.FILE.LAYER, gisMetadataLayerTemplate.getName());
|
|
|
|
+ //存入geom
|
|
|
|
+ rowData.put(GisSurveyExcelDefine.FILE.THE_GEOM, it.getGis());
|
|
|
|
+ }
|
|
|
|
+ return rowData;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ }
|
|
}
|
|
}
|