<?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.kxs.system.biz.mapper.KxsSysMsgMapper">

    <resultMap type="com.kxs.system.api.model.KxsSysMsg" id="KxsSysMsgMap">
        <result column="id" property="id"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="del_flag" property="delFlag"/>
        <result column="version" property="version"/>
        <result column="title" property="title"/>
        <result column="summary" property="summary"/>
        <result column="msg_type" property="msgType"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="bg_pic" property="bgPic"/>
        <result column="push_type" property="pushType"/>
        <result column="push_time" property="pushTime"/>
        <result column="url" property="url"/>
        <result column="content" property="content"/>

    </resultMap>

    <select id="getByPage" resultType="com.kxs.system.api.vo.kxsapp.sysMsg.SysMsgPageVO">
        select a.id, title, summary, msg_type, push_time, url, case when b.id is null then 0 else 1 end readFlag from
        kxs_sys_msg a
        left join
        (select msg_id, user_id from kxs_sys_msg_read where user_id = #{userId} GROUP BY msg_id )
        as b on a.id = b.msg_id
        <where>
            a.del_flag = '0'
        </where>
        order by a.create_time desc
    </select>
    <select id="getList" resultType="com.kxs.system.api.vo.kxsapp.sysMsg.SysMsgPageVO">
        select a.id from kxs_sys_msg a
        left join kxs_sys_msg_read b on a.id = b.msg_id and b.user_id = #{userId}
        <where>
            a.del_flag = '0'
            and b.id is null
        </where>
    </select>
    <select id="getNotReadCount" resultType="java.lang.Long">
        select count(a.id) from kxs_sys_msg a
        left join kxs_sys_msg_read b on a.id = b.msg_id and b.user_id = #{userId}
        <where>
            a.del_flag = '0'
            and b.id is null
        </where>
    </select>

</mapper>
