package cn.com.ctop.job.kuaishou.handler;

import cn.com.ctop.kuaishou.modules.report.mapper.EtlKuaishouAccountMaterialReportDailyMapper;
import cn.com.ctop.kuaishou.modules.report.service.IEtlKuaishouAccountMaterialReportDailyService;
import cn.com.ctop.kuaishou.modules.report.service.IEtlKuaishouReportAccountDailyService;
import cn.com.ctop.kuaishou.modules.report.service.IEtlKuaishouReportAccountHourlyService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.jeecg.common.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 账户维度-盯盘每日数据
 *
 * @author syh
 */
@Component
public class KuaishouDailyAccountReportLoadEtlJob {

    @Autowired
    private IEtlKuaishouReportAccountDailyService iEtlKuaishouReportAccountDailyService;
    @Autowired
    private IEtlKuaishouAccountMaterialReportDailyService etlKuaishouAccountMaterialReportDailyService;
    @Resource
    private EtlKuaishouAccountMaterialReportDailyMapper etlKuaishouAccountMaterialReportDailyMapper;
    @Autowired
    private IEtlKuaishouReportAccountHourlyService hourlyService;

    /**
     * 清洗账户维度-每日盯盘数据
     * @throws Exception
     */
    @XxlJob("kuaishouDailyAccountReportLoadEtl")
    public void execute() throws Exception {
        try {
            iEtlKuaishouReportAccountDailyService.queryEveryDayDataForAccount();
            hourlyService.updateYesterdayEtlHourlyData();
            XxlJobHelper.log("queryEveryDayDataForAccount success");
        } catch (Exception e) {
            XxlJobHelper.log(e.getMessage());
        }
    }

    /**
     * 快手账户素材数据清洗任务
     * @throws Exception
     */
    @XxlJob("etlKuaishouAccountMaterialReportDailyData")
    public void etlKuaishouAccountMaterialReportDailyData() throws Exception {
        try {
            etlKuaishouAccountMaterialReportDailyMapper.etlKuaishouAccountMaterialReportDailyData(DateUtils.formatDate());
            etlKuaishouAccountMaterialReportDailyMapper.etlKuaishouAccountMaterialReportDailyData(DateUtils.formatDate(DateUtils.addDay(new Date(),-1)));
            XxlJobHelper.log("queryEveryDayDataForAccount success");
        } catch (Exception e) {
            XxlJobHelper.log(e.getMessage());
        }
    }
}
