<?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.pms.mapper.majornetwork.StatationStatMapper">

    <!--获取指定的变电站信息-->
    <select id="getStatationStatInfo" resultType="com.njcn.device.pms.pojo.dto.PmsStatationStatInfoDTO">
        SELECT
        pm.Org_Id AS orgId,
        pm.Org_Name AS orgName,
        pm.Powerr_Id AS powerId,
        pm.Powerr_Name AS powerName,
        pm.Id AS monitorId,
        pm.`Name` AS monitorName,
        pss.Voltage_Level AS powerVoltageLevel
        FROM
        pms_monitor AS pm
        LEFT JOIN pms_statation_stat AS pss ON pss.Power_Id = pm.Powerr_Id
        WHERE
        pm.Status = 1
        AND pss.Status = 1
        <if test="pmsStatationStatInfoParam.powerIds != null and pmsStatationStatInfoParam.powerIds.size() > 0">
            AND pm.Powerr_Id IN
            <foreach collection="pmsStatationStatInfoParam.powerIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="pmsStatationStatInfoParam.orgIds != null and pmsStatationStatInfoParam.orgIds.size() > 0">
            AND pm.Org_Id IN
            <foreach collection="pmsStatationStatInfoParam.orgIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="pmsStatationStatInfoParam.powerVoltageLevel !=null and pmsStatationStatInfoParam.powerVoltageLevel.size() != 0">
            AND pss.Voltage_Level IN
            <foreach collection="pmsStatationStatInfoParam.powerVoltageLevel" item="item" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        <if test="pmsStatationStatInfoParam.powerName != null and pmsStatationStatInfoParam.powerName != ''">
            AND pm.Powerr_Name LIKE CONCAT('%',#{pmsStatationStatInfoParam.powerName},'%')
        </if>
    </select>


    <select id="getStatationStatPageList" resultType="com.njcn.device.pms.pojo.vo.StatationStatVO">
        select a.*, b.name orgName
        from pms_statation_stat a
        inner join sys_dept b on a.org_id = b.code and b.state = 1
        where a.status = 1
        <if test="baseParam.searchValue!=null and baseParam.searchValue!=''">
            and
            (
            a.Power_Id like concat('%',#{baseParam.searchValue},'%')
            or a.Power_Name like concat('%',#{baseParam.searchValue},'%')
            or b.name like concat('%',#{baseParam.searchValue},'%')
            )
        </if>
        order by a.Create_Time desc
    </select>

</mapper>
