<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hdkj.lt.bf.mapper.FeederTopoMapper">

    <select id="getBreakerPsrId" resultType="java.lang.String">
        with recursive res_tab as (select t.*, t.psr_id link_id
        from t_feeder_topo t
        where t.feeder = #{feeder}
        and psr_id = #{startKg}
        union all
        select t.*,
        if(FIND_IN_SET(t.psr_id, #{endKg})>0, '-', t.psr_id) link_id
        from t_feeder_topo t
        join res_tab p on t.start_kg_id = p.link_id
        where t.feeder = #{feeder}
        and t.psr_type in <foreach collection='kgPsrTypes' item='item' open="(" separator=',' close=')'>
        #{item}</foreach>)
        select psr_id
        from res_tab
        where link_id not in ('-', #{startKg});
    </select>
</mapper>
