package com.muyu.common.xxl.demo;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

@Log4j2
@Component
public class XxlJobDemoService {

    /**
     * 无参测试
     */
    @XxlJob("xxl-job-demo-no-param")
    public void xxlJobDemoNoParam(){
        log.info("调度名称：[{}] - 无参", "xxl-job-demo-no-param");
    }

    /**
     * 有参测试
     */
    @XxlJob("xxl-job-demo-one-param")
    public void xxlJobDemoOneParam(){
        String param = XxlJobHelper.getJobParam();
        log.info("调度名称：[{}] - 参数：[{}]", "xxl-job-demo-one-param", param);
    }
    /**
     * 分片测试
     */
    @XxlJob("xxl-job-slice-demo")
    public void xxlJobSliceDemo(){
        int shardTotal = XxlJobHelper.getShardTotal();
        int shardIndex = XxlJobHelper.getShardIndex();
        String param = XxlJobHelper.getJobParam();
        log.info("调度名称：[{}-[{}/{}(分片位置/分片总数)]] - 参数：[{}]", "xxl-job-slice-demo",shardIndex, shardTotal, param);
    }
}
