package org.jeecg.modules.ctop.job;

import cn.com.ctop.common.module.entity.CtopOauthToken;
import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class DailyFlowsJob implements Job {
    @Autowired
    private IKuaishouInterfaceService kuaishouInterfaceService;
    @Autowired
    private CtopOauthTokenMapper oauthTokenMapper;

    /**
     * 刷新token
     *
     * @param jobExecutionContext
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("media_id", "2");
        queryWrapper.groupBy("account_id");
        List<CtopOauthToken> ctopOauthTokens = oauthTokenMapper.selectList(queryWrapper);
        if (!Check.isNull(ctopOauthTokens)) {
            for (CtopOauthToken ctopOauthToken : ctopOauthTokens) {
                kuaishouInterfaceService.getDailyFlows(ctopOauthToken);
            }

        }

    }
}
