<?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.aucma.report.mapper.BoxTemperatureHistoryMapper">

    <resultMap type="BoxTemperatureHistory" id="BoxTemperatureHistoryResult">
        <result property="objId" column="obj_id"/>
        <result property="lineNo" column="line_no"/>
        <result property="gongwno" column="gongwno"/>
        <result property="cpno" column="cpno"/>
        <result property="cpmodel" column="cpmodel"/>
        <result property="factorymodel" column="factorymodel"/>
        <result property="voltage" column="voltage"/>
        <result property="point2" column="point2"/>
        <result property="testtime" column="testtime"/>
        <result property="testedtime" column="testedtime"/>
        <result property="etemp" column="etemp"/>
        <result property="begindatetime" column="begindatetime"/>
        <result property="cpresult" column="cpresult"/>
        <result property="enddatetime" column="enddatetime"/>
        <result property="username" column="username"/>
        <result property="remark" column="remark"/>
        <result property="testno" column="testno"/>
        <result property="tempMes" column="temp_mes"/>
        <result property="powerMes" column="power_mes"/>
        <result property="partMes" column="part_mes"/>
        <result property="isorder" column="isorder"/>
        <result property="lowvTime" column="lowv_time"/>
        <result property="lowvPowermin" column="lowv_powermin"/>
        <result property="lowvPowermax" column="lowv_powermax"/>
        <result property="lowvPowerfact" column="lowv_powerfact"/>
        <result property="lowvoltage" column="lowvoltage"/>
        <result property="syncDatetime" column="sync_datetime"/>
        <result property="frequency" column="frequency"/>
    </resultMap>

    <sql id="selectBoxTemperatureHistoryVo">
        select obj_id,
               line_no,
               gongwno,
               cpno,
               cpmodel,
               factorymodel,
               voltage,
               point2,
               testtime,
               testedtime,
               etemp,
               begindatetime,
               cpresult,
               enddatetime,
               username,
               remark,
               testno,
               temp_mes,
               power_mes,
               part_mes,
               isorder,
               lowv_time,
               lowv_powermin,
               lowv_powermax,
               lowv_powerfact,
               lowvoltage,
               sync_datetime,
               frequency
        from C##AUCMA_SCADA.box_temperaturehistory
    </sql>

    <select id="selectBoxTemperatureHistoryList" parameterType="BoxTemperatureHistory"
            resultMap="BoxTemperatureHistoryResult">
        <include refid="selectBoxTemperatureHistoryVo"/>
        <where>
            <if test="lineNo != null ">and line_no = #{lineNo}</if>
            <if test="gongwno != null ">and gongwno = #{gongwno}</if>
            <if test="cpno != null  and cpno != ''">and cpno = #{cpno}</if>
            <if test="cpmodel != null  and cpmodel != ''">and cpmodel = #{cpmodel}</if>
            <if test="factorymodel != null  and factorymodel != ''">and factorymodel = #{factorymodel}</if>
            <if test="voltage != null ">and voltage = #{voltage}</if>
            <if test="point2 != null  and point2 != ''">and point2 = #{point2}</if>
            <if test="testtime != null ">and testtime = #{testtime}</if>
            <if test="testedtime != null ">and testedtime = #{testedtime}</if>
            <if test="etemp != null ">and etemp = #{etemp}</if>
            <if test="params.beginBegindatetime != null and params.beginBegindatetime != '' and params.endBegindatetime != null and params.endBegindatetime != ''">
                and begindatetime between to_date(#{params.beginBegindatetime}, 'yyyy-mm-dd hh24:mi:ss') and
                to_date(#{params.endBegindatetime}, 'yyyy-mm-dd hh24:mi:ss')
            </if>
            <if test="cpresult != null  and cpresult != ''">and cpresult = #{cpresult}</if>
            <if test="enddatetime != null ">and enddatetime = #{enddatetime}</if>
            <if test="username != null  and username != ''">and username like concat(concat('%', #{username}), '%')</if>
            <if test="testno != null ">and testno = #{testno}</if>
            <if test="tempMes != null  and tempMes != ''">and temp_mes = #{tempMes}</if>
            <if test="powerMes != null  and powerMes != ''">and power_mes = #{powerMes}</if>
            <if test="partMes != null  and partMes != ''">and part_mes = #{partMes}</if>
            <if test="isorder != null  and isorder != ''">and isorder = #{isorder}</if>
            <if test="lowvTime != null ">and lowv_time = #{lowvTime}</if>
            <if test="lowvPowermin != null ">and lowv_powermin = #{lowvPowermin}</if>
            <if test="lowvPowermax != null ">and lowv_powermax = #{lowvPowermax}</if>
            <if test="lowvPowerfact != null ">and lowv_powerfact = #{lowvPowerfact}</if>
            <if test="lowvoltage != null ">and lowvoltage = #{lowvoltage}</if>
            <if test="syncDatetime != null ">and sync_datetime = #{syncDatetime}</if>
            <if test="frequency != null ">and frequency = #{frequency}</if>
        </where>
        order by enddatetime DESC
    </select>

    <select id="selectBoxTemperatureHistoryByObjId" parameterType="Long" resultMap="BoxTemperatureHistoryResult">
        <include refid="selectBoxTemperatureHistoryVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertBoxTemperatureHistory" parameterType="BoxTemperatureHistory">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_box_temperaturehistory.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into box_temperaturehistory
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">obj_id,</if>
            <if test="lineNo != null">line_no,</if>
            <if test="gongwno != null">gongwno,</if>
            <if test="cpno != null">cpno,</if>
            <if test="cpmodel != null">cpmodel,</if>
            <if test="factorymodel != null">factorymodel,</if>
            <if test="voltage != null">voltage,</if>
            <if test="point2 != null">point2,</if>
            <if test="testtime != null">testtime,</if>
            <if test="testedtime != null">testedtime,</if>
            <if test="etemp != null">etemp,</if>
            <if test="begindatetime != null">begindatetime,</if>
            <if test="cpresult != null">cpresult,</if>
            <if test="enddatetime != null">enddatetime,</if>
            <if test="username != null">username,</if>
            <if test="remark != null">remark,</if>
            <if test="testno != null">testno,</if>
            <if test="tempMes != null">temp_mes,</if>
            <if test="powerMes != null">power_mes,</if>
            <if test="partMes != null">part_mes,</if>
            <if test="isorder != null">isorder,</if>
            <if test="lowvTime != null">lowv_time,</if>
            <if test="lowvPowermin != null">lowv_powermin,</if>
            <if test="lowvPowermax != null">lowv_powermax,</if>
            <if test="lowvPowerfact != null">lowv_powerfact,</if>
            <if test="lowvoltage != null">lowvoltage,</if>
            <if test="syncDatetime != null">sync_datetime,</if>
            <if test="frequency != null">frequency,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="lineNo != null">#{lineNo},</if>
            <if test="gongwno != null">#{gongwno},</if>
            <if test="cpno != null">#{cpno},</if>
            <if test="cpmodel != null">#{cpmodel},</if>
            <if test="factorymodel != null">#{factorymodel},</if>
            <if test="voltage != null">#{voltage},</if>
            <if test="point2 != null">#{point2},</if>
            <if test="testtime != null">#{testtime},</if>
            <if test="testedtime != null">#{testedtime},</if>
            <if test="etemp != null">#{etemp},</if>
            <if test="begindatetime != null">#{begindatetime},</if>
            <if test="cpresult != null">#{cpresult},</if>
            <if test="enddatetime != null">#{enddatetime},</if>
            <if test="username != null">#{username},</if>
            <if test="remark != null">#{remark},</if>
            <if test="testno != null">#{testno},</if>
            <if test="tempMes != null">#{tempMes},</if>
            <if test="powerMes != null">#{powerMes},</if>
            <if test="partMes != null">#{partMes},</if>
            <if test="isorder != null">#{isorder},</if>
            <if test="lowvTime != null">#{lowvTime},</if>
            <if test="lowvPowermin != null">#{lowvPowermin},</if>
            <if test="lowvPowermax != null">#{lowvPowermax},</if>
            <if test="lowvPowerfact != null">#{lowvPowerfact},</if>
            <if test="lowvoltage != null">#{lowvoltage},</if>
            <if test="syncDatetime != null">#{syncDatetime},</if>
            <if test="frequency != null">#{frequency},</if>
        </trim>
    </insert>

    <update id="updateBoxTemperatureHistory" parameterType="BoxTemperatureHistory">
        update box_temperaturehistory
        <trim prefix="SET" suffixOverrides=",">
            <if test="lineNo != null">line_no = #{lineNo},</if>
            <if test="gongwno != null">gongwno = #{gongwno},</if>
            <if test="cpno != null">cpno = #{cpno},</if>
            <if test="cpmodel != null">cpmodel = #{cpmodel},</if>
            <if test="factorymodel != null">factorymodel = #{factorymodel},</if>
            <if test="voltage != null">voltage = #{voltage},</if>
            <if test="point2 != null">point2 = #{point2},</if>
            <if test="testtime != null">testtime = #{testtime},</if>
            <if test="testedtime != null">testedtime = #{testedtime},</if>
            <if test="etemp != null">etemp = #{etemp},</if>
            <if test="begindatetime != null">begindatetime = #{begindatetime},</if>
            <if test="cpresult != null">cpresult = #{cpresult},</if>
            <if test="enddatetime != null">enddatetime = #{enddatetime},</if>
            <if test="username != null">username = #{username},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="testno != null">testno = #{testno},</if>
            <if test="tempMes != null">temp_mes = #{tempMes},</if>
            <if test="powerMes != null">power_mes = #{powerMes},</if>
            <if test="partMes != null">part_mes = #{partMes},</if>
            <if test="isorder != null">isorder = #{isorder},</if>
            <if test="lowvTime != null">lowv_time = #{lowvTime},</if>
            <if test="lowvPowermin != null">lowv_powermin = #{lowvPowermin},</if>
            <if test="lowvPowermax != null">lowv_powermax = #{lowvPowermax},</if>
            <if test="lowvPowerfact != null">lowv_powerfact = #{lowvPowerfact},</if>
            <if test="lowvoltage != null">lowvoltage = #{lowvoltage},</if>
            <if test="syncDatetime != null">sync_datetime = #{syncDatetime},</if>
            <if test="frequency != null">frequency = #{frequency},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteBoxTemperatureHistoryByObjId" parameterType="Long">
        delete
        from box_temperaturehistory
        where obj_id = #{objId}
    </delete>

    <delete id="deleteBoxTemperatureHistoryByObjIds" parameterType="String">
        delete from box_temperaturehistory where obj_id in
        <foreach item="objId" collection="array" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </delete>
</mapper>