<?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.wecloud.im.mapper.ImInboxMapper">

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id
        , create_time, update_time, read_time, receiver_time, fk_appid, receiver, fk_msg_id, read_msg_status, receiver_msg_status, fk_conversation_id
    </sql>
    <update id="updateImMsgReceivedByIds">
        UPDATE im_inbox
        SET `im_inbox`.`update_time` = NOW(),
        `im_inbox`.`receiver_msg_status` = 1,
        `im_inbox`.`receiver_time` = NOW()
        WHERE
        im_inbox.receiver = #{clientId}
        AND im_inbox.fk_msg_id IN
        <foreach collection="msgIds" item="deptId" index="i" open="(" close=")" separator=",">
            #{deptId}
        </foreach>

    </update>
    <update id="updateImMsgReadByIds">
        UPDATE im_inbox
        SET `im_inbox`.`update_time` = NOW(),
        `im_inbox`.`read_msg_status` = 1,
        `im_inbox`.`read_time` = NOW()
        WHERE
        im_inbox.receiver = #{clientId}
        AND im_inbox.fk_msg_id IN
        <foreach collection="msgIds" item="deptId" index="i" open="(" close=")" separator=",">
            #{deptId}
        </foreach>
    </update>

    <select id="getImInboxById" resultType="com.wecloud.im.param.ImInboxQueryVo">
        select
        <include refid="Base_Column_List"/>
        from im_Inbox where id = #{id}
    </select>

    <select id="getImInboxPageList" parameterType="com.wecloud.im.param.ImInboxPageParam"
            resultType="com.wecloud.im.param.ImInboxQueryVo">
        select
        <include refid="Base_Column_List"/>
        from im_Inbox
    </select>

    <select id="countMyNotReadCount" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM im_inbox
        WHERE receiver = #{clientId}
          AND receiver_msg_status = 0
    </select>

</mapper>
