<?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.bytedance.mapper.PlatformCampaignStatisticInfoMapper">
    <resultMap id="voMap" type="org.jeecg.modules.ctop.vo.StatisticCampaignVo">
        <result column="statisticDate" property="statisticDate"/>
        <result column="proxy" property="proxy"/>
        <result column="deliverySystem" property="deliverySystem"/>
        <result column="channelName" property="channelName"/>
		<result column="content" property="content"/>
        <result column="meterial" property="meterial"/>
        <result column="priceType" property="priceType"/>
		<result column="directCondition" property="directCondition"/>
        <result column="basicDirect" property="basicDirect"/>
        <result column="cost" property="cost"/>
        <result column="coverViews" property="coverViews"/>
        <result column="coverClick" property="coverClick"/>
        <result column="creditRegistRateDay" property="creditRegistRateDay"/>
		<result column="creditRateDay" property="creditRateDay"/>
        <result column="completeRateDay" property="completeRateDay"/>
        <result column="registCreditRate" property="registCreditRate"/>
        <result column="registCompleteRate" property="registCompleteRate"/>
        <result column="creditRate" property="creditRate"/>
		<result column="completeRate" property="completeRate"/>
        <result column="materialViews" property="materialViews"/>
        <result column="actions" property="actions"/>
		<result column="clickRate" property="clickRate"/>
		<result column="actionClickRate" property="actionClickRate"/>
		<result column="abctr" property="abctr"/>
        <result column="clickPrice" property="clickPrice"/>
        <result column="actionPrice" property="actionPrice"/>
        <result column="registUserNum" property="registUserNum"/>
		<result column="complateUserNum" property="complateUserNum"/>
        <result column="creditUserNum" property="creditUserNum"/>
        <result column="registCompleteNum" property="registCompleteNum"/>
        <result column="registCreditNum" property="registCreditNum"/>
        <result column="registPrice" property="registPrice"/>
        <result column="completePrice" property="completePrice"/>
        <result column="creditPrice" property="creditPrice"/>
        <result column="registCompletePrice" property="registCompletePrice"/>
        <result column="registCreditPrice" property="registCreditPrice"/>
		<result column="clickRegistRate" property="clickRegistRate"/>
		<result column="actionRegistRate" property="actionRegistRate"/>
    </resultMap>

	<select id="getTotalStatisticVoByparams" resultMap="voMap">
        SELECT
	SUM(a.cost) AS 'cost',
	SUM(a.coverViews) AS 'coverViews',
	SUM(a.coverClick) AS 'coverClick',
	SUM(a.materialViews) AS 'materialViews',
	SUM(a.actions) AS'actions',
	SUM(a.coverClick) / SUM(a.coverViews) * 100 AS 'clickRate',
	SUM(a.actions) / SUM(a.coverClick) * 100 AS 'actionClickRate',
	SUM(a.actions) / SUM(a.coverClick) * SUM(a.coverClick) / SUM(a.coverViews) * 10000 AS 'abctr',
	SUM(a.cost) / SUM(a.coverClick) 'clickPrice',
	SUM(a.cost) / SUM(a.actions) 'actionPrice',
	sum(a.registUserNum) AS 'registUserNum',
	sum(a.complateUserNum) AS 'complateUserNum',
	sum(a.creditUserNum) AS 'creditUserNum',
	sum(a.registCompleteNum) AS 'registCompleteNum',
	sum(a.registCreditNum) AS 'registCreditNum',
	SUM(a.cost) / sum(a.registUserNum) AS 'registPrice',
	SUM(a.cost) / sum(a.complateUserNum) AS 'completePrice',
	SUM(a.cost) / sum(a.creditUserNum) AS 'creditPrice',
	SUM(a.cost) / sum(a.registCompleteNum) AS 'registCompletePrice',
	SUM(a.cost) / sum(a.registCreditNum) AS 'registCreditPrice',
	sum(a.registUserNum) / SUM(a.coverClick) * 100 AS 'clickRegistRate',
	sum(a.registUserNum) / SUM(a.actions) * 100 AS 'actionRegistRate',
	sum(a.complateUserNum) / sum(a.registUserNum) * 100 AS 'completeRate',
	sum(a.creditUserNum) / sum(a.complateUserNum) * 100 AS 'creditRate',
	sum(a.registCompleteNum) / sum(a.registUserNum) * 100 AS 'registCompleteRate',
	sum(a.creditUserNum) / sum(a.complateUserNum) * 100 AS 'registCreditRate',
	sum(a.registCompleteNum) / sum(a.complateUserNum) * 100 AS 'completeRateDay',
	sum(a.registCreditNum) / sum(a.creditUserNum) * 100 AS 'creditRateDay',
	sum(a.registCreditNum) / sum(a.registUserNum) * 100 AS 'creditRegistRateDay'
