package com.xxl.job.executor.report.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xxl.job.executor.report.entity.BytedancePlanDailyReport;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Description: 广告计划日报表信息
 * @Author: jeecg-boot
 * @Date: 2019-09-11
 * @Version: V1.0
 */
public interface BytedancePlanDailyReportMapper extends BaseMapper<BytedancePlanDailyReport> {

    void replaceBatch(@Param(value = "reports") List<BytedancePlanDailyReport> dailyReports);

    @Update("update ctop_bytedance_report_plan_daily " +
            "set channel_code = replace(substring_index(ad_name, '-', 1), '.apk', '') " +
            "where advertiser_id in (select account_id from ctop_user_allocation where project_id = #{projectId})")
    void cleanYzData(@Param(value = "projectId") Integer projectId);

    @Update("update ctop_bytedance_report_plan_daily " +
            "set channel_code = replace(replace(replace(substring_index(ad_name, '-', 2), '衍生计划-', ''), '.apk',''),'-','') " +
            "where advertiser_id in (select account_id from ctop_user_allocation where project_id = #{projectId}) " +
            "  and channel_code = '衍生计划' ")
    void cleanYzDataFuck(@Param(value = "projectId") Integer projectId);

    @Update("update ctop_bytedance_report_plan_daily " +
            "set channel_code = substring_index(ad_name, '-', 1) " +
            "where advertiser_id in (select account_id from ctop_user_allocation where project_id = #{projectId}) and stat_datetime =#{date}")
    void cleanChannelCodeData(@Param(value = "projectId") Integer projectId, @Param(value = "date") String date);

    @Update("update ctop_bytedance_report_plan_hourly report left join ctop_user_allocation allocation on report.advertiser_id = allocation.account_id " +
            "set channel_code = substring_index(ad_name,'-',2) " +
            "where allocation.project_id = #{projectId} and allocation.system_type = 'ios' and report.stat_datetime = #{date}")
    void cleanYddHourlyChannelCode(@Param(value = "projectId") Integer projectId, @Param(value = "date") String date);
}
