<?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="cn.com.ctop.common.module.mapper.ProductMapper">

    <select id="getUserNameByUserId" resultType="java.lang.String">
     select  realname  from sys_user
     where  id = #{userId}
    </select>
    <select id="getProductByMap" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
        id as 'id',
        product_name as 'productName'
        from ctop_product
        where id in
        <foreach collection="ids" item="ids" separator="," open="(" close=")">
            #{ids}
        </foreach>
    </select>

    <select id="getUserProductList" resultType="cn.com.ctop.common.module.entity.Product">
        select
        cp.id,
        cp.product_name as 'productName',
        ca.name as 'advertiserName'
        from
        ctop_product cp
        left join ctop_advertiser ca on
        cp.advertiser_id = ca.id
        where
        cp.id in (
        select
        DISTINCT(product_id)
        from
        ctop_project
        where
        product_id is not NULL
        and id in (
        select
        DISTINCT(project_id)
        from
        ctop_project_member
        <where>
            <if test="userIds !=null and userIds.size>0">
                AND user_id in
                <foreach collection="userIds" item="item" separator=","
                         open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        ) )
        <if test="productName != null and productName != ''">
            and cp.product_name like concat('%',#{productName},'%')
        </if>
        order by cp.create_time desc

    </select>

</mapper>