<?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.inspect.patrol.mapper.PatrolLinkageMessageMapper">
    
    <resultMap type="PatrolLinkageMessage" id="PatrolLinkageMessageResult">
        <result property="linkageMessageId"    column="linkage_message_id"    />
        <result property="type"    column="type"    />
        <result property="stationSerialNumber"    column="station_serial_number"    />
        <result property="monitorIndex"    column="monitor_index"    />
        <result property="content"    column="content"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectPatrolLinkageMessageVo">
        select linkage_message_id, type, station_serial_number, monitor_index, content, create_time from patrol_linkage_message
    </sql>

    <select id="selectPatrolLinkageMessageList" parameterType="PatrolLinkageMessage" resultMap="PatrolLinkageMessageResult">
        <include refid="selectPatrolLinkageMessageVo"/>
        <where>  
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="stationSerialNumber != null "> and station_serial_number = #{stationSerialNumber}</if>
            <if test="monitorIndex != null "> and monitor_index = #{monitorIndex}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
        </where>
    </select>
    
    <select id="selectPatrolLinkageMessageByLinkageMessageId" parameterType="Long" resultMap="PatrolLinkageMessageResult">
        <include refid="selectPatrolLinkageMessageVo"/>
        where linkage_message_id = #{linkageMessageId}
    </select>
        
    <insert id="insertPatrolLinkageMessage" parameterType="PatrolLinkageMessage" useGeneratedKeys="true" keyProperty="linkageMessageId">
        insert into patrol_linkage_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">type,</if>
            <if test="stationSerialNumber != null">station_serial_number,</if>
            <if test="monitorIndex != null">monitor_index,</if>
            <if test="content != null">content,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="stationSerialNumber != null">#{stationSerialNumber},</if>
            <if test="monitorIndex != null">#{monitorIndex},</if>
            <if test="content != null">#{content},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updatePatrolLinkageMessage" parameterType="PatrolLinkageMessage">
        update patrol_linkage_message
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="stationSerialNumber != null">station_serial_number = #{stationSerialNumber},</if>
            <if test="monitorIndex != null">monitor_index = #{monitorIndex},</if>
            <if test="content != null">content = #{content},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where linkage_message_id = #{linkageMessageId}
    </update>

    <delete id="deletePatrolLinkageMessageByLinkageMessageId" parameterType="Long">
        delete from patrol_linkage_message where linkage_message_id = #{linkageMessageId}
    </delete>

    <delete id="deletePatrolLinkageMessageByLinkageMessageIds" parameterType="String">
        delete from patrol_linkage_message where linkage_message_id in 
        <foreach item="linkageMessageId" collection="array" open="(" separator="," close=")">
            #{linkageMessageId}
        </foreach>
    </delete>
</mapper>