<?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.TransformerIcgeCacheMapper">

    <sql id="Base_Column_List">
            id as id,
            d_time as dTime,
            phase as phase,
            clamp as clamp,
            total_core_current as totalCoreCurrent,
            sensor_id as sensorId,
            site_id as siteId,
            main_tree_id as mainTreeId,
            sub_tree_id as subTreeId,
            type as type,
            run_status as runStatus,
            warning_value as warningValue
    </sql>
    
    <sql id="Base_Column_List2">
            t.id as id,
            t.d_time as dTime,
            t.phase as phase,
            t.clamp as clamp,
           <!--  t.total_core_current as totalCoreCurrent, -->
            CONVERT(t.total_core_current,DECIMAL(10,4) ) AS totalCoreCurrent,
            t.sensor_id as sensorId,
            t.site_id as siteId,
            t.main_tree_id as mainTreeId,
            t.sub_tree_id as subTreeId,
            t.type as type,
            t.run_status as equipmentStatus,
            t.warning_value as warningValue,
            ts.position_des as installLocation,
            ts.sensor_brand as brand,
            ts.manufactor as manufactor,
            ts.use_date as useDate
            
    </sql>

    <select id="selectTransformerIcgeCachePage" parameterType="com.huatek.busi.dto.TransformerIcgeCacheDto" resultType="com.huatek.busi.vo.TransformerIcgeCacheVo">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        transformer_icge_cache t
        WHERE 1=1
        <if test="id != null and id != ''">
             and t.id = #{id}
        </if>
        <if test="eqmId != null and eqmId != ''">
             and t.eqm_id = #{eqmId}
        </if>
        <if test="dTime != null">
             and t.d_time = #{dTime}
        </if>
        <if test="phase != null and phase != ''">
             and t.phase = #{phase}
        </if>
        <if test="clamp != null and clamp != ''">
             and t.clamp = #{clamp}
        </if>
        <if test="totalCoreCurrent != null and totalCoreCurrent != ''">
             and t.total_core_current = #{totalCoreCurrent}
        </if>
        <if test="cacId != null and cacId != ''">
             and t.cac_id = #{cacId}
        </if>
        <if test="sensorId != null and sensorId != ''">
             and t.sensor_id = #{sensorId}
        </if>
        <if test="siteId != null and siteId != ''">
             and t.site_id = #{siteId}
        </if>
        <if test="siteEqmCode != null and siteEqmCode != ''">
             and t.site_eqm_code = #{siteEqmCode}
        </if>
        <if test="txId != null and txId != ''">
             and t.tx_id = #{txId}
        </if>
        <if test="type != null and type != ''">
             and t.type = #{type}
        </if>
    </select>
	
	<select id="selectByTreeId" resultType="com.huatek.busi.entity.TransformerIcgeCache">
		SELECT
        <include refid="Base_Column_List"/>
        FROM
        transformer_icge_cache t
        WHERE t.main_tree_id = #{mainTreeId} and t.sub_tree_id = #{subTreeId} and t.type = #{type}
	</select>
	<!-- 获取铁芯、夹件实时数据 -->
	<select id="getFirstTransformerIcgeCacheInfo" parameterType="com.huatek.busi.dto.TransformerIcgeCacheDto" resultType="com.huatek.busi.vo.warning.BusiIcgeVo">
        SELECT
        	<include refid="Base_Column_List2"/>
        FROM
        	transformer_icge_cache t
        LEFT JOIN busi_transformer_sensor ts ON t.sensor_id = ts.sensor_code 
        <where>
	        <if test="siteId != null and siteId != ''">
	             and t.site_id = #{siteId}
	        </if>
	        <if test="mainTreeId != null and mainTreeId != ''">
	             and t.main_tree_id = #{mainTreeId}
	        </if>
	        <if test="subTreeId != null and subTreeId != ''">
	             and t.sub_tree_id = #{subTreeId}
	        </if>
	        <if test="sensorId != null and sensorId != ''">
	             and t.sensor_id = #{sensorId}
	        </if>
	        <if test="type != null and type != ''">
	             and t.type = #{type}
	        </if>
        </where>
    </select>
</mapper>