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

	<resultMap id="BaseResultMap" type="com.huatek.busi.entity.BusiTransformerLoad">
		<id column="id" jdbcType="VARCHAR" property="id" />
		<result column="site_id" jdbcType="VARCHAR" property="siteId" />
		<result column="equipment_id" jdbcType="VARCHAR" property="equipmentId" />
		<result column="main_tree_id" jdbcType="VARCHAR" property="mainTreeId" />
		<result column="load_rate" jdbcType="VARCHAR" property="loadRate" />
		<result column="load_time" jdbcType="DATE" property="loadTime" />
	</resultMap>


	<sql id="Base_Column_List">
		id, site_id, equipment_id, main_tree_id, load_rate, load_time
	</sql>

	<select id="getLoaByEquipmentIdAndDate" resultMap="BaseResultMap">
		SELECT
		<include refid="Base_Column_List" />
		FROM
		busi_transformer_load t
		<where>
			<if test="siteId != null  and siteId !='' ">
				t.site_id = #{siteId}
			</if>
			<if test="equipmentId != null and equipmentId !='' ">
				AND t.equipment_id = #{equipmentId}
			</if>
			<if test="loadTime != null">
				and load_time <![CDATA[=]]> #{loadTime}
			</if>
		</where>
	</select>


	<select id="getLoaByEquipmentIdAndDates" resultMap="BaseResultMap">
		SELECT
		<include refid="Base_Column_List" />
		FROM
		busi_transformer_load t
		<where>
			<if test="siteId != null  and siteId !='' ">
				t.site_id = #{siteId}
			</if>
			<if test="equipmentId != null and equipmentId !='' ">
				AND t.equipment_id = #{equipmentId}
			</if>
			<if test="startTime != null">
				and load_time <![CDATA[>=]]> #{startTime}
			</if>
			<if test="endTime != null">
				and load_time <![CDATA[<=]]> #{endTime}
			</if>
		</where>
	</select>

	<select id="getLoadRate" resultType="java.lang.String">
		select
			t.load_rate
		from 
			busi_transformer_load t
		where
			t.main_tree_id = #{mainTreeId} and t.load_time = #{loadTime}
		limit 1
	</select>
</mapper>