<?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.house365.ws.dao.mapper.UserMessageMapper">

    <resultMap id="infoMap" type="com.house365.beans.entity.UserMessageEntity">
        <result property="id" column="id"/>
        <result property="sender" column="sender"/>
        <result property="receiver" column="receiver"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="sqlId">
        id,sender,receiver,create_time,update_time
    </sql>

    <select id="getById" resultMap="infoMap" parameterType="Integer">
        SELECT
        <include refid="sqlId"/>
        FROM
        user_message
        where id = #{id}
    </select>

    <select id="queryByConditions" resultMap="infoMap" parameterType="map">
        SELECT
        <include refid="sqlId"/>
        FROM user_message
        where 1 = 1
        <if test="sender != null and sender != ''">
            AND sender = #{sender}
        </if>
        <if test="receiver != null and receiver != ''">
            AND receiver = #{receiver}
        </if>
        <if test="order != null and order >= 0">
            ORDER BY update_time DESC
        </if>
    </select>

    <insert id="save" parameterType="com.house365.beans.entity.UserMessageEntity">
        insert into user_message (sender,receiver,create_time,update_time)
        values
        ( #{sender},#{receiver},#{createTime},#{updateTime} )
    </insert>

    <update id="update" parameterType="com.house365.beans.entity.UserMessageEntity">
        UPDATE user_message
        SET
        update_time = #{updateTime}
        WHERE id = #{id}
    </update>

</mapper>