<?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.hw.ems.base.mapper.BaseDnbThresholdMapper">

    <resultMap type="BaseDnbThreshold" id="BaseDnbThresholdResult">
        <result property="objid"    column="objid"    />
        <result property="monitorId"    column="monitor_id"    />
        <result property="monitorName"    column="monitor_name"    />
        <result property="iAMax"    column="i_a_max"    />
        <result property="iAMin"    column="i_a_min"    />
        <result property="iBMax"    column="i_b_max"    />
        <result property="iBMin"    column="i_b_min"    />
        <result property="iCMax"    column="i_c_max"    />
        <result property="iCMin"    column="i_c_min"    />
        <result property="vAMax"    column="v_a_max"    />
        <result property="vAMin"    column="v_a_min"    />
        <result property="vBMax"    column="v_b_max"    />
        <result property="vBMin"    column="v_b_min"    />
        <result property="vCMax"    column="v_c_max"    />
        <result property="vCMin"    column="v_c_min"    />
        <result property="hourConsumption"    column="hour_consumption"    />
        <result property="dayConsumption"    column="day_consumption"    />
        <result property="lineLossRate"    column="line_loss_rate"    />
        <result property="thresholdStatus"    column="threshold_status"    />
        <result property="deptId"    column="dept_id"    />
        <result property="userId"    column="user_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBaseDnbThresholdVo">
        select objid, monitor_id, i_a_max, i_a_min, i_b_max, i_b_min,
               i_c_max, i_c_min, v_a_max, v_a_min, v_b_max, v_b_min, v_c_max,
               v_c_min, hour_consumption, day_consumption, line_loss_rate, threshold_status, dept_id, user_id,
               create_by, create_time, update_by, update_time
        from base_dnb_threshold
    </sql>

    <select id="selectBaseDnbThresholdList" parameterType="BaseDnbThreshold" resultMap="BaseDnbThresholdResult">
        select t.objid, t.monitor_id,mi.monitor_name, t.i_a_max, t.i_a_min, t.i_b_max, t.i_b_min,
        t.i_c_max, t.i_c_min, t.v_a_max, t.v_a_min, t.v_b_max, t.v_b_min, t.v_c_max,
        t.v_c_min, t.line_loss_rate, t.threshold_status, t.dept_id, t.user_id,
        t.create_by, t.create_time, t.update_by, t.update_time, t.hour_consumption, t.day_consumption
        from base_dnb_threshold t
        left join base_monitor_info mi on mi.monitor_id = t.monitor_id
        <where>
            <if test="monitorId != null  and monitorId != ''"> and t.monitor_id = #{monitorId}</if>
            <if test="iAMax != null "> and t.i_a_max = #{iAMax}</if>
            <if test="iAMin != null "> and t.i_a_min = #{iAMin}</if>
            <if test="iBMax != null "> and t.i_b_max = #{iBMax}</if>
            <if test="iBMin != null "> and t.i_b_min = #{iBMin}</if>
            <if test="iCMax != null "> and t.i_c_max = #{iCMax}</if>
            <if test="iCMin != null "> and t.i_c_min = #{iCMin}</if>
            <if test="vAMax != null "> and t.v_a_max = #{vAMax}</if>
            <if test="vAMin != null "> and t.v_a_min = #{vAMin}</if>
            <if test="vBMax != null "> and t.v_b_max = #{vBMax}</if>
            <if test="vBMin != null "> and t.v_b_min = #{vBMin}</if>
            <if test="vCMax != null "> and t.v_c_max = #{vCMax}</if>
            <if test="vCMin != null "> and t.v_c_min = #{vCMin}</if>
            <if test="lineLossRate != null "> and t.line_loss_rate = #{lineLossRate}</if>
            <if test="thresholdStatus != null "> and t.threshold_status = #{thresholdStatus}</if>
            <if test="deptId != null "> and t.dept_id = #{deptId}</if>
            <if test="userId != null "> and t.user_id = #{userId}</if>
        </where>
    </select>

    <select id="selectBaseDnbThresholdByObjid" parameterType="Long" resultMap="BaseDnbThresholdResult">
        <include refid="selectBaseDnbThresholdVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBaseDnbThreshold" parameterType="BaseDnbThreshold" useGeneratedKeys="true" keyProperty="objid">
        insert into base_dnb_threshold
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="monitorId != null">monitor_id,</if>
            <if test="iAMax != null">i_a_max,</if>
            <if test="iAMin != null">i_a_min,</if>
            <if test="iBMax != null">i_b_max,</if>
            <if test="iBMin != null">i_b_min,</if>
            <if test="iCMax != null">i_c_max,</if>
            <if test="iCMin != null">i_c_min,</if>
            <if test="vAMax != null">v_a_max,</if>
            <if test="vAMin != null">v_a_min,</if>
            <if test="vBMax != null">v_b_max,</if>
            <if test="vBMin != null">v_b_min,</if>
            <if test="vCMax != null">v_c_max,</if>
            <if test="vCMin != null">v_c_min,</if>
            <if test="hourConsumption != null">hour_consumption,</if>
            <if test="dayConsumption != null">day_consumption,</if>
            <if test="lineLossRate != null">line_loss_rate,</if>
            <if test="thresholdStatus != null">threshold_status,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="monitorId != null">#{monitorId},</if>
            <if test="iAMax != null">#{iAMax},</if>
            <if test="iAMin != null">#{iAMin},</if>
            <if test="iBMax != null">#{iBMax},</if>
            <if test="iBMin != null">#{iBMin},</if>
            <if test="iCMax != null">#{iCMax},</if>
            <if test="iCMin != null">#{iCMin},</if>
            <if test="vAMax != null">#{vAMax},</if>
            <if test="vAMin != null">#{vAMin},</if>
            <if test="vBMax != null">#{vBMax},</if>
            <if test="vBMin != null">#{vBMin},</if>
            <if test="vCMax != null">#{vCMax},</if>
            <if test="vCMin != null">#{vCMin},</if>
            <if test="hourConsumption != null">#{hourConsumption},</if>
            <if test="dayConsumption != null">#{dayConsumption},</if>
            <if test="lineLossRate != null">#{lineLossRate},</if>
            <if test="thresholdStatus != null">#{thresholdStatus},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateBaseDnbThreshold" parameterType="BaseDnbThreshold">
        update base_dnb_threshold
        <trim prefix="SET" suffixOverrides=",">
            <if test="monitorId != null">monitor_id = #{monitorId},</if>
            <if test="iAMax != null">i_a_max = #{iAMax},</if>
            <if test="iAMin != null">i_a_min = #{iAMin},</if>
            <if test="iBMax != null">i_b_max = #{iBMax},</if>
            <if test="iBMin != null">i_b_min = #{iBMin},</if>
            <if test="iCMax != null">i_c_max = #{iCMax},</if>
            <if test="iCMin != null">i_c_min = #{iCMin},</if>
            <if test="vAMax != null">v_a_max = #{vAMax},</if>
            <if test="vAMin != null">v_a_min = #{vAMin},</if>
            <if test="vBMax != null">v_b_max = #{vBMax},</if>
            <if test="vBMin != null">v_b_min = #{vBMin},</if>
            <if test="vCMax != null">v_c_max = #{vCMax},</if>
            <if test="vCMin != null">v_c_min = #{vCMin},</if>
            <if test="hourConsumption != null">hour_consumption = #{hourConsumption},</if>
            <if test="dayConsumption != null">day_consumption = #{dayConsumption},</if>
            <if test="lineLossRate != null">line_loss_rate = #{lineLossRate},</if>
            <if test="thresholdStatus != null">threshold_status = #{thresholdStatus},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where objid = #{objid}
    </update>

    <delete id="deleteBaseDnbThresholdByObjid" parameterType="Long">
        delete from base_dnb_threshold where objid = #{objid}
    </delete>

    <delete id="deleteBaseDnbThresholdByObjids" parameterType="String">
        delete from base_dnb_threshold where objid in
        <foreach item="objid" collection="array" open="(" separator="," close=")">
            #{objid}
        </foreach>
    </delete>
</mapper>
