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


import cn.com.ctop.common.module.utils.HttpUtils;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.jeecg.common.util.DateUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 睿选-头条相关定时
 */
@Component
public class RuiXuanBytedanceJob {

    public final static String URL = "http://ruixuan.api.bjhcstszkj.cn/bytedance";

    /**
     * 新增团长活动列表
     */
    @XxlJob("bytedanceColonelActivityJob")
    public void bytedanceColonelActivityJob() throws Exception {
        HttpUtils.httpGet(URL + "/addBytedanceColonelActivityList", null, null);
        XxlJobHelper.log(" --------团长活动列表，执行完成-------- ");
    }

    /**
     * 获取上个月团长订单
     */
    @XxlJob("bytedanceInstituteOrderColonel")
    public void bytedanceInstituteOrderColonel() throws Exception {
        //获取上个月1号
        String initMonth = DateUtils.initDateByMonth();
        String startTime = DateUtils.getMonthBefore("yyyy-MM-dd", initMonth, -1);

        String today = DateUtils.date2Str();
        //昨天
//        String yesterday = DateUtils.getLastDay(today, 1);
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("startTime", startTime);
        paramMap.put("endTime", today);
        HttpUtils.httpGet(URL + "/addBytedanceInstituteOrderColonel", paramMap, null);
        XxlJobHelper.log(" --------团长订单列表，执行完成 \n-------- 【时间区间】："+paramMap);
    }

    /**
     * 获取上 上个月 团长订单
     */
    @XxlJob("twoMonthsBytedanceOrder")
    public void twoMonthsBytedanceOrder() throws Exception {
        //获取上 上个月1号
        String initMonth = DateUtils.initDateByMonth();
        String startTime = DateUtils.getMonthBefore("yyyy-MM-dd", initMonth, -2);


        String today = DateUtils.date2Str();
        //昨天
//        String yesterday = DateUtils.getLastDay(today, 1);
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("startTime", startTime);
        paramMap.put("endTime", today);
        HttpUtils.httpGet(URL + "/addBytedanceInstituteOrderColonel", paramMap, null);
        XxlJobHelper.log(" --------团长订单列表，执行完成 \n --------【时间区间】："+paramMap);
    }

    /**
     * 新增团长订单
     */
    @XxlJob("todayBytedanceInstituteOrderColonel")
    public void todayBytedanceInstituteOrderColonel() throws Exception {
        String today = DateUtils.date2Str();
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("startTime", today);
        paramMap.put("endTime", today);
        HttpUtils.httpGet(URL + "/addBytedanceInstituteOrderColonel", paramMap, null);
        XxlJobHelper.log(" --------团长订单列表，执行完成 \n --------【时间区间】："+paramMap);
    }

}