FROM
	(
	SELECT
	h.*, h.cost / h.registUserNum AS 'registPrice',
	h.cost / h.complateUserNum AS 'completePrice',
	h.cost / h.creditUserNum AS 'creditPrice',
	h.cost / h.registCompleteNum AS 'registCompletePrice',
	h.cost / h.registCreditNum AS 'registCreditPrice',
	h.registUserNum / h.coverClick * 100 AS 'clickRegistRate',
	h.registUserNum / h.actions * 100 AS 'actionRegistRate',
	h.complateUserNum / h.registUserNum * 100 AS 'completeRate',
	h.creditUserNum / h.complateUserNum * 100 AS 'creditRate',
	h.registCompleteNum / h.registUserNum * 100 AS 'registCompleteRate',
	h.creditUserNum / h.complateUserNum * 100 AS 'registCreditRate',
	h.registCompleteNum / h.complateUserNum * 100 AS 'completeRateDay',
	h.registCreditNum / h.creditUserNum * 100 AS 'creditRateDay',
	h.registCreditNum / h.registUserNum * 100 AS 'creditRegistRateDay'
FROM
	(
		SELECT
			c.statistic_date AS 'statisticDate',
			'汇创思拓' AS 'proxy',
			(
				SELECT
					a44.child_channel
				FROM
					ctop_kuaishou_customer_plan_statistic_info a44
				WHERE
				a44.campaign_code = c.campaign_code
				ORDER BY
					a44.id DESC
				LIMIT 1
			) AS 'channelName',
			c.campaign_info AS 'content',
			c.cost AS 'cost',
			c.cover_exposure AS 'coverViews',
			c.cover_click AS 'coverClick',
			c.metarial_exposure AS 'materialViews',
			c.action AS 'actions',
			c.cover_click / c.cover_exposure * 100 AS 'clickRate',
			c.action / c.cover_click * 100 AS 'actionClickRate',
			c.action / c.cover_click * c.cover_click / c.cover_exposure * 10000 AS 'abctr',
			c.cost / c.cover_click 'clickPrice',
			c.cost / c.action 'actionPrice',
			(
				SELECT
					SUM(a1.regist_account_num)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a1
				WHERE
				    a1.campaign_code = c.campaign_code
			) AS 'registUserNum',
			(
				SELECT
					SUM(a2.complete_user)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a2
				WHERE
				    a2.campaign_code = c.campaign_code
			) AS 'complateUserNum',
			(
				SELECT
					SUM(a3.estimated_credit_number)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a3
				WHERE
					a3.campaign_code = c.campaign_code
			) AS 'creditUserNum',
			(
				SELECT
					SUM(a4.regist_complate_number)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a4
				WHERE
					a4.campaign_code = c.campaign_code
			) AS 'registCompleteNum',
			(
				SELECT
					SUM(
						a5.estimated_regist_credit_number
					)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a5
				WHERE
				  a5.campaign_code = c.campaign_code
			) AS 'registCreditNum'
		FROM
			ctop_kuaishou_platform_campaign_statistic_info AS c
		WHERE
			c.account_id = #{accountId}
		ORDER BY
			c.campaign_info
	) AS h) AS a
    </select>
    <select id="getVoByParams" resultMap="voMap">
