package com.gyee.gaia.meter.job;


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.stereotype.Component;

import static com.xxl.job.core.biz.model.ReturnT.FAIL_CODE;
import static com.xxl.job.core.biz.model.ReturnT.SUCCESS_CODE;


@Component
public class MyJobHandler {


    @XxlJob("MyJobHandler")
    public ReturnT<String> demoJobHandler2() 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(2000);
        System.out.println("thread-id:" + id + "执行完毕");
        XxlJobHelper.log("xxl.job测试2-参数：" + command + "执行成功，jobID:" + XxlJobHelper.getJobId() + "thread-id:" + id);


        Integer v = Integer.valueOf(command);
        if (v > 10) {
            XxlJobHelper.handleSuccess("调度成功");
            return new ReturnT(SUCCESS_CODE, "调度成功111");

        } else {
            ReturnT t = null;
            try {
                int ii = v / 0;

            } catch (Exception e) {
              t=  new ReturnT(FAIL_CODE, "调度失败111"+e);
                XxlJobHelper.handleFail("调度失败"+e);
            } finally {
                return t;
            }


        }

    }

}
