package com.skr.mdm.util;

import com.skr.mdm.constant.JobConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.quartz.JobKey;
import org.quartz.TriggerKey;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class JobUtil {

    /**
     * 获取 JobKey
     *
	 * @param id
     * @return
     */
    public static JobKey getJobKey(String id) {
        String jobKey = JobConstant.JOB_KEY_PREFIX + id;
        return new JobKey(jobKey);
    }

    /**
     * 获取jobKeys
	 *
	 * @param idList
     * @return
     */
    public static List<JobKey> getJobKeys(List<String> idList) {
        List<JobKey> jobKeys = new ArrayList<>(idList.size());
        if (CollectionUtils.isNotEmpty(idList)) {
            idList.forEach(id -> {
                String jobKey = JobConstant.JOB_KEY_PREFIX + id;
                jobKeys.add(new JobKey(jobKey));
            });
        }
        return jobKeys;
    }

    /**
	 * 获取TriggerKey
	 *
	 * @param id
	 * @return
	 */
	public static TriggerKey getTriggerKey(String id) {
		String triggerKey = JobConstant.TRIGGER_KEY_PREFIX + id;
		return new TriggerKey(triggerKey);
	}

	/**
	 * 获取自定义quartz key
	 * @param prefix
	 * @param id
	 * @param executeTime
	 * @return
	 */
	public static String getQuartzKey(String prefix, Integer id, String executeTime) {
		return prefix + "_" + id + "_" + executeTime;
	}

}
