<?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.MessageLogMapper">

    <resultMap id="infoMap" type="com.house365.beans.entity.MessageLogEntity">
        <result property="id" column="id"/>
        <result property="relateId" column="relate_id"/>
        <result property="sender" column="sender"/>
        <result property="receiver" column="receiver"/>
        <result property="messageTime" column="message_time"/>
        <result property="mobile" column="mobile"/>
        <result property="sendTime" column="send_time"/>
        <result property="messageInfo" column="message_info"/>
        <result property="sendStatus" column="send_status"/>
    </resultMap>


    <insert id="save" parameterType="com.house365.beans.entity.MessageLogEntity">
        INSERT INTO message_log (
            relate_id,
            sender,
            receiver,
            message_time,
            mobile,
            send_time,
            message_info,
            send_status
        )
        VALUES (
            #{relateId},
            #{sender},
            #{receiver},
            #{messageTime},
            #{mobile},
            #{sendTime},
            #{messageInfo},
            #{sendStatus}
        )
    </insert>

    <select id="queryByConditions" resultMap="infoMap" parameterType="map">
        SELECT *
        FROM message_log
        where 1 = 1
        AND send_time BETWEEN (SELECT SUBDATE(#{time},INTERVAL 8 HOUR )) AND #{time}
        <if test="sender != null and sender != ''">
            AND sender = #{sender}
        </if>
        <if test="receiver != null and receiver != ''">
            AND receiver = #{receiver}
        </if>
    </select>

</mapper>