<?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.gree.mall.manager.commonmapper.NoticeRecordBeanMapper">

    <select id="readCount" resultType="com.gree.mall.manager.bean.notice.NoticeRecordReadBean">
        select
             a.notice_id  'noticeId',
             count(a.notice_id) 'readCount'
        from
            notice_record a
        where
            read_flag = true
        and
            notice_id  in
        <foreach item="item" index="index" collection="noticeIds" open="(" separator=","
                 close=")">
            #{item}
        </foreach>
        group  by
            a.notice_id
    </select>
    <select id="list" resultType="com.gree.mall.manager.bean.notice.NoticeRecordReadBean">
        SELECT
        nr.*
        FROM
        notice_record nr
        ${ex.query}
        <if test="adminUserId != null and adminUserId !=''">
            and nr.admin_user_id = #{adminUserId}
        </if>
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            and nr.admin_company_id  in
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator=","
                     close=")">
                #{item}
            </foreach>
        </if>
        ${ex.orderBy}
        <if test="ex.orderBy == null or  ex.orderBy == ''">
            order by nr.create_time desc
        </if>

    </select>
    <select id="listNotice" resultType="com.gree.mall.manager.bean.notice.NoticeVO">
        SELECT
        nr.*
        FROM
        notice nr
        ${ex.query}
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            and nr.admin_company_id  in
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator=","
                     close=")">
                #{item}
            </foreach>
        </if>
        ${ex.orderBy}
        <if test="ex.orderBy == null or  ex.orderBy == ''">
            order by nr.create_time desc
        </if>
    </select>
    <select id="listRecord" resultType="com.gree.mall.manager.bean.notice.NoticeRecordReadVOBean">
        SELECT
        nr.*
        FROM
        notice_record nr
        ${ex.query}
        <if test="adminUserId != null and adminUserId !=''">
            and nr.admin_user_id = #{adminUserId}
        </if>
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            and nr.admin_company_id  in
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator=","
                     close=")">
                #{item}
            </foreach>
        </if>
        ${ex.orderBy}
        <if test="ex.orderBy == null or  ex.orderBy == ''">
            order by nr.create_time desc
        </if>

    </select>
    <select id="listNoticeWebsit" resultType="com.gree.mall.manager.bean.notice.NoticeWebsitVO">
        SELECT
        a.*
        FROM
        notice_websit a
        join notice_websit_record b on a.notice_websit_id = b.notice_websit_id
        ${ex.query}
        <if test="status != null and status !=''">
            and a.status = #{status}
        </if>
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            and a.company_wechat_id  in
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator=","
                     close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND b.admin_websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ${ex.orderBy}
        group by a.notice_websit_id
        <if test="ex.orderBy == null or  ex.orderBy == ''">
            order by a.create_time desc
        </if>

    </select>
    <select id="listWebsit" resultType="com.gree.mall.manager.bean.notice.NoticeWebsitRecordVO">
        SELECT
        a.*,
        b.*
        FROM
        notice_websit a
        join notice_websit_record b on a.notice_websit_id = b.notice_websit_id
        ${ex.query}
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            and a.company_wechat_id  in
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator=","
                     close=")">
                #{item}
            </foreach>
        </if>
        <if test="status != null and status !=''">
            and a.status = #{status}
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND b.admin_websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ${ex.orderBy}
        <if test="ex.orderBy == null or  ex.orderBy == ''">
            order by a.create_time desc
        </if>
    </select>
    <select id="listWarranty" resultType="com.gree.mall.manager.bean.worker.WorkerWarrantyVO">
        SELECT
        a.*
        FROM
        worker_warranty a
        ${ex.query}
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            and a.company_wechat_id  in
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator=","
                     close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ${ex.orderBy}
        <if test="ex.orderBy == null or  ex.orderBy == ''">
            order by a.create_time desc
        </if>
    </select>

</mapper>