GisSurveyThirdImporter.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. package com.shkpr.service.alambizplugin.components;
  2. import com.global.base.log.LogLevelFlag;
  3. import com.global.base.log.LogPrintMgr;
  4. import com.shkpr.service.alambizplugin.apiparam.GisSurveyThirdImportParams;
  5. import com.shkpr.service.alambizplugin.commtools.ExcelUtils;
  6. import com.shkpr.service.alambizplugin.commtools.PointCodeUtil;
  7. import com.shkpr.service.alambizplugin.components.checker.DuplicatePointsFinder;
  8. import com.shkpr.service.alambizplugin.components.checker.InvalidLinesFinder;
  9. import com.shkpr.service.alambizplugin.components.checker.InvalidPropertiesFinder;
  10. import com.shkpr.service.alambizplugin.constants.ExcelEnum;
  11. import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
  12. import com.shkpr.service.alambizplugin.constants.GisSurveyCheckStatusEnum;
  13. import com.shkpr.service.alambizplugin.constants.GisSurveyImportDefine;
  14. import com.shkpr.service.alambizplugin.constants.GisSurveyImportStatusEnum;
  15. import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
  16. import com.shkpr.service.alambizplugin.dbdao.services.intef.GisMetadataLayerTemplateService;
  17. import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyLayerApplyThirdCopyService;
  18. import com.shkpr.service.alambizplugin.dto.GisMetadataLayerTemplate;
  19. import com.shkpr.service.alambizplugin.dto.GisMetadataPropertyTemplate;
  20. import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyThirdCopy;
  21. import com.shkpr.service.alambizplugin.dto.GisSurveyPropertyValueThirdCopy;
  22. import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportElement;
  23. import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportResult;
  24. import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportResultDetail;
  25. import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportSubtask;
  26. import org.apache.commons.collections4.CollectionUtils;
  27. import org.apache.commons.lang3.StringUtils;
  28. import org.apache.commons.lang3.math.NumberUtils;
  29. import org.springframework.scheduling.annotation.Async;
  30. import org.springframework.scheduling.annotation.AsyncResult;
  31. import org.springframework.stereotype.Component;
  32. import org.springframework.util.concurrent.ListenableFuture;
  33. import java.io.IOException;
  34. import java.io.InputStream;
  35. import java.time.Duration;
  36. import java.time.LocalDateTime;
  37. import java.util.ArrayList;
  38. import java.util.Arrays;
  39. import java.util.HashMap;
  40. import java.util.List;
  41. import java.util.Map;
  42. import java.util.Objects;
  43. import java.util.concurrent.ExecutionException;
  44. import java.util.function.Consumer;
  45. import java.util.stream.Collectors;
  46. /**
  47. * 第三方导入执行器
  48. *
  49. * @author 欧阳劲驰
  50. * @since 1.0.0
  51. */
  52. @Component
  53. public class GisSurveyThirdImporter {
  54. /**
  55. * log
  56. */
  57. private final String mStrClassName;
  58. private final String mBizType;
  59. private final GisMetadataLayerTemplateService layerTemplateService;
  60. private final GisSurveyLayerApplyThirdCopyService gisSurveyLayerApplyThirdCopyService;
  61. private final DuplicatePointsFinder duplicatePointsFinder;
  62. private final InvalidLinesFinder invalidLinesFinder;
  63. private final InvalidPropertiesFinder invalidPropertiesFinder;
  64. public GisSurveyThirdImporter(GisMetadataLayerTemplateService layerTemplateService, GisSurveyLayerApplyThirdCopyService gisSurveyLayerApplyThirdCopyService
  65. , DuplicatePointsFinder duplicatePointsFinder, InvalidLinesFinder invalidLinesFinder, InvalidPropertiesFinder invalidPropertiesFinder) {
  66. mStrClassName = "GisSurveyThirdImporter";
  67. mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
  68. this.layerTemplateService = layerTemplateService;
  69. this.gisSurveyLayerApplyThirdCopyService = gisSurveyLayerApplyThirdCopyService;
  70. this.duplicatePointsFinder = duplicatePointsFinder;
  71. this.invalidLinesFinder = invalidLinesFinder;
  72. this.invalidPropertiesFinder = invalidPropertiesFinder;
  73. }
  74. /**
  75. * 第三方导入任务
  76. *
  77. * @param params 系统检查参数
  78. * @param inputStreams 文件输入流
  79. * @param onStartSubtask 启动子任务
  80. * @param onDeprecatedSubtask 弃用子任务(完成数据收集/取消)
  81. * @return 系统检查返回
  82. */
  83. @Async
  84. public ListenableFuture<GisSurveyThirdImportResult> thirdImportTask(GisSurveyThirdImportParams params, List<InputStream> inputStreams
  85. , Consumer<GisSurveyThirdImportSubtask> onStartSubtask, Consumer<String> onDeprecatedSubtask) {
  86. //构建返回
  87. GisSurveyThirdImportResult result = GisSurveyThirdImportResult.fail(params);
  88. //无效属性任务
  89. ListenableFuture<GisSurveyThirdImportResultDetail<Map<String, List<GisSurveyThirdImportElement>>>> invalidPropertiesFuture = null;
  90. //重复点号任务
  91. ListenableFuture<GisSurveyThirdImportResultDetail<List<GisSurveyThirdImportElement>>> duplicatePointsFuture = null;
  92. //无效线任务
  93. ListenableFuture<GisSurveyThirdImportResultDetail<List<GisSurveyThirdImportElement>>> invalidLinesFuture = null;
  94. //点集合
  95. List<Map<String, String>> points = new ArrayList<>();
  96. //线集合
  97. List<Map<String, String>> lines = new ArrayList<>();
  98. try {
  99. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
  100. , String.format(
  101. "开始执行第三方导入;任务id: %s"
  102. , params.getJobId()
  103. )
  104. );
  105. //解析excel
  106. parseExcel(inputStreams, points, lines);
  107. //提取图层名
  108. List<String> pointLayerNames = getLayerNames(points, GisSurveyImportDefine.POINT.LAYER);
  109. List<String> lineLayerNames = getLayerNames(lines, GisSurveyImportDefine.LINE.LAYER);
  110. //图层模版
  111. List<GisMetadataLayerTemplate> pointLayerTemplates = layerTemplateService.findByNatureAndNameIn(params.getNature(), pointLayerNames);
  112. List<GisMetadataLayerTemplate> lineLayerTemplates = layerTemplateService.findByNatureAndNameIn(params.getNature(), lineLayerNames);
  113. //无效属性检查
  114. invalidPropertiesFuture = invalidPropertiesFinder.findInvalidProperties(points, lines, pointLayerTemplates, lineLayerTemplates);
  115. //重复点检查
  116. duplicatePointsFuture = duplicatePointsFinder.findDuplicatePoints(points);
  117. //无效线检查
  118. invalidLinesFuture = invalidLinesFinder.finderInvalidLines(points, lines);
  119. //返回子任务
  120. onStartSubtask.accept(
  121. new GisSurveyThirdImportSubtask(invalidPropertiesFuture, duplicatePointsFuture, invalidLinesFuture)
  122. );
  123. //等待结果
  124. GisSurveyThirdImportResultDetail<Map<String, List<GisSurveyThirdImportElement>>> invalidPropertiesResult = invalidPropertiesFuture.get();
  125. //存入无效属性结果
  126. result.setInvalidLayersResult(untarInvalidProperties(invalidPropertiesResult, GisSurveyImportDefine.RESULT.INVALID_LAYERS));
  127. result.setMissingRequirementsResult(untarInvalidProperties(invalidPropertiesResult, GisSurveyImportDefine.RESULT.MISSING_REQUIREMENTS));
  128. result.setInvalidTypesResult(untarInvalidProperties(invalidPropertiesResult, GisSurveyImportDefine.RESULT.INVALID_TYPES));
  129. result.setOutRangesResult(untarInvalidProperties(invalidPropertiesResult, GisSurveyImportDefine.RESULT.OUT_RANGES));
  130. //存入重复点结果
  131. result.setDuplicatePointsResult(duplicatePointsFuture.get());
  132. //存入无效线结果
  133. result.setInvalidLinesResult(invalidLinesFuture.get());
  134. //结果未通过
  135. if (!checkResult(result)) {
  136. result.setImportStatus(GisSurveyImportStatusEnum.DATA_ERROR.getCode());
  137. result.setCompleteTime(LocalDateTime.now());
  138. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
  139. , String.format(
  140. "第三方导入结果未通过;任务id: %s, 用时(毫秒):%d",
  141. params.getJobId(),
  142. Duration.between(result.getRequestTime(), result.getCompleteTime()).toMillis()
  143. )
  144. );
  145. //弃用子任务
  146. onDeprecatedSubtask.accept(params.getJobId());
  147. return new AsyncResult<>(result);
  148. }
  149. //解码点线数据
  150. List<GisSurveyLayerApplyThirdCopy> layerApplyList = decodeDataToLayerApply(points, lines, pointLayerTemplates, lineLayerTemplates, params);
  151. //批量写入
  152. Boolean saved = gisSurveyLayerApplyThirdCopyService.saveAll(params.getJobId(), layerApplyList);
  153. if (!saved) {
  154. result.setCompleteTime(LocalDateTime.now());
  155. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
  156. , String.format(
  157. "第三方导入入库失败;任务id: %s, 用时(毫秒):%d",
  158. params.getJobId(),
  159. Duration.between(result.getRequestTime(), LocalDateTime.now()).toMillis()
  160. )
  161. );
  162. //弃用子任务
  163. onDeprecatedSubtask.accept(params.getJobId());
  164. return new AsyncResult<>(result);
  165. }
  166. //完成任务
  167. result.setImportStatus(GisSurveyImportStatusEnum.SUCCESS.getCode());
  168. result.setCompleteTime(LocalDateTime.now());
  169. result.setPreviewData(layerApplyList);
  170. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
  171. , String.format(
  172. "结束执行第三方导入;任务id: %s, 用时(毫秒):%d",
  173. params.getJobId(),
  174. Duration.between(result.getRequestTime(), result.getCompleteTime()).toMillis()
  175. )
  176. );
  177. //弃用子任务
  178. onDeprecatedSubtask.accept(params.getJobId());
  179. return new AsyncResult<>(result);
  180. } catch (InterruptedException | ExecutionException | IOException | RuntimeException e) {
  181. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
  182. , String.format(
  183. "监测到中断或执行异常,开始清除子任务 任务id:%s error:%s",
  184. params.getJobId(),
  185. e
  186. )
  187. );
  188. //清除子任务
  189. if (invalidPropertiesFuture != null) invalidPropertiesFuture.cancel(true);
  190. if (duplicatePointsFuture != null) duplicatePointsFuture.cancel(true);
  191. if (invalidLinesFuture != null) invalidLinesFuture.cancel(true);
  192. //失败信息
  193. result.setImportStatus(GisSurveyCheckStatusEnum.FAIL.getCode());
  194. result.setCompleteTime(LocalDateTime.now());
  195. //弃用子任务
  196. onDeprecatedSubtask.accept(params.getJobId());
  197. return new AsyncResult<>(result);
  198. }
  199. }
  200. /**
  201. * 解析excel
  202. *
  203. * @param inputStreams 输入流
  204. * @param points 点集合
  205. * @param lines 线集合
  206. * @throws IOException io异常
  207. */
  208. private void parseExcel(List<InputStream> inputStreams, List<Map<String, String>> points, List<Map<String, String>> lines) throws IOException, InterruptedException {
  209. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行解析excel ======>");
  210. long begin = System.currentTimeMillis();
  211. //解析文件
  212. for (InputStream inputStream : inputStreams) {
  213. //检查线程中断,并响应
  214. if (Thread.interrupted()) throw new InterruptedException();
  215. //解析excel
  216. Map<String, List<Map<String, String>>> excelData = ExcelUtils.parseExcelFile(inputStream,
  217. ExcelEnum.XLSX, 0, 2);
  218. //填入集合
  219. if (excelData != null && excelData.containsKey(GisMetadataDefine.TYPE_KINE.POINT))
  220. points.addAll(excelData.get(GisMetadataDefine.TYPE_KINE.POINT));
  221. if (excelData != null && excelData.containsKey(GisMetadataDefine.TYPE_KINE.LINE))
  222. lines.addAll(excelData.get(GisMetadataDefine.TYPE_KINE.LINE));
  223. //释放流
  224. inputStream.close();
  225. }
  226. long end = System.currentTimeMillis();
  227. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
  228. , String.format(
  229. "结束执行执行解析excel,用时(毫秒):%d"
  230. , (end - begin)
  231. )
  232. );
  233. }
  234. /**
  235. * 获取图层名称
  236. *
  237. * @param datas 数据
  238. * @param layerKey 图层的key
  239. * @return 图层名称集合
  240. */
  241. private List<String> getLayerNames(List<Map<String, String>> datas, String layerKey) {
  242. //去重图层
  243. return datas.parallelStream()
  244. .filter(data -> data.get(layerKey) != null)
  245. .map(data -> data.get(layerKey))
  246. .distinct()
  247. .collect(Collectors.toList());
  248. }
  249. /**
  250. * 解包无效属性
  251. *
  252. * @param invalidPropertiesResult 无效属性结果
  253. * @param resultKey 结果key
  254. * @return 具体结果
  255. */
  256. private GisSurveyThirdImportResultDetail<List<GisSurveyThirdImportElement>> untarInvalidProperties(
  257. GisSurveyThirdImportResultDetail<Map<String, List<GisSurveyThirdImportElement>>> invalidPropertiesResult
  258. , String resultKey) {
  259. //获取结果
  260. List<GisSurveyThirdImportElement> importElements = invalidPropertiesResult.getResults().get(resultKey);
  261. return new GisSurveyThirdImportResultDetail<>(true, importElements);
  262. }
  263. /**
  264. * 检查结果
  265. *
  266. * @param result 结果
  267. * @return 结果通过状态
  268. */
  269. private Boolean checkResult(GisSurveyThirdImportResult result) {
  270. List<GisSurveyThirdImportElement> invalidLayers = result.getInvalidLayersResult().getResults();
  271. List<GisSurveyThirdImportElement> missingRequirements = result.getMissingRequirementsResult().getResults();
  272. List<GisSurveyThirdImportElement> invalidTypesResult = result.getInvalidTypesResult().getResults();
  273. List<GisSurveyThirdImportElement> outRanges = result.getOutRangesResult().getResults();
  274. List<GisSurveyThirdImportElement> duplicatePoints = result.getDuplicatePointsResult().getResults();
  275. List<GisSurveyThirdImportElement> invalidLines = result.getInvalidLinesResult().getResults();
  276. //检查是否都为空
  277. return CollectionUtils.isEmpty(invalidLayers) && CollectionUtils.isEmpty(missingRequirements) &&
  278. CollectionUtils.isEmpty(invalidTypesResult) && CollectionUtils.isEmpty(outRanges) &&
  279. CollectionUtils.isEmpty(duplicatePoints) && CollectionUtils.isEmpty(invalidLines);
  280. }
  281. /**
  282. * 解码数据到采集元素对象
  283. * <p>从Map转为 {@code GisSurveyLayerApplyThirdCopy}</p>
  284. *
  285. * @param points 点数据
  286. * @param lines 线数据
  287. * @param pointLayerTemplates 点图层模版
  288. * @param lineLayerTemplates 线图层模版
  289. * @param params 导入参数
  290. * @return 格式化后数据
  291. */
  292. private List<GisSurveyLayerApplyThirdCopy> decodeDataToLayerApply(List<Map<String, String>> points, List<Map<String, String>> lines
  293. , List<GisMetadataLayerTemplate> pointLayerTemplates, List<GisMetadataLayerTemplate> lineLayerTemplates, GisSurveyThirdImportParams params) {
  294. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "导入结果通过,开始解码点线数据 ======>");
  295. long begin = System.currentTimeMillis();
  296. //按模版名分组,便于快速找到模版
  297. Map<String, GisMetadataLayerTemplate> poineTemplateMap = pointLayerTemplates.stream()
  298. .collect(Collectors.toMap(
  299. GisMetadataLayerTemplate::getName, it -> it,
  300. (it1, it2) -> it1
  301. ));
  302. Map<String, GisMetadataLayerTemplate> lineTemplateMap = lineLayerTemplates.stream()
  303. .collect(Collectors.toMap(
  304. GisMetadataLayerTemplate::getName, it -> it,
  305. (it1, it2) -> it1
  306. ));
  307. //采集元素象集合
  308. List<GisSurveyLayerApplyThirdCopy> result = new ArrayList<>();
  309. //点号映射,用于线写入上下游节点
  310. Map<String, String> pointNoMapping = new HashMap<>();
  311. //格式化点
  312. for (Map<String, String> point : points) {
  313. //获取模版
  314. GisMetadataLayerTemplate layerTemplate = poineTemplateMap.get(point.get(GisSurveyImportDefine.POINT.LAYER));
  315. //解码点对象
  316. GisSurveyLayerApplyThirdCopy layerApply = decodePointToLayerApply(point, layerTemplate, params);
  317. //存入点号
  318. pointNoMapping.put(layerApply.getNo(), layerApply.getCode());
  319. result.add(layerApply);
  320. }
  321. //格式化线
  322. for (Map<String, String> line : lines) {
  323. //获取模版
  324. GisMetadataLayerTemplate layerTemplate = lineTemplateMap.get(line.get(GisSurveyImportDefine.LINE.LAYER));
  325. //解码对象
  326. GisSurveyLayerApplyThirdCopy layerApply = decodeLineToLayerApply(line, layerTemplate, params, pointNoMapping);
  327. result.add(layerApply);
  328. }
  329. long end = System.currentTimeMillis();
  330. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
  331. , String.format(
  332. "结束执行解码点线数据,用时(毫秒):%d"
  333. , (end - begin)
  334. )
  335. );
  336. return result;
  337. }
  338. /**
  339. * 解码点数据到采集元素对象
  340. *
  341. * @param point 点数据
  342. * @param layerTemplate 图层模版
  343. * @param params 导入参数
  344. * @return 采集元素拷贝对象
  345. */
  346. private GisSurveyLayerApplyThirdCopy decodePointToLayerApply(Map<String, String> point, GisMetadataLayerTemplate layerTemplate, GisSurveyThirdImportParams params) {
  347. GisSurveyLayerApplyThirdCopy layerApply = new GisSurveyLayerApplyThirdCopy();
  348. //必填项
  349. layerApply.setJobId(params.getJobId());
  350. layerApply.setCode(PointCodeUtil.generateCode());
  351. layerApply.setLayer(layerTemplate.getKey());
  352. layerApply.setKind(GisMetadataDefine.TYPE_KINE.POINT);
  353. //解析坐标
  354. double[] coordinate = {Double.parseDouble(point.get(GisSurveyImportDefine.POINT.LNG)),
  355. Double.parseDouble(point.get(GisSurveyImportDefine.POINT.LAT))};
  356. layerApply.setGis(Arrays.toString(coordinate));
  357. //默认值
  358. layerApply.setApply(GisSurveyImportDefine.DEFAULT_VALUE.APPLY);
  359. layerApply.setSource(GisSurveyImportDefine.DEFAULT_VALUE.SOURCE);
  360. //高程和埋深
  361. String elevationStr = point.get(GisSurveyImportDefine.POINT.ELEVATION);
  362. if (NumberUtils.isParsable(elevationStr))
  363. layerApply.setElevation(Double.parseDouble(elevationStr));
  364. String depthStr = point.get(GisSurveyImportDefine.POINT.DEPTH);
  365. if (NumberUtils.isParsable(depthStr))
  366. layerApply.setDepth(Double.parseDouble(depthStr));
  367. //点号(长度64截断)
  368. layerApply.setNo(StringUtils.substring(point.get(GisSurveyImportDefine.POINT.NO), 0, 64));
  369. //遍历属性模版
  370. List<GisSurveyPropertyValueThirdCopy> propertyValueList = new ArrayList<>();
  371. for (GisMetadataPropertyTemplate propertyTemplate : layerTemplate.getPropertyTemplates()) {
  372. //解析属性
  373. GisSurveyPropertyValueThirdCopy propertyValue = decodeDataToPropertyValue(point, layerApply
  374. , propertyTemplate, params, GisSurveyImportDefine.LayerType.POINT);
  375. if (propertyValue != null) propertyValueList.add(propertyValue);
  376. }
  377. layerApply.setPropertyValueList(propertyValueList);
  378. return layerApply;
  379. }
  380. /**
  381. * 解码线数据到采集元素对象
  382. *
  383. * @param line 线数据
  384. * @param layerTemplate 图层模版
  385. * @param params 导入参数
  386. * @param pointNoMapping 点号映射
  387. * @return 采集元素拷贝对象
  388. */
  389. private GisSurveyLayerApplyThirdCopy decodeLineToLayerApply(Map<String, String> line, GisMetadataLayerTemplate layerTemplate, GisSurveyThirdImportParams params, Map<String, String> pointNoMapping) {
  390. GisSurveyLayerApplyThirdCopy layerApply = new GisSurveyLayerApplyThirdCopy();
  391. //必填项
  392. layerApply.setJobId(params.getJobId());
  393. layerApply.setCode(PointCodeUtil.generateCode());
  394. layerApply.setLayer(layerTemplate.getKey());
  395. layerApply.setKind(GisMetadataDefine.TYPE_KINE.LINE);
  396. //默认值
  397. layerApply.setApply(GisSurveyImportDefine.DEFAULT_VALUE.APPLY);
  398. layerApply.setSource(GisSurveyImportDefine.DEFAULT_VALUE.SOURCE);
  399. //上下游节点
  400. layerApply.setUpNode(pointNoMapping.get(line.get(GisSurveyImportDefine.LINE.UP_NO)));
  401. layerApply.setDownNode(pointNoMapping.get(line.get(GisSurveyImportDefine.LINE.DOWN_NO)));
  402. //遍历属性模版
  403. List<GisSurveyPropertyValueThirdCopy> propertyValueList = new ArrayList<>();
  404. for (GisMetadataPropertyTemplate propertyTemplate : layerTemplate.getPropertyTemplates()) {
  405. //解析属性
  406. GisSurveyPropertyValueThirdCopy propertyValue = decodeDataToPropertyValue(line, layerApply, propertyTemplate, params, GisSurveyImportDefine.LayerType.LINE);
  407. if (propertyValue != null) propertyValueList.add(propertyValue);
  408. }
  409. layerApply.setPropertyValueList(propertyValueList);
  410. return layerApply;
  411. }
  412. /**
  413. * 解码数据到属性值对象
  414. *
  415. * @param data 数据
  416. * @param layerApply 采集元素
  417. * @param propertyTemplate 属性模版
  418. * @param params 导出参数
  419. * @param layerType 图层类型
  420. * @return 属性值对象
  421. */
  422. private GisSurveyPropertyValueThirdCopy decodeDataToPropertyValue(Map<String, String> data, GisSurveyLayerApplyThirdCopy layerApply
  423. , GisMetadataPropertyTemplate propertyTemplate, GisSurveyThirdImportParams params, GisSurveyImportDefine.LayerType layerType) {
  424. //点号直接返回点号属性
  425. if (Objects.equals(GisSurveyImportDefine.TEMPLATE.CODE, propertyTemplate.getKey()))
  426. return new GisSurveyPropertyValueThirdCopy(params.getJobId(), layerApply.getCode()
  427. , propertyTemplate.getKey(), layerApply.getCode());
  428. //根据图层类型和模版映射,获取表头
  429. String templateName = propertyTemplate.getName();
  430. if (layerType == GisSurveyImportDefine.LayerType.POINT)
  431. switch (propertyTemplate.getKey()) {
  432. case GisSurveyImportDefine.TEMPLATE.LNG:
  433. templateName = GisSurveyImportDefine.POINT.LNG;
  434. break;
  435. case GisSurveyImportDefine.TEMPLATE.LAT:
  436. templateName = GisSurveyImportDefine.POINT.LAT;
  437. break;
  438. }
  439. if (layerType == GisSurveyImportDefine.LayerType.LINE)
  440. switch (propertyTemplate.getKey()) {
  441. case GisSurveyImportDefine.TEMPLATE.UP_NODE:
  442. templateName = GisSurveyImportDefine.LINE.UP_NO;
  443. break;
  444. case GisSurveyImportDefine.TEMPLATE.DOWN_NODE:
  445. templateName = GisSurveyImportDefine.LINE.DOWN_NO;
  446. break;
  447. }
  448. //获取值
  449. String value = data.get(templateName);
  450. //构建dto,并将值长度64截断
  451. if (StringUtils.isNotBlank(value)) return new GisSurveyPropertyValueThirdCopy(params.getJobId()
  452. , layerApply.getCode(), propertyTemplate.getKey(), StringUtils.substring(value, 0, 64));
  453. return null;
  454. }
  455. }