<?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.reghao.tnb.user.app.db.mapper.UserMessageMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into user_message
        (`msg_type`,`message_id`,`title`,`content`,`unread`,`user_id`)
        values 
        (#{msgType},#{messageId},#{title},#{content},#{unread},#{userId})
    </insert>

    <update id="updateSetRead">
        update user_message
        set update_time=now(),unread=0
        where message_id=#{messageId}
    </update>

    <select id="countByUnread" resultType="java.lang.Integer">
        select count(*)
        from user_message
        where unread is true and user_id=#{userId}
    </select>
    <select id="findByUnread" resultType="cn.reghao.tnb.user.app.model.po.UserMessage">
        select *
        from user_message
        where unread is true and user_id=#{userId}
    </select>
    <select id="findByMessageId" resultType="cn.reghao.tnb.user.app.model.po.UserMessage">
        select *
        from user_message
        where message_id=#{messageId}
    </select>
</mapper>
