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

        <!-- 通用查询映射结果 -->
        <resultMap id="BaseResultMap" type="com.storlead.sales.pojo.entity.customer.BulletinReadEntity">
                    <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="bulletin_id" property="bulletinId" />
                    <result column="read_user_id" property="readUserId" />
                    <result column="has_read" property="hasRead" />
                    <result column="former_owner_by" property="formerOwnerBy" />
        </resultMap>

    <resultMap id="BulletinReadVoResultMap" type="com.storlead.sales.pojo.vo.customer.BulletinReadVO">
        <id column="id" property="id"/>
        <result column="bulletin_id" property="bulletinId"/>
        <result column="read_user_id" property="readUserId"/>
        <result column="has_read" property="hasRead"/>
        <result column="staff_name" property="staffName"/>
        <result column="staff_photo" property="staffPhoto"/>
        <result column="create_by" property="createBy"/>
        <result column="update_by" property="updateBy"/>
        <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="sort" property="sort"/>
    </resultMap>

        <!-- 通用查询结果列 -->
        <sql id="Base_Column_List">
                create_time,
                update_time,
                is_delete,
                enabled,
                create_by,
                update_by,
                owner_by,
                sort,
            id, bulletin_id, read_user_id, has_read, former_owner_by
        </sql>

    <select id="listByBulletinIds"
            resultMap="BulletinReadVoResultMap">
        select br.id,bulletin_id,read_user_id,has_read, u.real_name as staff_name ,u.avatar as staff_photo,br.create_by,br.update_by,br.create_time,br.create_time as times,br.is_delete,br.enabled,br.sort,j.name as jobName,d.name as deptName
        from bulletin_read br
        LEFT JOIN user u on u.id=br.read_user_id
        LEFT JOIN dept d on d.id = u.dept_id
        LEFT JOIN job j on j.id=u.job_id
        where
        br.is_delete = 0
        <if test="bulletinIds!= null">
            AND br.bulletin_id IN
            <foreach collection="bulletinIds" index="index" item="id" separator="," close=")" open="(">
                #{id}
            </foreach>
        </if>
    </select>
    <select id="listByBulletinById"
            resultMap="BulletinReadVoResultMap">
        select br.id,bulletin_id,read_user_id,has_read, u.real_name as staff_name ,u.avatar as staff_photo,br.create_by,br.update_by,br.create_time,br.update_time,br.is_delete,br.enabled,br.sort
        from bulletin_read br
                 LEFT JOIN user u on u.id=br.read_user_id
        where  br.bulletin_id = #{bulletinId}  and br.is_delete = 0
    </select>

</mapper>
