<?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.xinelu.manage.mapper.chatrecordread.ChatRecordReadMapper">

    <resultMap id="BaseResultMap" type="com.xinelu.manage.domain.chatrecordread.ChatRecordRead">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="patientId" column="patient_id" jdbcType="BIGINT"/>
	        <result property="messageCategory" column="message_category" jdbcType="VARCHAR"/>
            <result property="chatRecordId" column="chat_record_id" jdbcType="BIGINT"/>
            <result property="readTime" column="read_time" jdbcType="TIMESTAMP"/>
            <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,patient_id,message_category,chat_record_id,
        read_time,create_by,create_time,
        update_by,update_time
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from chat_record_read
        where  id = #{id,jdbcType=INTEGER} 
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from chat_record_read
        where  id = #{id,jdbcType=INTEGER} 
    </delete>
    <insert id="insertList" keyColumn="id" keyProperty="id" parameterType="com.xinelu.manage.domain.chatrecordread.ChatRecordRead" useGeneratedKeys="true">
        insert into chat_record_read
	    ( id,patient_id,message_category,chat_record_id
	    ,read_time,create_by,create_time
	    ,update_by,update_time)
	    values
        <foreach collection="recordList" item="item" separator=",">
         (#{item.id,jdbcType=INTEGER},#{item.patientId,jdbcType=BIGINT},#{item.messageCategory,jdbcType=VARCHAR},
          #{item.chatRecordId,jdbcType=BIGINT}
        ,#{item.readTime,jdbcType=TIMESTAMP},#{item.createBy,jdbcType=VARCHAR},#{item.createTime,jdbcType=TIMESTAMP}
        ,#{item.updateBy,jdbcType=VARCHAR},#{item.updateTime,jdbcType=TIMESTAMP})
        </foreach>
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.xinelu.manage.domain.chatrecordread.ChatRecordRead" useGeneratedKeys="true">
        insert into chat_record_read
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="id != null">id,</if>
                <if test="patientId != null">patient_id,</if>
	            <if test="messageCategory != null">message_category,</if>
                <if test="chatRecordId != null">chat_record_id,</if>
                <if test="readTime != null">read_time,</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="id != null">#{id,jdbcType=INTEGER},</if>
                <if test="patientId != null">#{patientId,jdbcType=BIGINT},</if>
	            <if test="messageCategory != null">#{messageCategory,jdbcType=VARCHAR},</if>
                <if test="chatRecordId != null">#{chatRecordId,jdbcType=BIGINT},</if>
                <if test="readTime != null">#{readTime,jdbcType=TIMESTAMP},</if>
                <if test="createBy != null">#{createBy,jdbcType=VARCHAR},</if>
                <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
                <if test="updateBy != null">#{updateBy,jdbcType=VARCHAR},</if>
                <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.xinelu.manage.domain.chatrecordread.ChatRecordRead">
        update chat_record_read
        <set>
                <if test="patientId != null">
                    patient_id = #{patientId,jdbcType=BIGINT},
                </if>
		        <if test="messageCategory != null">
			        message_category = #{messageCategory,jdbcType=VARCHAR},
		        </if>
                <if test="chatRecordId != null">
                    chat_record_id = #{chatRecordId,jdbcType=BIGINT},
                </if>
                <if test="readTime != null">
                    read_time = #{readTime,jdbcType=TIMESTAMP},
                </if>
                <if test="createBy != null">
                    create_by = #{createBy,jdbcType=VARCHAR},
                </if>
                <if test="createTime != null">
                    create_time = #{createTime,jdbcType=TIMESTAMP},
                </if>
                <if test="updateBy != null">
                    update_by = #{updateBy,jdbcType=VARCHAR},
                </if>
                <if test="updateTime != null">
                    update_time = #{updateTime,jdbcType=TIMESTAMP},
                </if>
        </set>
        where   id = #{id,jdbcType=INTEGER} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.xinelu.manage.domain.chatrecordread.ChatRecordRead">
        update chat_record_read
        set 
            patient_id =  #{patientId,jdbcType=BIGINT},
            message_category = #{messageCategory,jdbcType=VARCHAR},
            chat_record_id =  #{chatRecordId,jdbcType=BIGINT},
            read_time =  #{readTime,jdbcType=TIMESTAMP},
            create_by =  #{createBy,jdbcType=VARCHAR},
            create_time =  #{createTime,jdbcType=TIMESTAMP},
            update_by =  #{updateBy,jdbcType=VARCHAR},
            update_time =  #{updateTime,jdbcType=TIMESTAMP}
        where   id = #{id,jdbcType=INTEGER} 
    </update>

	<select id="getList" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from chat_record_read
		<where>
			<if test="patientId != null">
				and patient_id = #{patientId,jdbcType=BIGINT}
			</if>
			<if test="messageCategory != null">
				and message_category = #{messageCategory,jdbcType=VARCHAR}
			</if>
			<if test="chatRecordId != null">
				and chat_record_id = #{chatRecordId,jdbcType=BIGINT}
			</if>
			<if test="readTime != null">
				and read_time = #{readTime,jdbcType=TIMESTAMP}
			</if>
		</where>
	</select>
</mapper>
