package org.jeecg.modules.ctop.controller;

import cn.com.ctop.common.module.utils.QueryGenerator;
import cn.com.ctop.crawler.modules.account.entity.KuaishouAppAccount;
import cn.com.ctop.crawler.modules.account.service.IKuaishouAppAccountService;
import cn.com.ctop.kuaishou.modules.app.service.IKuaishouAppService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author jeecg-boot
 * 2019年12月5日19:57:58
 */
@Slf4j
@RestController
@RequestMapping("/ctop/syncdata")
public class SyncDataController {

    @Autowired
    private IKuaishouAppService kuaishouAppService;
    @Autowired
    private IKuaishouAppAccountService kuaishouAppAccountService;


    @RequestMapping("/test2")
    public void test2() {
        try {
            Integer page = 1;
            while (page < 1000) {
                QueryWrapper<KuaishouAppAccount> queryWrapper = QueryGenerator.initQueryWrapper(new KuaishouAppAccount(), null);
                queryWrapper.eq("path", "/rest/n/feed/hot");
                List<KuaishouAppAccount> list = kuaishouAppAccountService.list(queryWrapper);
                if (list != null) {
                    for (KuaishouAppAccount kuaishouAppAccount : list) {
                        kuaishouAppService.adFetch(kuaishouAppAccount, page);
                    }
                }
                Thread.sleep(6000);
                page++;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
