<?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="org.jeecg.modules.ctop.mapper.ProjectMemberMapper">

    <select id="selectProjectsByUserId" resultType="java.lang.Long">
        select
        DISTINCT(project_id)
         from ctop_project_member
        where user_id = #{userId}
    </select>

    <!-- 设计师展示所有自己的角色下制作的视频 -->
    <select id="adminProjects" resultType="org.jeecg.modules.ctop.entity.ProjectMember">
        select
        id as projectId,
        project_name as projectName,
        advertiser_id as advertiserId,
        advertiser_name as advertiserName,
        media_id as mediaId,
        max_bid as maxBid,
        advertiser_name as advertiserName ,
        responsible_name as responsibleName
        from
        ctop_project
        where
        media_id in
        <foreach collection="mediaIds" item="item" separator=","
                 open="(" close=")">
            #{item}
        </foreach>
    </select>

    <!-- 视频报表设计师leader展示自己所在公司的所有项目 -->
    <select id="designLeaderProjects" resultType="org.jeecg.modules.ctop.entity.ProjectMember">
        select
            distinct b.id as projectId,
            b.project_name as projectName,
            b.advertiser_id as advertiserId,
            b.advertiser_name as advertiserName,
            b.media_id as mediaId
        from
        ctop_project_member a
        left join ctop_project b on a.project_id = b.id
        where
        b.company_id = #{companyId}
        and b.media_id in
        <foreach collection="mediaIds" item="item" separator=","
                 open="(" close=")">
            #{item}
        </foreach>
    </select>

    <!-- 设计师展示所有自己的角色下制作的视频 -->
    <select id="designProjects" resultType="org.jeecg.modules.ctop.entity.ProjectMember">
        select
            distinct a.project_id as projectId,
            b.project_name as projectName,
            b.advertiser_id as advertiserId,
            b.advertiser_name as advertiserName,
            b.media_id as mediaId
        from
        ctop_project_member a
        left join ctop_project b on a.project_id = b.id
        where a.user_id = #{userId}
        and b.media_id in
        <foreach collection="mediaIds" item="item" separator=","
                 open="(" close=")">
            #{item}
        </foreach>
    </select>

    <!-- 运营和运营负责人展示所在项目视频 -->
    <select id="operationProjects" resultType="org.jeecg.modules.ctop.entity.ProjectMember">
        select
           distinct b.id as projectId,
           b.project_name as projectName,
           b.advertiser_id as advertiserId,
           b.advertiser_name as advertiserName,
           b.media_id as mediaId
        from
        ctop_user_allocation a
        left join ctop_project b on a.project_id = b.id
        where a.user_id = #{userId}
        and b.media_id in
        <foreach collection="mediaIds" item="item" separator=","
                 open="(" close=")">
            #{item}
        </foreach>
    </select>

    <select id="getRoleCodeByUserId" resultType="string">
        select
        role_code
        from
        sys_user_role a
        left join sys_role b on a.role_id = b.id
        where a.user_id = #{userId}
    </select>

    <select id="getCompanyIdByUserId" resultType="string">
            select
            company_id
        from
        user_company
        where user_id = #{userId}
    </select>

</mapper>
