package com.docus.server.message.config;


import com.docus.server.message.feign.service.CollectTaskService;
import com.docus.server.message.mapper.DelayedMessagesMapper;
import com.docus.server.message.scheduler.JobScheduler;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * job执行需要的一些必须得service，dao，mapper和配置等管理，从这里获取，保证依赖都有注入
 *
 * @author YongBin Wen
 * @date 2024/1/23 14:13
 */
@Component
public class JobAdminConfig implements InitializingBean, DisposableBean {

    private static JobAdminConfig jobAdminConfig = null;

    public static JobAdminConfig getJobAdminConfig() {
        return jobAdminConfig;
    }

    // ---------------------- JobScheduler ----------------------

    private JobScheduler xxlJobScheduler;

    @Override
    public void afterPropertiesSet() throws Exception {
        jobAdminConfig = this;

        xxlJobScheduler = new JobScheduler();
        xxlJobScheduler.init();
    }

    @Override
    public void destroy() throws Exception {
        xxlJobScheduler.destroy();
    }

    // dao  service

    @Resource
    private DelayedMessagesMapper delayedMessagesMapper;

    @Resource
    private CollectTaskService collectTaskService;

    public DelayedMessagesMapper getDelayedMessagesMapper() {
        return delayedMessagesMapper;
    }
    public CollectTaskService getCollectTaskService() {
        return collectTaskService;
    }
}
