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

import cn.com.ctop.common.module.service.IUserAllocationService;
import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.common.module.utils.HttpUtils2;
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTemplateService;
import com.xxl.job.core.context.XxlJobHelper;
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;

@Component
public class TrackWarningJob {


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

    /**
     * 自定义创建监测链接预警
     */
    @XxlJob("monitorCreative")
    public void monitorCreative() {
        String url = jobUrl + "/jeecg-boot/monitor/trackMonitorLogs/monitorCreative";
        System.err.println("请求地址为:" + url);
        List<Long> idList = userAllocationService.getIdList();
        if (Check.isNull(idList)) {
            XxlJobHelper.log("自定义创意监测链接预警");
            return;
        }
        for (int i = 0; i < idList.size(); i++) {
            Long id = idList.get(i);
            Map<String, Object> requestMap = new HashMap<>();
            requestMap.put("accountId", id);
            HttpUtils2.httpGet(url, requestMap, null);
        }


    }

    /**
     * 程序化监测链接预警
     */
    @XxlJob("monitorProgramCreative")
    public void monitorProgramCreative() {
        String url = jobUrl + "/jeecg-boot/monitor/trackMonitorLogs/monitorProgramCreative";
        System.err.println("请求地址为:" + url);
        List<Long> idList = userAllocationService.getIdList();
        if (Check.isNull(idList)) {
            XxlJobHelper.log("自定义创意监测链接预警");
            return;
        }
        for (int i = 0; i < idList.size(); i++) {
            Long id = idList.get(i);
            Map<String, Object> requestMap = new HashMap<>();
            requestMap.put("accountId", id);
            HttpUtils2.httpGet(url, requestMap, null);
        }


    }

}
