package com.shkpr.service.alambizplugin.components; import com.global.base.log.LogLevelFlag; import com.global.base.log.LogPrintMgr; import com.shkpr.service.alambizplugin.apiparam.GisSurveyCheckParams; import com.shkpr.service.alambizplugin.components.checker.DuplicatePointsFinder; import com.shkpr.service.alambizplugin.components.checker.IsolatedLinesFinder; import com.shkpr.service.alambizplugin.components.checker.IsolatedPointsFinder; import com.shkpr.service.alambizplugin.components.checker.OverlapLinesFinder; import com.shkpr.service.alambizplugin.constants.GisSurveyCheckStatusEnum; import com.shkpr.service.alambizplugin.constants.GisSurveyCheckTypeEnum; import com.shkpr.service.alambizplugin.constants.LogFlagBusiType; import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyLayerApplyService; import com.shkpr.service.alambizplugin.dbdao.services.intef.TypeDefineService; import com.shkpr.service.alambizplugin.dto.GisSurveyCheckResult; import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine; import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyPoint; import com.shkpr.service.alambizplugin.dto.TypeDefine; 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.time.Duration; import java.time.LocalDateTime; import java.util.List; import java.util.Objects; import java.util.concurrent.ExecutionException; /** * 系统检查执行器 * * @author 欧阳劲驰 * @since 1.0.0 */ @Component public class GisSurveySystemChecker { /** * log */ private final String mStrClassName; private final String mBizType; private final GisSurveyLayerApplyService gisSurveyLayerApplyService; private final TypeDefineService typeDefineService; private final IsolatedPointsFinder isolatedPointsFinder; private final IsolatedLinesFinder isolatedLinesFinder; private final DuplicatePointsFinder duplicatePointsFinder; private final OverlapLinesFinder overlapLinesFinder; public GisSurveySystemChecker(GisSurveyLayerApplyService gisSurveyLayerApplyService, TypeDefineService typeDefineService, IsolatedPointsFinder isolatedPointsFinder, IsolatedLinesFinder isolatedLinesFinder, DuplicatePointsFinder duplicatePointsFinder, OverlapLinesFinder overlapLinesFinder) { mStrClassName = "GisSurveySystemChecker"; mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue(); this.gisSurveyLayerApplyService = gisSurveyLayerApplyService; this.typeDefineService = typeDefineService; this.isolatedPointsFinder = isolatedPointsFinder; this.isolatedLinesFinder = isolatedLinesFinder; this.duplicatePointsFinder = duplicatePointsFinder; this.overlapLinesFinder = overlapLinesFinder; } /** * 系统检查任务 * * @param params 系统检查参数 * @return 系统检查返回 */ @Async public ListenableFuture systemCheckTask(GisSurveyCheckParams params) { //项目id String projId = params.getProjId(); //任务id String jobId = params.getJobId(); //检查类型 Integer checkType = params.getCheckType(); //构建返回 GisSurveyCheckResult result = GisSurveyCheckResult.fail(); //孤立点任务 ListenableFuture> isolatedPointsFuture = null; //孤立线任务 ListenableFuture>> IsolatedLinesFuture = null; //重复点任务 ListenableFuture>> duplicatePointsFuture = null; //重叠线任务 ListenableFuture>> overlapLinesFuture = null; //点集合 List points = null; //线集合 List lines = null; try { LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName , String.format( "开始执行系统检查;检查类型 检查类型:%s 项目ID:%s 任务ID:%s" , checkType , projId , jobId ) ); //根据项目查询点线信息 if (Objects.equals(checkType, GisSurveyCheckTypeEnum.PROJECT.getCode())) { points = gisSurveyLayerApplyService.findAddPointByProjId(projId); lines = gisSurveyLayerApplyService.findAddLineByProjId(projId); } //根据任务查询点线信息 else if (Objects.equals(checkType, GisSurveyCheckTypeEnum.JOB.getCode())) { points = gisSurveyLayerApplyService.findAddPointByJobId(jobId); lines = gisSurveyLayerApplyService.findAddLineByJobId(jobId); } //查询经纬度类型定义 List typeDefines = typeDefineService.findLatLng(); //孤立点检查 if (points != null && lines != null) { isolatedPointsFuture = isolatedPointsFinder.findIsolatedPoints(points, lines); } //重复点检查 if (points != null) { duplicatePointsFuture = duplicatePointsFinder.findDuplicatePoints(points, typeDefines); } //孤立线和重叠线检查 if (lines != null) { IsolatedLinesFuture = isolatedLinesFinder.findIsolatedLines(lines); overlapLinesFuture = overlapLinesFinder.findDuplicateLines(lines); } //等待结果,并存入返回,优先监听点相关(执行速度快且只需要点集合,优先释放点集合内存) if (isolatedPointsFuture != null) { //监听孤立点 final List isolatedPoints = isolatedPointsFuture.get(); result.setIsolatedPoints(isolatedPoints); //释放点缓存(孤立点和重复点都完成时,后续不需要点数据,释放缓存节省内存) if (duplicatePointsFuture != null && duplicatePointsFuture.isDone()) points.clear(); } if (duplicatePointsFuture != null) { //监听重复点 final List> duplicatePointCodes = duplicatePointsFuture.get(); result.setDuplicatePoints(duplicatePointCodes); //释放点缓存(孤立点和重复点都完成时,后续不需要点数据,释放缓存节省内存) if (isolatedPointsFuture != null && isolatedPointsFuture.isDone()) points.clear(); } if (IsolatedLinesFuture != null) { //监听重复线 final List> isolatedLines = IsolatedLinesFuture.get(); result.setIsolatedLines(isolatedLines); } if (overlapLinesFuture != null) { //监听重叠线 final List> overlapLines = overlapLinesFuture.get(); result.setOverlapLines(overlapLines); } //完成检查 result.setCompleteTime(LocalDateTime.now()); result.setCheckStatus(GisSurveyCheckStatusEnum.SUCCESS.getCode()); LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName , String.format( "结束执行系统检查;检查类型: %d,项目ID:%s, 任务ID:,%s,用时(毫秒):%d", checkType, projId, jobId, Duration.between(result.getRequestTime(), result.getCompleteTime()).toMillis() ) ); return new AsyncResult<>(result); } catch (InterruptedException | ExecutionException e) { LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName , String.format( "监测到中断或执行异常,开始清除子任务 检查类型:%d,项目ID:%s, 任务ID:,%s,", checkType, projId, jobId ) ); //清除子任务 if (isolatedPointsFuture != null) isolatedPointsFuture.cancel(true); if (IsolatedLinesFuture != null) IsolatedLinesFuture.cancel(true); if (duplicatePointsFuture != null) duplicatePointsFuture.cancel(true); if (overlapLinesFuture != null) overlapLinesFuture.cancel(true); //失败信息 result.setCheckStatus(GisSurveyCheckStatusEnum.FAIL.getCode()); result.setCompleteTime(LocalDateTime.now()); return new AsyncResult<>(result); } } }