<?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.performance.mapper.OperateDetailMapper">

    <select id="selectBytedanceByParams" resultType="org.jeecg.modules.performance.entity.OperateDetail">
        select
            #{userId} as user_id,
            1 as media_type,
            #{accountId} as account_id,
            left(stat_datetime,10) as stat_date,
            sum(cost) as cost,
            (select
                user.id
            from
                sys_user_role userRole
            left join sys_user user on userRole.user_id = user.id
            left join sys_role role on userRole.role_id = role.id
            where
                org_code = #{orgCode}
            and
                role.role_name = '头条运营经理'
            ) as leader_id
        from
            ctop_bytedance_report_advertiser_daily
        where
            advertiser_id = #{accountId}
        and
            stat_datetime &gt;=#{startDate}
        and
            stat_datetime &lt;=#{endDate}
        group by stat_datetime
    </select>

    <select id="ByteDanceOperateDetailGroupAccountByDate" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
        (SELECT project_name from ctop_user_allocation where account_id=t1.account_id ) AS projectName,
        (SELECT auth_name from ctop_user_allocation where account_id=t1.account_id ) AS authName,
        ROUND(sum(t1.cost), 2) cost
        FROM
        ctop_performance_operate_detail  t1
        WHERE
        t1.stat_date &gt;=#{startDate}
        AND t1.stat_date &lt;=#{endDate}
        and t1.user_id=#{userId}
        and t1.media_type=1
        GROUP BY
        t1.account_id
    </select>

    <select id="kuaiShouOperateDetailGroupAccountByDate" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
        (SELECT project_name from ctop_user_allocation where account_id=t1.account_id ) AS projectName,
        (SELECT auth_name from ctop_user_allocation where account_id=t1.account_id ) AS authName,
        ROUND(sum(t1.cost), 2) cost
        FROM
        ctop_performance_operate_detail  t1
        WHERE
        t1.stat_date &gt;=#{startDate}
        AND t1.stat_date &lt;=#{endDate}
        and t1.user_id=#{userId}
        and t1.media_type=2
        GROUP BY
            t1.account_id
    </select>

</mapper>
