package org.stm.job;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.DateUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.stm.metric.entity.MetricApiCfg;
import org.stm.metric.entity.MetricReport;
import org.stm.metric.service.IMetricApiCfgService;
import org.stm.metric.service.IMetricReportService;
import org.stm.spider.entity.WbTmpCfg;
import org.stm.spider.service.IWbTmpCfgService;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
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();

        }
    }
}
