ElevationDiffFinder.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.shkpr.service.alambizplugin.components.checker;
  2. import com.global.base.log.LogLevelFlag;
  3. import com.global.base.log.LogPrintMgr;
  4. import com.shkpr.service.alambizplugin.commtools.BeanUtil;
  5. import com.shkpr.service.alambizplugin.components.AsyncResultManager;
  6. import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckKeys;
  7. import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckResultHead;
  8. import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
  9. import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine;
  10. import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckElement;
  11. import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckId;
  12. import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckResultDetail;
  13. import com.shkpr.service.alambizplugin.exception.UncheckedInterruptedException;
  14. import org.apache.commons.lang3.StringUtils;
  15. import org.apache.commons.lang3.math.NumberUtils;
  16. import org.springframework.scheduling.annotation.Async;
  17. import org.springframework.scheduling.annotation.AsyncResult;
  18. import org.springframework.stereotype.Component;
  19. import org.springframework.util.concurrent.ListenableFuture;
  20. import java.nio.file.Path;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.stream.Collectors;
  25. /**
  26. * 高程差寻找器
  27. *
  28. * @author 欧阳劲驰
  29. * @since 1.0.0
  30. */
  31. @Component
  32. public class ElevationDiffFinder {
  33. /**
  34. * log
  35. */
  36. private final String mStrClassName;
  37. private final String mBizType;
  38. private final AsyncResultManager asyncResultManager;
  39. public ElevationDiffFinder(AsyncResultManager asyncResultManager) {
  40. mStrClassName = "ElevationDiffFinder";
  41. mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
  42. this.asyncResultManager = asyncResultManager;
  43. }
  44. /**
  45. * 寻找高程差异常
  46. * <p>根据高程差和勘测长度判断,不涉及拓扑点</p><p>异常规则:高程差大于勘测长度</p>
  47. *
  48. * @param lines 线集合
  49. * @param systemCheckId 系统检查id
  50. * @return 高程差异常集合
  51. */
  52. @Async
  53. public ListenableFuture<GisSurveySystemCheckResultDetail> findElevationDiff(List<GisSurveyLayerApplyLine> lines
  54. , GisSurveySystemCheckId systemCheckId) throws InterruptedException {
  55. try {
  56. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行寻找高程差异常========>");
  57. long begin = System.currentTimeMillis();
  58. //并行流寻找高度差异常
  59. List<GisSurveySystemCheckElement> elements = lines.parallelStream()
  60. //响应中断
  61. .peek(line -> {
  62. if (Thread.currentThread().isInterrupted())
  63. throw new UncheckedInterruptedException(new InterruptedException());
  64. })
  65. .filter(line -> {
  66. //勘测长度字符串判断
  67. if (StringUtils.isBlank(line.getSurveyLength()) && NumberUtils.isParsable(line.getSurveyLength()))
  68. return false;
  69. try {
  70. //判断高程差是否大于勘测长度
  71. return line.getElevationDiff() > Double.parseDouble(line.getSurveyLength());
  72. } catch (NumberFormatException numberFormatException) {
  73. return false;
  74. }
  75. })
  76. .map(line -> BeanUtil.copy(line, GisSurveySystemCheckElement.class))
  77. .collect(Collectors.toList());
  78. return new AsyncResult<>(createResult(elements, systemCheckId, begin));
  79. } catch (UncheckedInterruptedException e) {
  80. throw e.getCause();
  81. }
  82. }
  83. /**
  84. * 创建结果
  85. *
  86. * @param data 数据
  87. * @param systemCheckId 系统检查id
  88. * @param begin 开始时间
  89. * @return 结果
  90. */
  91. private GisSurveySystemCheckResultDetail createResult(List<GisSurveySystemCheckElement> data
  92. , GisSurveySystemCheckId systemCheckId, long begin) {
  93. //数据大小
  94. final int size = data.size();
  95. //结果flag
  96. final String FLAG = systemCheckId.getFlag();
  97. //写入json和excel结果
  98. Path jsonPath = asyncResultManager.writeJson(data, FLAG, GisSurveySystemCheckKeys.ELEVATION_DIFF + ".json");
  99. Path excelPath = asyncResultManager.writeExcel(GisSurveySystemCheckResultHead.ELEVATION_DIFF,
  100. buildExcel(data), FLAG, GisSurveySystemCheckKeys.ELEVATION_DIFF + ".xlsx");
  101. long end = System.currentTimeMillis();
  102. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
  103. , String.format(
  104. "结束执行寻找孤立点,用时(毫秒):%d"
  105. , (end - begin)
  106. )
  107. );
  108. //构建结果
  109. return new GisSurveySystemCheckResultDetail(true
  110. , FLAG + "/" + jsonPath.getFileName()
  111. , FLAG + "/" + excelPath.getFileName()
  112. , size);
  113. }
  114. /**
  115. * 构建excel数据
  116. *
  117. * @param data 数据
  118. * @return excel数据
  119. */
  120. private List<Map<String, Object>> buildExcel(List<GisSurveySystemCheckElement> data) {
  121. return data.stream().map(element -> {
  122. Map<String, Object> map = new HashMap<>();
  123. map.put(GisSurveySystemCheckResultHead.KEYS.UP_NO, element.getUpNo());
  124. map.put(GisSurveySystemCheckResultHead.KEYS.DOWN_NO, element.getDownNo());
  125. map.put(GisSurveySystemCheckResultHead.KEYS.CODE, element.getCode());
  126. map.put(GisSurveySystemCheckResultHead.KEYS.UP_NODE, element.getUpNode());
  127. map.put(GisSurveySystemCheckResultHead.KEYS.DOWN_NODE, element.getDownNode());
  128. map.put(GisSurveySystemCheckResultHead.KEYS.NAME, element.getName());
  129. return map;
  130. }).collect(Collectors.toList());
  131. }
  132. }