package com.gyee.wisdom.alarm.schedule.job;

import com.gyee.wisdom.alarm.schedule.entity.AlarmHistory;
import com.xxl.job.core.biz.model.ReturnT;
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.stereotype.Component;

import java.util.List;

import static com.xxl.job.core.biz.model.ReturnT.SUCCESS;

/**
 * @description:
 * @auther: Wanghs
 * @date: 2022-03-08
 */

@Component
public class MyJobHandler  {


    @XxlJob("MyJobHandler")
    public ReturnT<AlarmHistory> demoJobHandler() throws Exception {

        String jobParam = XxlJobHelper.getJobParam(); //获取任务参数

        XxlJobHelper.log("输出执行日志，日志文件存放的位置可在“执行器”配置文件进行自定义，" +
                "默认目录格式为：/data/applogs/xxl-job/jobhandler/“格式化日期”/“数据库调度日志记录的主键ID.log”。" +
                "执行日志可以通过xxl-job-admin进行查看");

        AlarmHistory doResult=new AlarmHistory();

        ReturnT<AlarmHistory> returnT=new ReturnT<>(doResult);
        returnT.setCode(ReturnT.SUCCESS_CODE);
        returnT.setMsg("执行结果描述（异常，成功，失败等）");
        return  returnT;
    }

    @XxlJob("MyJobHandler2")
    public ReturnT<String> demoJobHandler2(String param) throws Exception {
        String command = XxlJobHelper.getJobParam();
        long id = Thread.currentThread().getId();
        System.out.println("xxl.job测试2-参数："+command+"，jobID:"+XxlJobHelper.getJobId()+"thread-id:"+id);
       Thread.sleep(5000);
       System.out.println("thread-id:"+id+"执行完毕");
        XxlJobHelper.log("xxl.job测试2-参数："+command+"执行成功，jobID:"+XxlJobHelper.getJobId()+"thread-id:"+id);

        return SUCCESS;
    }

}
