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

    <resultMap type="BaseWaterThreshold" id="BaseWaterThresholdResult">
        <result property="objid"    column="objid"    />
        <result property="monitorId"    column="monitor_id"    />
        <result property="monitorName"    column="monitor_name"    />
        <result property="maxTraffic"    column="max_traffic"    />
        <result property="minTraffic"    column="min_traffic"    />
        <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="selectBaseWaterThresholdVo">
        select objid, monitor_id, monitor_name, line_loss_rate, max_traffic, min_traffic, hour_consumption, day_consumption,
               threshold_status, dept_id, user_id, create_by, create_time,
               update_by, update_time
        from base_water_threshold
    </sql>

    <select id="selectBaseWaterThresholdList" parameterType="BaseWaterThreshold" resultMap="BaseWaterThresholdResult">
        select t.objid, t.monitor_id, mi.monitor_name, t.line_loss_rate, t.max_traffic, t.min_traffic, t.hour_consumption, t.day_consumption,
           t.threshold_status, t.dept_id, t.user_id, t.create_by, t.create_time,
           t.update_by, t.update_time
        from base_water_threshold t
        left join base_monitor_info mi on mi.monitor_id = t.monitor_id
        <where>
            <if test="monitorId != null  and monitorId != ''"> and monitor_id = #{monitorId}</if>
            <if test="monitorName != null  and monitorName != ''"> and monitor_name like concat('%', #{monitorName}, '%')</if>
            <if test="lineLossRate != null "> and line_loss_rate = #{lineLossRate}</if>
            <if test="thresholdStatus != null "> and threshold_status = #{thresholdStatus}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>

    <select id="selectBaseWaterThresholdByObjid" parameterType="Long" resultMap="BaseWaterThresholdResult">
        <include refid="selectBaseWaterThresholdVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBaseWaterThreshold" parameterType="BaseWaterThreshold" useGeneratedKeys="true" keyProperty="objid">
        insert into base_water_threshold
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="monitorId != null">monitor_id,</if>
            <if test="monitorName != null">monitor_name,</if>
            <if test="maxTraffic != null">max_traffic,</if>
            <if test="minTraffic != null">min_traffic,</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="monitorName != null">#{monitorName},</if>
            <if test="maxTraffic != null">#{maxTraffic},</if>
            <if test="minTraffic != null">#{minTraffic},</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="updateBaseWaterThreshold" parameterType="BaseWaterThreshold">
        update base_water_threshold
        <trim prefix="SET" suffixOverrides=",">
            <if test="monitorId != null">monitor_id = #{monitorId},</if>
            <if test="monitorName != null">monitor_name = #{monitorName},</if>
            <if test="maxTraffic != null">max_traffic = #{maxTraffic},</if>
            <if test="minTraffic != null">min_traffic = #{minTraffic},</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="deleteBaseWaterThresholdByObjid" parameterType="Long">
        delete from base_water_threshold where objid = #{objid}
    </delete>

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