package com.hdkj.lt.bf.mapper;

import com.hdkj.lt.core.bizms.modle.dto.FhzgPlanTransferSchemePathDetailDTO;
import com.hdkj.lt.core.bizms.modle.po.fault.FaultAwaitTransferSwitchSection;
import com.hdkj.lt.core.bizms.modle.po.fault.FaultPowerCut;
import com.hdkj.lt.core.bizms.modle.po.fault.FaultPowerCutSwitch;
import com.hdkj.lt.core.bizms.modle.po.fault.FaultTransferSchemePathDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 停电计划转供方案过程态详情分页查询
 *
 * @author zhuzhe
 * @since 2025-05-16
 */
@Mapper
public interface FhzgFaultGenerateGraphMapper {

    /**
     * 查询转供范围
     * @param faultId
     * @return
     */
    List<FaultAwaitTransferSwitchSection> selectSwitchSectionList(@Param("faultId") Long faultId);

    List<FaultPowerCutSwitch> selectPowerCutSwitchList(@Param("faultId") Long faultId);


    FaultPowerCut selectFhzgPlanById(Long planId);

    List<FaultTransferSchemePathDetail> selectSchemePathDetailByFault(@Param("faultId") Long faultId);

    @Select("<script>" +
            "with recursive res_tab as (\n" +
            "    select t.psr_id, t.name, t.start_kg_id from t_feeder_topo t\n" +
            "    where t.psr_id = #{startSwitchId} and t.feeder = #{lineId}\n" +
            "    union\n" +
            "    select if(t.psr_id in <foreach collection='endSwitchIds' item='item' open='(' separator=',' close=')'>#{item}</foreach>, '-', t.psr_id) psr_id,\n" +
            "        t.name switch_name, t.start_kg_id\n" +
            "    from t_feeder_topo t join res_tab p on t.start_kg_id = p.psr_id\n" +
            "    and t.psr_type in " +
            "   <foreach collection = 'switchTypes' item = 'item' open = '(' separator = ',' close = ')'>#{item}</foreach>\n" +
            "and t.normal_open !='true'\n" +
            ") select psr_id switch_id, `name` switch_name, start_kg_id from res_tab where psr_id not in (#{startSwitchId}, '-')" +
            "</script>")
    List<FhzgPlanTransferSchemePathDetailDTO> getSwitchSectionInfo(@Param("lineId")String lineId, @Param("startSwitchId")String startSwitchId, @Param("endSwitchIds")List<String> endSwitchIds, @Param("switchTypes")List<String> switchTypes);

    String selectSwitchByCustomerId(@Param("customerId") String customerId);
}
