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

import cn.com.ctop.common.module.service.IMaterialInfoService;
import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.common.module.utils.HttpUtils2;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
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;

@Slf4j
@Component
public class DuxiaomanJob {

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

    @Autowired
    private IMaterialInfoService materialInfoService;

    /**
     * 将1-待上传状态de素材 进行 上传媒体
     */
    @XxlJob("uploadMaterialJob")
    public void uploadMaterial() throws InterruptedException {
        String url = jobUrl + "/jeecg-boot/duxiaoman/materialInfo/uploadMaterial";

        //0-待审核,1-待上传,2-审批中,3-审核通过,4-审核不通过,5-预审核，6-预审核拒绝，7-上传成功，8-上传失败
        List<String> idList = materialInfoService.getDuxiaomanMaterialInfoByStatus(1);
        if (Check.isNull(idList)) {
            return;
        }
        for (String id : idList) {
            Map<String, Object> requestMap = new HashMap<>();
            requestMap.put("id", id);
            HttpUtils2.httpGet(url, requestMap, null);
            Thread.sleep(2000);
        }
    }

    /**
     * 将7-上传成功状态de素材 进行 素材报备
     */
    @XxlJob("materialReportJob")
    public void materialReport() throws InterruptedException {
        String url = jobUrl + "/jeecg-boot/duxiaoman/materialInfo/materialReport";

        //0-待审核,1-待上传,2-审批中,3-审核通过,4-审核不通过,5-预审核，6-预审核拒绝，7-上传成功，8-上传失败
        List<String> idList = materialInfoService.getDuxiaomanMaterialInfoByStatus(7);
        if (Check.isNull(idList)) {
            return;
        }
        for (String id : idList) {
            Map<String, Object> requestMap = new HashMap<>();
            requestMap.put("id", id);
            HttpUtils2.httpGet(url, requestMap, null);
            Thread.sleep(2000);
        }
    }

    /**
     * 将2-审批中状态的素材 进行 更新报备状态
     */
    @XxlJob("materialDetailJob")
    public void materialDetail() throws InterruptedException {
        String url = jobUrl + "/jeecg-boot/duxiaoman/materialInfo/materialDetail";

        //0-待审核,1-待上传,2-审批中,3-审核通过,4-审核不通过,5-预审核，6-预审核拒绝，7-上传成功，8-上传失败
        List<String> idList = materialInfoService.getDuxiaomanMaterialInfoByStatus(2);
        List<String> idList2 = materialInfoService.getDuxiaomanMaterialInfoByTime();
        idList.addAll(idList2);
        if (Check.isNull(idList)) {
            return;
        }
        for (String id : idList) {
            Map<String, Object> requestMap = new HashMap<>();
            requestMap.put("id", id);
            HttpUtils2.httpGet(url, requestMap, null);
            Thread.sleep(2000);
        }
    }
}
