GisSurveySystemChecker.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.GisSurveyCheckParams;
  5. import com.shkpr.service.alambizplugin.components.checker.DuplicatePointsFinder;
  6. import com.shkpr.service.alambizplugin.components.checker.IsolatedLinesFinder;
  7. import com.shkpr.service.alambizplugin.components.checker.IsolatedPointsFinder;
  8. import com.shkpr.service.alambizplugin.components.checker.OverlapLinesFinder;
  9. import com.shkpr.service.alambizplugin.constants.GisSurveyCheckStatusEnum;
  10. import com.shkpr.service.alambizplugin.constants.GisSurveyCheckTypeEnum;
  11. import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
  12. import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyLayerApplyService;
  13. import com.shkpr.service.alambizplugin.dbdao.services.intef.TypeDefineService;
  14. import com.shkpr.service.alambizplugin.dto.GisSurveyCheckResult;
  15. import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine;
  16. import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyPoint;
  17. import com.shkpr.service.alambizplugin.dto.TypeDefine;
  18. import org.springframework.scheduling.annotation.Async;
  19. import org.springframework.scheduling.annotation.AsyncResult;
  20. import org.springframework.stereotype.Component;
  21. import org.springframework.util.concurrent.ListenableFuture;
  22. import java.time.Duration;
  23. import java.time.LocalDateTime;
  24. import java.util.List;
  25. import java.util.Objects;
  26. import java.util.concurrent.ExecutionException;
  27. /**
  28. * 系统检查执行器
  29. *
  30. * @author 欧阳劲驰
  31. * @since 1.0.0
  32. */
  33. @Component
  34. public class GisSurveySystemChecker {
  35. /**
  36. * log
  37. */
  38. private final String mStrClassName;
  39. private final String mBizType;
  40. private final GisSurveyLayerApplyService gisSurveyLayerApplyService;
  41. private final TypeDefineService typeDefineService;
  42. private final IsolatedPointsFinder isolatedPointsFinder;
  43. private final IsolatedLinesFinder isolatedLinesFinder;
  44. private final DuplicatePointsFinder duplicatePointsFinder;
  45. private final OverlapLinesFinder overlapLinesFinder;
  46. public GisSurveySystemChecker(GisSurveyLayerApplyService gisSurveyLayerApplyService, TypeDefineService typeDefineService, IsolatedPointsFinder isolatedPointsFinder, IsolatedLinesFinder isolatedLinesFinder, DuplicatePointsFinder duplicatePointsFinder, OverlapLinesFinder overlapLinesFinder) {
  47. mStrClassName = "GisSurveySystemChecker";
  48. mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
  49. this.gisSurveyLayerApplyService = gisSurveyLayerApplyService;
  50. this.typeDefineService = typeDefineService;
  51. this.isolatedPointsFinder = isolatedPointsFinder;
  52. this.isolatedLinesFinder = isolatedLinesFinder;
  53. this.duplicatePointsFinder = duplicatePointsFinder;
  54. this.overlapLinesFinder = overlapLinesFinder;
  55. }
  56. /**
  57. * 系统检查任务
  58. *
  59. * @param params 系统检查参数
  60. * @return 系统检查返回
  61. */
  62. @Async
  63. public ListenableFuture<GisSurveyCheckResult> systemCheckTask(GisSurveyCheckParams params) {
  64. //项目id
  65. String projId = params.getProjId();
  66. //任务id
  67. String jobId = params.getJobId();
  68. //检查类型
  69. Integer checkType = params.getCheckType();
  70. //构建返回
  71. GisSurveyCheckResult result = GisSurveyCheckResult.fail();
  72. //孤立点任务
  73. ListenableFuture<List<String>> isolatedPointsFuture = null;
  74. //孤立线任务
  75. ListenableFuture<List<List<String>>> IsolatedLinesFuture = null;
  76. //重复点任务
  77. ListenableFuture<List<List<String>>> duplicatePointsFuture = null;
  78. //重叠线任务
  79. ListenableFuture<List<List<String>>> overlapLinesFuture = null;
  80. //点集合
  81. List<GisSurveyLayerApplyPoint> points = null;
  82. //线集合
  83. List<GisSurveyLayerApplyLine> lines = null;
  84. try {
  85. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
  86. , String.format(
  87. "开始执行系统检查;检查类型 检查类型:%s 项目ID:%s 任务ID:%s"
  88. , checkType
  89. , projId
  90. , jobId
  91. )
  92. );
  93. //根据项目查询点线信息
  94. if (Objects.equals(checkType, GisSurveyCheckTypeEnum.PROJECT.getCode())) {
  95. points = gisSurveyLayerApplyService.findAddPointByProjId(projId);
  96. lines = gisSurveyLayerApplyService.findAddLineByProjId(projId);
  97. }
  98. //根据任务查询点线信息
  99. else if (Objects.equals(checkType, GisSurveyCheckTypeEnum.JOB.getCode())) {
  100. points = gisSurveyLayerApplyService.findAddPointByJobId(jobId);
  101. lines = gisSurveyLayerApplyService.findAddLineByJobId(jobId);
  102. }
  103. //查询经纬度类型定义
  104. List<TypeDefine> typeDefines = typeDefineService.findLatLng();
  105. //孤立点检查
  106. if (points != null && lines != null) {
  107. isolatedPointsFuture = isolatedPointsFinder.findIsolatedPoints(points, lines);
  108. }
  109. //重复点检查
  110. if (points != null) {
  111. duplicatePointsFuture = duplicatePointsFinder.findDuplicatePoints(points, typeDefines);
  112. }
  113. //孤立线和重叠线检查
  114. if (lines != null) {
  115. IsolatedLinesFuture = isolatedLinesFinder.findIsolatedLines(lines);
  116. overlapLinesFuture = overlapLinesFinder.findDuplicateLines(lines);
  117. }
  118. //等待结果,并存入返回,优先监听点相关(执行速度快且只需要点集合,优先释放点集合内存)
  119. if (isolatedPointsFuture != null) {
  120. //监听孤立点
  121. final List<String> isolatedPoints = isolatedPointsFuture.get();
  122. result.setIsolatedPoints(isolatedPoints);
  123. //释放点缓存(孤立点和重复点都完成时,后续不需要点数据,释放缓存节省内存)
  124. if (duplicatePointsFuture != null && duplicatePointsFuture.isDone()) points.clear();
  125. }
  126. if (duplicatePointsFuture != null) {
  127. //监听重复点
  128. final List<List<String>> duplicatePointCodes = duplicatePointsFuture.get();
  129. result.setDuplicatePoints(duplicatePointCodes);
  130. //释放点缓存(孤立点和重复点都完成时,后续不需要点数据,释放缓存节省内存)
  131. if (isolatedPointsFuture != null && isolatedPointsFuture.isDone()) points.clear();
  132. }
  133. if (IsolatedLinesFuture != null) {
  134. //监听重复线
  135. final List<List<String>> isolatedLines = IsolatedLinesFuture.get();
  136. result.setIsolatedLines(isolatedLines);
  137. }
  138. if (overlapLinesFuture != null) {
  139. //监听重叠线
  140. final List<List<String>> overlapLines = overlapLinesFuture.get();
  141. result.setOverlapLines(overlapLines);
  142. }
  143. //完成检查
  144. result.setCompleteTime(LocalDateTime.now());
  145. result.setCheckStatus(GisSurveyCheckStatusEnum.SUCCESS.getCode());
  146. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
  147. , String.format(
  148. "结束执行系统检查;检查类型: %d,项目ID:%s, 任务ID:,%s,用时(毫秒):%d",
  149. checkType,
  150. projId,
  151. jobId,
  152. Duration.between(result.getRequestTime(), result.getCompleteTime()).toMillis()
  153. )
  154. );
  155. return new AsyncResult<>(result);
  156. } catch (InterruptedException | ExecutionException e) {
  157. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
  158. , String.format(
  159. "监测到中断或执行异常,开始清除子任务 检查类型:%d,项目ID:%s, 任务ID:,%s,",
  160. checkType,
  161. projId,
  162. jobId
  163. )
  164. );
  165. //清除子任务
  166. if (isolatedPointsFuture != null) isolatedPointsFuture.cancel(true);
  167. if (IsolatedLinesFuture != null) IsolatedLinesFuture.cancel(true);
  168. if (duplicatePointsFuture != null) duplicatePointsFuture.cancel(true);
  169. if (overlapLinesFuture != null) overlapLinesFuture.cancel(true);
  170. //失败信息
  171. result.setCheckStatus(GisSurveyCheckStatusEnum.FAIL.getCode());
  172. result.setCompleteTime(LocalDateTime.now());
  173. return new AsyncResult<>(result);
  174. }
  175. }
  176. }