<?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="jnpf.notice.mapper.FtbNoticeAnnouncementsReceiveMapper">

    <resultMap id="BaseResultMap" type="jnpf.model.notice.domain.FtbNoticeAnnouncementsReceive">
            <id property="id" column="F_Id" jdbcType="VARCHAR"/>
            <result property="announcementId" column="F_AnnouncementId" jdbcType="VARCHAR"/>
            <result property="userId" column="F_UserId" jdbcType="VARCHAR"/>
            <result property="alertStatus" column="F_AlertStatus" jdbcType="TINYINT"/>
            <result property="readStatus" column="F_ReadStatus" jdbcType="TINYINT"/>
            <result property="alertTime" column="F_AlertTime" jdbcType="TIMESTAMP"/>
            <result property="readTime" column="F_ReadTime" jdbcType="TIMESTAMP"/>
            <result property="enabledMark" column="F_EnabledMark" jdbcType="INTEGER"/>
            <result property="tenantId" column="F_TenantId" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        F_Id,F_AnnouncementId,F_UserId,
        F_AlertStatus,F_ReadStatus,F_AlertTime,
        F_ReadTime,F_EnabledMark,F_CreatorUserId,
        F_CreatorTime,F_LastModifyUserId,F_LastModifyTime,
        F_DeleteUserId,F_DeleteTime,F_TenantId
    </sql>
    <!--根据阅读状态查询用户列表-->
    <select id="queryUserListForReadStatus"
            resultType="jnpf.model.notice.dto.FtbNoticeAnnouncementsReceiveDto">

        select receive.F_Id             as id,
               receive.F_AnnouncementId as announcementId,
               receive.F_UserId         as userId,
               receive.F_AlertStatus    as alertStatus,
               receive.F_ReadStatus     as readStatus,
               receive.F_AlertTime      as alertTime,
               receive.F_ReadTime       as readTime,
               receive.F_IsCancel       as isCancel,
               receive.F_EnabledMark    as enabledMark,
               u.F_RealName            as userName

        from ftb_notice_announcements_receive as receive
        join base_user as u on receive.F_UserId = u.F_Id
        where receive.F_EnabledMark = 1 and receive.F_IsCancel = 0
            and receive.F_AnnouncementId = #{params.announcementId}
        <if test="params.type!= null and params.type!=0 ">
            and receive.F_ReadStatus =#{params.type}
        </if>
        <if test="params.powerUserIds != null and params.powerUserIds.size() > 0">
            and receive.F_UserId  in
            <foreach collection="params.powerUserIds" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>
    <select id="queryCountAcceptUserNum" resultType="jnpf.model.cultivate.dto.learn.BatchCommonCountDto">
        SELECT
            count( re.F_UserId ) AS num,
            re.F_AnnouncementId AS selectKey
        FROM
            ftb_notice_announcements_receive AS re
                JOIN base_user ON base_user.F_Id = re.F_UserId
        WHERE
         re.F_AnnouncementId  IN
        <foreach collection="adList" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
          AND re.F_EnabledMark = 1
          AND re.F_IsCancel = 0
        GROUP BY
            re.F_AnnouncementId;
    </select>
    <select id="batchQueryNoAlertUserNum" resultType="jnpf.model.cultivate.dto.learn.BatchCommonCountDto">

        SELECT
        count( re.F_UserId ) AS num,
        re.F_AnnouncementId AS selectKey
        FROM
        ftb_notice_announcements_receive AS re
        JOIN base_user ON base_user.F_Id = re.F_UserId
        WHERE
        re.F_AnnouncementId  IN
        <foreach collection="adList" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and re.F_AlertStatus = 1
        AND re.F_EnabledMark = 1
        AND re.F_IsCancel = 0
        GROUP BY
        re.F_AnnouncementId;
    </select>
</mapper>
