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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 快手账户流水报表
 */
@Component
public class KuaishouDailyFlowsJob {
    @Autowired
    private IKuaishouInterfaceService kuaishouInterfaceService;
    @Autowired
    private ICtopOauthTokenService oauthTokenService;
    @XxlJob("kuaishouDailyFlowsJob")
    public void execute() {
        String param = XxlJobHelper.getJobParam();
        if (param==null || param.trim().length()==0) {
            XxlJobHelper.log("param["+ param +"] invalid.");
            XxlJobHelper.handleFail();
            return;
        }
        CtopOauthToken token = oauthTokenService.getOauthTokenByAccountId(param);
        if (null == token) {
            XxlJobHelper.log("获取头条token数据异常：账户{}token不存在",param);
            XxlJobHelper.handleFail();
            return;
        }
        kuaishouInterfaceService.getDailyFlows(token);
    }
}
