<?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.IecBydworkParamMapper">
    <sql id="Base_Column_List">
		id as id,
		site_id as siteId,
		eqm_code as eqmCode,
		stype as stype,
		start_time as startTime,
		stop_time as stopTime,
		higth_voltage as higthVoltage,
		higthCurrent as higthCurrent,
		record_date as recordDate,
		ins_date as insDate
	</sql>

    <resultMap id="BaseResultMap" type="com.huatek.busi.entity.IecBydworkParam">
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <result column="site_id" jdbcType="VARCHAR" property="siteId"/>
        <result column="eqm_code" jdbcType="VARCHAR" property="eqmCode"/>
        <result column="system_code" jdbcType="VARCHAR" property="systemCode"/>
        <result column="stype" jdbcType="INTEGER" property="stype"/>
        <result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
        <result column="stop_time" jdbcType="TIMESTAMP" property="stopTime"/>
        <result column="higth_voltage" jdbcType="DECIMAL" property="higthVoltage"/>
        <result column="higth_current" jdbcType="DECIMAL" property="higthCurrent"/>
        <result column="record_date" jdbcType="TIMESTAMP" property="recordDate"/>
        <result column="ins_date" jdbcType="TIMESTAMP" property="insDate"/>
    </resultMap>


    <select id="getOneData" parameterType="com.huatek.busi.entity.IecBydworkParam"
            resultType="com.huatek.busi.entity.IecBydworkParam">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        iec_bydwork_param t
        WHERE 1=1
        <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="stype != null and stype != ''">
            and t.stype = #{stype}
        </if>
        <if test="startTime != null and startTime != ''">
            and t.start_time = #{startTime}
        </if>
        <if test="stopTime != null and stopTime != ''">
            and t.stop_time = #{stopTime}
        </if>
        <if test="higthVoltage != null and higthVoltage != ''">
            and t.higth_voltage = #{higthVoltage}
        </if>
        <if test="higthCurrent != null and higthCurrent != ''">
            and t.higthCurrent = #{higthCurrent}
        </if>

        <if test="recordDate != null and recordDate != ''">
            and t.record_date = #{recordDate}
        </if>
        <if test="insDate != null and insDate != ''">
            and t.ins_date = #{insDate}
        </if>
    </select>

    <select id="getIecType" resultType="com.huatek.busi.entity.IecBydworkParam">
		SELECT
		*
		FROM
		iec_bydwork_param t
		WHERE
		t.eqm_code = #{eqmCode}
        and t.start_time &lt;= #{cacDate}
		and t.stop_time &gt;= #{cacDate}
		ORDER BY t.stop_time desc
		limit 0, 1
	</select>


    <select id="getIecType2" resultType="com.huatek.busi.entity.IecBydworkParam">
		SELECT
		*
		FROM
		iec_bydwork_param t
		WHERE
		t.eqm_code = #{eqmCode}
		OR
        t.system_code = #{eqmCode}
		ORDER BY t.stop_time desc
		limit 0, 1
	</select>

    <!-- 获取变压器前一天到当天工作集合 -->
    <select id="getBeforToCurrenttWork" resultMap="BaseResultMap">
        SELECT
        *
        FROM
        `iec_bydwork_param` t
        <where>
            <if test="siteId != null  and siteId !='' ">
                t.site_id = #{siteId}
            </if>
            <if test="eqmCode != null and eqmCode !='' ">
                AND t.eqm_code = #{eqmCode}
            </if>
            <if test="startTime != null">
                AND t.start_time <![CDATA[>]]>#{startTime}
            </if>
            <if test="endTime != null">
                AND t.stop_time <![CDATA[<]]>#{endTime}
            </if>
        </where>
    </select>

    <!-- 获取变压器前一天到当天工作集合 -->
    <select id="getIecBydworkParamWorks" resultMap="BaseResultMap">
        SELECT
        *
        FROM
        `iec_bydwork_param` t
        <where>
            <if test="siteId != null  and siteId !='' ">
                t.site_id = #{siteId}
            </if>
            <if test="eqmCode != null and eqmCode !='' ">
                AND t.eqm_code = #{eqmCode}
            </if>
            <if test="startTime != null">
                AND t.start_time <![CDATA[>=]]>#{startTime}
            </if>
            <if test="endTime != null">
                AND t.stop_time <![CDATA[<]]>#{endTime}
            </if>
        </where>
    </select>


    <!-- 获取变压器当天工作集合 -->
    <select id="getCurrnetWork" resultMap="BaseResultMap">
        SELECT
        *
        FROM
        `iec_bydwork_param` t
        <where>
            <if test="siteId != null  and siteId !='' ">
                t.site_id = #{siteId}
            </if>
            <if test="eqmCode != null and eqmCode !='' ">
                AND t.eqm_code = #{eqmCode}
            </if>
            <if test="startTime != null">
                AND t.start_time <![CDATA[>=]]>#{startTime}
            </if>
            <if test="endTime != null">
                AND t.stop_time <![CDATA[<]]>#{endTime}
            </if>

        </where>
    </select>

    <!--获取变压器前一天到当天工作集合  -->
    <select id="getCurrentToAfterWork" resultMap="BaseResultMap">
        SELECT
        *
        FROM
        `iec_bydwork_param` t
        <where>
            <if test="siteId != null  and siteId !='' ">
                t.site_id = #{siteId}
            </if>
            <if test="eqmCode != null and eqmCode !='' ">
                AND t.eqm_code = #{eqmCode}
            </if>
            <if test="startTime != null">
                AND t.start_time <![CDATA[>]]>#{startTime}
            </if>
            <if test="endTime != null">
                AND t.stop_time <![CDATA[<]]>#{endTime}
            </if>
        </where>
    </select>

    <select id="getIecBydworkParam" resultType="com.huatek.busi.entity.IecBydworkParam">
		SELECT
		  t.stype as stype,
		  t.higth_voltage as higthVoltage,
		  t.higth_current as higthCurrent,
		  t.record_date as recordDate
		FROM iec_bydwork_param t
		WHERE t.eqm_code = #{equipmentId}
		AND t.start_time &lt;= #{time}
		AND t.stop_time &gt;= #{time}
		ORDER BY t.start_time DESC
		LIMIT 1
	</select>

    <select id="queryIecBydworkParamPointList" parameterType="com.huatek.busi.dto.curve.IecBydworkParamPointDto"
            resultType="com.huatek.busi.vo.curve.IecBydworkParamPointVo">
		SELECT
		  t.stype,
		  t.start_time AS startTime,
		  t.stop_time AS stopTime,
		  t.higth_voltage AS higthVoltage,
		  t.higth_current AS higthCurrent
		FROM iec_bydwork_param t
		WHERE t.site_id = #{siteId}
		AND t.eqm_code = #{transformerId}
		AND t.start_time &gt;= #{startTime}
		AND t.stop_time &lt; #{endTime}
		ORDER BY t.start_time ASC
	</select>

    <select id="getdworkParamByEqmCode" resultType="com.huatek.busi.vo.curve.IecBydworkParamPointVo">
		SELECT t.stype,t.higth_voltage AS higthVoltage,t.higth_current AS higthCurrent FROM (
		(SELECT * FROM iec_bydwork_param WHERE eqm_code = #{eqmCode} AND stype = 1 ORDER BY record_date DESC LIMIT 1)
		UNION
		(SELECT * FROM iec_bydwork_param WHERE eqm_code = #{eqmCode} AND stype = 2 ORDER BY record_date DESC LIMIT 1 )) t
	</select>

    <!-- 获取变压器前一天工作集合 -->
    <select id="getIecBydworkParamWorksCal" resultMap="BaseResultMap">
        SELECT
        *
        FROM
        `iec_bydwork_param` t
        <where>
            <if test="stype != null and stype !='' ">
                AND t.stype = #{stype}
            </if>
            <if test="recordDate != null and recordDate != ''">
                and date_format( t.record_date,'%y%m%d') =date_format( #{recordDate},'%y%m%d')
            </if>
        </where>
    </select>

</mapper>