<?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.huatek.busi.mapper.RptAretMonitorMapper">

    <sql id="Base_Column_List">
            id as id,
            cac_monitor_type_code as cacMonitorTypeCode,
            site_id as siteId,
            main_tree_id as mainTreeId,
            sub_tree_id as subTreeId,
            main_equipment_id as mainEquipmentId,
            sub_equipment_id as subEquipmentId,
            arrester_count as arresterCount,
            spring_count as springCount,
            summer_count as summerCount,
            autumn_count as autumnCount,
            winter_count as winterCount,
            dangtian_count as dangtianCount,
            last_time as lastTime,
            a_sensor_id as aSensorId,
            a_full_alc as aFullAlc,
            a_hindrance_alc as aHindranceAlc,
            b_sensor_id as bSensorId,
            b_full_alc as bFullAlc,
            b_hindrance_alc as bHindranceAlc,
            c_sensor_id as cSensorId,
            c_full_alc as cFullAlc,
            c_hindrance_alc as cHindranceAlc,
            create_time as createTime,
            remark as remark,
            run_state as runState
    </sql>
    <sql id="Base_Column_List2">
           t.id as id,
           t.site_id as siteId,
           t.arrester_count as arresterCount,
           t.last_time as lastTime,
           t.a_sensor_id as aSensorId,
           t.a_full_alc as aFullAlc,
           t.a_hindrance_alc as aHindranceAlc,
           t.b_sensor_id as bSensorId,
           t.b_full_alc as bFullAlc,
           t.b_hindrance_alc as bHindranceAlc,
           t.c_sensor_id as cSensorId,
           t.c_full_alc as cFullAlc,
           t.c_hindrance_alc as cHindranceAlc,
           t.create_time as createTime,
           t.run_state as runState
    </sql>
    <select id="selectRptAretMonitorPage" parameterType="com.huatek.busi.dto.RptAretMonitorDto" resultType="com.huatek.busi.vo.RptAretMonitorVo">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        rpt_aret_monitor t
        WHERE 1=1
        <if test="id != null and id != ''">
             and t.id = #{id}
        </if>
        <if test="siteId != null and siteId != ''">
             and t.site_id = #{siteId}
        </if>
        <if test="eqmCode != null and eqmCode != ''">
             and t.eqm_code = #{eqmCode}
        </if>
        <if test="eqmId != null and eqmId != ''">
             and t.eqm_id = #{eqmId}
        </if>
        <if test="arresterCount != null">
             and t.arrester_count = #{arresterCount}
        </if>
        <if test="springCount != null">
             and t.spring_count = #{springCount}
        </if>
        <if test="summerCount != null">
             and t.summer_count = #{summerCount}
        </if>
        <if test="autumnCount != null">
             and t.autumn_count = #{autumnCount}
        </if>
        <if test="winterCount != null">
             and t.winter_count = #{winterCount}
        </if>
        <if test="dangtianCount != null">
             and t.dangtian_count = #{dangtianCount}
        </if>
        <if test="lastTime != null">
             and t.last_time = #{lastTime}
        </if>
        <if test="aSensorId != null and aSensorId != ''">
             and t.a_sensor_id = #{aSensorId}
        </if>
        <if test="aFullAlc != null">
             and t.a_full_alc = #{aFullAlc}
        </if>
        <if test="aHindranceAlc != null">
             and t.a_hindrance_alc = #{aHindranceAlc}
        </if>
        <if test="bSensorId != null and bSensorId != ''">
             and t.b_sensor_id = #{bSensorId}
        </if>
        <if test="bFullAlc != null">
             and t.b_full_alc = #{bFullAlc}
        </if>
        <if test="bHindranceAlc != null">
             and t.b_hindrance_alc = #{bHindranceAlc}
        </if>
        <if test="cSensorId != null and cSensorId != ''">
             and t.c_sensor_id = #{cSensorId}
        </if>
        <if test="cFullAlc != null">
             and t.c_full_alc = #{cFullAlc}
        </if>
        <if test="cHindranceAlc != null">
             and t.c_hindrance_alc = #{cHindranceAlc}
        </if>
        <if test="createTime != null">
             and t.create_time = #{createTime}
        </if>
        <if test="remark != null and remark != ''">
             and t.remark = #{remark}
        </if>
    </select>
	<select id="getRptAretMonitor" resultType="com.huatek.busi.entity.RptAretMonitor">
		SELECT
        	<include refid="Base_Column_List"/>
        FROM
        	rpt_aret_monitor t
        WHERE t.sub_tree_id = #{subTreeId}
	</select>
	<!-- 获取避雷器实时监测数据 -->
	<select id="getUptoDateRptAretMonitor" parameterType="com.huatek.busi.dto.RptAretMonitorDto" resultType="com.huatek.busi.vo.RptAretMonitorVo">
        SELECT
        <include refid="Base_Column_List2"/>
        FROM
        rpt_aret_monitor t
       <where>
	        <if test="siteId != null and siteId != ''">
	             and t.site_id = #{siteId}
	        </if>
	        <if test="sensorId != null and sensorId != ''">
	             and (
	             		t.a_sensor_id = #{sensorId}
	             		OR t.b_sensor_id = #{sensorId}
	             		OR t.c_sensor_id = #{sensorId}
	             	  )
	        </if>
	        
       </where>
    </select>
</mapper>