<?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.toesbieya.jxc.mapper.MsgMapper">
    <select id="getReadByUser" parameterType="cn.toesbieya.jxc.model.vo.search.MsgPersonalSearch"
            resultType="cn.toesbieya.jxc.model.entity.Msg">
        select a.id,
               a.title,
               a.content,
               a.type,
               a.pname,
               a.ptime
        from msg a
                     join msg_state b on a.id = b.mid
        where b.uid = #{uid}
        order by a.id desc
    </select>

    <select id="getUnreadByUser" parameterType="cn.toesbieya.jxc.model.vo.search.MsgPersonalSearch"
            resultType="cn.toesbieya.jxc.model.entity.Msg">
        select id,
               title,
               content,
               type,
               pname,
               ptime
        from msg
        where status = 1
          and ptime <![CDATA[ >= ]]> #{ctime}
          and (broadcast = 1 or broadcast = 0 and find_in_set(recipient, #{uid}))
          and id not in (select mid from msg_state where uid = #{uid})
        order by id desc
    </select>
</mapper>