123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- 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;
- }
- /**
- * 寻找高程差异常
- * <p>根据高程差和勘测长度判断,不涉及拓扑点</p><p>异常规则:高程差大于勘测长度</p>
- *
- * @param lines 线集合
- * @param systemCheckId 系统检查id
- * @return 高程差异常集合
- */
- @Async
- public ListenableFuture<GisSurveySystemCheckResultDetail> findElevationDiff(List<GisSurveyLayerApplyLine> lines
- , GisSurveySystemCheckId systemCheckId) throws InterruptedException {
- try {
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, "开始执行寻找高程差异常========>");
- long begin = System.currentTimeMillis();
- //并行流寻找高度差异常
- List<GisSurveySystemCheckElement> 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<GisSurveySystemCheckElement> 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<Map<String, Object>> buildExcel(List<GisSurveySystemCheckElement> data) {
- return data.stream().map(element -> {
- Map<String, Object> 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());
- }
- }
|