<?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.xxl.job.executor.common.mapper.UserAllocationMapper">

    <select id="selectAccountListByProjectId" resultType="com.xxl.job.executor.common.entity.UserAllocation">
        select
        a.user_id as userId,
        a.user_name as userName,
        a.auth_name as authName,
        a.account_id as accountId
        from
        ctop_user_allocation a
        left join ctop_project b on a.project_id = b.id
        where b.id = #{projectId}
    </select>

    <select id="queryAdvertiserId" resultType="String">
        select
            distinct advertiser_id
        from
            ctop_user_allocation
        where account_id=#{accountId}
    </select>
    <select id="queryUserIdByAccountId" resultType="String">
        select
            distinct user_id
        from
            ctop_user_allocation
        where account_id=#{accountId}
    </select>

    <select id="getAccountListByProject" resultType="com.alibaba.fastjson.JSONObject">
       select
       account_id as 'accountId',
       user_name as 'userName',
       auth_name as 'authName'
       from ctop_user_allocation
       where project_id = #{projectId}
       order by create_time desc
    </select>

    <select id="getUserIdListByProjectId" resultType="com.alibaba.fastjson.JSONObject">
   SELECT t1.user_id as 'userId',
    t1.account_id as 'accountId',
    t1.user_name  as 'userName'
    from  ctop_kuaishou_advertiser_base_info t1  LEFT JOIN
    ctop_user_allocation  t2
    ON t1.account_id = t2.account_id
    WHERE t2.project_id = #{projectId}
    GROUP BY t1.user_id;
    </select>


    <select id="getAccountIdListByUserId" resultType="com.alibaba.fastjson.JSONObject">
    SELECT
    t1.account_id as 'accountId',
    t1.auth_name  as 'authName',
    t1.user_name as 'userName'
    from ctop_user_allocation   t1  LEFT JOIN
    ctop_kuaishou_advertiser_base_info t2
    ON t1.account_id = t2.account_id
    WHERE t2.user_id = #{userId}
    AND t1.account_status = 0
    </select>

    <select id="getProjectIdByAccountId" resultType="java.lang.Long">
    select  project_id  from  ctop_user_allocation
    where account_id = #{accountId}
    limit 1
    </select>

    <select id="getUserAllocation" resultType="com.xxl.job.executor.common.entity.UserAllocation">
    select  *  from  ctop_user_allocation
    where account_id=#{accountId}
    limit 1
    </select>


</mapper>
