package org.jeecg.modules.ctop.job;

import cn.com.ctop.crawler.modules.account.entity.KuaishouAppAccount;
import cn.com.ctop.crawler.modules.account.entity.KuaishouIosAccount;
import cn.com.ctop.crawler.modules.account.service.IKuaishouAppAccountService;
import cn.com.ctop.crawler.modules.account.service.IKuaishouIosAccountService;
import cn.com.ctop.kuaishou.modules.app.service.IKuaishouAppService;
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 KuaishouCrawlerJob implements Job {
    @Autowired
    private IKuaishouAppService kuaishouAppService;
    @Autowired
    private IKuaishouAppAccountService kuaishouAppAccountService;
    @Autowired
    private IKuaishouIosAccountService kuaishouIosAccountService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {
            Integer page = 1;
            QueryWrapper<KuaishouAppAccount> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("path","/rest/n/feed/hot");
            List<KuaishouAppAccount> list = kuaishouAppAccountService.list(queryWrapper);
            if (list != null) {
                for (KuaishouAppAccount kuaishouAppAccount : list) {
                    try {
                        kuaishouAppService.adFetch(kuaishouAppAccount, page);
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }

            QueryWrapper<KuaishouIosAccount> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("path","/rest/n/feed/hot");
            List<KuaishouIosAccount> list2 = kuaishouIosAccountService.list(queryWrapper2);
            if (list2 != null) {
                for (KuaishouIosAccount kuaishouIosAccount : list2) {
                    try {
                        kuaishouAppService.adFetch(kuaishouIosAccount);
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
