package com.hdkj.lt.bf.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hdkj.hussar.ApiResponse;
import com.hdkj.lt.base.constants.CommonConstant;
import com.hdkj.lt.base.constants.DictConstants;
import com.hdkj.lt.bf.entity.FhzgPlanPowerCut;
import com.hdkj.lt.bf.entity.dto.*;
import com.hdkj.lt.bf.entity.vo.*;
import com.hdkj.lt.bf.mapper.*;
import com.hdkj.lt.bf.service.*;
import com.hdkj.lt.core.bizms.modle.dto.EventQueryDTO;
import com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO;
import com.hdkj.lt.core.bizms.modle.po.FeederTopo;
import com.hdkj.lt.core.bizms.modle.po.fault.FaultDistMappingFile;
import com.hdkj.lt.core.bizms.modle.po.fault.FaultPowerCut;
import com.hdkj.lt.core.bizms.modle.po.fault.FaultTransferScheme;
import com.hdkj.lt.core.bizms.modle.po.fault.FhzgFaultSwitchInfoList;
import com.hdkj.lt.core.bizms.modle.po.operationAbnormality.FhzgGridOperationAbnormality;
import com.hdkj.lt.core.bizms.modle.po.operationAbnormality.FhzgOperationAbnormalitySwitchingSequence;
import com.hdkj.lt.core.bizms.modle.po.operationAbnormality.FhzgOperationAbnormalityTransferAreaResult;
import com.hdkj.lt.core.bizms.modle.po.operationAbnormality.FhzgOperationAbnormalityTransferScheme;
import com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanSwitchInfoList;
import com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferScheme;
import com.hdkj.lt.core.bizms.modle.po.plan.PlanDistMappingFile;
import com.hdkj.lt.core.sys.dao.FhzgOrganSuffixMapper;
import com.hdkj.lt.modle.dto.abnormal.AbnormalOperationDTO;
import com.hdkj.lt.modle.dto.abnormal.ApiAbnormalDataDTO;
import com.hdkj.lt.modle.dto.abnormal.FeederResultDTO;
import com.hdkj.lt.modle.dto.abnormal.ListFeederDTO;
import com.hdkj.lt.modle.dto.jsty.*;
import com.hdkj.lt.modle.vo.svg.DirectCurrentVO;
import io.jsonwebtoken.lang.Assert;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author: wenhao
 * @Create: 2025/07/09 19:35
 * @Version: 1.0
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ShowCartoonServiceImpl implements ShowCartoonService {

    private final FhzgPlanTransferSchemeService planTransferSchemeService; //计划停电方案

    private final FhzgPlanPowerCutService planPowerCutService; //计划停电

    private final IPlanDistMappingFileService planDistMappingFileService; //计划事件附件

    private final FhzgGenerateGraphService generateGraphService; //计划停电转供路径

    private final FhzgPlanSwitchInfoListMapper planSwitchInfoListMapper;

    private final FhzgPlanTransferSchemeSwitchingSequenceService planTransferSchemeSwitchingSequenceService; //计划停电方案开关动作顺序

    private final IFaultTransferSchemeService faultTransferSchemeService; //故障停电方案

    private final IFaultPowerCutService faultPowerCutService; //故障停电

    private final IFaultDistMappingFileService faultDistMappingFileService; //故障事件附件

    private final IFaultTransferSchemeSwitchingSequenceService faultTransferSchemeSwitchingSequenceService; //故障停电方案开关动作顺序

    private final FhzgOrganSuffixMapper fhzgOrganSuffixMapper;

    private final FhzgGenerateGraphMapper fhzgGenerateGraphMapper;

    private final FhzgFaultGenerateGraphService faultGenerateGraphService; //故障停电转供路径

    private final FhzgFaultSwitchInfoListMapper faultSwitchInfoListMapper;

    private final FhzgOperationAbnormalityService operationAbnormalityService; //运行调优

    private final FhzgOperationAbnormalityTransferSchemeService operationAbnormalityTransferSchemeService;

    private final FhzgSwitchingSequenceMapper switchingSequenceMapper; //运行调优开关动作顺序

    private final FhzgOperationAbnormalityTransferAreaResultMapper fhzgOperationAbnormalityTransferAreaResultMapper; //运行调优转供前后负载率

    private final FhzgGridOperationAbnormalityMapper gridOperationAbnormalityMapper;

    @Override
    public void generateCartoonData(Long objId, String objType) {
        if (StringUtils.equals(objType, "1")) { //计划停电
            List<FhzgPlanTransferScheme> schemeList = planTransferSchemeService.lambdaQuery().eq(FhzgPlanTransferScheme::getPlanId, objId).list();
            if (CollectionUtils.isNotEmpty(schemeList)) {
                for (FhzgPlanTransferScheme planTransferScheme : schemeList) {
                    this.planData(planTransferScheme.getId());
                }
            }
        } else if (StringUtils.equals(objType, "2")) { //故障停电
            List<FaultTransferScheme> schemeList = faultTransferSchemeService.lambdaQuery().eq(FaultTransferScheme::getFaultId, objId).list();
            if (CollectionUtils.isNotEmpty(schemeList)) {
                for (FaultTransferScheme faultTransferScheme : schemeList) {
                    this.faultData(faultTransferScheme.getId());
                }
            }
        } else { //运行调优
            List<FhzgOperationAbnormalityTransferScheme> schemeList = operationAbnormalityTransferSchemeService.lambdaQuery().eq(FhzgOperationAbnormalityTransferScheme::getOaId, objId).list();
            if (CollectionUtils.isNotEmpty(schemeList)) {
                for (FhzgOperationAbnormalityTransferScheme operationAbnormalityTransferScheme : schemeList) {
                    this.operationAbnormalityData(operationAbnormalityTransferScheme.getId());
                }
            }
        }
    }

    @Override
    public ShowCartoonDataVO getCartoonData(CartoonDataQueryDTO queryDTO) {
        if (StringUtils.equals(queryDTO.getSchemeType(), "1")) { //计划停电
            FhzgPlanTransferScheme planTransferScheme = planTransferSchemeService.getById(queryDTO.getSchemeId());
            Assert.notNull(planTransferScheme, "该方案不存在");
            if (StringUtils.isNotBlank(planTransferScheme.getCartoonDataJson())) {
                return JSON.parseObject(planTransferScheme.getCartoonDataJson(), ShowCartoonDataVO.class);
            }
        } else if (StringUtils.equals(queryDTO.getSchemeType(), "2")) { //故障停电
            FaultTransferScheme faultTransferScheme = faultTransferSchemeService.getById(queryDTO.getSchemeId());
            Assert.notNull(faultTransferScheme, "该方案不存在");
            if (StringUtils.isNotBlank(faultTransferScheme.getCartoonDataJson())) {
                return JSON.parseObject(faultTransferScheme.getCartoonDataJson(), ShowCartoonDataVO.class);
            }
        } else { //运行调优
            FhzgOperationAbnormalityTransferScheme operationAbnormalityTransferScheme = operationAbnormalityTransferSchemeService.getById(queryDTO.getSchemeId());
            Assert.notNull(operationAbnormalityTransferScheme, "该方案不存在");
            if (StringUtils.isNotBlank(operationAbnormalityTransferScheme.getCartoonDataJson())) {
                return JSON.parseObject(operationAbnormalityTransferScheme.getCartoonDataJson(), ShowCartoonDataVO.class);
            }
        }
        return ShowCartoonDataVO.builder().build();
    }

    @Override
    public List<DirectCurrentDataVO> getDirectCurrentData(DirectCurrentDTO queryDTO) {
        // 获取动态svg的朝流信息
        List<String> kgPsrTypes = Arrays.asList(DictConstants.KG_PSR_TYPE.split(","));
        List<DirectCurrentSwitchVO> directCurrents = gridOperationAbnormalityMapper.getDistDynamicSvgDirectCurrentInfo(queryDTO, kgPsrTypes);
        Map<String, List<String>> directCurrentMap = directCurrents.stream()
                .collect(Collectors.groupingBy(
                        DirectCurrentSwitchVO::getDirectCurrent,
                        Collectors.mapping(DirectCurrentSwitchVO::getPsrId, Collectors.toList())));
        List<String> forwardCurrent = Optional.ofNullable(directCurrentMap.get(CommonConstant.ZERO)).orElse(Lists.newArrayList()); // 正向开关
        List<String> reverseCurrent = Optional.ofNullable(directCurrentMap.get(CommonConstant.ONE)).orElse(Lists.newArrayList()); // 反向开关
        List<String> linkPsrIdList = directCurrents.stream().filter(e -> StringUtils.equals("-", e.getLinkId()))
                .map(DirectCurrentSwitchVO::getPsrId).collect(Collectors.toList()); // 开关分的动作临界开关

        // 当开关只有合没有开的动作时，会环流需要处理朝流信息
        List<String> filterSwitchIdList = Lists.newArrayList();
        List<String> switchIdList = forwardCurrent.stream().filter(e -> reverseCurrent.contains(e) && !linkPsrIdList.contains(e)).collect(Collectors.toList());
        if (ObjectUtils.isNotEmpty(switchIdList)) {
            // 需要找出开关的对应线路的 分动作开关当线路找不到分开关时，直接找出线开关
            List<FilterLineSwitchVO> filterLineSwitch = directCurrents.stream()
                    .filter(e -> StringUtils.isNotEmpty(e.getLinkId()))
                    .collect(Collectors.groupingBy(DirectCurrentSwitchVO::getLinkId))
                    .entrySet().stream().map(e -> {
                        List<String> startKgIdList = e.getValue().stream()
                                .filter(en -> StringUtils.equals("-", en.getLinkId()))
                                .map(DirectCurrentSwitchVO::getPsrId).collect(Collectors.toList());
                        if (ObjectUtils.isEmpty(startKgIdList)) {
                            startKgIdList.addAll(e.getValue().stream()
                                    .filter(en -> StringUtils.equals(en.getPsrId(), en.getLinkId()))
                                    .map(DirectCurrentSwitchVO::getPsrId).collect(Collectors.toList()));
                        }
                        return FilterLineSwitchVO.builder().feeder(e.getKey())
                                .switchIds(startKgIdList.stream().collect(Collectors.joining(","))).build();
                    }).collect(Collectors.toList());
            filterSwitchIdList.addAll(gridOperationAbnormalityMapper.getFilterDirectCurrentSwitchInfo(filterLineSwitch, kgPsrTypes));
        }

        // 获取朝流信息
        DynamicSvgDirectVO dynamicSvgDirect = gridOperationAbnormalityMapper.getDistLineDynamicSvgDirectCurrent(queryDTO.getObjId());
        List<DirectCurrentVO> directCurrentList = Optional.ofNullable(dynamicSvgDirect)
                .filter(e -> StringUtils.isNotEmpty(e.getClListJson()))
                .map(e -> JSON.parseArray(e.getClListJson(), DirectCurrentVO.class)).orElse(Lists.newArrayList());
        List<DirectCurrentDataVO> directCurrentDataList = directCurrentList.stream()
                .filter(en -> ListUtils.union(forwardCurrent, reverseCurrent).contains(en.getNextId()) && !filterSwitchIdList.contains(en.getNextId()))
                .map(en -> {
                    DirectCurrentDataVO directCurrentData = BeanUtil.copyProperties(en, DirectCurrentDataVO.class);
                    directCurrentData.setDirectCurrent(forwardCurrent.contains(en.getNextId()) ? CommonConstant.ZERO : CommonConstant.ONE);
                    return directCurrentData;
                }).collect(Collectors.toList());
        return directCurrentDataList;
    }

    private void planData(Long schemeId) {
        // 节点1：计划停电/故障停电/重过载事件
        FhzgPlanTransferScheme planTransferScheme = planTransferSchemeService.getById(schemeId);
        Assert.notNull(planTransferScheme, "该方案不存在");
        FhzgPlanPowerCut planPowerCut = planPowerCutService.getById(planTransferScheme.getPlanId());
        Assert.notNull(planPowerCut, "该计划停电不存在");
        String lineId = planPowerCut.getLineId();
        PlanDistMappingFile eventFile = planDistMappingFileService.lambdaQuery().eq(PlanDistMappingFile::getPlanId, planPowerCut.getId()).eq(PlanDistMappingFile::getLineId, lineId)
                .eq(PlanDistMappingFile::getFileType, "4").last("limit 1").one();
        // 节点1：计划停电/故障停电/重过载事件
        ShowCartoonDataVO.SvgFileVO eventSvg = ShowCartoonDataVO.SvgFileVO.builder().build();
        Optional.ofNullable(eventFile).ifPresent(e -> eventSvg.setFileId(e.getFileId()));
        // 节点2：计划停电/故障停电/重过载位置
        SchemeQueryDTO schemeQueryDTO = new SchemeQueryDTO();
        schemeQueryDTO.setPlanId(planPowerCut.getId());
        List<BreakerAreaVO> eventPosition = generateGraphService.getSwitchListByOutArea(schemeQueryDTO);
        // 节点3：待转供区域
        List<BreakerAreaVO> transferArea = generateGraphService.getSwitchListByTransferSection(schemeQueryDTO);
        // 节点4：线路负载计算（转供前负载）
        ShowCartoonDataVO.LineLoadRateVO beforeTransferLoadRate = ShowCartoonDataVO.LineLoadRateVO.builder().build();
        // todo：转供前各个线路的负载率
        LocalDateTime planStartTime = planPowerCut.getPlanStartTime();
        FhzgPlanSwitchInfoList planSwitchInfoList = planSwitchInfoListMapper.selectOne(new LambdaQueryWrapper<FhzgPlanSwitchInfoList>()
                .eq(FhzgPlanSwitchInfoList::getPlanId, planPowerCut.getId()).last("limit 1"));
        List<FeederCheckRuleDTO> feederCheckRuleList = JSON.parseArray(planSwitchInfoList.getFeederCheckRuleJson(), FeederCheckRuleDTO.class);
        List<AllSwitchInfoListDTO> lineSwitchInfoList = JSON.parseArray(planSwitchInfoList.getAllSwitchInfoListJson(), AllSwitchInfoListDTO.class);
        OperationAbnormalityQueryDTO queryDTO = new OperationAbnormalityQueryDTO();
        queryDTO.setFeederId(lineId);
        List<BreakerAreaVO> defaultOverviewSwitch = operationAbnormalityService.getDefaultOverviewSwitch(queryDTO);
        // todo：取对侧线路
        XferPlanDTO xferPlanDTO = JSON.parseObject(planTransferScheme.getRowJson(), XferPlanDTO.class);
        List<XferSupplyAreaDTO> xferSupplyAreaList = xferPlanDTO.getXferSupplyAreaList();
        List<ShowCartoonDataVO.OppositeLineLoadRateVO> beforeOppositeLineLoadRate = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(lineSwitchInfoList)) {
            for (AllSwitchInfoListDTO lineSwitchInfo : lineSwitchInfoList) {
                String feederId = lineSwitchInfo.getFeederId();
                // todo：单个线路的所有开关
                List<AllSwitchInfoDTO> allSwitchList = lineSwitchInfo.getAllSwitchList();
                // 查询出线开关
                LambdaQueryWrapper<FeederTopo> wrapper = new LambdaQueryWrapper<FeederTopo>().eq(FeederTopo::getFeeder, feederId).eq(FeederTopo::getIsStartKg, 1)
                        .in(FeederTopo::getPsrType, Arrays.asList(DictConstants.KG_PSR_TYPE.split(",")));
                // 动态切换表名
                //*ztj ArgTableNameHandler.setArgument(fhzgOrganSuffixMapper.getOrganSuffixByPlanIdOrLineId(planPowerCut.getId(), feederId));
                List<FeederTopo> leadoutBreakerList = fhzgGenerateGraphMapper.getFeederTopo(wrapper);
                AllSwitchInfoDTO lineSwitch = null;
                if (CollectionUtils.isNotEmpty(leadoutBreakerList)) {
                    Optional<AllSwitchInfoDTO> optional = allSwitchList.stream().filter(e -> StringUtils.equals(e.getPsrID(), leadoutBreakerList.get(0).getPsrId())).findFirst();
                    if (optional.isPresent()) {
                        lineSwitch = optional.get();
                    }
                }
                if (Objects.nonNull(lineSwitch)) {
                    BigDecimal maxI = null;
                    LocalDateTime localDateTime = planStartTime.withHour(0).withMinute(0).withSecond(0);
                    Map<LocalDateTime, BigDecimal> switchInfoIMap = Maps.newLinkedHashMap();
                    // todo：单个开关的96点I
                    for (BigDecimal iValue : lineSwitch.getI()) {
                        switchInfoIMap.put(localDateTime, iValue);
                        localDateTime = localDateTime.plusMinutes(15);
                    }
                    List<LocalDateTime> keys = Lists.newLinkedList(switchInfoIMap.keySet());
                    for (int i = 0; i < keys.size(); i++) {
                        LocalDateTime dateTime = keys.get(i);
                        if (!dateTime.isAfter(planStartTime)) {
                            if (i == keys.size() - 1) {
                                maxI = switchInfoIMap.get(dateTime);
                                break;
                            }
                            LocalDateTime nextDateTime = keys.get(i + 1);
                            if (planStartTime.isBefore(nextDateTime)) {
                                maxI = switchInfoIMap.get(dateTime);
                                break;
                            }
                        }
                    }
                    if (Objects.nonNull(maxI) && CollectionUtils.isNotEmpty(feederCheckRuleList)) {
                        // 本侧线路负载
                        if (StringUtils.equals(lineId, feederId)) {
                            for (FeederCheckRuleDTO feederCheckRuleDTO : feederCheckRuleList) {
                                if (StringUtils.equals(lineId, feederCheckRuleDTO.getFeederId())) {
                                    beforeTransferLoadRate.setLineLoadRate(maxI.multiply(new BigDecimal(100)).divide(new BigDecimal(feederCheckRuleDTO.getRateCurrent()), 2, RoundingMode.HALF_UP));
                                    break;
                                }
                            }
                        }
                    }
                    // 对侧线路负载
                    for (BreakerAreaVO overviewSwitch : defaultOverviewSwitch) {
                        if (StringUtils.equals(feederId, overviewSwitch.getOppositeLineId())) {
                            ShowCartoonDataVO.OppositeLineLoadRateVO oppositeLineLoadRateVO = ShowCartoonDataVO.OppositeLineLoadRateVO.builder().oppositeLineId(feederId).isFullLine(overviewSwitch.getIsFullLine())
                                    .startSwitch(overviewSwitch.getStartSwitch()).midSwitch(overviewSwitch.getMidSwitch()).endSwitch(overviewSwitch.getEndSwitch()).build();
                            if (Objects.nonNull(maxI) && CollectionUtils.isNotEmpty(feederCheckRuleList)) {
                                for (XferSupplyAreaDTO xferSupplyAreaDTO : xferSupplyAreaList) {
                                    String psrID = xferSupplyAreaDTO.getLinkLineInfo().getPsrID();
                                    if (StringUtils.equals(feederId, psrID)) {
                                        for (FeederCheckRuleDTO feederCheckRuleDTO : feederCheckRuleList) {
                                            if (StringUtils.equals(feederId, feederCheckRuleDTO.getFeederId())) {
                                                oppositeLineLoadRateVO.setOppositeLineLoadRate(maxI.multiply(new BigDecimal(100)).divide(new BigDecimal(feederCheckRuleDTO.getRateCurrent()), 2, RoundingMode.HALF_UP));
                                                break;
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                            beforeOppositeLineLoadRate.add(oppositeLineLoadRateVO);
                            break;
                        }
                    }
                }
            }
        }
        beforeTransferLoadRate.setLineId(lineId).setOppositeLineLoadRate(beforeOppositeLineLoadRate);
        // 节点5：转供方案计算（切换方案图）
        ShowCartoonDataVO.SvgFileVO schemeSvg = ShowCartoonDataVO.SvgFileVO.builder().build();
        schemeSvg.setFileId(planTransferScheme.getFileId());
        // 节点6：开关操作（开关动作顺序）
        planTransferScheme.setPageNum(1L);
        planTransferScheme.setPageSize(Long.MAX_VALUE);
        Page<FhzgPlanTransferSchemeSwitchingSequenceDTO> page = planTransferSchemeSwitchingSequenceService.getTransferSchemeSwitchingSequenceBySchemeIdPage(planTransferScheme);
        List<FhzgPlanTransferSchemeSwitchingSequenceDTO> switchingSequence = page.getRecords();
        // 节点7：线路重组（获取转供路径）
        schemeQueryDTO.setSchemeId(planTransferScheme.getId());
        List<BreakerAreaVO> pathOverviewSwitch = generateGraphService.getPathOverviewSwitch(schemeQueryDTO);
        // 节点8：计算转供后负载
        Map<String, BreakerAreaVO> pathOverviewSwitchMap = pathOverviewSwitch.stream().collect(Collectors.toMap(BreakerAreaVO::getOppositeLineId, i -> i));
        ShowCartoonDataVO.LineLoadRateVO afterTransferLoadRate = ShowCartoonDataVO.LineLoadRateVO.builder().build();
        List<AllSwitchInfoListDTO> allSwitchInfoList = xferPlanDTO.getAllSwitchInfoList();
        List<ShowCartoonDataVO.OppositeLineLoadRateVO> afterOppositeLineLoadRate = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(allSwitchInfoList)) {
            for (AllSwitchInfoListDTO lineSwitchInfo : allSwitchInfoList) {
                String feederId = lineSwitchInfo.getFeederId();
                // todo：单个线路的所有开关
                List<AllSwitchInfoDTO> allSwitchList = lineSwitchInfo.getAllSwitchList();
                // 查询出线开关
                LambdaQueryWrapper<FeederTopo> wrapper = new LambdaQueryWrapper<FeederTopo>().eq(FeederTopo::getFeeder, feederId).eq(FeederTopo::getIsStartKg, 1)
                        .in(FeederTopo::getPsrType, Arrays.asList(DictConstants.KG_PSR_TYPE.split(",")));
                // 动态切换表名
                //*ztj ArgTableNameHandler.setArgument(fhzgOrganSuffixMapper.getOrganSuffixByPlanIdOrLineId(planPowerCut.getId(), feederId));
                List<FeederTopo> leadoutBreakerList = fhzgGenerateGraphMapper.getFeederTopo(wrapper);
                AllSwitchInfoDTO lineSwitch = null;
                if (CollectionUtils.isNotEmpty(leadoutBreakerList)) {
                    Optional<AllSwitchInfoDTO> optional = allSwitchList.stream().filter(e -> StringUtils.equals(e.getPsrID(), leadoutBreakerList.get(0).getPsrId())).findFirst();
                    if (optional.isPresent()) {
                        lineSwitch = optional.get();
                    }
                }
                if (Objects.nonNull(lineSwitch)) {
                    BigDecimal maxI = null;
                    LocalDateTime localDateTime = planStartTime.withHour(0).withMinute(0).withSecond(0);
                    Map<LocalDateTime, BigDecimal> switchInfoIMap = Maps.newLinkedHashMap();
                    // todo：单个开关的96点I
                    for (BigDecimal iValue : lineSwitch.getI()) {
                        switchInfoIMap.put(localDateTime, iValue);
                        localDateTime = localDateTime.plusMinutes(15);
                    }
                    List<LocalDateTime> keys = Lists.newLinkedList(switchInfoIMap.keySet());
                    for (int i = 0; i < keys.size(); i++) {
                        LocalDateTime dateTime = keys.get(i);
                        if (!dateTime.isAfter(planStartTime)) {
                            if (i == keys.size() - 1) {
                                maxI = switchInfoIMap.get(dateTime);
                                break;
                            }
                            LocalDateTime nextDateTime = keys.get(i + 1);
                            if (planStartTime.isBefore(nextDateTime)) {
                                maxI = switchInfoIMap.get(dateTime);
                                break;
                            }
                        }
                    }
                    if (Objects.nonNull(maxI) && CollectionUtils.isNotEmpty(feederCheckRuleList)) {
                        // 本侧线路负载
                        if (StringUtils.equals(lineId, feederId)) {
                            for (FeederCheckRuleDTO feederCheckRuleDTO : feederCheckRuleList) {
                                if (StringUtils.equals(lineId, feederCheckRuleDTO.getFeederId())) {
                                    afterTransferLoadRate.setLineLoadRate(maxI.multiply(new BigDecimal(100)).divide(new BigDecimal(feederCheckRuleDTO.getRateCurrent()), 2, RoundingMode.HALF_UP));
                                    break;
                                }
                            }
                        }
                        // 对侧线路负载
                        for (XferSupplyAreaDTO xferSupplyAreaDTO : xferSupplyAreaList) {
                            String psrID = xferSupplyAreaDTO.getLinkLineInfo().getPsrID();
                            if (StringUtils.equals(feederId, psrID)) {
                                for (FeederCheckRuleDTO feederCheckRuleDTO : feederCheckRuleList) {
                                    if (StringUtils.equals(feederId, feederCheckRuleDTO.getFeederId())) {

                                        BreakerAreaVO breakerAreaVO = pathOverviewSwitchMap.get(feederId);
                                        afterOppositeLineLoadRate.add(ShowCartoonDataVO.OppositeLineLoadRateVO.builder().oppositeLineId(feederId)
                                                .oppositeLineLoadRate(maxI.multiply(new BigDecimal(100)).divide(new BigDecimal(feederCheckRuleDTO.getRateCurrent()), 2, RoundingMode.HALF_UP))
                                                .isFullLine(breakerAreaVO.getIsFullLine())
                                                .startSwitch(breakerAreaVO.getStartSwitch())
                                                .endSwitch(breakerAreaVO.getEndSwitch())
                                                .midSwitch(breakerAreaVO.getMidSwitch())
                                                .build());
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
        afterTransferLoadRate.setLineId(lineId).setOppositeLineLoadRate(afterOppositeLineLoadRate);
        ShowCartoonDataVO dataVO = ShowCartoonDataVO.builder().eventSvg(eventSvg).eventPosition(eventPosition).transferArea(transferArea).beforeTransferLoadRate(beforeTransferLoadRate).schemeSvg(schemeSvg)
                .switchingSequence(switchingSequence).pathOverviewSwitch(pathOverviewSwitch).afterTransferLoadRate(afterTransferLoadRate).build();
        planTransferScheme.setCartoonDataJson(JSON.toJSONString(dataVO));
        planTransferSchemeService.updateById(planTransferScheme);
    }

    private void faultData(Long schemeId) {
        // 节点1：计划停电/故障停电/重过载事件
        FaultTransferScheme faultTransferScheme = faultTransferSchemeService.getById(schemeId);
        Assert.notNull(faultTransferScheme, "该方案不存在");
        FaultPowerCut faultPowerCut = faultPowerCutService.getById(faultTransferScheme.getFaultId());
        Assert.notNull(faultPowerCut, "该故障停电不存在");
        String lineId = faultPowerCut.getLineId();
        FaultDistMappingFile eventFile = faultDistMappingFileService.lambdaQuery().eq(FaultDistMappingFile::getFaultId, faultPowerCut.getId()).eq(FaultDistMappingFile::getLineId, lineId)
                .eq(FaultDistMappingFile::getFileType, "4").last("limit 1").one();
        ShowCartoonDataVO.SvgFileVO eventSvg = ShowCartoonDataVO.SvgFileVO.builder().build();
        Optional.ofNullable(eventFile).ifPresent(e -> eventSvg.setFileId(e.getFileId()));
        // 节点2：计划停电/故障停电/重过载位置
        EventQueryDTO eventQueryDTO = new EventQueryDTO();
        eventQueryDTO.setPlanId(faultPowerCut.getId());
        List<BreakerAreaVO> eventPosition = faultGenerateGraphService.getSwitchListByOutArea(eventQueryDTO);
        // 节点3：待转供区域
        List<BreakerAreaVO> transferArea = faultGenerateGraphService.getSwitchListByTransferSection(eventQueryDTO);
        // 节点4：线路负载计算（转供前负载）
        ShowCartoonDataVO.LineLoadRateVO beforeTransferLoadRate = ShowCartoonDataVO.LineLoadRateVO.builder().build();
        // todo：转供前各个线路的负载率
        LocalDateTime faultStartTime = faultPowerCut.getFaultStartTime();
        FhzgFaultSwitchInfoList faultSwitchInfoList = faultSwitchInfoListMapper.selectOne(new LambdaQueryWrapper<FhzgFaultSwitchInfoList>()
                .eq(FhzgFaultSwitchInfoList::getFaultId, faultPowerCut.getId()).last("limit 1"));
        List<FeederCheckRuleDTO> feederCheckRuleList = JSON.parseArray(faultSwitchInfoList.getFeederCheckRuleJson(), FeederCheckRuleDTO.class);
        List<AllSwitchInfoListDTO> lineSwitchInfoList = JSON.parseArray(faultSwitchInfoList.getAllSwitchInfoListJson(), AllSwitchInfoListDTO.class);
        OperationAbnormalityQueryDTO queryDTO = new OperationAbnormalityQueryDTO();
        queryDTO.setFeederId(lineId);
        List<BreakerAreaVO> defaultOverviewSwitch = operationAbnormalityService.getDefaultOverviewSwitch(queryDTO);
        // todo：取对侧线路
        XferPlanDTO xferPlanDTO = JSON.parseObject(faultTransferScheme.getRowJson(), XferPlanDTO.class);
        List<XferSupplyAreaDTO> xferSupplyAreaList = xferPlanDTO.getXferSupplyAreaList();
        List<ShowCartoonDataVO.OppositeLineLoadRateVO> beforeOppositeLineLoadRate = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(lineSwitchInfoList)) {
            for (AllSwitchInfoListDTO lineSwitchInfo : lineSwitchInfoList) {
                String feederId = lineSwitchInfo.getFeederId();
                // todo：单个线路的所有开关
                List<AllSwitchInfoDTO> allSwitchList = lineSwitchInfo.getAllSwitchList();
                // 查询出线开关
                LambdaQueryWrapper<FeederTopo> wrapper = new LambdaQueryWrapper<FeederTopo>().eq(FeederTopo::getFeeder, feederId).eq(FeederTopo::getIsStartKg, 1)
                        .in(FeederTopo::getPsrType, Arrays.asList(DictConstants.KG_PSR_TYPE.split(",")));
                //动态切换表名
                //*ztj ArgTableNameHandler.setArgument(fhzgOrganSuffixMapper.getOrganSuffixByFaultIdOrLineId(faultPowerCut.getId(), feederId));
                List<FeederTopo> leadoutBreakerList = fhzgGenerateGraphMapper.getFeederTopo(wrapper);
                AllSwitchInfoDTO lineSwitch = null;
                if (CollectionUtils.isNotEmpty(leadoutBreakerList)) {
                    Optional<AllSwitchInfoDTO> optional = allSwitchList.stream().filter(e -> StringUtils.equals(e.getPsrID(), leadoutBreakerList.get(0).getPsrId())).findFirst();
                    if (optional.isPresent()) {
                        lineSwitch = optional.get();
                    }
                }
                if (Objects.nonNull(lineSwitch)) {
                    BigDecimal maxI = null;
                    LocalDateTime localDateTime = faultStartTime.withHour(0).withMinute(0).withSecond(0);
                    Map<LocalDateTime, BigDecimal> switchInfoIMap = Maps.newLinkedHashMap();
                    // todo：单个开关的96点I
                    for (BigDecimal iValue : lineSwitch.getI()) {
                        switchInfoIMap.put(localDateTime, iValue);
                        localDateTime = localDateTime.plusMinutes(15);
                    }
                    List<LocalDateTime> keys = Lists.newLinkedList(switchInfoIMap.keySet());
                    for (int i = 0; i < keys.size(); i++) {
                        LocalDateTime dateTime = keys.get(i);
                        if (!dateTime.isAfter(faultStartTime)) {
                            if (i != keys.size() - 1) {
                                maxI = switchInfoIMap.get(dateTime);
                                break;
                            }
                            LocalDateTime nextDateTime = keys.get(i + 1);
                            if (faultStartTime.isBefore(nextDateTime)) {
                                maxI = switchInfoIMap.get(dateTime);
                                break;
                            }
                        }
                    }
                    if (Objects.nonNull(maxI) && CollectionUtils.isNotEmpty(feederCheckRuleList)) {
                        // 本侧线路负载
                        if (StringUtils.equals(lineId, feederId)) {
                            for (FeederCheckRuleDTO feederCheckRuleDTO : feederCheckRuleList) {
                                if (StringUtils.equals(lineId, feederCheckRuleDTO.getFeederId())) {
                                    beforeTransferLoadRate.setLineLoadRate(maxI.multiply(new BigDecimal(100)).divide(new BigDecimal(feederCheckRuleDTO.getRateCurrent()), 2, RoundingMode.HALF_UP));
                                    break;
                                }
                            }
                        }
                    }
                    // 对侧线路负载
                    for (BreakerAreaVO overviewSwitch : defaultOverviewSwitch) {
                        if (StringUtils.equals(feederId, overviewSwitch.getOppositeLineId())) {
                            ShowCartoonDataVO.OppositeLineLoadRateVO oppositeLineLoadRateVO = ShowCartoonDataVO.OppositeLineLoadRateVO.builder().oppositeLineId(feederId).isFullLine(overviewSwitch.getIsFullLine())
                                    .startSwitch(overviewSwitch.getStartSwitch()).midSwitch(overviewSwitch.getMidSwitch()).endSwitch(overviewSwitch.getEndSwitch()).build();
                            if (Objects.nonNull(maxI) && CollectionUtils.isNotEmpty(feederCheckRuleList)) {
                                for (XferSupplyAreaDTO xferSupplyAreaDTO : xferSupplyAreaList) {
                                    String psrID = xferSupplyAreaDTO.getLinkLineInfo().getPsrID();
                                    if (StringUtils.equals(feederId, psrID)) {
                                        for (FeederCheckRuleDTO feederCheckRuleDTO : feederCheckRuleList) {
                                            if (StringUtils.equals(feederId, feederCheckRuleDTO.getFeederId())) {
                                                oppositeLineLoadRateVO.setOppositeLineLoadRate(maxI.multiply(new BigDecimal(100)).divide(new BigDecimal(feederCheckRuleDTO.getRateCurrent()), 2, RoundingMode.HALF_UP));
                                                break;
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                            beforeOppositeLineLoadRate.add(oppositeLineLoadRateVO);
                            break;
                        }
                    }
                }
            }
        }
        beforeTransferLoadRate.setLineId(lineId).setOppositeLineLoadRate(beforeOppositeLineLoadRate);
        // 节点5：转供方案计算（切换方案图）
        ShowCartoonDataVO.SvgFileVO schemeSvg = ShowCartoonDataVO.SvgFileVO.builder().build();
        schemeSvg.setFileId(faultTransferScheme.getFileId());
        // 节点6：开关操作（开关动作顺序）
        faultTransferScheme.setPageNum(1L);
        faultTransferScheme.setPageSize(Long.MAX_VALUE);
        Page<FhzgFaultTransferSchemeSwitchingSequenceDTO> page = faultTransferSchemeSwitchingSequenceService.getTransferSchemeSwitchingSequenceBySchemeIdPage(faultTransferScheme);
        List<FhzgPlanTransferSchemeSwitchingSequenceDTO> switchingSequence = page.getRecords().stream().map(e -> {
            FhzgPlanTransferSchemeSwitchingSequenceDTO switchingSequenceDTO = new FhzgPlanTransferSchemeSwitchingSequenceDTO();
            BeanUtils.copyProperties(e, switchingSequenceDTO);
            return switchingSequenceDTO;
        }).collect(Collectors.toList());
        // 节点7：线路重组（获取转供路径）
        SchemeQueryDTO schemeQueryDTO = new SchemeQueryDTO();
        schemeQueryDTO.setSchemeId(faultTransferScheme.getId());
        schemeQueryDTO.setPlanId(faultPowerCut.getId());
        List<BreakerAreaVO> pathOverviewSwitch = faultGenerateGraphService.getPathOverviewSwitch(schemeQueryDTO);
        // 节点8：计算转供后负载
        Map<String, BreakerAreaVO> pathOverviewSwitchMap = pathOverviewSwitch.stream().collect(Collectors.toMap(BreakerAreaVO::getOppositeLineId, i -> i));
        ShowCartoonDataVO.LineLoadRateVO afterTransferLoadRate = ShowCartoonDataVO.LineLoadRateVO.builder().build();
        List<AllSwitchInfoListDTO> allSwitchInfoList = xferPlanDTO.getAllSwitchInfoList();
        List<ShowCartoonDataVO.OppositeLineLoadRateVO> afterOppositeLineLoadRate = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(allSwitchInfoList)) {
            for (AllSwitchInfoListDTO lineSwitchInfo : allSwitchInfoList) {
                String feederId = lineSwitchInfo.getFeederId();
                // todo：单个线路的所有开关
                List<AllSwitchInfoDTO> allSwitchList = lineSwitchInfo.getAllSwitchList();
                // 查询出线开关
                LambdaQueryWrapper<FeederTopo> wrapper = new LambdaQueryWrapper<FeederTopo>().eq(FeederTopo::getFeeder, feederId).eq(FeederTopo::getIsStartKg, 1)
                        .in(FeederTopo::getPsrType, Arrays.asList(DictConstants.KG_PSR_TYPE.split(",")));
                //动态切换表名
                //*ztj ArgTableNameHandler.setArgument(fhzgOrganSuffixMapper.getOrganSuffixByFaultIdOrLineId(faultPowerCut.getId(), feederId));
                List<FeederTopo> leadoutBreakerList = fhzgGenerateGraphMapper.getFeederTopo(wrapper);
                AllSwitchInfoDTO lineSwitch = null;
                if (CollectionUtils.isNotEmpty(leadoutBreakerList)) {
                    Optional<AllSwitchInfoDTO> optional = allSwitchList.stream().filter(e -> StringUtils.equals(e.getPsrID(), leadoutBreakerList.get(0).getPsrId())).findFirst();
                    if (optional.isPresent()) {
                        lineSwitch = optional.get();
                    }
                }
                if (Objects.nonNull(lineSwitch)) {
                    BigDecimal maxI = null;
                    LocalDateTime localDateTime = faultStartTime.withHour(0).withMinute(0).withSecond(0);
                    Map<LocalDateTime, BigDecimal> switchInfoIMap = Maps.newLinkedHashMap();
                    // todo：单个开关的96点I
                    for (BigDecimal iValue : lineSwitch.getI()) {
                        switchInfoIMap.put(localDateTime, iValue);
                        localDateTime = localDateTime.plusMinutes(15);
                    }
                    List<LocalDateTime> keys = Lists.newLinkedList(switchInfoIMap.keySet());
                    for (int i = 0; i < keys.size(); i++) {
                        LocalDateTime dateTime = keys.get(i);
                        if (!dateTime.isAfter(faultStartTime)) {
                            if (i != keys.size() - 1) {
                                maxI = switchInfoIMap.get(dateTime);
                                break;
                            }
                            LocalDateTime nextDateTime = keys.get(i + 1);
                            if (faultStartTime.isBefore(nextDateTime)) {
                                maxI = switchInfoIMap.get(dateTime);
                                break;
                            }
                        }
                    }
                    if (Objects.nonNull(maxI) && CollectionUtils.isNotEmpty(feederCheckRuleList)) {
                        // 本侧线路负载
                        if (StringUtils.equals(lineId, feederId)) {
                            for (FeederCheckRuleDTO feederCheckRuleDTO : feederCheckRuleList) {
                                if (StringUtils.equals(lineId, feederCheckRuleDTO.getFeederId())) {
                                    afterTransferLoadRate.setLineLoadRate(maxI.multiply(new BigDecimal(100)).divide(new BigDecimal(feederCheckRuleDTO.getRateCurrent()), 2, RoundingMode.HALF_UP));
                                    break;
                                }
                            }
                        }
                        // 对侧线路负载
                        for (XferSupplyAreaDTO xferSupplyAreaDTO : xferSupplyAreaList) {
                            String psrID = xferSupplyAreaDTO.getLinkLineInfo().getPsrID();
                            if (StringUtils.equals(feederId, psrID)) {
                                for (FeederCheckRuleDTO feederCheckRuleDTO : feederCheckRuleList) {
                                    if (StringUtils.equals(feederId, feederCheckRuleDTO.getFeederId())) {
                                        BreakerAreaVO breakerAreaVO = pathOverviewSwitchMap.get(feederId);
                                        afterOppositeLineLoadRate.add(ShowCartoonDataVO.OppositeLineLoadRateVO.builder().oppositeLineId(feederId)
                                                .oppositeLineLoadRate(maxI.multiply(new BigDecimal(100)).divide(new BigDecimal(feederCheckRuleDTO.getRateCurrent()), 2, RoundingMode.HALF_UP))
                                                .isFullLine(breakerAreaVO.getIsFullLine())
                                                .startSwitch(breakerAreaVO.getStartSwitch())
                                                .endSwitch(breakerAreaVO.getEndSwitch())
                                                .midSwitch(breakerAreaVO.getMidSwitch())
                                                .build());
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
        afterTransferLoadRate.setLineId(lineId).setOppositeLineLoadRate(afterOppositeLineLoadRate);
        ShowCartoonDataVO dataVO = ShowCartoonDataVO.builder().eventSvg(eventSvg).eventPosition(eventPosition).transferArea(transferArea).beforeTransferLoadRate(beforeTransferLoadRate).schemeSvg(schemeSvg)
                .switchingSequence(switchingSequence).pathOverviewSwitch(pathOverviewSwitch).afterTransferLoadRate(afterTransferLoadRate).build();
        faultTransferScheme.setCartoonDataJson(JSON.toJSONString(dataVO));
        faultTransferSchemeService.updateById(faultTransferScheme);
    }

    private void operationAbnormalityData(Long schemeId) {
        // 节点1：计划停电/故障停电/重过载事件
        FhzgOperationAbnormalityTransferScheme operationAbnormalityTransferScheme = operationAbnormalityTransferSchemeService.getById(schemeId);
        Assert.notNull(operationAbnormalityTransferScheme, "该方案不存在");
        FhzgGridOperationAbnormality operationAbnormality = operationAbnormalityService.getById(operationAbnormalityTransferScheme.getOaId());
        Assert.notNull(operationAbnormality, "该运行调优不存在");
        ShowCartoonDataVO.SvgFileVO eventSvg = ShowCartoonDataVO.SvgFileVO.builder().build();
        eventSvg.setFileId(operationAbnormality.getFileId());
        String lineId = operationAbnormality.getLineId();
        // 节点2：计划停电/故障停电/重过载位置
        List<BreakerAreaVO> eventPosition = Lists.newArrayList();
        // 节点3：待转供区域
        List<BreakerAreaVO> transferArea = Lists.newArrayList();
        // 节点4：线路负载计算（转供前负载）& 节点8：计算转供后负载
        ShowCartoonDataVO.LineLoadRateVO beforeTransferLoadRate = ShowCartoonDataVO.LineLoadRateVO.builder().build();
        ShowCartoonDataVO.LineLoadRateVO afterTransferLoadRate = ShowCartoonDataVO.LineLoadRateVO.builder().build();
        OperationAbnormalityQueryDTO queryDTO = new OperationAbnormalityQueryDTO();
        queryDTO.setFeederId(lineId);
        queryDTO.setObjId(String.valueOf(schemeId));
        List<BreakerAreaVO> defaultOverviewSwitch = operationAbnormalityService.getDefaultOverviewSwitch(queryDTO);
        Map<String, BreakerAreaVO> defaultOverviewSwitchMap = defaultOverviewSwitch.stream().collect(Collectors.toMap(BreakerAreaVO::getOppositeLineId, i -> i));

        //todo:转供后开关待修改
        FhzgOperationAbnormalityTransferAreaResult operationAbnormalityTransferAreaResult = fhzgOperationAbnormalityTransferAreaResultMapper.selectOne(new LambdaQueryWrapper<FhzgOperationAbnormalityTransferAreaResult>()
                .eq(FhzgOperationAbnormalityTransferAreaResult::getOaId, operationAbnormality.getId()).last("limit 1"));
        Optional.ofNullable(operationAbnormalityTransferAreaResult.getTransferAreaJson())
                .map(e -> JSON.parseObject(e, ApiResponse.class)).filter(e -> ObjectUtils.isNotEmpty(e.getData()))
                .map(e -> JSON.parseObject(JSON.toJSONString(e.getData()), ApiAbnormalDataDTO.class))
                .ifPresent(data -> {
                    AbnormalOperationDTO abnormalOperationDTO = data.getResult();
                    FeederResultDTO feederResult = abnormalOperationDTO.getFeederResult();
                    List<ShowCartoonDataVO.OppositeLineLoadRateVO> beforeOppositeLineLoadRate = Lists.newArrayList();
                    List<ShowCartoonDataVO.OppositeLineLoadRateVO> afterOppositeLineLoadRate = Lists.newArrayList();
                    for (ListFeederDTO listFeederDTO : feederResult.getListFeeder()) {
                        BigDecimal beforeLoadRate = listFeederDTO.getBeforeI().multiply(new BigDecimal(100)).divide(listFeederDTO.getRateCurrent(), 2, RoundingMode.HALF_UP);
                        BigDecimal afterLoadRate = listFeederDTO.getAfterI().multiply(new BigDecimal(100)).divide(listFeederDTO.getRateCurrent(), 2, RoundingMode.HALF_UP);
                        BreakerAreaVO breakerAreaVO = defaultOverviewSwitchMap.get(listFeederDTO.getPsrID());
                        if (StringUtils.equals(lineId, listFeederDTO.getPsrID())) {
                            beforeTransferLoadRate.setLineId(lineId).setLineLoadRate(beforeLoadRate);
                            afterTransferLoadRate.setLineId(lineId).setLineLoadRate(afterLoadRate);
                        } else {
                            beforeOppositeLineLoadRate.add(ShowCartoonDataVO.OppositeLineLoadRateVO.builder()
                                    .oppositeLineId(listFeederDTO.getPsrID())
                                    .oppositeLineLoadRate(beforeLoadRate)
                                    .isFullLine(breakerAreaVO.getIsFullLine())
                                    .startSwitch(breakerAreaVO.getStartSwitch())
                                    .endSwitch(breakerAreaVO.getEndSwitch())
                                    .midSwitch(breakerAreaVO.getMidSwitch())
                                    .build());
                            afterOppositeLineLoadRate.add(ShowCartoonDataVO.OppositeLineLoadRateVO.builder()
                                    .oppositeLineId(listFeederDTO.getPsrID())
                                    .oppositeLineLoadRate(afterLoadRate)
                                    .build());
                        }
                    }
                    beforeTransferLoadRate.setOppositeLineLoadRate(beforeOppositeLineLoadRate);
                    afterTransferLoadRate.setOppositeLineLoadRate(afterOppositeLineLoadRate);
                });
        // 节点5：转供方案计算（切换方案图）
        ShowCartoonDataVO.SvgFileVO schemeSvg = ShowCartoonDataVO.SvgFileVO.builder().build();
        schemeSvg.setFileId(operationAbnormalityTransferScheme.getFileId());
        // 节点6：开关操作（开关动作顺序）
        List<FhzgPlanTransferSchemeSwitchingSequenceDTO> switchingSequence = switchingSequenceMapper.selectList(new LambdaQueryWrapper<FhzgOperationAbnormalitySwitchingSequence>()
                        .eq(FhzgOperationAbnormalitySwitchingSequence::getOaId, operationAbnormality.getId()).orderByAsc(FhzgOperationAbnormalitySwitchingSequence::getSwitchingSeq))
                .stream().map(e -> {
                    FhzgPlanTransferSchemeSwitchingSequenceDTO switchingSequenceDTO = new FhzgPlanTransferSchemeSwitchingSequenceDTO();
                    switchingSequenceDTO.setId(e.getId());
                    switchingSequenceDTO.setSchemeId(e.getOaId());
                    switchingSequenceDTO.setSwitchId(e.getSwitchId());
                    switchingSequenceDTO.setSwitchName(e.getSwitchName());
                    switchingSequenceDTO.setIsAutoSwitch(e.getIsAutoSwitch());
                    switchingSequenceDTO.setOperationContent(e.getOperationType());
                    switchingSequenceDTO.setSwitchingSeq(e.getSwitchingSeq());
                    return switchingSequenceDTO;
                }).collect(Collectors.toList());
        // 节点7：线路重组（获取转供路径）
        OperationAbnormalityQueryDTO operationAbnormalityQueryDTO = new OperationAbnormalityQueryDTO();
        operationAbnormalityQueryDTO.setSchemeId(operationAbnormality.getId());
        operationAbnormalityQueryDTO.setFeederId(operationAbnormality.getLineId());
        List<BreakerAreaVO> pathOverviewSwitch = operationAbnormalityService.getPathOverviewSwitch(operationAbnormalityQueryDTO);
        ShowCartoonDataVO dataVO = ShowCartoonDataVO.builder().eventSvg(eventSvg).eventPosition(eventPosition).transferArea(transferArea).beforeTransferLoadRate(beforeTransferLoadRate).schemeSvg(schemeSvg)
                .switchingSequence(switchingSequence).pathOverviewSwitch(pathOverviewSwitch).afterTransferLoadRate(afterTransferLoadRate).build();
        operationAbnormalityTransferScheme.setCartoonDataJson(JSON.toJSONString(dataVO));
        operationAbnormalityTransferSchemeService.updateById(operationAbnormalityTransferScheme);
    }

}
