<?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.hdkj.lt.bf.mapper.FhzgNoticeMapper">

    <resultMap id="BaseResultMap" type="com.hdkj.lt.bf.entity.FhzgNotice">
        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="title" column="title" jdbcType="VARCHAR"/>
        <result property="type" column="type" jdbcType="TINYINT"/>
        <result property="status" column="status" jdbcType="TINYINT"/>
        <result property="userId" column="user_id" jdbcType="BIGINT"/>
        <result property="userName" column="user_name" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <select id="getNoticeList" resultType="com.hdkj.lt.bf.entity.vo.NoticeListVO">
        select fn.id, fn.title, fn.content, if(fnrr.id is not null, 1, 0) as isRead, fn.create_time
        from fhzg_notice fn
        left join fhzg_notice_receive_record fnrr on fn.id = fnrr.notice_id
        and fnrr.user_id = #{userId}
        where fn.type = 1 and fn.status = 1
        <if test= "isRead != null ">
            and if(fnrr.id is not null, 1, 0) = #{isRead}
        </if>
        order by create_time desc
        limit #{offset},#{pageSize}
    </select>

    <select id="getNoticeListCount" resultType="java.lang.Long">
        select count(*)
        from fhzg_notice fn
        left join fhzg_notice_receive_record fnrr on fn.id = fnrr.notice_id
        and fnrr.user_id = #{userId}
        where fn.type = 1 and fn.status = 1
        <if test="isRead != null">
            and if(fnrr.id is not null, 1, 0) = #{isRead}
        </if>
    </select>

    <select id="getAllUnreadNoticeId" resultType="java.lang.Long">
        select fn.id
        from fhzg_notice fn
                 left join fhzg_notice_receive_record fnrr on fn.id = fnrr.notice_id and fnrr.user_id = #{userId}
        where fn.type = 1 and fnrr.id is null;
    </select>

</mapper>
