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.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;


public class TargetingTagsJob implements Job {
    @Autowired
    private IKuaishouInterfaceService iKuaishouInterfaceService;
    @Autowired
    private CtopOauthTokenMapper oauthTokenMapper;

    /**
     * 定时更新 快手 标签
     *
     * @param jobExecutionContext
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        Thread thread = new Thread() {
            @Override
            public void run() {
                QueryWrapper<CtopOauthToken> tokenQueryWrapper = new QueryWrapper<>();
                tokenQueryWrapper.eq("media_id", 2);
                tokenQueryWrapper.orderByDesc("create_time");
                tokenQueryWrapper.last("limit 1");
                CtopOauthToken token = oauthTokenMapper.selectOne(tokenQueryWrapper);
                iKuaishouInterfaceService.getTargetingTags(token.getAccountId(), token.getAccessToken());
                iKuaishouInterfaceService.areaList(token.getAccessToken());
            }
        };
        thread.start();

    }
}
