<?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.device.pq.mapper.LineIntegrityDataMapper">

    <!--根据供电公司索引获取出省会的信息-->
    <select id="getProvinceList" resultType="com.njcn.device.pq.pojo.vo.LineIntegrityDataVO">
        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="com.njcn.device.pq.pojo.vo.LineIntegrityDataVO">
        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="com.njcn.device.pq.pojo.vo.LineIntegrityDataVO">
        SELECT
        DISTINCT
        sub.id,
        sub.pid,
        sub.`Level`,
        sub.sort,
        sub.`Name`,
        sdd.`Name` AS subScale
        FROM
        pq_line line
        INNER JOIN pq_line wire ON line.pid = wire.id
        INNER JOIN pq_line dev ON wire.pid = dev.id
        INNER JOIN pq_line sub ON dev.pid = sub.id
        INNER JOIN pq_substation AS psub ON sub.id = psub.id
        INNER JOIN sys_dict_data AS sdd ON psub.Scale = sdd.id
        WHERE
        line.id in
        <foreach collection="lineIndexes" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <!--根据监测点索引集合获取监测点详细参数-->
    <select id="getDetailedParametersForLine" resultType="com.njcn.device.pq.pojo.vo.LineIntegrityDataVO">
        SELECT
        line.Id as 'id',
        line.pid as 'pid',
        line.Pids as 'pids',
        line.`Name` AS 'name',
        line.`Level`as 'Level',
        pd.Update_Time AS 'updateTime',
        line.Sort as 'sort',
        pd.Com_Flag as 'ComFlag',
        sdd.`Name` AS 'LineScale',
        device.`Name` AS 'deviceName',
        pd.IP AS 'ip',
        msdd.`Name` AS 'manufacturer',
        pldsdd.`Name` AS 'lineGradeName',
        pldsdd.`id` AS 'lineGrade',
        pldsdd.Algo_Describe AS `algoDescribe`,
        pld.Load_Type AS 'loadType'
        FROM
        pq_line AS line
        LEFT JOIN pq_line AS voltage ON line.Pid = voltage.Id
        LEFT JOIN pq_line AS device ON voltage.pid = device.id
        LEFT JOIN pq_voltage AS pv ON voltage.id = pv.id
        LEFT JOIN pq_device AS pd ON device.id = pd.id
        LEFT JOIN sys_dict_data AS sdd ON sdd.id = pv.Scale
        LEFT JOIN pq_line_detail AS pld ON line.id = pld.Id
        LEFT JOIN sys_dict_data AS pldsdd ON pld.Line_Grade = pldsdd.id
        LEFT JOIN sys_dict_data AS msdd ON pd.Manufacturer = msdd.`id`
        WHERE
        line.`Level` = 6
        AND
        line.id in
        <foreach collection="lineIndexes" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="lineGrade != null and lineGrade != ''">
            and pld.Line_Grade = #{lineGrade}
        </if>
    </select>
    <select id="getAlarmAlgoDescribe" resultType="com.njcn.device.pq.pojo.vo.AlarmStrategyVO">
        SELECT
        sdd.id AS id,
        sdd.Algo_Describe AS algoDescribe,
        pas.Integrity_Value AS integrityValue
        FROM sys_dict_data sdd
        LEFT JOIN  pqs_alarm_strategy pas ON pas.Id = sdd.Id
        WHERE sdd.Id IN
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item.id}
        </foreach>
    </select>

</mapper>