SELECT
	h.*, h.cost / h.registUserNum AS 'registPrice',
	h.cost / h.complateUserNum AS 'completePrice',
	h.cost / h.creditUserNum AS 'creditPrice',
	h.cost / h.registCompleteNum AS 'registCompletePrice',
	h.cost / h.registCreditNum AS 'registCreditPrice',
	h.registUserNum / h.coverClick * 100 AS 'clickRegistRate',
	h.registUserNum / h.actions * 100 AS 'actionRegistRate',
	h.complateUserNum / h.registUserNum * 100 AS 'completeRate',
	h.creditUserNum / h.complateUserNum * 100 AS 'creditRate',
	h.registCompleteNum / h.registUserNum * 100 AS 'registCompleteRate',
	h.creditUserNum / h.complateUserNum * 100 AS 'registCreditRate',
	h.registCompleteNum / h.complateUserNum * 100 AS 'completeRateDay',
	h.registCreditNum / h.creditUserNum * 100 AS 'creditRateDay',
	h.registCreditNum / h.registUserNum * 100 AS 'creditRegistRateDay'
FROM
	(
		SELECT
			c.statistic_date AS 'statisticDate',
			'汇创思拓' AS 'proxy',
			(
				SELECT
					a.child_channel
				FROM
					ctop_kuaishou_customer_plan_statistic_info a
				WHERE
				 a.campaign_code = c.campaign_code
				ORDER BY
					a.id DESC
				LIMIT 1
			) AS 'channelName',
			c.campaign_info AS 'content',
			c.cost AS 'cost',
			c.cover_exposure AS 'coverViews',
			c.cover_click AS 'coverClick',
			c.metarial_exposure AS 'materialViews',
			c.action AS 'actions',
			c.cover_click / c.cover_exposure * 100 AS 'clickRate',
			c.action / c.cover_click * 100 AS 'actionClickRate',
			c.action / c.cover_click * c.cover_click / c.cover_exposure * 10000 AS 'abctr',
			c.cost / c.cover_click 'clickPrice',
			c.cost / c.action 'actionPrice',
			(
				SELECT
					SUM(a1.regist_account_num)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a1
				WHERE
					a1.campaign_code = c.campaign_code
			) AS 'registUserNum',
			(
				SELECT
					SUM(a2.complete_user)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a2
				WHERE
					a2.campaign_code = c.campaign_code
			) AS 'complateUserNum',
			(
				SELECT
					SUM(a3.estimated_credit_number)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a3
				WHERE
					a3.campaign_code = c.campaign_code
			) AS 'creditUserNum',
			(
				SELECT
					SUM(a4.regist_complate_number)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a4
				WHERE
					a4.campaign_code = c.campaign_code
			) AS 'registCompleteNum',
			(
				SELECT
					SUM(
						a5.estimated_regist_credit_number
					)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a5
				WHERE
					a5.campaign_code = c.campaign_code
			) AS 'registCreditNum'
		FROM
			ctop_kuaishou_platform_campaign_statistic_info AS c
		WHERE
			c.account_id = #{accountId}
			and c.cost!=0
		ORDER BY
			c.campaign_info
	) AS h
    </select>

	<select id="sumZeroVoByParams" resultMap="voMap">
