<?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.sqx.modules.message.dao.MessageInfoDao">

    <update id="updateSendState">
          update message_info s set s.is_see=2 where s.is_see=0
        <if test="userId!=null">
            and s.user_id=#{userId}
        </if>
    </update>
    <select id="selectMessageByUserIdLimit1" resultType="com.sqx.modules.message.entity.MessageInfo">
        select *
        from message_info
        where user_id = #{userId}
           and state!=20 and state!=3 and state!=6
        ORDER BY create_at DESC LIMIT 1
    </select>
    <select id="selectComplaintByType" resultType="com.sqx.modules.message.entity.MessageInfo">
        SELECT
            m.*,
            IFNULL(u.user_name, "用户不存在") AS byUserName
        FROM
            message_info m
                LEFT JOIN tb_user u
                          ON m.by_user_id = u.user_id
        WHERE (m.state=3 or m.state=6)
        <if test="messageInfo.userName!=null and messageInfo.userName!=''">
            and u.user_name like concat("%",#{messageInfo.userName},"%")
        </if>
        <if  test="messageInfo.state!=null and messageInfo.state!=''">
            and m.state = #{messageInfo.state}
        </if>
        order by m.create_at desc
    </select>


</mapper>