<?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.bytedance.advertise.mapper.ByteDanceGeneralCopywriterMapper">
    <select id="selectGeneralCopywriterReport" resultType="java.util.HashMap">




        SELECT
            a.id,
            a.status,
            a.account_id as accountId,
            d.creative_id as creativeId,
            a.text_copywriter AS textCopywriter,
            count(*) AS creativeCount,
            sum(d.cost) AS sumCost,
            sum(d.show_num) AS sumShowMaterial,
            sum(d.click) AS sumClick,
            sum(d.show_num) AS sumConvertMaterial
        FROM
            ctop_bytedance_general_copywriter a
        LEFT JOIN ctop_bytedance_creative b ON a.text_copywriter = b.title and a.account_id = b.account_id
        LEFT JOIN ctop_bytedance_report_creative_daily d ON b.id = d.creative_id
        WHERE
            1 = 1
            <if test="status!=null">and a.`status` = #{status}</if>
            <if test="keyWord!=null and keyWord!=''">and a.text_copywriter like concat('%',#{keyWord},'%')</if>
            <if test="startTime!=null and startTime!=''">and STR_TO_DATE(d.stat_datetime,'%Y-%m-%d') &gt;= STR_TO_DATE(#{startTime},'%Y-%m-%d')</if>
            <if test="endTime!=null and endTime!=''">and STR_TO_DATE(d.stat_datetime,'%Y-%m-%d') &lt;= STR_TO_DATE(#{endTime},'%Y-%m-%d')</if>
        <if test="accountIds!=null and accountIds!=''">
            AND a.account_id IN
            <foreach item="item" index="index" collection="accountIds"
                     open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        GROUP BY
        a.text_copywriter

    </select>

    <select id="selectCreativeWordPackageByName" resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceCreativeWordPackage">
        select * from ctop_bytedance_creative_word_package where name = #{name}
    </select>
    <select id="getRandThree"
            resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceGeneralCopywriter">
        select * from ctop_bytedance_general_copywriter where status = 1 and account_id = #{accountId} order by rand() limit 3
    </select>

    <select id="getRandTen"
            resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceGeneralCopywriter">
        select * from ctop_bytedance_general_copywriter where status = 1 and account_id = #{accountId} order by rand() limit 10
    </select>

    <select id="selectAllDataByTextCopywriter" resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceGeneralCopywriter">
        select * from ctop_bytedance_general_copywriter where text_copywriter = #{textCopywriter}

    </select>
</mapper>