<?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.TMessageDetailInfoMapper">
    
    <resultMap type="TMessageDetailInfo" id="TMessageDetailInfoResult">
        <result property="messageDetailId"    column="message_detail_id"    />
        <result property="messageId"    column="message_id"    />
        <result property="personId"    column="person_id"    />
        <result property="messageDetailStatus"    column="message_detail_status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result column="person_name" property="personName"/>
    </resultMap>

    <sql id="selectTMessageDetailInfoVo">
        SELECT
            detail.message_detail_id,
            detail.message_id,
            detail.person_id,
            detail.message_detail_status,
            detail.create_time,
            detail.update_time,
            detail.remark,
            (select person_name from t_line_patrol_person person where person.person_id = detail.person_id) as person_name
        FROM
            t_message_detail_info detail
    </sql>

    <select id="selectTMessageDetailInfoList" parameterType="TMessageDetailInfo" resultMap="TMessageDetailInfoResult">
        <include refid="selectTMessageDetailInfoVo"/>
        <where>  
            <if test="messageId != null "> and detail.message_id = #{messageId}</if>
            <if test="personId != null "> and detail.person_id = #{personId}</if>
            <if test="messageDetailStatus != null  and messageDetailStatus != ''"> and detail.message_detail_status = #{messageDetailStatus}</if>
        </where>
    </select>
    
    <select id="selectTMessageDetailInfoById" parameterType="Long" resultMap="TMessageDetailInfoResult">
        <include refid="selectTMessageDetailInfoVo"/>
        where detail.message_detail_id = #{messageDetailId}
    </select>
        
    <insert id="insertTMessageDetailInfo" parameterType="TMessageDetailInfo" useGeneratedKeys="true" keyProperty="messageDetailId">
        insert into t_message_detail_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="messageId != null">message_id,</if>
            <if test="personId != null">person_id,</if>
            <if test="messageDetailStatus != null">message_detail_status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="messageId != null">#{messageId},</if>
            <if test="personId != null">#{personId},</if>
            <if test="messageDetailStatus != null">#{messageDetailStatus},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTMessageDetailInfo" parameterType="TMessageDetailInfo">
        update t_message_detail_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="messageId != null">message_id = #{messageId},</if>
            <if test="personId != null">person_id = #{personId},</if>
            <if test="messageDetailStatus != null">message_detail_status = #{messageDetailStatus},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where message_detail_id = #{messageDetailId}
    </update>

    <delete id="deleteTMessageDetailInfoById" parameterType="Long">
        delete from t_message_detail_info where message_detail_id = #{messageDetailId}
    </delete>

    <delete id="deleteTMessageDetailInfoByIds" parameterType="String">
        delete from t_message_detail_info where message_detail_id in 
        <foreach item="messageDetailId" collection="array" open="(" separator="," close=")">
            #{messageDetailId}
        </foreach>
    </delete>

    <delete id="deleteMessageDetailByMessageId" parameterType="Long">
        delete from t_message_detail_info where message_id = #{messageId}
    </delete>
</mapper>