<?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.FtbNoticeAnnouncementsMapper">

    <resultMap id="BaseResultMap" type="jnpf.model.notice.domain.FtbNoticeAnnouncements">
            <id property="id" column="F_Id" jdbcType="VARCHAR"/>
            <result property="categoryId" column="F_CategoryId" jdbcType="INTEGER"/>
            <result property="title" column="F_Title" jdbcType="VARCHAR"/>
            <result property="shortContent" column="F_ShortContent" jdbcType="VARCHAR"/>
            <result property="content" column="F_Content" jdbcType="VARCHAR"/>
            <result property="needRead" column="F_NeedRead" jdbcType="TINYINT"/>
            <result property="isScheduled" column="F_IsScheduled" jdbcType="TINYINT"/>
            <result property="scheduledTime" column="F_ScheduledTime" jdbcType="TIMESTAMP"/>
            <result property="status" column="F_Status" jdbcType="TINYINT"/>
            <result property="enabledMark" column="F_EnabledMark" jdbcType="INTEGER"/>
            <result property="publishUserId" column="F_PublishUserId" jdbcType="VARCHAR"/>
            <result property="creatorUserId" column="F_CreatorUserId" jdbcType="VARCHAR"/>
            <result property="creatorTime" column="F_CreatorTime" jdbcType="TIMESTAMP"/>
            <result property="lastModifyUserId" column="F_LastModifyUserId" jdbcType="VARCHAR"/>
            <result property="lastModifyTime" column="F_LastModifyTime" jdbcType="TIMESTAMP"/>
            <result property="tenantId" column="F_TenantId" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        F_Id,F_CategoryId,F_Title,
        F_ShortContent,F_Content,F_NeedRead,
        F_IsScheduled,F_ScheduledTime,F_Status,
        F_EnabledMark,F_CreatorUserId,
        F_CreatorTime,F_LastModifyUserId,F_LastModifyTime,
        F_DeleteUserId,F_DeleteTime,F_TenantId
    </sql>
    <!--web端分页查询公告信息-->
    <select id="getWebPageList" resultType="jnpf.model.notice.dto.FtbNoticeAnnouncementsDto">
        select a.F_Id as id,
        a.F_CategoryId as categoryId,
        a.F_Title as title,
        a.F_ShortContent as shortContent,
        a.F_NeedRead as needRead,
        a.F_IsScheduled as isScheduled,
        a.F_ReceiveUserType as receiveUserType,
        a.F_ScheduledTime as scheduledTime,
        a.F_PublishTime as publishTime,
        a.F_Status as status,
        a.F_CreatorTime as creatorTime,
        a.F_LastModifyTime as lastModifyTime,
        a.F_UserCount as userCount,
        a.F_CreatorUserId     as creatorUserId,
        a.F_PublishUserId     as publishUserId,
        a.F_CreateUserName as createUserName,
        a.F_PublicUserName as publicUserName,
        c.F_Name as categoryName
        from ftb_notice_announcements AS a
        left join ftb_notice_categories as c
        on a.F_CategoryId = c.F_Id
        left join ftb_personnels_staff_roster as roster
        on a.F_CreatorUserId = roster.F_UserId
        where a.F_EnabledMark = 1
        <if test="params.startDate!= null and params.endDate!= null">
            and a.F_CreatorTime between #{params.startDate} and #{params.endDate}
        </if>
        <if test="params.keyWord!= null and params.keyWord!= ''">
            and (
            a.F_Title like CONCAT('%',#{params.keyWord},'%')
            or a.F_ShortContent like CONCAT('%',#{params.keyWord},'%')
            or roster.F_Name like CONCAT('%',#{params.keyWord},'%')
            )
        </if>

        <if test="params.categoryId!= null and params.categoryId!= ''">
            and a.F_CategoryId =#{params.categoryId}
        </if>
        <if test="params.innerPowerUserId!= null and params.innerPowerUserId!= ''">
            and a.F_CreatorUserId =#{params.innerPowerUserId}
        </if>

        <if test="params.status!= null and params.status!=0 ">
            and a.F_Status =#{params.status}
        </if>

        order by a.F_CreatorTime DESC
    </select>

    <!--app端分页查询公告信息-->
    <select id="getAppPageList" resultType="jnpf.model.notice.dto.FtbNoticeAnnouncementsDto">
        select a.F_Id as id,
        a.F_CategoryId as categoryId,
        a.F_Title as title,
        a.F_ShortContent as shortContent,
        a.F_NeedRead as needRead,
        a.F_IsScheduled as isScheduled,
        a.F_ReceiveUserType as receiveUserType,
        a.F_ScheduledTime as scheduledTime,
        a.F_PublishTime as publishTime,
        a.F_Status as status,
        a.F_CreatorTime as creatorTime,
        a.F_LastModifyTime as lastModifyTime,
        a.F_UserCount as userCount,
        c.F_Name as categoryName,
        a.F_CreateUserName as createUserName,
        a.F_PublicUserName as publicUserName,
        a.F_CreatorUserId     as creatorUserId,
        a.F_PublishUserId     as publishUserId
        from ftb_notice_announcements AS a
        left join ftb_notice_categories as c
        on a.F_CategoryId = c.F_Id
        where a.F_EnabledMark = 1
        <if test="params.startDate!= null and params.endDate!= null">
            and a.F_CreatorTime between #{params.startDate} and #{params.endDate}
        </if>
        <if test="params.keyWord!= null and params.keyWord!= ''">
            and (
            a.F_Title like CONCAT('%',#{params.keyWord},'%')
            or a.F_ShortContent like CONCAT('%',#{params.keyWord},'%')
            )
        </if>
        <if test="params.innerCategoryList != null and params.innerCategoryList.size() > 0 ">
            and a.F_CategoryId IN
            <foreach item="id" index="index" collection="params.innerCategoryList" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>


        <if test="params.status!= null and params.status!=0 ">
            and a.F_Status =#{params.status}
        </if>
        <if test="params.innerPowerUserId!= null and params.innerPowerUserId!= ''">
            and a.F_CreatorUserId =#{params.innerPowerUserId}
        </if>

        order by a.F_CreatorTime DESC
    </select>
    <!--web我的分页查询公告信息-->
    <select id="getMyWebPageList" resultType="jnpf.model.notice.dto.MyNoticeAnnouncementsDto">
        select a.F_Id                as announcementId,
               a.F_CategoryId        as categoryId,
               a.F_Title             as title,
               a.F_ShortContent      as shortContent,
               a.F_NeedRead          as needRead,
               a.F_PublishTime       as publishTime,
               a.F_Status            as status,
               a.F_CreatorUserId     as creatorUserId,
               a.F_PublishUserId     as publishUserId,
               c.F_Name              as categoryName,
                a.F_CreateUserName as createUserName,
                a.F_PublicUserName as publicUserName,
               receive.F_UserId      as userId,
               receive.F_AlertStatus as alertStatus,
               receive.F_ReadStatus  as readStatus,
               receive.F_ReadTime    as readTime

        from ftb_notice_announcements_receive as receive
                 left join ftb_notice_announcements as a on receive.F_AnnouncementId = a.F_Id
                 left join ftb_notice_categories as c on a.F_CategoryId = c.F_Id
                 left join ftb_personnels_staff_roster as roster on a.F_CreatorUserId = roster.F_UserId

        where receive.F_EnabledMark = 1
          and a.F_EnabledMark = 1
          and a.F_Status = 3
          and receive.F_UserId = #{params.userId}
          and receive.F_IsCancel = 0

        <if test="params.startDate!= null and params.endDate!= null">
            and a.F_PublishTime between #{params.startDate} and #{params.endDate}
        </if>
        <if test="params.keyWord!= null and params.keyWord!= ''">
            and (
            a.F_Title like CONCAT('%',#{params.keyWord},'%')
            or a.F_ShortContent like CONCAT('%',#{params.keyWord},'%')
            or roster.F_Name like CONCAT('%',#{params.keyWord},'%')
            )
        </if>

        <if test="params.categoryId!= null and params.categoryId!= ''">
            and a.F_CategoryId =#{params.categoryId}
        </if>
        <if test="params.needRead!= null and params.needRead!=0">
            and a.F_NeedRead =#{params.needRead}
        </if>
        <if test="params.readStatus!= null and params.readStatus!=0">
            and receive.F_ReadStatus =#{params.readStatus}
        </if>
        order by a.F_PublishTime DESC
    </select>
    <!--web端查询我的公告信息 分页查询公告信息-->
    <select id="getAppMyPageList" resultType="jnpf.model.notice.dto.MyNoticeAnnouncementsDto">
        select a.F_Id                as announcementId,
        a.F_CategoryId        as categoryId,
        a.F_Title             as title,
        a.F_ShortContent      as shortContent,
        a.F_NeedRead          as needRead,
        a.F_PublishTime       as publishTime,
        a.F_Status            as status,
        a.F_CreatorUserId     as creatorUserId,
        a.F_PublishUserId     as publishUserId,
        a.F_CreateUserName as createUserName,
        a.F_PublicUserName as publicUserName,
        c.F_Name              as categoryName,
        receive.F_UserId      as userId,
        receive.F_AlertStatus as alertStatus,
        receive.F_ReadStatus  as readStatus,
        receive.F_ReadTime    as readTime

        from ftb_notice_announcements_receive as receive
        left join ftb_notice_announcements as a on receive.F_AnnouncementId = a.F_Id
        left join ftb_notice_categories as c on a.F_CategoryId = c.F_Id

        where receive.F_EnabledMark = 1
        and a.F_EnabledMark = 1
        and a.F_Status = 3
        and receive.F_UserId = #{params.userId}
        and receive.F_IsCancel = 0

        <if test="params.startDate!= null and params.endDate!= null">
            and a.F_PublishTime between #{params.startDate} and #{params.endDate}
        </if>
        <if test="params.keyWord!= null and params.keyWord!= ''">
            and (
            a.F_Title like CONCAT('%',#{params.keyWord},'%')
            or a.F_ShortContent like CONCAT('%',#{params.keyWord},'%')
            )
        </if>

        <if test="params.innerCategoryList != null and params.innerCategoryList.size() > 0 ">
            and a.F_CategoryId IN
            <foreach item="id" index="index" collection="params.innerCategoryList" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="params.needRead!= null and params.needRead!=0">
            and a.F_NeedRead =#{params.needRead}
        </if>
        <if test="params.readStatus!= null and params.readStatus!=0">
            and receive.F_ReadStatus =#{params.readStatus}
        </if>
        order by a.F_PublishTime DESC

    </select>
    <!--app端查询我的公告列表-->
    <select id="getAppMyList" resultType="jnpf.model.notice.dto.MyNoticeAnnouncementsDto">

        select a.F_Id                as announcementId,
               a.F_CategoryId        as categoryId,
               a.F_Title             as title,
               a.F_ShortContent      as shortContent,
               a.F_NeedRead          as needRead,
               a.F_PublishTime       as publishTime,
               a.F_Status            as status,
               a.F_CreatorUserId     as creatorUserId,
               a.F_PublishUserId     as publishUserId,
               a.F_CreateUserName as createUserName,
               a.F_PublicUserName as publicUserName,
               c.F_Name              as categoryName,
               receive.F_UserId      as userId,
               receive.F_AlertStatus as alertStatus,
               receive.F_ReadStatus  as readStatus,
               receive.F_ReadTime    as readTime

        from ftb_notice_announcements_receive as receive
                 left join ftb_notice_announcements as a on receive.F_AnnouncementId = a.F_Id
                 left join ftb_notice_categories as c on a.F_CategoryId = c.F_Id

        where receive.F_EnabledMark = 1
          and a.F_EnabledMark = 1
          and a.F_Status = 3
          and receive.F_UserId = #{userId}
          and receive.F_IsCancel = 0
        order by a.F_PublishTime DESC limit #{num}
    </select>
    <!--查询我的未读的公告列表-->
    <select id="queryAllMyNoRead" resultType="jnpf.model.notice.dto.MyNoticeAnnouncementsMsgDto">
        select a.F_Id as announcementId,
        a.F_CategoryId as categoryId,
        a.F_Title as title,
        a.F_ShortContent as shortContent,
        a.F_NeedRead as needRead,
        a.F_PublishTime as publishTime,
        a.F_Status as status,
        a.F_CreatorUserId as creatorUserId,
        a.F_PublishUserId as publishUserId,
        a.F_CreateUserName as createUserName,
        a.F_PublicUserName as publicUserName,
        c.F_Name as categoryName,
        receive.F_UserId as userId,
        receive.F_AlertStatus as alertStatus,
        receive.F_ReadStatus as readStatus,
        receive.F_ReadTime as readTime

        from ftb_notice_announcements_receive as receive
        left join ftb_notice_announcements as a on receive.F_AnnouncementId = a.F_Id
        left join ftb_notice_categories as c on a.F_CategoryId = c.F_Id

        where receive.F_EnabledMark = 1
        and a.F_EnabledMark = 1
        and a.F_Status = 3
        and receive.F_ReadStatus = 1
        and receive.F_UserId = #{userId}
        and receive.F_IsCancel = 0
        <if test="needRead!= null and needRead!=0">
            and a.F_NeedRead =#{needRead}
        </if>
        order by a.F_PublishTime DESC
        <if test="num!= null and num!=0">
            limit #{num}
        </if>
    </select>
    <!--web查询我的未读公告列表-->
    <select id="queryAllWebMyNoRead" resultType="jnpf.model.notice.dto.MyNoticeAnnouncementsMsgDto">
        select a.F_Id as announcementId,
        a.F_CategoryId as categoryId,
        a.F_Title as title,
        a.F_ShortContent as shortContent,
        a.F_NeedRead as needRead,
        a.F_PublishTime as publishTime,
        a.F_Status as status,
        a.F_CreatorUserId as creatorUserId,
        a.F_PublishUserId as publishUserId,
        a.F_CreateUserName as createUserName,
        a.F_PublicUserName as publicUserName,
        c.F_Name as categoryName,
        receive.F_UserId as userId,
        receive.F_AlertStatus as alertStatus,
        receive.F_ReadStatus as readStatus,
        receive.F_ReadTime as readTime

        from ftb_notice_announcements_receive as receive
        left join ftb_notice_announcements as a on receive.F_AnnouncementId = a.F_Id
        left join ftb_notice_categories as c on a.F_CategoryId = c.F_Id

        where receive.F_EnabledMark = 1
        and a.F_EnabledMark = 1
        and a.F_Status = 3
        and receive.F_ReadStatus = 1
        and receive.F_UserId = #{userId}
        and receive.F_IsCancel = 0
        and receive.F_WebCancel=0
        <if test="needRead!= null and needRead!=0">
            and a.F_NeedRead =#{needRead}
        </if>
        order by a.F_PublishTime DESC
    </select>
</mapper>
