<?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.wzpmc.dao.ChatDao">
    <insert id="sendMessage" parameterType="cn.wzpmc.pojo.Message" useGeneratedKeys="true" keyProperty="id">
        insert into message
        set content=#{content},
            sender=#{sender},
            type=#{type},
            sendtime=#{sendtime};
    </insert>
    <update id="recall" parameterType="cn.wzpmc.pojo.Message">
        update message
        set recall=1
        where id = #{id};
    </update>
    <select id="getMessage" resultType="cn.wzpmc.pojo.Message">
        select m.*,u.base64 from message m inner join user u on u.username = m.sender where m.id >= #{id_min} and m.recall = 0 order by m.id desc limit #{count};
    </select>
    <select id="getUserHeadPortrait" resultType="java.lang.String">
        select `base64` from user where BINARY `username`=#{username};
    </select>
    <select id="getCount" resultType="java.lang.Integer">
        select COUNT(*) from message;
    </select>
    <select id="getNewMessage" resultType="cn.wzpmc.pojo.Message">
        select m.*,u.base64 from message m inner join user u on u.username = m.sender where m.id >= #{id_min} and m.id &lt;= #{id_max} and m.recall = 0 order by m.id desc limit #{count};
    </select>
</mapper>