package cn.com.ctop.job.kuaishou.handler;

import cn.com.ctop.common.module.service.ICtopOauthTokenService;
import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.common.module.utils.HttpUtils2;
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroupTemplate;
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTemplateService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class KuaishouCreateCreativeJob {

    @Autowired
    private IKuaiShouGroupTemplateService groupTemplateService;
    @Autowired
    private ICtopOauthTokenService tokenService;

    @Value("${xxl-job.requestUrl}")
    private String jobUrl;

    /**
     * 组创建成功-创意待创建
     */
    @XxlJob("kuaihouCreateCreative")
    public void execute() {
        String url = jobUrl + "/jeecg-boot/batch/kuaiShouGroupTemplate/createUnitAgain";
        QueryWrapper<KuaiShouGroupTemplate> templateQueryWrapper = new QueryWrapper<>();
        templateQueryWrapper.eq("task_status", 2);
        templateQueryWrapper.eq("creative_status", 0);
        templateQueryWrapper.orderByAsc("create_time");
        templateQueryWrapper.last("limit 200");
        List<KuaiShouGroupTemplate> list = groupTemplateService.list(templateQueryWrapper);
        if (Check.isNull(list)) {
            return;
        }
        for (KuaiShouGroupTemplate template : list) {
            Map<String, Object> requestMap = new HashMap<>();
            requestMap.put("id", template.getId());
            HttpUtils2.httpGet(url, requestMap, null);
        }
    }

}
