package com.xxl.job.executor.jobhandler;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.executor.batch.service.IKuaishouInterfaceService;
import com.xxl.job.executor.common.entity.CtopOauthToken;
import com.xxl.job.executor.common.service.ICtopOauthTokenService;
import com.xxl.job.executor.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class KuaishouOperationRecordJob {
    @Autowired
    private IKuaishouInterfaceService kuaishouInterfaceService;
    @Autowired
    private ICtopOauthTokenService tokenService;
    @XxlJob("kuaishouOperationRecord")
    public void execute(){
        String param = XxlJobHelper.getJobParam();
        if (param==null || param.trim().length()==0) {
            XxlJobHelper.log("param["+ param +"] invalid.");
            XxlJobHelper.handleFail();
            return;
        }
        CtopOauthToken token = tokenService.getOauthTokenByAccountId(param);
        if (null == token) {
            XxlJobHelper.log("获取头条token数据异常：账户{}token不存在",param);
            XxlJobHelper.handleFail();
            return;
        }
        Date getDate = DateUtils.addDay(new Date(), -1);
        String date = DateUtils.formatDate(getDate);
        kuaishouInterfaceService.getOperationRecord(token.getAccountId(), token.getAccessToken(), 1, date, date);
        kuaishouInterfaceService.getOperationRecord(token.getAccountId(),token.getAccessToken(),2, date, date);
        kuaishouInterfaceService.getOperationRecord(token.getAccountId(),token.getAccessToken(),3, date, date);
        kuaishouInterfaceService.getOperationRecord(token.getAccountId(),token.getAccessToken(),4, date, date);
        kuaishouInterfaceService.getOperationRecord(token.getAccountId(),token.getAccessToken(),5, date, date);
        kuaishouInterfaceService.getOperationRecord(token.getAccountId(),token.getAccessToken(),6, date, date);
        kuaishouInterfaceService.getOperationRecord(token.getAccountId(),token.getAccessToken(),7, date, date);
    }

}
