<?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.njcn.product.device.ledger.mapper.TreeMapper">


    <!--监测点-->
    <select id="getMancLineListByLineIds" resultType="TerminalTree">
        select distinct a.id,a.pid,a.name,a.level,a.sort,e.pt_type
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_device d on c.id = d.id
        inner join pq_line_detail e on a.id = e.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and d.manufacturer = #{manufacturer}
        and a.state = 1
        order by sort
    </select>
    <!--母线-->
    <select id="getMancVoltageListByLineIds" resultType="TerminalTree">
        select distinct b.id,b.pid,b.name,b.level,b.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_device d on c.id = d.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and d.manufacturer = #{manufacturer}
        and a.state = 1
        order by sort
    </select>

    <!--设备-->
    <select id="getMancDevListByLineIds" resultType="TerminalTree">
        select distinct c.id,c.pid,c.name,c.level,c.sort,d.com_flag comFlag
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_device d on c.id = d.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and d.manufacturer = #{manufacturer}
        and a.state = 1
        order by sort
    </select>

    <!--变电站-->
    <select id="getMancSubListByLineIds" resultType="TerminalTree">
        select distinct d.id,d.pid,d.name,d.level,d.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_line d on c.pid = d.id
        inner join pq_device e on c.id = e.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and e.manufacturer = #{manufacturer}
        and a.state = 1
        order by sort
    </select>

    <!--供电公司-->
    <select id="getMancGdListByLineIds" resultType="TerminalTree">
        select distinct e.id,e.pid,e.name,e.level,e.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_line d on c.pid = d.id
        inner join pq_line e on d.pid = e.id
        inner join pq_device f on c.id = f.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and f.manufacturer = #{manufacturer}
        and a.state = 1
        order by sort
    </select>

    <!--省份-->
    <select id="getMancProvListByLineIds" resultType="TerminalTree">
        select distinct f.id,f.pid,h.name,f.level,f.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_line d on c.pid = d.id
        inner join pq_line e on d.pid = e.id
        inner join pq_line f on e.pid = f.id
        inner join pq_device g on c.id = g.id
        inner join sys_area h on f.name = h.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and g.manufacturer = #{manufacturer}
        and a.state = 1
        order by sort
    </select>


    <!--电压等级++++++++++++++++++++++++++++++++++-->

    <!--监测点-->
    <select id="getScaleLineListByLineIds" resultType="TerminalTree">
        select distinct a.id,a.pid,a.name,a.level,a.sort,d.pt_type
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_voltage c on c.id = b.id
        inner join pq_line_detail d on a.id = d.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and c.scale = #{scale}
        and a.state = 1
        order by sort
    </select>
    <!--母线-->
    <select id="getScaleVoltageListByLineIds" resultType="TerminalTree">
        select distinct b.id,b.pid,b.name,b.level,b.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_voltage c on c.id = b.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and c.scale = #{scale}
        and a.state = 1
        order by sort
    </select>

    <!--设备-->
    <select id="getScaleDevListByLineIds" resultType="TerminalTree">
        select distinct c.id,c.pid,c.name,c.level,c.sort,e.com_flag comFlag
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_voltage d on b.id = d.id
        inner join pq_device e on c.id = e.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and d.scale = #{scale}
        and a.state = 1
        order by sort
    </select>

    <!--变电站-->
    <select id="getScaleSubListByLineIds" resultType="TerminalTree">
        select distinct d.id,d.pid,d.name,d.level,d.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_line d on c.pid = d.id
        inner join pq_voltage e on b.id = e.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and e.scale = #{scale}
        and a.state = 1
        order by sort
    </select>

    <!--供电公司-->
    <select id="getScaleGdListByLineIds" resultType="TerminalTree">
        select distinct e.id,e.pid,e.name,e.level,e.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_line d on c.pid = d.id
        inner join pq_line e on d.pid = e.id
        inner join pq_voltage f on b.id = f.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and f.scale = #{scale}
        and a.state = 1
        order by sort
    </select>

    <!--省份-->
    <select id="getScaleProvListByLineIds" resultType="TerminalTree">
        select distinct f.id,f.pid,h.name,f.level,f.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_line d on c.pid = d.id
        inner join pq_line e on d.pid = e.id
        inner join pq_line f on e.pid = f.id
        inner join pq_voltage g on b.id = g.id
        inner join sys_area h on f.name = h.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and g.scale = #{scale}
        and a.state = 1
        order by sort
    </select>


    <!--干扰源类型++++++++++++++++++++++++++++++-->

    <!--监测点-->
    <select id="getLoadTypeLineListByLineIds" resultType="TerminalTree">
        select distinct a.id,a.pid,a.name,a.level,a.sort,c.pt_type
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line_detail c on c.id = a.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and c.load_type = #{loadType}
        and a.state = 1
        order by sort
    </select>

    <!--母线-->
    <select id="getLoadTypeVoltageListByLineIds" resultType="TerminalTree">
        select distinct b.id,b.pid,b.name,b.level,b.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line_detail c on c.id = a.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and c.load_type = #{loadType}
        and a.state = 1
        order by sort
    </select>

    <!--设备-->
    <select id="getLoadTypeDevListByLineIds" resultType="TerminalTree">
        select distinct c.id,c.pid,c.name,c.level,c.sort,e.com_flag comFlag
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_line_detail d on a.id = d.id
        inner join pq_device e on c.id = e.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and d.load_type = #{loadType}
        and a.state = 1
        order by sort
    </select>

    <!--变电站-->
    <select id="getLoadTypeSubListByLineIds" resultType="TerminalTree">
        select distinct d.id,d.pid,d.name,d.level,d.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_line d on c.pid = d.id
        inner join pq_line_detail e on a.id = e.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and e.load_type = #{loadType}
        and a.state = 1
        order by sort
    </select>

    <!--供电公司-->
    <select id="getLoadTypeGdListByLineIds" resultType="TerminalTree">
        select distinct e.id,e.pid,e.name,e.level,e.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_line d on c.pid = d.id
        inner join pq_line e on d.pid = e.id
        inner join pq_line_detail f on a.id = f.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and f.load_type = #{loadType}
        and a.state = 1
        order by sort
    </select>

    <!--省份-->
    <select id="getLoadTypeProvListByLineIds" resultType="TerminalTree">
        select distinct f.id,f.pid,h.name,f.level,f.sort
        from pq_line a
        inner join pq_line b on a.pid = b.id
        inner join pq_line c on b.pid = c.id
        inner join pq_line d on c.pid = d.id
        inner join pq_line e on d.pid = e.id
        inner join pq_line f on e.pid = f.id
        inner join pq_line_detail g on a.id = g.id
        inner join sys_area h on f.name = h.id
        where a.id in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and g.load_type = #{loadType}
        and a.state = 1
        order by sort
    </select>


    <!--根据供电公司索引获取出省会的信息-->
    <select id="getProvinceList" resultType="TerminalTree">
        SELECT
        DISTINCT(pro.id),
        pro.pid,
        pro.level,
        pro.sort,
        area.name name
        FROM
        pq_line pro,
        pq_line gd,
        sys_area area
        WHERE
        pro.id = gd.pid
        AND
        pro.name = area.id
        AND
        gd.id in
        <foreach collection="gdIndex" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <!--获取出供电公司的信息-->
    <select id="getGdList" resultType="TerminalTree">
        SELECT gd.id,
               gd.pid,
               gd.LEVEL,
               gd.sort,
               gd.Name
        FROM pq_line gd
        WHERE
        gd.id in
        <foreach collection="gdIndex" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>


    <!--获取出变电站的信息-->
    <select id="getSubList" resultType="TerminalTree">
        SELECT
            sub.id,
            sub.pid,
            sub.LEVEL,
            sub.sort,
            sub.Name
        FROM
            pq_line sub
        WHERE
            sub.id in
        <foreach collection="subIndex" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <!--根据监测点索引获取监测点级五层树数据-->
    <select id="getLineList" resultType="TerminalTree">
        SELECT
            line.id,
            line.pid,
            line.LEVEL,
            line.sort,
            line.pids,
            CONCAT(voltage.name, '_', line.name) name,
            comFlag.Com_Flag,
            detail.pt_type,
            detail.obj_id
        FROM
            pq_line line,
            pq_line_detail detail,
            pq_line voltage,
            pq_line device,
            pq_device comFlag
        WHERE
            line.id = detail.id
          AND
            line.pid = voltage.id
          AND
            voltage.pid = device.id
          AND
            device.id = comFlag.id
          AND line.id in
            <foreach collection="lineIndex" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
    </select>






</mapper>