SELECT
	a.statisticDate AS 'statisticDate',
			'汇创思拓' AS 'proxy',
			'消费0用户统计信息' as 'channelName',
			'消费0用户' AS 'content',
	SUM(a.cost) AS 'cost',
	SUM(a.coverViews) AS 'coverViews',
	SUM(a.coverClick) AS 'coverClick',
	SUM(a.materialViews) AS 'materialViews',
	SUM(a.actions) AS'actions',
	SUM(a.coverClick) / SUM(a.coverViews) * 100 AS 'clickRate',
	SUM(a.actions) / SUM(a.coverClick) * 100 AS 'actionClickRate',
	SUM(a.actions) / SUM(a.coverClick) * SUM(a.coverClick) / SUM(a.coverViews) * 10000 AS 'abctr',
	SUM(a.cost) / SUM(a.coverClick) 'clickPrice',
	SUM(a.cost) / SUM(a.actions) 'actionPrice',
	sum(a.registUserNum) AS 'registUserNum',
	sum(a.complateUserNum) AS 'complateUserNum',
	sum(a.creditUserNum) AS 'creditUserNum',
	sum(a.registCompleteNum) AS 'registCompleteNum',
	sum(a.registCreditNum) AS 'registCreditNum',
	SUM(a.cost) / sum(a.registUserNum) AS 'registPrice',
	SUM(a.cost) / sum(a.complateUserNum) AS 'completePrice',
	SUM(a.cost) / sum(a.creditUserNum) AS 'creditPrice',
	SUM(a.cost) / sum(a.registCompleteNum) AS 'registCompletePrice',
	SUM(a.cost) / sum(a.registCreditNum) AS 'registCreditPrice',
	sum(a.registUserNum) / SUM(a.coverClick) * 100 AS 'clickRegistRate',
	sum(a.registUserNum) / SUM(a.actions) * 100 AS 'actionRegistRate',
	sum(a.complateUserNum) / sum(a.registUserNum) * 100 AS 'completeRate',
	sum(a.creditUserNum) / sum(a.complateUserNum) * 100 AS 'creditRate',
	sum(a.registCompleteNum) / sum(a.registUserNum) * 100 AS 'registCompleteRate',
	sum(a.creditUserNum) / sum(a.complateUserNum) * 100 AS 'registCreditRate',
	sum(a.registCompleteNum) / sum(a.complateUserNum) * 100 AS 'completeRateDay',
	sum(a.registCreditNum) / sum(a.creditUserNum) * 100 AS 'creditRateDay',
	sum(a.registCreditNum) / sum(a.registUserNum) * 100 AS 'creditRegistRateDay'
