package com.yihu.figure.service;

import com.yihu.figure.job.HealthJob;
import com.yihu.figure.job.QuartzHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @author ysj
 */
@Service
public class JobService {
    @Autowired
    private QuartzHelper quartzHelper;


    private String healthJob = "healthJob";
    private String healthJobCron = "0 30 23 * * ?";
//    private String healthJobCron = "0 26 9 * * ?";
    public void startHealthJob() throws Exception {
        if (!quartzHelper.isExistJob(healthJob)) {
            quartzHelper.addJob(HealthJob.class, healthJobCron, healthJob, new HashMap<>());
        } else {
            throw new Exception("已经启动");
        }
    }

    public void stopHealthJob() throws Exception {
        if (quartzHelper.isExistJob(healthJob)) {
            quartzHelper.removeJob(healthJob);
        } else {
            throw new Exception("已经停止");
        }
    }
}
