|
|
@@ -2,7 +2,7 @@
|
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
|
|
<mapper namespace="cn.com.ctop.job.bytedance.data.mapper.ReportsAdPushMapper">
|
|
|
<select id="updateTime" resultType="java.lang.String">
|
|
|
- select date_format(max(update_time), '%Y-%m-%d %H:%i:%s') from application.media_ad_report_daily
|
|
|
+ select date_format(max(update_at), '%Y-%m-%d %H:%i:%s') from application.user_data_report_daily
|
|
|
where stat_date = ${date} limit 1
|
|
|
</select>
|
|
|
|
|
|
@@ -64,53 +64,112 @@
|
|
|
round(ifnull(sum(iap_real_cost_amount), 0), 2) as iap_real_cost_amount
|
|
|
</sql>
|
|
|
|
|
|
+ <sql id="coreIndicatorSqlPart">
|
|
|
+ round(ifnull(sum(cost_amount),0), 2) as cost_amount,
|
|
|
+ round(ifnull(sum(mj_cost_amount),0), 2) as mj_cost_amount,
|
|
|
+ round(ifnull(sum(dj_cost_amount),0), 2) as dj_cost_amount,
|
|
|
+ round(ifnull(sum(real_cost_amount), 0), 2) as real_cost_amount,
|
|
|
+ round(ifnull(sum(dj_real_cost_amount), 0), 2) as dj_real_cost_amount,
|
|
|
+ round(ifnull(sum(mj_real_cost_amount), 0), 2) as mj_real_cost_amount,
|
|
|
+ round(ifnull(sum(pay_amount), 0), 2) AS pay_amount,
|
|
|
+ round(ifnull(sum(dj_pay_amount), 0), 2) AS dj_pay_amount,
|
|
|
+ round(ifnull(sum(mj_pay_amount), 0), 2) AS mj_pay_amount,
|
|
|
+ round(ifnull(sum(share_iaa_amount), 0), 2) as share_iaa_amount,
|
|
|
+ round(ifnull(sum(dj_share_iaa_amount), 0), 2) as dj_share_iaa_amount,
|
|
|
+ round(ifnull(sum(mj_share_iaa_amount), 0), 2) as mj_share_iaa_amount,
|
|
|
+ round(ifnull(sum(share_iaa_amount_3), 0) + ifnull(sum(share_pay_amount), 0) - ifnull(sum(real_cost_amount), 0), 2) AS real_profit,
|
|
|
+ round(ifnull(sum(dj_share_iaa_amount_3), 0) + ifnull(sum(dj_share_pay_amount), 0) - ifnull(sum(dj_real_cost_amount), 0), 2) AS dj_real_profit,
|
|
|
+ round(ifnull(sum(mj_share_iaa_amount_3), 0) + ifnull(sum(mj_share_pay_amount), 0) - ifnull(sum(mj_real_cost_amount), 0), 2) AS mj_real_profit,
|
|
|
+ round(ifnull(sum(iaa_amount), 0) + ifnull(sum(pay_amount), 0) - ifnull(sum(cost_amount), 0), 2) AS water_profit,
|
|
|
+ round(ifnull(sum(dj_iaa_amount), 0) + ifnull(sum(dj_pay_amount), 0) - ifnull(sum(dj_cost_amount), 0), 2) AS dj_water_profit,
|
|
|
+ round(ifnull(sum(mj_iaa_amount), 0) + ifnull(sum(mj_pay_amount), 0) - ifnull(sum(mj_cost_amount), 0), 2) AS mj_water_profit,
|
|
|
+ concat(round(if(ifnull(sum(real_cost_amount),0)=0, 0, (ifnull(sum(share_iaa_amount_3),0)+ifnull(sum(share_pay_amount),0))/sum(real_cost_amount)*100), 2), '%') AS real_roi,
|
|
|
+ concat(round(if(ifnull(sum(dj_real_cost_amount),0)=0, 0, (ifnull(sum(dj_share_iaa_amount_3),0)+ifnull(sum(dj_share_pay_amount),0))/sum(dj_real_cost_amount)*100), 2), '%') AS dj_real_roi,
|
|
|
+ concat(round(if(ifnull(sum(mj_real_cost_amount),0)=0, 0, (ifnull(sum(mj_share_iaa_amount_3),0)+ifnull(sum(mj_share_pay_amount),0))/sum(mj_real_cost_amount)*100), 2), '%') AS mj_real_roi,
|
|
|
+ round(ifnull(sum(share_iaa_amount), 0) + ifnull(sum(share_pay_amount), 0), 2) as end_amount,
|
|
|
+ round(ifnull(sum(dj_share_iaa_amount), 0) + ifnull(sum(dj_share_pay_amount), 0), 2) as dj_end_amount,
|
|
|
+ round(ifnull(sum(mj_share_iaa_amount), 0) + ifnull(sum(mj_share_pay_amount), 0), 2) as mj_end_amount
|
|
|
+ </sql>
|
|
|
+
|
|
|
<select id="tmpPushData" resultType="java.util.Map">
|
|
|
select
|
|
|
- <include refid="costAmount"/>,
|
|
|
- <include refid="realCostAmount"/>,
|
|
|
- <include refid="payAmount"/>,
|
|
|
- <include refid="shareIaaAmount"/>,
|
|
|
- <include refid="realProfit"/>,
|
|
|
- <include refid="realRoi"/>,
|
|
|
- <include refid="endAmount"/>
|
|
|
+ <include refid="coreIndicatorSqlPart"/>
|
|
|
FROM
|
|
|
- (select sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount, max(update_time) as update_time
|
|
|
- from application.media_ad_report_daily
|
|
|
- where stat_date = ${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
- ) tb1,
|
|
|
- (select sum(pay_amount) as pay_amount,
|
|
|
- sum(iaa_amount) as iaa_amount,
|
|
|
- sum(share_iaa_amount_3) as share_iaa_amount_3,
|
|
|
- sum(share_pay_amount) as share_pay_amount,
|
|
|
- sum(share_iaa_amount) as share_iaa_amount
|
|
|
- from application.user_data_report_daily
|
|
|
- where stat_date = ${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
- ) tb2
|
|
|
+ (select sum(cost_amount) as cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(cost_amount, 0) else 0 end) as dj_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(cost_amount, 0) else 0 end) as mj_cost_amount,
|
|
|
+ sum(real_cost_amount) as real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(real_cost_amount, 0) else 0 end) as dj_real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(real_cost_amount, 0) else 0 end) as mj_real_cost_amount,
|
|
|
+ max(t1.update_time) as update_time
|
|
|
+ from application.media_ad_report_daily t1
|
|
|
+ left join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
+ where stat_date = #{date}
|
|
|
+ and t2.business_line in (1,6,7,4,8,9,10)
|
|
|
+ ) tb1,
|
|
|
+ (select sum(pay_amount) as pay_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(pay_amount, 0) else 0 end) as dj_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(pay_amount, 0) else 0 end) as mj_pay_amount,
|
|
|
+ sum(share_iaa_amount) as share_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_iaa_amount, 0) else 0 end) as dj_share_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_iaa_amount, 0) else 0 end) as mj_share_iaa_amount,
|
|
|
+ sum(share_iaa_amount_3) as share_iaa_amount_3,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_iaa_amount_3, 0) else 0 end) as dj_share_iaa_amount_3,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_iaa_amount_3, 0) else 0 end) as mj_share_iaa_amount_3,
|
|
|
+ sum(share_pay_amount) as share_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_pay_amount, 0) else 0 end) as dj_share_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_pay_amount, 0) else 0 end) as mj_share_pay_amount,
|
|
|
+ sum(iaa_amount) as iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(iaa_amount, 0) else 0 end) as dj_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(iaa_amount, 0) else 0 end) as mj_iaa_amount
|
|
|
+ from application.user_data_report_daily t1
|
|
|
+ left join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
+ where stat_date = #{date}
|
|
|
+ and t2.business_line in (1,6,7,4,8,9,10)
|
|
|
+ ) tb2
|
|
|
</select>
|
|
|
<select id="adHourData" resultType="java.util.Map">
|
|
|
select
|
|
|
- <include refid="costAmount"/>,
|
|
|
- <include refid="realCostAmount"/>,
|
|
|
- <include refid="payAmount"/>,
|
|
|
- <include refid="shareIaaAmount"/>,
|
|
|
- <include refid="realProfit"/>,
|
|
|
- <include refid="waterProfit"/>,
|
|
|
- <include refid="realRoi"/>,
|
|
|
- <include refid="endAmount"/>
|
|
|
+ <include refid="coreIndicatorSqlPart"/>
|
|
|
from
|
|
|
- (select sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount
|
|
|
- from application.media_ad_report_hourly
|
|
|
- where stat_date = #{date} and `hour`= #{hour} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
+ (select sum(cost_amount) as cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(cost_amount, 0) else 0 end) as dj_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(cost_amount, 0) else 0 end) as mj_cost_amount,
|
|
|
+ sum(real_cost_amount) as real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(real_cost_amount, 0) else 0 end) as dj_real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(real_cost_amount, 0) else 0 end) as mj_real_cost_amount
|
|
|
+ from application.media_ad_report_hourly t1
|
|
|
+ left join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
+ where stat_date = #{date} and `hour`= #{hour}
|
|
|
+ and t2.business_line in (1,6,7,4,8,9,10)
|
|
|
) tb1,
|
|
|
- (select sum(pay_amount) as pay_amount, sum(iaa_amount) as iaa_amount,
|
|
|
+ (select sum(pay_amount) as pay_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(pay_amount, 0) else 0 end) as dj_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(pay_amount, 0) else 0 end) as mj_pay_amount,
|
|
|
+ sum(share_iaa_amount) as share_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_iaa_amount, 0) else 0 end) as dj_share_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_iaa_amount, 0) else 0 end) as mj_share_iaa_amount,
|
|
|
sum(share_iaa_amount_3) as share_iaa_amount_3,
|
|
|
- sum(share_iaa_amount) as share_iaa_amount, sum(share_pay_amount) as share_pay_amount
|
|
|
- from application.user_data_report_hourly
|
|
|
- where stat_date = #{date} and `hour`= #{hour} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_iaa_amount_3, 0) else 0 end) as dj_share_iaa_amount_3,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_iaa_amount_3, 0) else 0 end) as mj_share_iaa_amount_3,
|
|
|
+ sum(share_pay_amount) as share_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_pay_amount, 0) else 0 end) as dj_share_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_pay_amount, 0) else 0 end) as mj_share_pay_amount,
|
|
|
+ sum(iaa_amount) as iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(iaa_amount, 0) else 0 end) as dj_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(iaa_amount, 0) else 0 end) as mj_iaa_amount
|
|
|
+ from application.user_data_report_hourly t1
|
|
|
+ left join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
+ where stat_date = #{date} and `hour`= #{hour}
|
|
|
+ and t2.business_line in (1,6,7,4,8,9,10)
|
|
|
) tb2
|
|
|
</select>
|
|
|
<select id="tmpTopMovie" resultType="java.util.Map">
|
|
|
- select tb4.ly_movie_name as movie_name, tb4.movie_project_source, tb5.dict_name as movie_project_source_name,
|
|
|
+ select tb4.ly_movie_name as movie_name, tb4.movie_project_source, tb5.dict_name as movie_project_source_name, tb4.movie_type,
|
|
|
group_concat(distinct case tb4.movie_source when 2 then '2' else '1' end) as movie_source,
|
|
|
rank() over (order by sum(iaa_amount)+sum(pay_amount) desc) as rk,
|
|
|
<include refid="endAmount"/>,
|
|
|
@@ -150,52 +209,70 @@
|
|
|
group by movie_id
|
|
|
) tb3 on tb1.movie_id=tb3.movie_id
|
|
|
left join
|
|
|
- (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_project_source,ly_movie_name from tidb.deepthink.all_moive
|
|
|
+ (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_project_source,project_ad_date, ly_movie_name, movie_type from tidb.deepthink.all_moive
|
|
|
) tb4 on tb1.movie_id=tb4.moive_id
|
|
|
left join
|
|
|
(select dict_key, dict_name from tidb.deepthink.dt_dictionary where select_key='movie_project_source'
|
|
|
) tb5 on tb4.movie_project_source=tb5.dict_key
|
|
|
where 1=1 and tb1.movie_id!='-9999'
|
|
|
- group by tb4.ly_movie_name, tb4.movie_project_source, tb5.dict_name
|
|
|
+ group by tb4.ly_movie_name, tb4.movie_project_source, tb5.dict_name, tb4.movie_type
|
|
|
order by sum(iaa_amount)+sum(pay_amount) desc
|
|
|
limit 20
|
|
|
</select>
|
|
|
|
|
|
<select id="adDailyData" resultType="java.util.Map">
|
|
|
select
|
|
|
- <include refid="costAmount"/>,
|
|
|
- <include refid="realCostAmount"/>,
|
|
|
- <include refid="payAmount"/>,
|
|
|
- <include refid="shareIaaAmount"/>,
|
|
|
- <include refid="realProfit"/>,
|
|
|
- <include refid="waterProfit"/>,
|
|
|
- <include refid="realRoi"/>,
|
|
|
- <include refid="endAmount"/>,
|
|
|
+ <include refid="coreIndicatorSqlPart"/>
|
|
|
+ ,
|
|
|
date_format(max(update_time), '%Y-%m-%d %H:%i:%s') as update_time
|
|
|
from
|
|
|
- (select sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount, max(update_time) as update_time
|
|
|
- from application.media_ad_report_daily
|
|
|
- where stat_date = #{date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
+ (select sum(cost_amount) as cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(cost_amount, 0) else 0 end) as dj_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(cost_amount, 0) else 0 end) as mj_cost_amount,
|
|
|
+ sum(real_cost_amount) as real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(real_cost_amount, 0) else 0 end) as dj_real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(real_cost_amount, 0) else 0 end) as mj_real_cost_amount,
|
|
|
+ max(t1.update_time) as update_time
|
|
|
+ from application.media_ad_report_daily t1
|
|
|
+ left join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
+ where stat_date = #{date}
|
|
|
+ and t2.business_line in (1,6,7,4,8,9,10)
|
|
|
) tb1,
|
|
|
- (select sum(pay_amount) as pay_amount, sum(iaa_amount) as iaa_amount,
|
|
|
- sum(share_iaa_amount) as share_iaa_amount, sum(share_pay_amount) as share_pay_amount,
|
|
|
- sum(share_iaa_amount_3) as share_iaa_amount_3
|
|
|
- from application.user_data_report_daily
|
|
|
- where stat_date = #{date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
+ (select sum(pay_amount) as pay_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(pay_amount, 0) else 0 end) as dj_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(pay_amount, 0) else 0 end) as mj_pay_amount,
|
|
|
+ sum(share_iaa_amount) as share_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_iaa_amount, 0) else 0 end) as dj_share_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_iaa_amount, 0) else 0 end) as mj_share_iaa_amount,
|
|
|
+ sum(share_iaa_amount_3) as share_iaa_amount_3,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_iaa_amount_3, 0) else 0 end) as dj_share_iaa_amount_3,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_iaa_amount_3, 0) else 0 end) as mj_share_iaa_amount_3,
|
|
|
+ sum(share_pay_amount) as share_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_pay_amount, 0) else 0 end) as dj_share_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_pay_amount, 0) else 0 end) as mj_share_pay_amount,
|
|
|
+ sum(iaa_amount) as iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(iaa_amount, 0) else 0 end) as dj_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(iaa_amount, 0) else 0 end) as mj_iaa_amount
|
|
|
+ from application.user_data_report_daily t1
|
|
|
+ left join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
+ where stat_date = #{date}
|
|
|
+ and t2.business_line in (1,6,7,4,8,9,10)
|
|
|
) tb2
|
|
|
</select>
|
|
|
|
|
|
<select id="todayTopMovie" resultType="com.alibaba.fastjson.JSONObject" >
|
|
|
select
|
|
|
- tb4.ly_movie_name as movie_name, tb4.movie_project_source, tb6.dict_name as movie_project_source_name,
|
|
|
+ tb4.movie_name as movie_name, tb4.movie_project_source, tb6.dict_name as movie_project_source_name, tb4.movie_type,
|
|
|
case
|
|
|
- when (DATEDIFF(STR_TO_DATE(tb1.stat_date, '%Y%m%d'), STR_TO_DATE(tb4.project_ad_date, '%Y%m%d')) + 1) between 1
|
|
|
+ when (DATEDIFF(STR_TO_DATE(${date}, '%Y%m%d'), STR_TO_DATE(tb4.project_ad_date, '%Y%m%d')) + 1) between 1
|
|
|
and 3 then '新剧1阶'
|
|
|
- when (DATEDIFF(STR_TO_DATE(tb1.stat_date, '%Y%m%d'), STR_TO_DATE(tb4.project_ad_date, '%Y%m%d')) + 1) between 4
|
|
|
+ when (DATEDIFF(STR_TO_DATE(${date}, '%Y%m%d'), STR_TO_DATE(tb4.project_ad_date, '%Y%m%d')) + 1) between 4
|
|
|
and 7 then '新剧2阶'
|
|
|
- when (DATEDIFF(STR_TO_DATE(tb1.stat_date, '%Y%m%d'), STR_TO_DATE(tb4.project_ad_date, '%Y%m%d')) + 1) between 8
|
|
|
+ when (DATEDIFF(STR_TO_DATE(${date}, '%Y%m%d'), STR_TO_DATE(tb4.project_ad_date, '%Y%m%d')) + 1) between 8
|
|
|
and 15 then '次新剧'
|
|
|
- when (DATEDIFF(STR_TO_DATE(tb1.stat_date, '%Y%m%d'), STR_TO_DATE(tb4.project_ad_date, '%Y%m%d')) + 1) >=15 then
|
|
|
+ when (DATEDIFF(STR_TO_DATE(${date}, '%Y%m%d'), STR_TO_DATE(tb4.project_ad_date, '%Y%m%d')) + 1) >=15 then
|
|
|
'老剧'
|
|
|
else 999 end as project_ad_step,
|
|
|
<include refid="endAmount"/>,
|
|
|
@@ -210,44 +287,47 @@
|
|
|
<include refid="iapCostAmount"/>,
|
|
|
round(ifnull(sum(hour_cost_amount), 0), 2) as hour_cost_amount
|
|
|
from
|
|
|
- (select ${date} as stat_date, movie_id from application.media_ad_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
- union select ${date} as stat_date, movie_id from application.user_data_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))) tb1
|
|
|
- left join
|
|
|
(
|
|
|
- select movie_id, sum(iaa_cost_amount) as iaa_cost_amount, sum(iaa_real_cost_amount) as iaa_real_cost_amount,
|
|
|
+ select ma_appid, movie_id, sum(iaa_cost_amount) as iaa_cost_amount, sum(iaa_real_cost_amount) as iaa_real_cost_amount,
|
|
|
sum(iap_cost_amount) as iap_cost_amount, sum(iap_real_cost_amount) as iap_real_cost_amount,
|
|
|
sum(iaa_cost_amount)+sum(iap_cost_amount) as cost_amount,
|
|
|
sum(iaa_real_cost_amount)+sum(iap_real_cost_amount) as real_cost_amount
|
|
|
from
|
|
|
- (select movie_id, round(ifnull(sum(cost_amount),0),2) as iaa_cost_amount, sum(real_cost_amount) as iaa_real_cost_amount, 0 as iap_cost_amount, 0 as iap_real_cost_amount
|
|
|
- from application.media_ad_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10) and business_method='IAA')
|
|
|
- group by movie_id
|
|
|
+ (select ma_appid, movie_id, round(ifnull(sum(cost_amount),0),2) as iaa_cost_amount, sum(real_cost_amount) as iaa_real_cost_amount, 0 as iap_cost_amount, 0 as iap_real_cost_amount
|
|
|
+ from application.media_ad_report_daily where stat_date=${date}
|
|
|
+ and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10) and business_method='IAA')
|
|
|
+ group by ma_appid, movie_id
|
|
|
union all
|
|
|
- select movie_id, 0 as iaa_cost_amount, 0 as iaa_real_cost_amount,round(ifnull(sum(cost_amount),0),2) as cost_amount, sum(real_cost_amount) as real_cost_amount
|
|
|
- from application.media_ad_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10) and business_method='IAP')
|
|
|
- group by movie_id) subt2
|
|
|
- group by movie_id
|
|
|
- ) tb2 on tb1.movie_id=tb2.movie_id
|
|
|
- left join
|
|
|
- (select movie_id, sum(iaa_amount) as iaa_amount, sum(pay_amount) as pay_amount,
|
|
|
+ select ma_appid, movie_id, 0 as iaa_cost_amount, 0 as iaa_real_cost_amount,round(ifnull(sum(cost_amount),0),2) as cost_amount, sum(real_cost_amount) as real_cost_amount
|
|
|
+ from application.media_ad_report_daily where stat_date=${date}
|
|
|
+ and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10) and business_method='IAP')
|
|
|
+ group by ma_appid, movie_id) subt2
|
|
|
+ group by ma_appid, movie_id
|
|
|
+ ) tb2
|
|
|
+ full join
|
|
|
+ (select ma_appid, movie_id, sum(iaa_amount) as iaa_amount, sum(pay_amount) as pay_amount,
|
|
|
sum(share_iaa_amount_3) as share_iaa_amount_3,
|
|
|
ifnull(sum(share_iaa_amount), 0) as share_iaa_amount,
|
|
|
ifnull(sum(share_pay_amount), 0) as share_pay_amount
|
|
|
from application.user_data_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
- group by movie_id
|
|
|
- ) tb3 on tb1.movie_id=tb3.movie_id
|
|
|
+ group by ma_appid, movie_id
|
|
|
+ ) tb3 on tb2.movie_id=tb3.movie_id and tb2.ma_appid = tb3.ma_appid
|
|
|
+ left join tidb.deepthink.mini_app_info app on coalesce(tb2.ma_appid, tb3.ma_appid)=app.app_id
|
|
|
left join
|
|
|
- (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_project_source,project_ad_date, ly_movie_name from tidb.deepthink.all_moive
|
|
|
- ) tb4 on tb1.movie_id=tb4.moive_id
|
|
|
+ (select moive_id as movie_id, movie_name, standard_movie_id, standard_movie_name, movie_source, movie_project_source,project_ad_date, ly_movie_name, movie_type from tidb.deepthink.all_moive
|
|
|
+ ) tb4
|
|
|
+ on coalesce(tb2.movie_id, tb3.movie_id)=tb4.movie_id and find_in_set(tb4.movie_source, app.movie_sources)> 0
|
|
|
left join
|
|
|
- (select movie_id, ifnull(sum(cost_amount), 0) as hour_cost_amount from application.media_ad_report_hourly
|
|
|
+ (select ma_appid, movie_id, ifnull(sum(cost_amount), 0) as hour_cost_amount
|
|
|
+ from application.media_ad_report_hourly
|
|
|
where stat_date=${date} and `hour`=${hour} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
- group by movie_id) tb5 on tb1.movie_id=tb5.movie_id
|
|
|
+ group by ma_appid, movie_id
|
|
|
+ ) tb5 on tb4.movie_id=tb5.movie_id and app.app_id = tb5.ma_appid
|
|
|
left join
|
|
|
(select dict_key, dict_name from tidb.deepthink.dt_dictionary where select_key='movie_project_source'
|
|
|
) tb6 on tb4.movie_project_source=tb6.dict_key
|
|
|
- where 1=1 and tb1.movie_id != '-9999'
|
|
|
- group by 1,2,3,4
|
|
|
+ where 1=1 and tb4.movie_id != '-9999'
|
|
|
+ group by 1,2,3,4,5
|
|
|
order by ${sort}
|
|
|
limit 20
|
|
|
</select>
|
|
|
@@ -287,11 +367,69 @@
|
|
|
left join (select user_id, nick_name, phonenumber, dept_id, status, del_flag from tidb.deepthink.sys_user) tb4
|
|
|
on tb1.user_id=tb4.user_id
|
|
|
left join (
|
|
|
- select dp.dept_id, dp.dept_name, ifnull(subdp.dept_id, dp.dept_id) as sub_dept_id, ifnull(subdp.dept_name, dp.dept_name) as sub_dept_name from (select * from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)) dp
|
|
|
+ select dp.dept_id, dp.dept_name, ifnull(subdp.dept_id, dp.dept_id) as sub_dept_id, ifnull(subdp.dept_name, dp.dept_name) as sub_dept_name from (select * from tidb.deepthink.sys_dept where parent_id in (300)) dp
|
|
|
right join tidb.deepthink.sys_dept subdp on dp.dept_id=subdp.parent_id
|
|
|
where dp.dept_id is not null
|
|
|
union all
|
|
|
- select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)
|
|
|
+ select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (300)
|
|
|
+ ) tb5
|
|
|
+ on tb4.dept_id = tb5.sub_dept_id
|
|
|
+ where tb1.user_id is not null and (tb4.nick_name not like '%IAP%' and tb4.nick_name not like '%IAA%')
|
|
|
+ and tb4.status = 0 and tb4.del_flag = 0
|
|
|
+ group by tb1.user_id, tb4.phonenumber, tb4.nick_name, tb5.dept_id, tb5.dept_name
|
|
|
+ having sum(cost_amount)>1
|
|
|
+ order by rk asc
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="optimizerCostRankV2" resultType="java.util.Map">
|
|
|
+ select tb1.user_id, tb4.phonenumber, tb4.nick_name, tb5.dept_id, tb5.dept_name,
|
|
|
+ rank() over (order by sum(cost_amount) desc) as rk,
|
|
|
+ <include refid="costAmount"/>,
|
|
|
+ <include refid="iaaRoi"/>,
|
|
|
+ <include refid="iapRoi"/>,
|
|
|
+ round(sum(dj_cost_amount), 2) as dj_cost_amount,
|
|
|
+ round(sum(mj_cost_amount), 2) as mj_cost_amount
|
|
|
+ from
|
|
|
+ (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null) tb1
|
|
|
+ left join
|
|
|
+ (select advertiser_id, sum(iaa_cost_amount) as iaa_cost_amount, sum(iaa_real_cost_amount) as iaa_real_cost_amount,
|
|
|
+ sum(iap_cost_amount) as iap_cost_amount, sum(iap_real_cost_amount) as iap_real_cost_amount,
|
|
|
+ sum(iaa_cost_amount)+sum(iap_cost_amount) as cost_amount,
|
|
|
+ sum(iaa_real_cost_amount)+sum(iap_real_cost_amount) as real_cost_amount,
|
|
|
+ sum(dj_cost_amount) as dj_cost_amount,
|
|
|
+ sum(mj_cost_amount) as mj_cost_amount
|
|
|
+ FROM
|
|
|
+ (select advertiser_id,
|
|
|
+ round(ifnull(sum(case when t2.business_method='IAA' then cost_amount else 0 end), 0), 2) as iaa_cost_amount,
|
|
|
+ round(ifnull(sum(case when t2.business_method='IAA' then real_cost_amount else 0 end), 0), 2) as iaa_real_cost_amount,
|
|
|
+ round(ifnull(sum(case when t2.business_method='IAP' then cost_amount else 0 end), 0), 2) as iap_cost_amount,
|
|
|
+ round(ifnull(sum(case when t2.business_method='IAP' then real_cost_amount else 0 end), 0), 2) as iap_real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(cost_amount, 0) else 0 end) as dj_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(cost_amount, 0) else 0 end) as mj_cost_amount
|
|
|
+ from application.media_ad_report_daily t1
|
|
|
+ join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
+ where stat_date=${date} and t2.business_line in (1,6,7,4,8,9,10)
|
|
|
+ group by advertiser_id
|
|
|
+ )subtb2
|
|
|
+ group by advertiser_id
|
|
|
+ ) tb2
|
|
|
+ on tb1.advertiser_id = tb2.advertiser_id
|
|
|
+ left join (select advertiser_id,
|
|
|
+ round(ifnull(sum(share_iaa_amount_3), 0),2) as share_iaa_amount_3,
|
|
|
+ sum(share_iaa_amount) as share_iaa_amount,
|
|
|
+ sum(share_pay_amount) as share_pay_amount
|
|
|
+ from application.user_data_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
+ group by advertiser_id) tb3
|
|
|
+ on tb1.advertiser_id = tb3.advertiser_id
|
|
|
+ left join (select user_id, nick_name, phonenumber, dept_id, status, del_flag from tidb.deepthink.sys_user) tb4
|
|
|
+ on tb1.user_id=tb4.user_id
|
|
|
+ left join (
|
|
|
+ select dp.dept_id, dp.dept_name, ifnull(subdp.dept_id, dp.dept_id) as sub_dept_id, ifnull(subdp.dept_name, dp.dept_name) as sub_dept_name from (select * from tidb.deepthink.sys_dept where parent_id in (300)) dp
|
|
|
+ right join tidb.deepthink.sys_dept subdp on dp.dept_id=subdp.parent_id
|
|
|
+ where dp.dept_id is not null
|
|
|
+ union all
|
|
|
+ select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (300)
|
|
|
) tb5
|
|
|
on tb4.dept_id = tb5.sub_dept_id
|
|
|
where tb1.user_id is not null and (tb4.nick_name not like '%IAP%' and tb4.nick_name not like '%IAA%')
|
|
|
@@ -300,6 +438,9 @@
|
|
|
having sum(cost_amount)>1
|
|
|
order by rk asc
|
|
|
</select>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
<select id="optimizerDateData" resultType="java.util.Map">
|
|
|
select tb1.user_id,tb4.phonenumber,tb4.nick_name, tb5.dept_id,
|
|
|
<include refid="costAmount"/>,
|
|
|
@@ -320,16 +461,18 @@
|
|
|
from application.user_data_report_daily
|
|
|
where stat_date = #{date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
group by advertiser_id) tb3 on tb1.advertiser_id = tb3.advertiser_id
|
|
|
- left join (select user_id, nick_name, phonenumber, dept_id from tidb.deepthink.sys_user) tb4
|
|
|
+ left join (select user_id, nick_name, phonenumber, dept_id, status, del_flag from tidb.deepthink.sys_user) tb4
|
|
|
on tb1.user_id=tb4.user_id
|
|
|
left join (
|
|
|
- select dp.dept_id, dp.dept_name, ifnull(subdp.dept_id, dp.dept_id) as sub_dept_id, ifnull(subdp.dept_name, dp.dept_name) as sub_dept_name from (select * from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)) dp
|
|
|
+ select dp.dept_id, dp.dept_name, ifnull(subdp.dept_id, dp.dept_id) as sub_dept_id, ifnull(subdp.dept_name, dp.dept_name) as sub_dept_name from (select * from tidb.deepthink.sys_dept where parent_id in (300)) dp
|
|
|
right join tidb.deepthink.sys_dept subdp on dp.dept_id=subdp.parent_id
|
|
|
where dp.dept_id is not null
|
|
|
union all
|
|
|
- select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)
|
|
|
+ select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (300)
|
|
|
) tb5
|
|
|
on tb4.dept_id = tb5.sub_dept_id
|
|
|
+ where tb1.user_id is not null and (tb4.nick_name not like '%IAP%' and tb4.nick_name not like '%IAA%')
|
|
|
+ and tb4.status = 0 and tb4.del_flag = 0
|
|
|
group by tb1.user_id, tb4.phonenumber, tb4.nick_name, tb5.dept_id
|
|
|
having sum(cost_amount)>0
|
|
|
</select>
|
|
|
@@ -353,22 +496,31 @@
|
|
|
from application.user_data_report_hourly
|
|
|
where stat_date = #{date} and `hour`= #{hour} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
group by advertiser_id) tb3 on tb1.advertiser_id = tb3.advertiser_id
|
|
|
- left join (select user_id, nick_name, phonenumber from tidb.deepthink.sys_user) tb4
|
|
|
+ left join (select user_id, nick_name, phonenumber, status, del_flag from tidb.deepthink.sys_user) tb4
|
|
|
on tb1.user_id=tb4.user_id
|
|
|
+ where tb1.user_id is not null and (tb4.nick_name not like '%IAP%' and tb4.nick_name not like '%IAA%')
|
|
|
+ and tb4.status = 0 and tb4.del_flag = 0
|
|
|
group by tb1.user_id, tb4.phonenumber
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<select id="deptCostRank" resultType="java.util.Map">
|
|
|
- select tb5.dept_id, tb5.dept_name,
|
|
|
+ select tb5.sub_dept_id as dept_id, concat(tb5.dept_name, '-', tb5.sub_dept_name) as dept_name,
|
|
|
rank() over (order by sum(cost_amount) desc) as rk,
|
|
|
<include refid="costAmount"/>,
|
|
|
+ sum(dj_cost_amount) as dj_cost_amount,
|
|
|
+ sum(mj_cost_amount) as mj_cost_amount,
|
|
|
ifnull(sum(cost_amount_hour), 0) as cost_amount_hour
|
|
|
from
|
|
|
(select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null) tb1
|
|
|
- left join (select advertiser_id, sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount
|
|
|
- from application.media_ad_report_daily where stat_date=#{date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
+ left join (select advertiser_id, sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(cost_amount, 0) else 0 end) as dj_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(cost_amount, 0) else 0 end) as mj_cost_amount
|
|
|
+ from application.media_ad_report_daily t1
|
|
|
+ join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
+ where stat_date=#{date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where t2.business_line in (1,6,7,4,8,9,10))
|
|
|
group by advertiser_id) tb2
|
|
|
on tb1.advertiser_id = tb2.advertiser_id
|
|
|
left join (select advertiser_id, sum(cost_amount) as cost_amount_hour
|
|
|
@@ -378,14 +530,14 @@
|
|
|
left join (select user_id, nick_name, phonenumber, dept_id from tidb.deepthink.sys_user) tb4
|
|
|
on tb1.user_id=tb4.user_id
|
|
|
left join (
|
|
|
- select dp.dept_id, dp.dept_name, ifnull(subdp.dept_id, dp.dept_id) as sub_dept_id, ifnull(subdp.dept_name, dp.dept_name) as sub_dept_name from (select * from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)) dp
|
|
|
+ select dp.dept_id, dp.dept_name, ifnull(subdp.dept_id, dp.dept_id) as sub_dept_id, ifnull(subdp.dept_name, dp.dept_name) as sub_dept_name from (select * from tidb.deepthink.sys_dept where parent_id in (300)) dp
|
|
|
right join tidb.deepthink.sys_dept subdp on dp.dept_id=subdp.parent_id
|
|
|
where dp.dept_id is not null
|
|
|
union all
|
|
|
- select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)
|
|
|
+ select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (300)
|
|
|
) tb5
|
|
|
on tb4.dept_id = tb5.sub_dept_id
|
|
|
- group by tb5.dept_id, tb5.dept_name
|
|
|
+ group by tb5.sub_dept_id, tb5.dept_name, tb5.sub_dept_name
|
|
|
having sum(cost_amount)>1
|
|
|
order by rk asc
|
|
|
limit 10
|
|
|
@@ -456,15 +608,7 @@
|
|
|
where tb1.ma_appid != tb2.ma_appid
|
|
|
order by tb2.user_id
|
|
|
</select>
|
|
|
- <select id="deptRank2" resultType="java.util.Map">
|
|
|
- select tb5.dept_id, tb5.dept_name,
|
|
|
- rank() over (order by sum(cost_amount) desc) as rk,
|
|
|
- <include refid="costAmount"/>,
|
|
|
- <include refid="sharePayAmount"/>,
|
|
|
- <include refid="shareIaaAmount3"/>,
|
|
|
- <include refid="iaaRoi"/>,
|
|
|
- <include refid="iapRoi"/>
|
|
|
- from
|
|
|
+ <sql id="deptRankSqlPart">
|
|
|
(select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null and user_id != -9999 ) tb1
|
|
|
left join
|
|
|
(select advertiser_id, sum(iaa_cost_amount) as iaa_cost_amount, sum(iaa_real_cost_amount) as iaa_real_cost_amount,
|
|
|
@@ -480,30 +624,51 @@
|
|
|
from application.media_ad_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10) and business_method='IAP')
|
|
|
group by advertiser_id)subtb2
|
|
|
group by advertiser_id
|
|
|
- ) tb2
|
|
|
+ ) tb2
|
|
|
on tb1.advertiser_id = tb2.advertiser_id
|
|
|
- left join (select advertiser_id,
|
|
|
- round(ifnull(sum(share_iaa_amount_3), 0),2) as share_iaa_amount_3,
|
|
|
- ifnull(sum(share_iaa_amount), 0) as share_iaa_amount,
|
|
|
- sum(share_pay_amount) as share_pay_amount
|
|
|
- from application.user_data_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
- group by advertiser_id) tb3
|
|
|
- on tb1.advertiser_id = tb3.advertiser_id
|
|
|
- left join (select user_id, nick_name, phonenumber, dept_id from tidb.deepthink.sys_user) tb4
|
|
|
- on tb1.user_id=tb4.user_id
|
|
|
- left join (
|
|
|
- select dp.dept_id, dp.dept_name, ifnull(subdp.dept_id, dp.dept_id) as sub_dept_id, ifnull(subdp.dept_name, dp.dept_name) as sub_dept_name from (select * from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)) dp
|
|
|
+ left join (select advertiser_id,
|
|
|
+ round(ifnull(sum(share_iaa_amount_3), 0),2) as share_iaa_amount_3,
|
|
|
+ ifnull(sum(share_iaa_amount), 0) as share_iaa_amount,
|
|
|
+ sum(share_pay_amount) as share_pay_amount
|
|
|
+ from application.user_data_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
+ group by advertiser_id) tb3
|
|
|
+ on tb1.advertiser_id = tb3.advertiser_id
|
|
|
+ left join (select user_id, nick_name, phonenumber, dept_id from tidb.deepthink.sys_user) tb4
|
|
|
+ on tb1.user_id=tb4.user_id
|
|
|
+ left join (
|
|
|
+ select dp.dept_id, dp.dept_name, ifnull(subdp.dept_id, dp.dept_id) as sub_dept_id, ifnull(subdp.dept_name, dp.dept_name) as sub_dept_name from (select * from tidb.deepthink.sys_dept where parent_id in (300)) dp
|
|
|
right join tidb.deepthink.sys_dept subdp on dp.dept_id=subdp.parent_id
|
|
|
where dp.dept_id is not null
|
|
|
union all
|
|
|
- select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)
|
|
|
- ) tb5
|
|
|
- on tb4.dept_id = tb5.sub_dept_id
|
|
|
- where tb4.user_id is not null
|
|
|
- group by tb5.dept_id, tb5.dept_name
|
|
|
+ select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (300)
|
|
|
+ ) tb5
|
|
|
+ on tb4.dept_id = tb5.sub_dept_id
|
|
|
+ where tb4.user_id is not null and tb5.dept_id is not null
|
|
|
+ </sql>
|
|
|
+ <select id="deptRank2" resultType="java.util.Map">
|
|
|
+ select tb5.sub_dept_id as dept_id, concat(tb5.dept_name, '-', tb5.sub_dept_name) as dept_name,
|
|
|
+ rank() over (order by sum(cost_amount) desc) as rk,
|
|
|
+ <include refid="costAmount"/>,
|
|
|
+ <include refid="sharePayAmount"/>,
|
|
|
+ <include refid="shareIaaAmount3"/>,
|
|
|
+ <include refid="iaaRoi"/>,
|
|
|
+ <include refid="iapRoi"/>
|
|
|
+ from
|
|
|
+ <include refid="deptRankSqlPart"/>
|
|
|
+ group by tb5.sub_dept_id, tb5.sub_dept_name, tb5.dept_name
|
|
|
having sum(cost_amount)>1
|
|
|
order by rk
|
|
|
</select>
|
|
|
+ <select id="deptRankTotal" resultType="java.util.Map">
|
|
|
+ select 0 as dept_id, '总计' as dept_name, '总计' as rk,
|
|
|
+ <include refid="costAmount"/>,
|
|
|
+ <include refid="sharePayAmount"/>,
|
|
|
+ <include refid="shareIaaAmount3"/>,
|
|
|
+ <include refid="iaaRoi"/>,
|
|
|
+ <include refid="iapRoi"/>
|
|
|
+ from
|
|
|
+ <include refid="deptRankSqlPart"/>
|
|
|
+ </select>
|
|
|
<select id="cutDeptRank" resultType="java.util.Map">
|
|
|
select row_number() over (order by sum(cost) desc) as ranks,
|
|
|
dept_name as dept_name,
|
|
|
@@ -535,30 +700,53 @@
|
|
|
</select>
|
|
|
<select id="allBusinessPushData" resultType="java.util.Map">
|
|
|
select
|
|
|
- <include refid="costAmount"/>,
|
|
|
- <include refid="realCostAmount"/>,
|
|
|
- <include refid="payAmount"/>,
|
|
|
- <include refid="iaaAmount"/>,
|
|
|
- <include refid="shareIaaAmount"/>,
|
|
|
- <include refid="realProfit"/>,
|
|
|
- <include refid="waterProfit"/>,
|
|
|
- <include refid="waterEndAmount"/>,
|
|
|
- <include refid="endAmount"/>,
|
|
|
- date_format(max(update_time), '%Y-%m-%d %H:%i:%s') as update_time
|
|
|
+ round(ifnull(sum(iaa_amount), 0) + ifnull(sum(pay_amount), 0), 2) AS water_end_amount,
|
|
|
+ round(ifnull(sum(dj_iaa_amount), 0) + ifnull(sum(dj_pay_amount), 0), 2) AS dj_water_end_amount,
|
|
|
+ round(ifnull(sum(mj_iaa_amount), 0) + ifnull(sum(mj_pay_amount), 0), 2) AS mj_water_end_amount,
|
|
|
+ round(ifnull(sum(share_iaa_amount), 0) + ifnull(sum(share_pay_amount), 0), 2) as end_amount,
|
|
|
+ round(ifnull(sum(dj_share_iaa_amount), 0) + ifnull(sum(dj_share_pay_amount), 0), 2) as dj_end_amount,
|
|
|
+ round(ifnull(sum(mj_share_iaa_amount), 0) + ifnull(sum(mj_share_pay_amount), 0), 2) as mj_end_amount,
|
|
|
+ round(ifnull(sum(share_iaa_amount_3), 0) + ifnull(sum(share_pay_amount), 0) - ifnull(sum(real_cost_amount), 0), 2) AS real_profit,
|
|
|
+ round(ifnull(sum(dj_share_iaa_amount_3), 0) + ifnull(sum(dj_share_pay_amount), 0) - ifnull(sum(dj_real_cost_amount), 0), 2) AS dj_real_profit,
|
|
|
+ round(ifnull(sum(mj_share_iaa_amount_3), 0) + ifnull(sum(mj_share_pay_amount), 0) - ifnull(sum(mj_real_cost_amount), 0), 2) AS mj_real_profit,
|
|
|
+ date_format(max(update_at), '%Y-%m-%d %H:%i:%s') as update_time
|
|
|
from
|
|
|
- (select sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount, max(update_time) as update_time
|
|
|
- from application.media_ad_report_daily
|
|
|
+ (select sum(cost_amount) as cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(cost_amount, 0) else 0 end) as dj_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(cost_amount, 0) else 0 end) as mj_cost_amount,
|
|
|
+ sum(real_cost_amount) as real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(real_cost_amount, 0) else 0 end) as dj_real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(real_cost_amount, 0) else 0 end) as mj_real_cost_amount,
|
|
|
+ max(t1.update_time) as update_time
|
|
|
+ from application.media_ad_report_daily t1
|
|
|
+ left join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ left join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
where stat_date = #{date}
|
|
|
) tb1,
|
|
|
- (select sum(pay_amount) as pay_amount, sum(iaa_amount) as iaa_amount,
|
|
|
- sum(share_iaa_amount) as share_iaa_amount, sum(share_pay_amount) as share_pay_amount,
|
|
|
- sum(share_iaa_amount_3) as share_iaa_amount_3
|
|
|
- from application.user_data_report_daily
|
|
|
+ (select sum(pay_amount) as pay_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(pay_amount, 0) else 0 end) as dj_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(pay_amount, 0) else 0 end) as mj_pay_amount,
|
|
|
+ sum(share_iaa_amount) as share_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_iaa_amount, 0) else 0 end) as dj_share_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_iaa_amount, 0) else 0 end) as mj_share_iaa_amount,
|
|
|
+ sum(share_iaa_amount_3) as share_iaa_amount_3,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_iaa_amount_3, 0) else 0 end) as dj_share_iaa_amount_3,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_iaa_amount_3, 0) else 0 end) as mj_share_iaa_amount_3,
|
|
|
+ sum(share_pay_amount) as share_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(share_pay_amount, 0) else 0 end) as dj_share_pay_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(share_pay_amount, 0) else 0 end) as mj_share_pay_amount,
|
|
|
+ sum(iaa_amount) as iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(iaa_amount, 0) else 0 end) as dj_iaa_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(iaa_amount, 0) else 0 end) as mj_iaa_amount, max(update_at) as update_at
|
|
|
+ from application.user_data_report_daily t1
|
|
|
+ left join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ left join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
where stat_date = #{date}
|
|
|
+ and t2.business_line in (1,6,7,4,8,9,10)
|
|
|
) tb2
|
|
|
</select>
|
|
|
<select id="allBusinessTopMovie" resultType="java.util.Map">
|
|
|
- select tb4.ly_movie_name as movie_name, tb4.movie_project_source, tb5.dict_name as movie_project_source_name,
|
|
|
+ select tb4.ly_movie_name as movie_name, tb4.movie_project_source, tb5.dict_name as movie_project_source_name, tb4.movie_type,
|
|
|
group_concat(distinct case tb4.movie_source when 2 then '2' else '1' end) as movie_source,
|
|
|
rank() over (order by sum(share_iaa_amount)+sum(share_pay_amount) desc) as rk,
|
|
|
<include refid="endAmount"/>,
|
|
|
@@ -583,13 +771,13 @@
|
|
|
group by movie_id
|
|
|
) tb3 on tb1.movie_id=tb3.movie_id
|
|
|
left join
|
|
|
- (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_project_source, ly_movie_name from tidb.deepthink.all_moive
|
|
|
+ (select moive_id, standard_movie_id, standard_movie_name, movie_source, movie_type, movie_project_source, ly_movie_name from tidb.deepthink.all_moive
|
|
|
) tb4 on tb1.movie_id=tb4.moive_id
|
|
|
left join
|
|
|
(select dict_key, dict_name from tidb.deepthink.dt_dictionary where select_key='movie_project_source'
|
|
|
) tb5 on tb4.movie_project_source=tb5.dict_key
|
|
|
where 1=1 and tb1.movie_id!='-9999'
|
|
|
- group by tb4.ly_movie_name, tb4.movie_project_source, tb5.dict_name
|
|
|
+ group by tb4.ly_movie_name, tb4.movie_project_source, tb5.dict_name, tb4.movie_type
|
|
|
order by sum(share_iaa_amount)+sum(share_pay_amount) desc
|
|
|
limit 20
|
|
|
</select>
|