<?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="cn.ezhizao.project.business.message.mapper.BizMessageMapper">

    <resultMap type="cn.ezhizao.project.business.message.domain.BizMessage" id="BizMessageResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getList" parameterType="BizMessage" resultMap="BizMessageResult">
        SELECT t.*, fu.user_name as from_user_name, fu.nick_name as from_nick_name, tu.user_name as to_user_name,
        tu.nick_name as to_nick_name FROM biz_message t left join sys_user fu on fu.user_id = t.from_user_id
        left join sys_user tu on tu.user_id = t.to_user_id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            1=1
            <if test="fromUserId != null ">AND t.from_user_id = #{fromUserId}</if>
            <if test="toUserId != null ">AND t.to_user_id = #{toUserId}</if>
        </trim>
        order by t.msg_read, t.message_date desc
    </select>

    <delete id="physicalDelete">
        DELETE FROM biz_message
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
            <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
