123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646 |
- package com.shkpr.service.alambizplugin.components;
- import com.global.base.log.LogLevelFlag;
- import com.global.base.log.LogPrintMgr;
- import com.shkpr.service.alambizplugin.apiparam.GisSurveyThirdImportParams;
- import com.shkpr.service.alambizplugin.commtools.CRSUtil;
- import com.shkpr.service.alambizplugin.commtools.ExcelUtils;
- import com.shkpr.service.alambizplugin.commtools.PointCodeUtil;
- import com.shkpr.service.alambizplugin.commtools.ThirdImportTemplateUtils;
- import com.shkpr.service.alambizplugin.commtools.norule.JPSurveyApplyColumn;
- import com.shkpr.service.alambizplugin.commtools.norule.RuleFormatSetting;
- import com.shkpr.service.alambizplugin.commtools.norule.SurveyCommonAssistant;
- import com.shkpr.service.alambizplugin.components.checker.DuplicatePointsFinder;
- import com.shkpr.service.alambizplugin.components.checker.InvalidLinesFinder;
- import com.shkpr.service.alambizplugin.components.checker.InvalidPropertiesFinder;
- import com.shkpr.service.alambizplugin.constants.CommAsyncStatusEnum;
- import com.shkpr.service.alambizplugin.constants.CommCRSDefine;
- import com.shkpr.service.alambizplugin.constants.ExcelEnum;
- import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
- import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
- import com.shkpr.service.alambizplugin.constants.GisSurveyImportStatusEnum;
- 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.GisSurveyLayerApplyThirdCopyService;
- import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyProjectInfoService;
- import com.shkpr.service.alambizplugin.dto.GisMetadataLayerTemplate;
- import com.shkpr.service.alambizplugin.dto.GisMetadataPropertyTemplate;
- import com.shkpr.service.alambizplugin.dto.GisSurveyCondition;
- import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyThirdCopy;
- import com.shkpr.service.alambizplugin.dto.GisSurveyPropertyValueThirdCopy;
- import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportElement;
- import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportResult;
- import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportResultDetail;
- import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportSubtask;
- import org.apache.commons.collections4.CollectionUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.commons.lang3.math.NumberUtils;
- import org.locationtech.jts.geom.Coordinate;
- import org.locationtech.jts.geom.Geometry;
- import org.locationtech.jts.geom.GeometryFactory;
- import org.locationtech.jts.geom.PrecisionModel;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.scheduling.annotation.AsyncResult;
- import org.springframework.stereotype.Component;
- import org.springframework.util.concurrent.ListenableFuture;
- import java.io.IOException;
- import java.io.InputStream;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.time.Duration;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- import java.util.concurrent.ConcurrentHashMap;
- import java.util.concurrent.ExecutionException;
- import java.util.function.Consumer;
- import java.util.stream.Collectors;
- /**
- * 第三方导入执行器
- *
- * @author 欧阳劲驰
- * @since 1.0.0
- */
- @Component
- public class GisSurveyThirdImporter {
- /**
- * log
- */
- private final String mStrClassName;
- private final String mBizType;
- private final GeometryFactory geometryFactory;
- private final GisSurveyProjectInfoService projectInfoService;
- private final GisSurveyJobInfoService jobInfoService;
- private final GisMetadataLayerTemplateService layerTemplateService;
- private final GisSurveyLayerApplyThirdCopyService layerApplyThirdCopyService;
- private final DuplicatePointsFinder duplicatePointsFinder;
- private final InvalidLinesFinder invalidLinesFinder;
- private final InvalidPropertiesFinder invalidPropertiesFinder;
- public GisSurveyThirdImporter(GisSurveyProjectInfoService projectInfoService
- , GisSurveyJobInfoService jobInfoService
- , GisMetadataLayerTemplateService layerTemplateService
- , GisSurveyLayerApplyThirdCopyService layerApplyThirdCopyService
- , DuplicatePointsFinder duplicatePointsFinder
- , InvalidLinesFinder invalidLinesFinder
- , InvalidPropertiesFinder invalidPropertiesFinder) {
- mStrClassName = "GisSurveyThirdImporter";
- mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
- geometryFactory = new GeometryFactory(new PrecisionModel(), 4490);
- this.projectInfoService = projectInfoService;
- this.jobInfoService = jobInfoService;
- this.layerTemplateService = layerTemplateService;
- this.layerApplyThirdCopyService = layerApplyThirdCopyService;
- this.duplicatePointsFinder = duplicatePointsFinder;
- this.invalidLinesFinder = invalidLinesFinder;
- this.invalidPropertiesFinder = invalidPropertiesFinder;
- }
- /**
- * 第三方导入任务
- *
- * @param params 系统检查参数
- * @param inputStreams 文件输入流
- * @param onStartSubtask 启动子任务
- * @param onDeprecatedSubtask 弃用子任务(完成数据收集/取消)
- * @return 系统检查返回
- */
- @Async
- public ListenableFuture<GisSurveyThirdImportResult> thirdImportTask(GisSurveyThirdImportParams params, List<InputStream> inputStreams
- , Consumer<GisSurveyThirdImportSubtask> onStartSubtask, Consumer<String> onDeprecatedSubtask) {
- //构建返回
- GisSurveyThirdImportResult result = GisSurveyThirdImportResult.fail(params);
- result.setOperator(params.getOperator());
- //无效属性任务
- ListenableFuture<GisSurveyThirdImportResultDetail<Map<String, List<GisSurveyThirdImportElement>>>> invalidPropertiesFuture = null;
- //重复点号任务
- ListenableFuture<GisSurveyThirdImportResultDetail<List<GisSurveyThirdImportElement>>> duplicatePointsFuture = null;
- //无效线任务
- ListenableFuture<GisSurveyThirdImportResultDetail<List<GisSurveyThirdImportElement>>> invalidLinesFuture = null;
- //点集合
- List<Map<String, String>> points = new ArrayList<>();
- //线集合
- List<Map<String, String>> lines = new ArrayList<>();
- try {
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
- , String.format(
- "开始执行第三方导入;任务id: %s"
- , params.getJobId()
- )
- );
- //解析excel
- parseExcel(inputStreams, points, lines);
- //项目约束条件
- List<GisSurveyCondition> projectConstraints = projectInfoService.findConstraintsByJobId(params.getJobId());
- //提取图层名
- List<String> pointLayerNames = getLayerNames(points, GisSurveyExcelDefine.FILE.POINT_LAYER);
- List<String> lineLayerNames = getLayerNames(lines, GisSurveyExcelDefine.FILE.LINE_LAYER);
- //图层模版
- List<GisMetadataLayerTemplate> pointLayerTemplates = layerTemplateService.findByNatureAndNameIn(params.getNature(), pointLayerNames);
- List<GisMetadataLayerTemplate> lineLayerTemplates = layerTemplateService.findByNatureAndNameIn(params.getNature(), lineLayerNames);
- //无效属性检查
- invalidPropertiesFuture = invalidPropertiesFinder.findInvalidProperties(points, lines
- , pointLayerTemplates, lineLayerTemplates, params.getCheckConstraint(), projectConstraints);
- //重复点检查
- duplicatePointsFuture = duplicatePointsFinder.findDuplicatePoints(points, pointLayerTemplates);
- //无效线检查
- invalidLinesFuture = invalidLinesFinder.finderInvalidLines(points, lines, pointLayerTemplates, lineLayerTemplates);
- //返回子任务
- onStartSubtask.accept(
- new GisSurveyThirdImportSubtask(invalidPropertiesFuture, duplicatePointsFuture, invalidLinesFuture)
- );
- //等待结果
- GisSurveyThirdImportResultDetail<Map<String, List<GisSurveyThirdImportElement>>> invalidPropertiesResult = invalidPropertiesFuture.get();
- //存入无效属性结果
- result.setInvalidLayersResult(untarInvalidProperties(invalidPropertiesResult, GisSurveyExcelDefine.RESULT.INVALID_LAYERS));
- result.setMissingRequirementsResult(untarInvalidProperties(invalidPropertiesResult, GisSurveyExcelDefine.RESULT.MISSING_REQUIREMENTS));
- result.setInvalidTypesResult(untarInvalidProperties(invalidPropertiesResult, GisSurveyExcelDefine.RESULT.INVALID_TYPES));
- result.setOutRangesResult(untarInvalidProperties(invalidPropertiesResult, GisSurveyExcelDefine.RESULT.OUT_RANGES));
- result.setOutConstraintResult(untarInvalidProperties(invalidPropertiesResult, GisSurveyExcelDefine.RESULT.OUT_CONSTRAINT));
- //存入重复点结果
- result.setDuplicatePointsResult(duplicatePointsFuture.get());
- //存入无效线结果
- result.setInvalidLinesResult(invalidLinesFuture.get());
- //结果未通过
- if (!checkResult(result)) {
- result.setImportStatus(GisSurveyImportStatusEnum.DATA_ERROR.getCode());
- result.setCompleteTime(LocalDateTime.now());
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
- , String.format(
- "第三方导入结果未通过;任务id: %s, 用时(毫秒):%d",
- params.getJobId(),
- Duration.between(result.getRequestTime(), result.getCompleteTime()).toMillis()
- )
- );
- //弃用子任务
- onDeprecatedSubtask.accept(params.getJobId());
- return new AsyncResult<>(result);
- }
- //解码点线数据
- List<GisSurveyLayerApplyThirdCopy> layerApplyList = decodeDataToLayerApply(points, lines, pointLayerTemplates, lineLayerTemplates, params);
- //重置点号
- if (params.getResetNo()) resetNo(params.getJobId(), layerApplyList);
- //批量写入
- Boolean saved = layerApplyThirdCopyService.saveAll(params.getJobId(), layerApplyList);
- if (!saved) {
- result.setCompleteTime(LocalDateTime.now());
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
- , String.format(
- "第三方导入入库失败;任务id: %s, 用时(毫秒):%d",
- params.getJobId(),
- Duration.between(result.getRequestTime(), LocalDateTime.now()).toMillis()
- )
- );
- //弃用子任务
- onDeprecatedSubtask.accept(params.getJobId());
- return new AsyncResult<>(result);
- }
- //完成任务
- result.setImportStatus(GisSurveyImportStatusEnum.SUCCESS.getCode());
- result.setCompleteTime(LocalDateTime.now());
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
- , String.format(
- "结束执行第三方导入;任务id: %s, 用时(毫秒):%d",
- params.getJobId(),
- Duration.between(result.getRequestTime(), result.getCompleteTime()).toMillis()
- )
- );
- //弃用子任务
- onDeprecatedSubtask.accept(params.getJobId());
- return new AsyncResult<>(result);
- } catch (InterruptedException | ExecutionException | IOException | RuntimeException e) {
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
- , String.format(
- "监测到中断或执行异常,开始清除子任务 任务id:%s error:%s",
- params.getJobId(),
- e
- )
- );
- //清除子任务
- if (invalidPropertiesFuture != null) invalidPropertiesFuture.cancel(true);
- if (duplicatePointsFuture != null) duplicatePointsFuture.cancel(true);
- if (invalidLinesFuture != null) invalidLinesFuture.cancel(true);
- //失败信息
- result.setImportStatus(CommAsyncStatusEnum.FAIL.getCode());
- result.setCompleteTime(LocalDateTime.now());
- //弃用子任务
- onDeprecatedSubtask.accept(params.getJobId());
- return new AsyncResult<>(result);
- }
- }
- /**
- * 解析excel
- *
- * @param inputStreams 输入流
- * @param points 点集合
- * @param lines 线集合
- * @throws IOException io异常
- */
- private void parseExcel(List<InputStream> inputStreams, List<Map<String, String>> points, List<Map<String, String>> lines) throws IOException, InterruptedException {
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行解析excel ======>");
- long begin = System.currentTimeMillis();
- //解析文件
- for (InputStream inputStream : inputStreams) {
- //检查线程中断,并响应
- if (Thread.interrupted()) throw new InterruptedException();
- //解析excel
- Map<String, List<Map<String, String>>> excelData = ExcelUtils.parseExcelFile(inputStream, ExcelEnum.XLSX
- , GisSurveyExcelDefine.FILE_HANDLE.HEADER_ROW_NUM, GisSurveyExcelDefine.FILE_HANDLE.DATA_ROW_NUM);
- //填入集合
- if (excelData != null && excelData.containsKey(GisMetadataDefine.TYPE_KINE.POINT))
- points.addAll(excelData.get(GisMetadataDefine.TYPE_KINE.POINT));
- if (excelData != null && excelData.containsKey(GisMetadataDefine.TYPE_KINE.LINE))
- lines.addAll(excelData.get(GisMetadataDefine.TYPE_KINE.LINE));
- //释放流
- inputStream.close();
- }
- long end = System.currentTimeMillis();
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
- , String.format(
- "结束执行执行解析excel,用时(毫秒):%d"
- , (end - begin)
- )
- );
- }
- /**
- * 获取图层名称
- *
- * @param datas 数据
- * @param layerKey 文件图层的key
- * @return 图层名称集合
- */
- private List<String> getLayerNames(List<Map<String, String>> datas, String layerKey) {
- //去重图层
- return datas.parallelStream()
- .filter(data -> data.get(layerKey) != null)
- .map(data -> data.get(layerKey))
- .distinct()
- .collect(Collectors.toList());
- }
- /**
- * 解包无效属性
- *
- * @param invalidPropertiesResult 无效属性结果
- * @param resultKey 结果key
- * @return 具体结果
- */
- private GisSurveyThirdImportResultDetail<List<GisSurveyThirdImportElement>> untarInvalidProperties(
- GisSurveyThirdImportResultDetail<Map<String, List<GisSurveyThirdImportElement>>> invalidPropertiesResult
- , String resultKey) {
- //获取结果
- List<GisSurveyThirdImportElement> importElements = invalidPropertiesResult.getResults().get(resultKey);
- return new GisSurveyThirdImportResultDetail<>(true, importElements);
- }
- /**
- * 检查结果
- *
- * @param result 结果
- * @return 结果通过状态
- */
- private Boolean checkResult(GisSurveyThirdImportResult result) {
- List<GisSurveyThirdImportElement> invalidLayers = result.getInvalidLayersResult().getResults();
- List<GisSurveyThirdImportElement> missingRequirements = result.getMissingRequirementsResult().getResults();
- List<GisSurveyThirdImportElement> invalidTypesResult = result.getInvalidTypesResult().getResults();
- List<GisSurveyThirdImportElement> outRanges = result.getOutRangesResult().getResults();
- List<GisSurveyThirdImportElement> outConstraint = result.getOutConstraintResult().getResults();
- List<GisSurveyThirdImportElement> duplicatePoints = result.getDuplicatePointsResult().getResults();
- List<GisSurveyThirdImportElement> invalidLines = result.getInvalidLinesResult().getResults();
- //检查是否都为空
- return CollectionUtils.isEmpty(invalidLayers) && CollectionUtils.isEmpty(missingRequirements) &&
- CollectionUtils.isEmpty(invalidTypesResult) && CollectionUtils.isEmpty(outRanges) &&
- CollectionUtils.isEmpty(outConstraint) && CollectionUtils.isEmpty(duplicatePoints) &&
- CollectionUtils.isEmpty(invalidLines);
- }
- /**
- * 解码数据到采集元素对象
- * <p>从Map转为 {@code GisSurveyLayerApplyThirdCopy}</p>
- *
- * @param points 点数据
- * @param lines 线数据
- * @param pointLayerTemplates 点图层模版
- * @param lineLayerTemplates 线图层模版
- * @param params 导入参数
- * @return 格式化后数据
- */
- private List<GisSurveyLayerApplyThirdCopy> decodeDataToLayerApply(List<Map<String, String>> points, List<Map<String, String>> lines
- , List<GisMetadataLayerTemplate> pointLayerTemplates, List<GisMetadataLayerTemplate> lineLayerTemplates, GisSurveyThirdImportParams params) {
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "导入结果通过,开始解码点线数据 ======>");
- long begin = System.currentTimeMillis();
- //按模版名分组,便于快速找到模版
- Map<String, GisMetadataLayerTemplate> poineTemplateMap = pointLayerTemplates.stream()
- .collect(Collectors.toMap(
- GisMetadataLayerTemplate::getName, it -> it,
- (it1, it2) -> it1
- ));
- Map<String, GisMetadataLayerTemplate> lineTemplateMap = lineLayerTemplates.stream()
- .collect(Collectors.toMap(
- GisMetadataLayerTemplate::getName, it -> it,
- (it1, it2) -> it1
- ));
- //采集元素象集合
- List<GisSurveyLayerApplyThirdCopy> result = new ArrayList<>();
- //点号映射,用于线写入上下游节点
- Map<String, String> pointNoMapping = new HashMap<>();
- //格式化点
- for (Map<String, String> point : points) {
- //获取模版
- GisMetadataLayerTemplate layerTemplate = poineTemplateMap.get(point.get(GisSurveyExcelDefine.FILE.POINT_LAYER));
- //解码点对象
- GisSurveyLayerApplyThirdCopy layerApply = decodePointToLayerApply(point, layerTemplate, params);
- //存入点号
- pointNoMapping.put(layerApply.getNo(), layerApply.getCode());
- result.add(layerApply);
- }
- //格式化线
- for (Map<String, String> line : lines) {
- //获取模版
- GisMetadataLayerTemplate layerTemplate = lineTemplateMap.get(line.get(GisSurveyExcelDefine.FILE.LINE_LAYER));
- //解码对象
- GisSurveyLayerApplyThirdCopy layerApply = decodeLineToLayerApply(line, layerTemplate, params, pointNoMapping);
- result.add(layerApply);
- }
- long end = System.currentTimeMillis();
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
- , String.format(
- "结束执行解码点线数据,用时(毫秒):%d"
- , (end - begin)
- )
- );
- return result;
- }
- /**
- * 解码点数据到采集元素对象
- *
- * @param point 点数据
- * @param layerTemplate 图层模版
- * @param params 导入参数
- * @return 采集元素拷贝对象
- */
- private GisSurveyLayerApplyThirdCopy decodePointToLayerApply(Map<String, String> point, GisMetadataLayerTemplate layerTemplate, GisSurveyThirdImportParams params) {
- GisSurveyLayerApplyThirdCopy layerApply = new GisSurveyLayerApplyThirdCopy();
- //必填项
- layerApply.setJobId(params.getJobId());
- layerApply.setCode(PointCodeUtil.generateCode());
- layerApply.setLayer(layerTemplate.getKey());
- layerApply.setKind(GisMetadataDefine.TYPE_KINE.POINT);
- //默认值
- layerApply.setApply(GisSurveyExcelDefine.DEFAULT_VALUE.APPLY);
- layerApply.setSource(GisSurveyExcelDefine.DEFAULT_VALUE.SOURCE);
- //点号(长度64截断)
- String noStr = ThirdImportTemplateUtils.getValue(point, layerTemplate, GisSurveyExcelDefine.TEMPLATE.NO);
- if (StringUtils.isNotBlank(noStr))
- layerApply.setNo(StringUtils.substring(noStr, 0, 64));
- //经纬度
- Double lng = null;
- Double lat = null;
- //遍历属性模版
- List<GisSurveyPropertyValueThirdCopy> propertyValueList = new ArrayList<>();
- for (GisMetadataPropertyTemplate propertyTemplate : layerTemplate.getPropertyTemplates()) {
- //解析属性
- GisSurveyPropertyValueThirdCopy propertyValue = decodeDataToPropertyValue(point, layerApply
- , propertyTemplate, params);
- //不为空,填入数据
- if (propertyValue != null) {
- propertyValueList.add(propertyValue);
- //经纬度属性
- if (Objects.equals(propertyValue.getProperty(), GisSurveyExcelDefine.TEMPLATE.LNG)
- && NumberUtils.isParsable(propertyValue.getValue()))
- lng = Double.valueOf(propertyValue.getValue());
- if (Objects.equals(propertyValue.getProperty(), GisSurveyExcelDefine.TEMPLATE.LAT)
- && NumberUtils.isParsable(propertyValue.getValue()))
- lat = Double.valueOf(propertyValue.getValue());
- //高程和埋深
- if (Objects.equals(propertyValue.getProperty(), GisSurveyExcelDefine.TEMPLATE.ELEVATION)
- && NumberUtils.isParsable(propertyValue.getValue()))
- layerApply.setElevation(Double.valueOf(propertyValue.getValue()));
- if (Objects.equals(propertyValue.getProperty(), GisSurveyExcelDefine.TEMPLATE.DEPTH)
- && NumberUtils.isParsable(propertyValue.getValue()))
- layerApply.setDepth(Double.valueOf(propertyValue.getValue()));
- }
- }
- //处理经纬度
- if (lng != null && lat != null) {
- //构建geom
- Geometry geometry = geometryFactory.createPoint(new Coordinate(lng, lat));
- //如源不为大地2000
- if (!Objects.equals(params.getSourceCRSCode(), CommCRSDefine.CGCS2000)) {
- //转换坐标系
- Geometry transform = CRSUtil.transform(geometry, params.getSourceCRSCode(), CommCRSDefine.CGCS2000);
- if (transform != null) {
- //回填geom
- geometry = transform;
- //获取解析后的经纬度
- Coordinate coordinate = geometry.getCoordinate();
- String lngStr = BigDecimal.valueOf(coordinate.getX()).toPlainString();
- String latStr = BigDecimal.valueOf(coordinate.getY()).toPlainString();
- //回填经纬度属性
- propertyValueList.stream()
- .filter(it -> Objects.equals(it.getProperty(), GisSurveyExcelDefine.TEMPLATE.LAT))
- .forEach(it -> it.setValue(latStr));
- propertyValueList.stream()
- .filter(it -> Objects.equals(it.getProperty(), GisSurveyExcelDefine.TEMPLATE.LNG))
- .forEach(it -> it.setValue(lngStr));
- }
- }
- //设置geom
- layerApply.setGis(geometry);
- }
- //设置属性
- layerApply.setPropertyValues(propertyValueList);
- return layerApply;
- }
- /**
- * 解码线数据到采集元素对象
- *
- * @param line 线数据
- * @param layerTemplate 图层模版
- * @param params 导入参数
- * @param pointNoMapping 点号映射
- * @return 采集元素拷贝对象
- */
- private GisSurveyLayerApplyThirdCopy decodeLineToLayerApply(Map<String, String> line, GisMetadataLayerTemplate layerTemplate, GisSurveyThirdImportParams params, Map<String, String> pointNoMapping) {
- GisSurveyLayerApplyThirdCopy layerApply = new GisSurveyLayerApplyThirdCopy();
- //必填项
- layerApply.setJobId(params.getJobId());
- layerApply.setCode(PointCodeUtil.generateCode());
- layerApply.setLayer(layerTemplate.getKey());
- layerApply.setKind(GisMetadataDefine.TYPE_KINE.LINE);
- //默认值
- layerApply.setApply(GisSurveyExcelDefine.DEFAULT_VALUE.APPLY);
- layerApply.setSource(GisSurveyExcelDefine.DEFAULT_VALUE.SOURCE);
- //上下游节点
- String upNoStr = ThirdImportTemplateUtils.getValue(line, layerTemplate, GisSurveyExcelDefine.TEMPLATE.UP_NO);
- if (StringUtils.isNotBlank(upNoStr)) {
- layerApply.setUpNode(pointNoMapping.get(upNoStr));
- }
- String downNoStr = ThirdImportTemplateUtils.getValue(line, layerTemplate, GisSurveyExcelDefine.TEMPLATE.DOWN_NO);
- if (StringUtils.isNotBlank(downNoStr)) {
- layerApply.setDownNode(pointNoMapping.get(downNoStr));
- }
- //遍历属性模版
- List<GisSurveyPropertyValueThirdCopy> propertyValueList = new ArrayList<>();
- for (GisMetadataPropertyTemplate propertyTemplate : layerTemplate.getPropertyTemplates()) {
- //解析属性
- GisSurveyPropertyValueThirdCopy propertyValue = decodeDataToPropertyValue(line, layerApply, propertyTemplate, params);
- if (propertyValue != null) propertyValueList.add(propertyValue);
- }
- layerApply.setPropertyValues(propertyValueList);
- return layerApply;
- }
- /**
- * 解码数据到属性值对象
- *
- * @param data 数据
- * @param layerApply 采集元素
- * @param propertyTemplate 属性模版
- * @param params 导出参数
- * @return 属性值对象
- */
- private GisSurveyPropertyValueThirdCopy decodeDataToPropertyValue(Map<String, String> data, GisSurveyLayerApplyThirdCopy layerApply
- , GisMetadataPropertyTemplate propertyTemplate, GisSurveyThirdImportParams params) {
- //点号直接返回点号属性
- if (Objects.equals(GisSurveyExcelDefine.TEMPLATE.CODE, propertyTemplate.getKey()))
- return new GisSurveyPropertyValueThirdCopy(params.getJobId(), layerApply.getCode()
- , propertyTemplate.getKey(), layerApply.getCode());
- if (Objects.equals(GisSurveyExcelDefine.TEMPLATE.UP_NODE, propertyTemplate.getKey()))
- return new GisSurveyPropertyValueThirdCopy(params.getJobId(), layerApply.getCode()
- , propertyTemplate.getKey(), layerApply.getUpNode());
- if (Objects.equals(GisSurveyExcelDefine.TEMPLATE.DOWN_NODE, propertyTemplate.getKey()))
- return new GisSurveyPropertyValueThirdCopy(params.getJobId(), layerApply.getCode()
- , propertyTemplate.getKey(), layerApply.getDownNode());
- //获取表头
- String templateName = propertyTemplate.getName();
- //获取值
- String value = data.get(templateName);
- //构建dto
- if (StringUtils.isNotBlank(value)) {
- //double按数字处理,否则按字符串处理
- if (propertyTemplate.getType().equals(GisSurveyExcelDefine.DATA_TYPE.DOUBLE)
- && propertyTemplate.getPrecisions() != null) {
- //如能被解析,则处理精度,否则设置为0
- if (NumberUtils.isParsable(value)) {
- //值按精度设置小数位,并抹去0
- value = new BigDecimal(value)
- .setScale(propertyTemplate.getPrecisions(), RoundingMode.DOWN)
- .stripTrailingZeros()
- .toPlainString();
- } else value = "0";
- } else {
- //值长度64截断
- value = StringUtils.substring(value, 0, 64);
- }
- return new GisSurveyPropertyValueThirdCopy(params.getJobId()
- , layerApply.getCode(), propertyTemplate.getKey(), value);
- }
- return null;
- }
- /**
- * 重置点号
- *
- * @param jobId 任务id
- * @param layerApplyList 采集元素集合
- */
- private void resetNo(String jobId, List<GisSurveyLayerApplyThirdCopy> layerApplyList) {
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始重置点号 ======>");
- long begin = System.currentTimeMillis();
- //点号规则
- final List<RuleFormatSetting> ruleFormat = jobInfoService.findRuleFormat(jobId);
- //点号映射
- Map<String, String> noMapping = new ConcurrentHashMap<>();
- //并行遍历元素,处理点的点号
- layerApplyList.parallelStream()
- .filter(la -> Objects.equals(la.getKind(), GisMetadataDefine.TYPE_KINE.POINT))
- .forEach(la -> {
- //生成点号
- String no = SurveyCommonAssistant.genNo(
- la.getCode(),
- la.getPropertyValues().stream()
- .map(pv -> new JPSurveyApplyColumn(pv.getProperty(), pv.getValue()))
- .collect(Collectors.toList()),
- ruleFormat
- );
- //设置元素点号
- la.setNo(no);
- //设置属性点号
- la.getPropertyValues().stream()
- .filter(it -> Objects.equals(it.getProperty(), GisSurveyExcelDefine.TEMPLATE.NO))
- .forEach(it -> it.setValue(no));
- //设置点号映射
- noMapping.put(la.getCode(), no);
- });
- //处理线的上下点号
- layerApplyList.parallelStream()
- .filter(la -> Objects.equals(la.getKind(), GisMetadataDefine.TYPE_KINE.LINE))
- .forEach(la -> {
- //处理上点号
- if (noMapping.containsKey(la.getUpNode())) {
- //设置属性点号
- la.getPropertyValues().stream()
- .filter(it -> Objects.equals(it.getProperty(), GisSurveyExcelDefine.TEMPLATE.UP_NO))
- .forEach(it -> it.setValue(noMapping.get(la.getUpNode())));
- }
- //处理下点号
- if (noMapping.containsKey(la.getDownNode())) {
- //设置属性点号
- la.getPropertyValues().stream()
- .filter(it -> Objects.equals(it.getProperty(), GisSurveyExcelDefine.TEMPLATE.DOWN_NO))
- .forEach(it -> it.setValue(noMapping.get(la.getDownNode())));
- }
- });
- long end = System.currentTimeMillis();
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
- , String.format(
- "结束执行执行重置点号,用时(毫秒):%d"
- , (end - begin)
- )
- );
- }
- }
|