<?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.ruoyi.ems.base.mapper.EmsBaseMonitorThresholdMapper">

    <resultMap type="EmsBaseMonitorThreshold" id="EmsBaseMonitorThresholdResult">
        <result property="objId" column="obj_id"/>
        <result property="monitorCode" column="monitor_code"/>
        <result property="monitorType" column="monitor_type"/>
        <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="isFlag" column="is_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="monitorName" column="monitor_name"/>
    </resultMap>

    <sql id="selectEmsBaseMonitorThresholdVo">
        select ebmt.obj_id,
               ebmt.monitor_code,
               ebmi.monitor_name,
               ebmt.monitor_type,
               ebmt.i_a_max,
               ebmt.i_a_min,
               ebmt.i_b_max,
               ebmt.i_b_min,
               ebmt.i_c_max,
               ebmt.i_c_min,
               ebmt.v_a_max,
               ebmt.v_a_min,
               ebmt.v_b_max,
               ebmt.v_b_min,
               ebmt.v_c_max,
               ebmt.v_c_min,
               ebmt.hour_consumption,
               ebmt.day_consumption,
               ebmt.line_loss_rate,
               ebmt.is_flag,
               ebmt.create_by,
               ebmt.create_time,
               ebmt.update_by,
               ebmt.update_time
        from ems_base_monitor_threshold ebmt
                 left join ems_base_monitor_info ebmi on ebmi.monitor_code = ebmt.monitor_code
    </sql>

    <select id="selectEmsBaseMonitorThresholdList" parameterType="EmsBaseMonitorThreshold"
            resultMap="EmsBaseMonitorThresholdResult">
        <include refid="selectEmsBaseMonitorThresholdVo"/>
        <where>
            <if test="monitorCode != null  and monitorCode != ''">and ebmt.monitor_code = #{monitorCode}</if>
            <if test="monitorType != null ">and ebmt.monitor_type = #{monitorType}</if>
            <if test="hourConsumption != null ">and ebmt.hour_consumption = #{hourConsumption}</if>
            <if test="dayConsumption != null ">and ebmt.day_consumption = #{dayConsumption}</if>
            <if test="lineLossRate != null ">and ebmt.line_loss_rate = #{lineLossRate}</if>
            <if test="isFlag != null  and isFlag != ''">and ebmt.is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectEmsBaseMonitorThresholdByObjId" parameterType="Long" resultMap="EmsBaseMonitorThresholdResult">
        <include refid="selectEmsBaseMonitorThresholdVo"/>
        where ebmt.obj_id = #{objId}
    </select>

    <insert id="insertEmsBaseMonitorThreshold" parameterType="EmsBaseMonitorThreshold" useGeneratedKeys="true"
            keyProperty="objId">
        insert into ems_base_monitor_threshold
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="monitorCode != null and monitorCode != ''">monitor_code,</if>
            <if test="monitorType != null">monitor_type,</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="isFlag != null">is_flag,</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="monitorCode != null and monitorCode != ''">#{monitorCode},</if>
            <if test="monitorType != null">#{monitorType},</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="isFlag != null">#{isFlag},</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="updateEmsBaseMonitorThreshold" parameterType="EmsBaseMonitorThreshold">
        update ems_base_monitor_threshold
        <trim prefix="SET" suffixOverrides=",">
            <if test="monitorCode != null and monitorCode != ''">monitor_code = #{monitorCode},</if>
            <if test="monitorType != null">monitor_type = #{monitorType},</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="isFlag != null">is_flag = #{isFlag},</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 obj_id = #{objId}
    </update>

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

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