|
@@ -0,0 +1,412 @@
|
|
|
+<?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.MediaReportMapper">
|
|
|
+ <select id="queryAdvertiserNameByCompanyId" resultType="com.alibaba.fastjson.JSONObject">
|
|
|
+ SELECT id,
|
|
|
+ name
|
|
|
+ from ctop_advertiser
|
|
|
+ where company_id = #{companyId}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="queryProjectNameByAdvertiserId" resultType="com.alibaba.fastjson.JSONObject">
|
|
|
+ SELECT id,
|
|
|
+ project_name
|
|
|
+ from ctop_project
|
|
|
+ where advertiser_id = #{advertiserId}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="queryAllBy" resultType="com.alibaba.fastjson.JSONObject">
|
|
|
+ SELECT e.*
|
|
|
+ from (
|
|
|
+ SELECT r.*, (r.todayCost - r.yesterdayCost) as diffCost
|
|
|
+ from (
|
|
|
+ SELECT t1.advertiser_type as mediaType,
|
|
|
+ t1.company_id as companyId,
|
|
|
+ t1.id as advertiserId,
|
|
|
+ t1.NAME as advertiserName,
|
|
|
+ t2.id as projectId,
|
|
|
+ t2.project_name as projectName,
|
|
|
+ t2.responsible_name as operatorManger,
|
|
|
+ t2.design_responsible_name as designManger,
|
|
|
+ (SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ from ctop_user_allocation t3
|
|
|
+ where t2.id = t3.project_id) as operator,
|
|
|
+ (SELECT realname from sys_user u WHERE u.id = t1.sale_id) as sale,
|
|
|
+ (SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ from ctop_project_member member
|
|
|
+ where t2.id = member.project_id
|
|
|
+ and role_code = 'plan') as plan,
|
|
|
+ (SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ from ctop_project_member member
|
|
|
+ where t2.id = member.project_id
|
|
|
+ and role_code = 'shot') as shot,
|
|
|
+ (SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ from ctop_project_member member
|
|
|
+ where t2.id = member.project_id
|
|
|
+ and role_code = 'clip') as clip,
|
|
|
+ case
|
|
|
+ when
|
|
|
+ (SELECT sum(cost)
|
|
|
+ from ctop_bytedance_report_advertiser_daily report
|
|
|
+ where report.advertiser_id in (SELECT account_id
|
|
|
+ from ctop_user_allocation t3
|
|
|
+ where t2.id = t3.project_id)
|
|
|
+ and report.stat_datetime = '${todayDate} 00:00:00') is null then 0
|
|
|
+ else (SELECT sum(cost)
|
|
|
+ from ctop_bytedance_report_advertiser_daily report
|
|
|
+ where report.advertiser_id in (SELECT account_id
|
|
|
+ from ctop_user_allocation t3
|
|
|
+ where t2.id = t3.project_id)
|
|
|
+ and report.stat_datetime = '${todayDate} 00:00:00') END as todayCost,
|
|
|
+ case
|
|
|
+ when
|
|
|
+ (SELECT sum(cost)
|
|
|
+ from ctop_bytedance_report_advertiser_daily report
|
|
|
+ where report.advertiser_id in (SELECT account_id
|
|
|
+ from ctop_user_allocation t3
|
|
|
+ where t2.id = t3.project_id)
|
|
|
+ and report.stat_datetime = '${yesterdayDate} 00:00:00') is null then 0
|
|
|
+ else (SELECT sum(cost)
|
|
|
+ from ctop_bytedance_report_advertiser_daily report
|
|
|
+ where report.advertiser_id in (SELECT account_id
|
|
|
+ from ctop_user_allocation t3
|
|
|
+ where t2.id = t3.project_id)
|
|
|
+ and report.stat_datetime = '${yesterdayDate} 00:00:00') end as yesterdayCost
|
|
|
+ FROM ctop_advertiser t1
|
|
|
+ LEFT JOIN ctop_project t2 ON t1.id = t2.advertiser_id
|
|
|
+ where t1.advertiser_type = 1 and t2.id is not null) as r
|
|
|
+
|
|
|
+ UNION
|
|
|
+
|
|
|
+ SELECT r.*, (r.todayCost - r.yesterdayCost) as diffCost
|
|
|
+ from (
|
|
|
+ SELECT t1.advertiser_type as mediaType,
|
|
|
+ t1.company_id as companyId,
|
|
|
+ t1.id as advertiserId,
|
|
|
+ t1.NAME as advertiserName,
|
|
|
+ t2.id as projectId,
|
|
|
+ t2.project_name as projectName,
|
|
|
+ t2.responsible_name as operatorManger,
|
|
|
+ t2.design_responsible_name as designManger,
|
|
|
+ (SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ from ctop_user_allocation t3
|
|
|
+ where t2.id = t3.project_id) as operator,
|
|
|
+ (SELECT realname from sys_user u WHERE u.id = t1.sale_id) as sale,
|
|
|
+ (SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ from ctop_project_member member
|
|
|
+ where t2.id = member.project_id
|
|
|
+ and role_code = 'plan') as plan,
|
|
|
+ (SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ from ctop_project_member member
|
|
|
+ where t2.id = member.project_id
|
|
|
+ and role_code = 'shot') as shot,
|
|
|
+ (SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ from ctop_project_member member
|
|
|
+ where t2.id = member.project_id
|
|
|
+ and role_code = 'clip') as clip,
|
|
|
+ case
|
|
|
+ when
|
|
|
+ (SELECT sum(charge)
|
|
|
+ from ctop_kuaishou_report_daily_account report
|
|
|
+ where report.account_id in (SELECT account_id
|
|
|
+ from ctop_user_allocation t3
|
|
|
+ where t2.id = t3.project_id)
|
|
|
+ and report.stat_date = '${todayDate}') is null then 0
|
|
|
+ ELSE (SELECT sum(charge)
|
|
|
+ from ctop_kuaishou_report_daily_account report
|
|
|
+ where report.account_id in (SELECT account_id
|
|
|
+ from ctop_user_allocation t3
|
|
|
+ where t2.id = t3.project_id)
|
|
|
+ and report.stat_date = '${todayDate}') END as todayCost,
|
|
|
+ case
|
|
|
+ when
|
|
|
+ (SELECT sum(charge)
|
|
|
+ from ctop_kuaishou_report_daily_account report
|
|
|
+ where report.account_id in (SELECT account_id
|
|
|
+ from ctop_user_allocation t3
|
|
|
+ where t2.id = t3.project_id)
|
|
|
+ and report.stat_date = '${yesterdayDate}') is null then 0
|
|
|
+ ELSE (SELECT sum(charge)
|
|
|
+ from ctop_kuaishou_report_daily_account report
|
|
|
+ where report.account_id in (SELECT account_id
|
|
|
+ from ctop_user_allocation t3
|
|
|
+ where t2.id = t3.project_id)
|
|
|
+ and report.stat_date = '${yesterdayDate}') end as yesterdayCost
|
|
|
+ FROM ctop_advertiser t1
|
|
|
+ LEFT JOIN ctop_project t2 ON t1.id = t2.advertiser_id
|
|
|
+ where t1.advertiser_type = 2 and t2.id is not null) as r
|
|
|
+
|
|
|
+ union
|
|
|
+
|
|
|
+ SELECT r.*, (r.todayCost - r.yesterdayCost) as diffCost
|
|
|
+ from (
|
|
|
+ SELECT '0' as mediaType,
|
|
|
+ '-' as companyId,
|
|
|
+ id as advertiserId,
|
|
|
+ corporation_name as advertiserName,
|
|
|
+ '-' as projectId,
|
|
|
+ account_name as projectName,
|
|
|
+ '-' as operatorManger,
|
|
|
+ '-' as designManger,
|
|
|
+ '-' as operator,
|
|
|
+ '-' as sale,
|
|
|
+ '-' as plan,
|
|
|
+ '-' as shot,
|
|
|
+ '-' as clip,
|
|
|
+ case
|
|
|
+ WHEN
|
|
|
+ (SELECT sum(balance)
|
|
|
+ from ctop_kuaishou_agent_account report
|
|
|
+ where report.id = t1.id
|
|
|
+ and report.create_time like '%${todayDate}%') is null THEN 0
|
|
|
+ ELSE (SELECT sum(balance)
|
|
|
+ from ctop_kuaishou_agent_account report
|
|
|
+ where report.id = t1.id
|
|
|
+ and report.create_time like '%${todayDate}%') end as todayCost,
|
|
|
+ case
|
|
|
+ WHEN
|
|
|
+ (SELECT sum(balance)
|
|
|
+ from ctop_kuaishou_agent_account report
|
|
|
+ where report.id = t1.id
|
|
|
+ and report.create_time like '%${yesterdayDate}%') is null THEN 0
|
|
|
+ ELSE (SELECT sum(balance)
|
|
|
+ from ctop_kuaishou_agent_account report
|
|
|
+ where report.id = t1.id
|
|
|
+ and report.create_time like '%${yesterdayDate}%') end as yesterdayCost
|
|
|
+ from ctop_kuaishou_agent_account t1
|
|
|
+ where t1.create_time like '%${yesterdayDate}%'
|
|
|
+ GROUP by advertiserName, projectName) as r) as e
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="queryMediaReportBy" resultType="com.alibaba.fastjson.JSONObject">
|
|
|
+ SELECT e.*
|
|
|
+ FROM (
|
|
|
+ SELECT r.*,
|
|
|
+ (r.todayCost - r.yesterdayCost) AS diffCost
|
|
|
+ FROM (
|
|
|
+ SELECT t1.advertiser_type AS mediaType,
|
|
|
+ t1.company_id as companyId,
|
|
|
+ t1.id as advertiserId,
|
|
|
+ t1.NAME as advertiserName,
|
|
|
+ t2.id as projectId,
|
|
|
+ t2.project_name AS projectName,
|
|
|
+ t2.responsible_name AS operatorManger,
|
|
|
+ t2.design_responsible_name AS designManger,
|
|
|
+ (
|
|
|
+ SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ FROM ctop_user_allocation t3
|
|
|
+ WHERE t2.id = t3.project_id
|
|
|
+ ) AS operator,
|
|
|
+ (
|
|
|
+ SELECT realname
|
|
|
+ FROM sys_user u
|
|
|
+ WHERE u.id = t1.sale_id
|
|
|
+ ) AS sale,
|
|
|
+ (
|
|
|
+ SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ FROM ctop_project_member member
|
|
|
+ WHERE t2.id = member.project_id
|
|
|
+ AND role_code = 'plan'
|
|
|
+ ) AS plan,
|
|
|
+ (
|
|
|
+ SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ FROM ctop_project_member member
|
|
|
+ WHERE t2.id = member.project_id
|
|
|
+ AND role_code = 'shot'
|
|
|
+ ) AS shot,
|
|
|
+ (
|
|
|
+ SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ FROM ctop_project_member member
|
|
|
+ WHERE t2.id = member.project_id
|
|
|
+ AND role_code = 'clip'
|
|
|
+ ) AS clip,
|
|
|
+ CASE
|
|
|
+ WHEN (
|
|
|
+ SELECT sum(cost)
|
|
|
+ FROM ctop_bytedance_report_advertiser_daily report
|
|
|
+ WHERE report.advertiser_id IN (
|
|
|
+ SELECT account_id
|
|
|
+ FROM ctop_user_allocation t3
|
|
|
+ WHERE t2.id = t3.project_id
|
|
|
+ )
|
|
|
+ AND report.stat_datetime = '${todayDate} 00:00:00'
|
|
|
+ ) IS NULL THEN
|
|
|
+ 0
|
|
|
+ ELSE
|
|
|
+ (
|
|
|
+ SELECT sum(cost)
|
|
|
+ FROM ctop_bytedance_report_advertiser_daily report
|
|
|
+ WHERE report.advertiser_id IN (
|
|
|
+ SELECT account_id
|
|
|
+ FROM ctop_user_allocation t3
|
|
|
+ WHERE t2.id = t3.project_id
|
|
|
+ )
|
|
|
+ AND report.stat_datetime = '${todayDate} 00:00:00'
|
|
|
+ )
|
|
|
+ END AS todayCost,
|
|
|
+ CASE
|
|
|
+ WHEN (
|
|
|
+ SELECT sum(cost)
|
|
|
+ FROM ctop_bytedance_report_advertiser_daily report
|
|
|
+ WHERE report.advertiser_id IN (
|
|
|
+ SELECT account_id
|
|
|
+ FROM ctop_user_allocation t3
|
|
|
+ WHERE t2.id = t3.project_id
|
|
|
+ )
|
|
|
+ AND report.stat_datetime = '${yesterdayDate} 00:00:00'
|
|
|
+ ) IS NULL THEN
|
|
|
+ 0
|
|
|
+ ELSE
|
|
|
+ (
|
|
|
+ SELECT sum(cost)
|
|
|
+ FROM ctop_bytedance_report_advertiser_daily report
|
|
|
+ WHERE report.advertiser_id IN (
|
|
|
+ SELECT account_id
|
|
|
+ FROM ctop_user_allocation t3
|
|
|
+ WHERE t2.id = t3.project_id
|
|
|
+ )
|
|
|
+ AND report.stat_datetime = '${yesterdayDate} 00:00:00'
|
|
|
+ )
|
|
|
+ END AS yesterdayCost
|
|
|
+ FROM ctop_advertiser t1
|
|
|
+ LEFT JOIN ctop_project t2 ON t1.id = t2.advertiser_id
|
|
|
+ WHERE t1.advertiser_type = 1 and t2.id is not null
|
|
|
+ ) AS r
|
|
|
+ UNION
|
|
|
+ SELECT r.*,
|
|
|
+ (r.todayCost - r.yesterdayCost) AS diffCost
|
|
|
+ FROM (
|
|
|
+ SELECT t1.advertiser_type AS mediaType,
|
|
|
+ t1.company_id as companyId,
|
|
|
+ t1.id as advertiserId,
|
|
|
+ t1.NAME as advertiserName,
|
|
|
+ t2.id as projectId,
|
|
|
+ t2.project_name AS projectName,
|
|
|
+ t2.responsible_name AS operatorManger,
|
|
|
+ t2.design_responsible_name AS designManger,
|
|
|
+ (
|
|
|
+ SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ FROM ctop_user_allocation t3
|
|
|
+ WHERE t2.id = t3.project_id
|
|
|
+ ) AS operator,
|
|
|
+ (
|
|
|
+ SELECT realname
|
|
|
+ FROM sys_user u
|
|
|
+ WHERE u.id = t1.sale_id
|
|
|
+ ) AS sale,
|
|
|
+ (
|
|
|
+ SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ FROM ctop_project_member member
|
|
|
+ WHERE t2.id = member.project_id
|
|
|
+ AND role_code = 'plan'
|
|
|
+ ) AS plan,
|
|
|
+ (
|
|
|
+ SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ FROM ctop_project_member member
|
|
|
+ WHERE t2.id = member.project_id
|
|
|
+ AND role_code = 'shot'
|
|
|
+ ) AS shot,
|
|
|
+ (
|
|
|
+ SELECT GROUP_CONCAT(DISTINCT user_name)
|
|
|
+ FROM ctop_project_member member
|
|
|
+ WHERE t2.id = member.project_id
|
|
|
+ AND role_code = 'clip'
|
|
|
+ ) AS clip,
|
|
|
+ CASE
|
|
|
+ WHEN (
|
|
|
+ SELECT sum(charge)
|
|
|
+ FROM ctop_kuaishou_report_daily_account report
|
|
|
+ WHERE report.account_id IN (
|
|
|
+ SELECT account_id
|
|
|
+ FROM ctop_user_allocation t3
|
|
|
+ WHERE t2.id = t3.project_id
|
|
|
+ )
|
|
|
+ AND report.stat_date = '${todayDate}'
|
|
|
+ ) IS NULL THEN
|
|
|
+ 0
|
|
|
+ ELSE
|
|
|
+ (
|
|
|
+ SELECT sum(charge)
|
|
|
+ FROM ctop_kuaishou_report_daily_account report
|
|
|
+ WHERE report.account_id IN (
|
|
|
+ SELECT account_id
|
|
|
+ FROM ctop_user_allocation t3
|
|
|
+ WHERE t2.id = t3.project_id
|
|
|
+ )
|
|
|
+ AND report.stat_date = '${todayDate}'
|
|
|
+ )
|
|
|
+ END AS todayCost,
|
|
|
+ CASE
|
|
|
+ WHEN (
|
|
|
+ SELECT sum(charge)
|
|
|
+ FROM ctop_kuaishou_report_daily_account report
|
|
|
+ WHERE report.account_id IN (
|
|
|
+ SELECT account_id
|
|
|
+ FROM ctop_user_allocation t3
|
|
|
+ WHERE t2.id = t3.project_id
|
|
|
+ )
|
|
|
+ AND report.stat_date = '${yesterdayDate}'
|
|
|
+ ) IS NULL THEN
|
|
|
+ 0
|
|
|
+ ELSE
|
|
|
+ (
|
|
|
+ SELECT sum(charge)
|
|
|
+ FROM ctop_kuaishou_report_daily_account report
|
|
|
+ WHERE report.account_id IN (
|
|
|
+ SELECT account_id
|
|
|
+ FROM ctop_user_allocation t3
|
|
|
+ WHERE t2.id = t3.project_id
|
|
|
+ )
|
|
|
+ AND report.stat_date = '${yesterdayDate}'
|
|
|
+ )
|
|
|
+ END AS yesterdayCost
|
|
|
+ FROM ctop_advertiser t1
|
|
|
+ LEFT JOIN ctop_project t2 ON t1.id = t2.advertiser_id
|
|
|
+ WHERE t1.advertiser_type = 2 and t2.id is not null
|
|
|
+ ) AS r) as e
|
|
|
+ where companyId = ${condition}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="queryAgentReportBy" resultType="com.alibaba.fastjson.JSONObject">
|
|
|
+ SELECT e.* from(
|
|
|
+ SELECT r.*, (r.todayCost - r.yesterdayCost) as diffCost
|
|
|
+ from (
|
|
|
+ SELECT '0' as mediaType,
|
|
|
+ '-' as companyId,
|
|
|
+ id as advertiserId,
|
|
|
+ corporation_name as advertiserName,
|
|
|
+ '-' as projectId,
|
|
|
+ account_name as projectName,
|
|
|
+ '-' as operatorManger,
|
|
|
+ '-' as designManger,
|
|
|
+ '-' as operator,
|
|
|
+ '-' as sale,
|
|
|
+ '-' as plan,
|
|
|
+ '-' as shot,
|
|
|
+ '-' as clip,
|
|
|
+ case
|
|
|
+ WHEN
|
|
|
+ (SELECT sum(balance)
|
|
|
+ from ctop_kuaishou_agent_account report
|
|
|
+ where report.id = t1.id
|
|
|
+ and report.create_time like '%${todayDate}%') is null THEN 0
|
|
|
+ ELSE (SELECT sum(balance)
|
|
|
+ from ctop_kuaishou_agent_account report
|
|
|
+ where report.id = t1.id
|
|
|
+ and report.create_time like '%${todayDate}%') end as todayCost,
|
|
|
+ case
|
|
|
+ WHEN
|
|
|
+ (SELECT sum(balance)
|
|
|
+ from ctop_kuaishou_agent_account report
|
|
|
+ where report.id = t1.id
|
|
|
+ and report.create_time like '%${yesterdayDate}%') is null THEN 0
|
|
|
+ ELSE (SELECT sum(balance)
|
|
|
+ from ctop_kuaishou_agent_account report
|
|
|
+ where report.id = t1.id
|
|
|
+ and report.create_time like '%${yesterdayDate}%') end as yesterdayCost
|
|
|
+ from ctop_kuaishou_agent_account t1
|
|
|
+ where t1.create_time like '%${yesterdayDate}%'
|
|
|
+ GROUP by advertiserName, projectName
|
|
|
+ )as r) as e
|
|
|
+ </select>
|
|
|
+</mapper>
|