FROM
	(
	SELECT
	h.*, h.cost / h.registUserNum AS 'registPrice',
	h.cost / h.complateUserNum AS 'completePrice',
	h.cost / h.creditUserNum AS 'creditPrice',
	h.cost / h.registCompleteNum AS 'registCompletePrice',
	h.cost / h.registCreditNum AS 'registCreditPrice',
	h.registUserNum / h.coverClick * 100 AS 'clickRegistRate',
	h.registUserNum / h.actions * 100 AS 'actionRegistRate',
	h.complateUserNum / h.registUserNum * 100 AS 'completeRate',
	h.creditUserNum / h.complateUserNum * 100 AS 'creditRate',
	h.registCompleteNum / h.registUserNum * 100 AS 'registCompleteRate',
	h.creditUserNum / h.complateUserNum * 100 AS 'registCreditRate',
	h.registCompleteNum / h.complateUserNum * 100 AS 'completeRateDay',
	h.registCreditNum / h.creditUserNum * 100 AS 'creditRateDay',
	h.registCreditNum / h.registUserNum * 100 AS 'creditRegistRateDay'
FROM
	(
		SELECT
			c.statistic_date AS 'statisticDate',
			'汇创思拓' AS 'proxy',
			(
				SELECT
					a44.child_channel
				FROM
					ctop_kuaishou_customer_plan_statistic_info a44
				WHERE
					a44.campaign_code = c.campaign_code
				ORDER BY
					a44.id DESC
				LIMIT 1
			) AS 'channelName',
			c.campaign_info AS 'content',
			c.cost AS 'cost',
			c.cover_exposure AS 'coverViews',
			c.cover_click AS 'coverClick',
			c.metarial_exposure AS 'materialViews',
			c.action AS 'actions',
			c.cover_click / c.cover_exposure * 100 AS 'clickRate',
			c.action / c.cover_click * 100 AS 'actionClickRate',
			c.action / c.cover_click * c.cover_click / c.cover_exposure * 10000 AS 'abctr',
			c.cost / c.cover_click 'clickPrice',
			c.cost / c.action 'actionPrice',
			(
				SELECT
					SUM(a1.regist_account_num)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a1
				WHERE
					a1.campaign_code = c.campaign_code
			) AS 'registUserNum',
			(
				SELECT
					SUM(a2.complete_user)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a2
				WHERE
					a2.campaign_code = c.campaign_code
			) AS 'complateUserNum',
			(
				SELECT
					SUM(a3.estimated_credit_number)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a3
				WHERE
					a3.campaign_code = c.campaign_code
			) AS 'creditUserNum',
			(
				SELECT
					SUM(a4.regist_complate_number)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a4
				WHERE
					a4.campaign_code = c.campaign_code
			) AS 'registCompleteNum',
			(
				SELECT
					SUM(
						a5.estimated_regist_credit_number
					)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a5
				WHERE
					a5.campaign_code = c.campaign_code
			) AS 'registCreditNum'
		FROM
			ctop_kuaishou_platform_campaign_statistic_info AS c
		WHERE
			c.account_id = #{accountId} and c.campaign_code != 'biaodan'
			AND c.cost = 0
		ORDER BY
			c.campaign_info
	) AS h) AS a
    </select>

	<select id="sumZaodianVoByParams" resultMap="voMap">
		SELECT
	a.statisticDate AS 'statisticDate',
			'汇创思拓' AS 'proxy',
			'消费0用户统计信息' as 'channelName',
			'早点消费0用户' AS 'content',
	SUM(a.cost) AS 'cost',
	SUM(a.coverViews) AS 'coverViews',
	SUM(a.coverClick) AS 'coverClick',
	SUM(a.materialViews) AS 'materialViews',
	SUM(a.actions) AS'actions',
	SUM(a.coverClick) / SUM(a.coverViews) * 100 AS 'clickRate',
	SUM(a.actions) / SUM(a.coverClick) * 100 AS 'actionClickRate',
	SUM(a.actions) / SUM(a.coverClick) * SUM(a.coverClick) / SUM(a.coverViews) * 10000 AS 'abctr',
	SUM(a.cost) / SUM(a.coverClick) 'clickPrice',
	SUM(a.cost) / SUM(a.actions) 'actionPrice',
	sum(a.registUserNum)/SUM(1) AS 'registUserNum',
	sum(a.complateUserNum)/SUM(1) AS 'complateUserNum',
	sum(a.creditUserNum)/SUM(1) AS 'creditUserNum',
	sum(a.registCompleteNum)/SUM(1) AS 'registCompleteNum',
	sum(a.registCreditNum)/SUM(1) AS 'registCreditNum',
	SUM(a.cost) / sum(a.registUserNum) AS 'registPrice',
	SUM(a.cost) / sum(a.complateUserNum) AS 'completePrice',
	SUM(a.cost) / sum(a.creditUserNum) AS 'creditPrice',
	SUM(a.cost) / sum(a.registCompleteNum) AS 'registCompletePrice',
	SUM(a.cost) / sum(a.registCreditNum) AS 'registCreditPrice',
	sum(a.registUserNum) / SUM(a.coverClick) * 100 AS 'clickRegistRate',
	sum(a.registUserNum) / SUM(a.actions) * 100 AS 'actionRegistRate',
	sum(a.complateUserNum) / sum(a.registUserNum) * 100 AS 'completeRate',
	sum(a.creditUserNum) / sum(a.complateUserNum) * 100 AS 'creditRate',
	sum(a.registCompleteNum) / sum(a.registUserNum) * 100 AS 'registCompleteRate',
	sum(a.creditUserNum) / sum(a.complateUserNum) * 100 AS 'registCreditRate',
	sum(a.registCompleteNum) / sum(a.complateUserNum) * 100 AS 'completeRateDay',
	sum(a.registCreditNum) / sum(a.creditUserNum) * 100 AS 'creditRateDay',
	sum(a.registCreditNum) / sum(a.registUserNum) * 100 AS 'creditRegistRateDay'
