package org.jeecg.modules.stm.job;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.stm.spider.entity.WbTmpCfg;
import org.jeecg.modules.stm.spider.service.IWbTmpCfgService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class SpiderJob implements Job {
    @Autowired
    private IWbTmpCfgService wbTmpCfgService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info(String.format("获取API数据，时间:" + DateUtils.getTimestamp()));
        List<WbTmpCfg> wbTmpCfgList = wbTmpCfgService.list();
        try {
            List<Integer> existDocIdList = new ArrayList<>();
            for (WbTmpCfg wbTmpCfg : wbTmpCfgList) {
                int pageInd = 0;
                do {
                    pageInd++;
                    int flag = wbTmpCfgService.processWbTmpCfg(wbTmpCfg, existDocIdList, pageInd,null);
                    if(flag==1) {
                        break;
                    }
                    Thread.sleep(1000);

                } while(pageInd<4);

            }
        } catch (Exception e) {
            e.printStackTrace();

        }
    }
}
