<?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.storlead.sales.mapper.customer.BulletinMapper">

        <!-- 通用查询映射结果 -->
        <resultMap id="BaseResultMap" type="com.storlead.sales.pojo.entity.customer.BulletinEntity">
                    <id column="id" property="id" />
                <result column="create_time" property="createTime" />
                <result column="update_time" property="updateTime" />
                <result column="is_delete" property="isDelete" />
                <result column="enabled" property="enabled" />
                <result column="create_by" property="createBy" />
                <result column="update_by" property="updateBy" />
                <result column="owner_by" property="ownerBy" />
                <result column="sort" property="sort" />
                    <result column="deadline_date" property="deadlineDate" />
                    <result column="title" property="title" />
                    <result column="content" property="content" />
                    <result column="bulletin_type" property="bulletinType" />
                    <result column="notice_time" property="noticeTime" />
                    <result column="notice_user_ids" property="noticeUserIds" />
                    <result column="former_owner_by" property="formerOwnerBy" />
        </resultMap>

        <!-- 通用查询结果列 -->
        <sql id="Base_Column_List">
                create_time,
                update_time,
                is_delete,
                enabled,
                create_by,
                update_by,
                owner_by,
                sort,
            id, deadline_date, title, content, bulletin_type, notice_time, notice_user_ids, former_owner_by
        </sql>

    <select id="listVO" resultType="com.storlead.sales.pojo.vo.customer.BulletinVO">
        select b.id,b.deadline_date,b.title,b.column_value,b.content,b.bulletin_type,b.notice_time,b.notice_user_ids,b.is_talk,b.create_time,b.update_time,b.is_delete,b.enabled,b.create_by,b.update_by,b.sort,br.has_read as isRead
        FROM bulletin b
        left join bulletin_read br on b.id = br.bulletin_id and br.read_user_id = #{userId}
        where  b.is_delete = 0
<!--        and (-->
<!--        b.create_by = #{userId} or-->
<!--        b.bulletin_type=1 or-->
<!--        find_in_set(#{userId},b.notice_user_ids)>0-->
<!--        &lt;!&ndash; OR exists (SELECT * FROM data_user_focus_note as fs LEFT join bulletin b1 on fs.data_id =  b1.id  WHERE  fs.data_type in (60) and fs.user_id = #{userId}) &ndash;&gt;-->
<!--        )-->
        <if test="param.id !=null">
            and b.id = #{param.id}
        </if>
        <if test="param.title !=null">
            and b.title like concat('%',#{param.title},'%')
        </if>
        <if test="param.createByIds != null and param.createByIds.size > 0">
            and b.create_by in
            <foreach item="id" index="index" collection="param.createByIds"
                     open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="param.columnValue !=null">
            and b.column_value = #{param.columnValue}
        </if>
        <if test="param.startDate !=null">
            and date (b.create_time) &gt;= #{param.startDate}
        </if>
        <if test="param.endDate !=null ">
            and date (b.create_time) &lt;= #{param.endDate}
        </if>
        order by b.id desc
    </select>

</mapper>