FROM
	(
	SELECT
	h.*, h.cost / h.registUserNum AS 'registPrice',
	h.cost / h.complateUserNum AS 'completePrice',
	h.cost / h.creditUserNum AS 'creditPrice',
	h.cost / h.registCompleteNum AS 'registCompletePrice',
	h.cost / h.registCreditNum AS 'registCreditPrice',
	h.registUserNum / h.coverClick * 100 AS 'clickRegistRate',
	h.registUserNum / h.actions * 100 AS 'actionRegistRate',
	h.complateUserNum / h.registUserNum * 100 AS 'completeRate',
	h.creditUserNum / h.complateUserNum * 100 AS 'creditRate',
	h.registCompleteNum / h.registUserNum * 100 AS 'registCompleteRate',
	h.creditUserNum / h.complateUserNum * 100 AS 'registCreditRate',
	h.registCompleteNum / h.complateUserNum * 100 AS 'completeRateDay',
	h.registCreditNum / h.creditUserNum * 100 AS 'creditRateDay',
	h.registCreditNum / h.registUserNum * 100 AS 'creditRegistRateDay'
FROM
	(
		SELECT
			c.statistic_date AS 'statisticDate',
			'汇创思拓' AS 'proxy',
			(
				SELECT
					a44.child_channel
				FROM
					ctop_kuaishou_customer_plan_statistic_info a44
				WHERE
					a44.campaign_code = c.campaign_code
				ORDER BY
					a44.id DESC
				LIMIT 1
			) AS 'channelName',
			c.campaign_info AS 'content',
			c.cost AS 'cost',
			c.cover_exposure AS 'coverViews',
			c.cover_click AS 'coverClick',
			c.metarial_exposure AS 'materialViews',
			c.action AS 'actions',
			c.cover_click / c.cover_exposure * 100 AS 'clickRate',
			c.action / c.cover_click * 100 AS 'actionClickRate',
			c.action / c.cover_click * c.cover_click / c.cover_exposure * 10000 AS 'abctr',
			c.cost / c.cover_click 'clickPrice',
			c.cost / c.action 'actionPrice',
			(
				SELECT
					SUM(a1.regist_account_num)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a1
				WHERE
					a1.campaign_code = c.campaign_code
			) AS 'registUserNum',
			(
				SELECT
					SUM(a2.complete_user)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a2
				WHERE
					a2.campaign_code = c.campaign_code
			) AS 'complateUserNum',
			(
				SELECT
					SUM(a3.estimated_credit_number)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a3
				WHERE
					a3.campaign_code = c.campaign_code
			) AS 'creditUserNum',
			(
				SELECT
					SUM(a4.regist_complate_number)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a4
				WHERE
					a4.campaign_code = c.campaign_code
			) AS 'registCompleteNum',
			(
				SELECT
					SUM(
						a5.estimated_regist_credit_number
					)
				FROM
					ctop_kuaishou_customer_plan_statistic_info a5
				WHERE
					a5.campaign_code = c.campaign_code
			) AS 'registCreditNum'
		FROM
			ctop_kuaishou_platform_campaign_statistic_info AS c
		WHERE
			c.account_id = #{accountId} and c.campaign_code = 'biaodan'
			AND c.cost = 0
		ORDER BY
			c.campaign_info
	) AS h) AS a
	</select>
</mapper>