package com.shkpr.service.alambizplugin.components.checker; import com.global.base.log.LogLevelFlag; import com.global.base.log.LogPrintMgr; import com.shkpr.service.alambizplugin.commtools.BeanUtil; import com.shkpr.service.alambizplugin.components.AsyncResultManager; import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckKeys; import com.shkpr.service.alambizplugin.constants.GisSurveySystemCheckResultHead; import com.shkpr.service.alambizplugin.constants.LogFlagBusiType; import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine; import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckElement; import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckId; import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckResultDetail; import com.shkpr.service.alambizplugin.exception.UncheckedInterruptedException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; 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.nio.file.Path; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 高程差寻找器 * * @author 欧阳劲驰 * @since 1.0.0 */ @Component public class ElevationDiffFinder { /** * log */ private final String mStrClassName; private final String mBizType; private final AsyncResultManager asyncResultManager; public ElevationDiffFinder(AsyncResultManager asyncResultManager) { mStrClassName = "ElevationDiffFinder"; mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue(); this.asyncResultManager = asyncResultManager; } /** * 寻找高程差异常 *

根据高程差和勘测长度判断,不涉及拓扑点

异常规则:高程差大于勘测长度

* * @param lines 线集合 * @param systemCheckId 系统检查id * @return 高程差异常集合 */ @Async public ListenableFuture findElevationDiff(List lines , GisSurveySystemCheckId systemCheckId) throws InterruptedException { try { LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行寻找高程差异常========>"); long begin = System.currentTimeMillis(); //并行流寻找高度差异常 List elements = lines.parallelStream() //响应中断 .peek(line -> { if (Thread.currentThread().isInterrupted()) throw new UncheckedInterruptedException(new InterruptedException()); }) .filter(line -> { //勘测长度字符串判断 if (StringUtils.isBlank(line.getSurveyLength()) && NumberUtils.isParsable(line.getSurveyLength())) return false; try { //判断高程差是否大于勘测长度 return line.getElevationDiff() > Double.parseDouble(line.getSurveyLength()); } catch (NumberFormatException numberFormatException) { return false; } }) .map(line -> BeanUtil.copy(line, GisSurveySystemCheckElement.class)) .collect(Collectors.toList()); return new AsyncResult<>(createResult(elements, systemCheckId, begin)); } catch (UncheckedInterruptedException e) { throw e.getCause(); } } /** * 创建结果 * * @param data 数据 * @param systemCheckId 系统检查id * @param begin 开始时间 * @return 结果 */ private GisSurveySystemCheckResultDetail createResult(List data , GisSurveySystemCheckId systemCheckId, long begin) { //数据大小 final int size = data.size(); //结果flag final String FLAG = systemCheckId.getFlag(); //写入json和excel结果 Path jsonPath = asyncResultManager.writeJson(data, FLAG, GisSurveySystemCheckKeys.ELEVATION_DIFF + ".json"); Path excelPath = asyncResultManager.writeExcel(GisSurveySystemCheckResultHead.ELEVATION_DIFF, buildExcel(data), FLAG, GisSurveySystemCheckKeys.ELEVATION_DIFF + ".xlsx"); long end = System.currentTimeMillis(); LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName , String.format( "结束执行寻找孤立点,用时(毫秒):%d" , (end - begin) ) ); //构建结果 return new GisSurveySystemCheckResultDetail(true , FLAG + "/" + jsonPath.getFileName() , FLAG + "/" + excelPath.getFileName() , size); } /** * 构建excel数据 * * @param data 数据 * @return excel数据 */ private List> buildExcel(List data) { return data.stream().map(element -> { Map map = new HashMap<>(); map.put(GisSurveySystemCheckResultHead.KEYS.UP_NO, element.getUpNo()); map.put(GisSurveySystemCheckResultHead.KEYS.DOWN_NO, element.getDownNo()); map.put(GisSurveySystemCheckResultHead.KEYS.CODE, element.getCode()); map.put(GisSurveySystemCheckResultHead.KEYS.UP_NODE, element.getUpNode()); map.put(GisSurveySystemCheckResultHead.KEYS.DOWN_NODE, element.getDownNode()); map.put(GisSurveySystemCheckResultHead.KEYS.NAME, element.getName()); return map; }).collect(Collectors.toList()); } }