<?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.zehong.system.mapper.TMonitorDeviceMapper">
    
    <resultMap type="TMonitorDevice" id="TMonitorDeviceResult">
        <result property="monitorId"    column="monitor_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="deviceThreshold"    column="device_threshold"    />
        <result property="relationPipeId"    column="relation_pipe_id"    />
        <result property="relationPipeThreshold"    column="relation_pipe_threshold"    />
        <result property="relationDeviceId"    column="relation_device_id"    />
        <result property="relationDeviceThreshold"    column="relation_device_threshold"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTMonitorDeviceVo">
        select monitor_id, device_id, device_threshold, relation_pipe_id, relation_pipe_threshold, relation_device_id, relation_device_threshold, create_time, update_time from t_monitor_device
    </sql>

    <select id="selectTMonitorDeviceList" parameterType="TMonitorDevice" resultMap="TMonitorDeviceResult">
        <include refid="selectTMonitorDeviceVo"/>
        <where>  
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="deviceThreshold != null "> and device_threshold = #{deviceThreshold}</if>
            <if test="relationPipeId != null "> and relation_pipe_id = #{relationPipeId}</if>
            <if test="relationPipeThreshold != null "> and relation_pipe_threshold = #{relationPipeThreshold}</if>
            <if test="relationDeviceId != null "> and relation_device_id = #{relationDeviceId}</if>
            <if test="relationDeviceThreshold != null "> and relation_device_threshold = #{relationDeviceThreshold}</if>
        </where>
    </select>
    
    <select id="selectTMonitorDeviceById" parameterType="Long" resultMap="TMonitorDeviceResult">
        <include refid="selectTMonitorDeviceVo"/>
        where monitor_id = #{monitorId}
    </select>
        
    <insert id="insertTMonitorDevice" parameterType="TMonitorDevice" useGeneratedKeys="true" keyProperty="monitorId">
        insert into t_monitor_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="deviceThreshold != null">device_threshold,</if>
            <if test="relationPipeId != null">relation_pipe_id,</if>
            <if test="relationPipeThreshold != null">relation_pipe_threshold,</if>
            <if test="relationDeviceId != null">relation_device_id,</if>
            <if test="relationDeviceThreshold != null">relation_device_threshold,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceThreshold != null">#{deviceThreshold},</if>
            <if test="relationPipeId != null">#{relationPipeId},</if>
            <if test="relationPipeThreshold != null">#{relationPipeThreshold},</if>
            <if test="relationDeviceId != null">#{relationDeviceId},</if>
            <if test="relationDeviceThreshold != null">#{relationDeviceThreshold},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateTMonitorDevice" parameterType="TMonitorDevice">
        update t_monitor_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceThreshold != null">device_threshold = #{deviceThreshold},</if>
            <if test="relationPipeId != null">relation_pipe_id = #{relationPipeId},</if>
            <if test="relationPipeThreshold != null">relation_pipe_threshold = #{relationPipeThreshold},</if>
            <if test="relationDeviceId != null">relation_device_id = #{relationDeviceId},</if>
            <if test="relationDeviceThreshold != null">relation_device_threshold = #{relationDeviceThreshold},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where monitor_id = #{monitorId}
    </update>

    <delete id="deleteTMonitorDeviceById" parameterType="Long">
        delete from t_monitor_device where monitor_id = #{monitorId}
    </delete>

    <delete id="deleteTMonitorDeviceByIds" parameterType="String">
        delete from t_monitor_device where monitor_id in 
        <foreach item="monitorId" collection="array" open="(" separator="," close=")">
            #{monitorId}
        </foreach>
    </delete>
</mapper>