package com.qmth.sop.task;

//import com.qmth.sop.common.threadPool.MyThreadPool;

import com.qmth.sop.task.listener.MyJobListener;
import org.activiti.spring.boot.SecurityAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.quartz.Scheduler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication(scanBasePackages = "com.qmth.*", exclude = {SecurityAutoConfiguration.class})
@MapperScan({"com.qmth.sop.business.mapper"})
//主要就是定义扫描的路径从中找出标识了需要装配的类自动装配到spring的bean容器中,做过web开发的同学一定都有用过@Controller，@Service，@Repository注解，查看其源码你会发现，他们中有一个共同的注解@Component，没错@ComponentScan注解默认就会装配标识了@Controller，@Service，@Repository，@Component注解的类到spring容器中
@EntityScan(basePackages = {"com.qmth.sop.business.entity"}) // 用来扫描和发现指定包及其子包中的Entity定义
@EnableTransactionManagement // spring开启事务支持
@EnableAsync // 开启异步任务
@EnableCaching // 开启缓存注解
public class TaskApplication {

    public static void main(String[] args) {
        SpringApplication.run(TaskApplication.class, args);
    }

//    @Primary
//    @Bean
//    public TaskExecutor primaryTaskExecutor() {
//        return new MyThreadPool();
//    }

    @Bean
    public Scheduler scheduler(Scheduler scheduler) throws Exception {
        // 添加Scheduler 监听器
//        KeyMatcher<JobKey> keyMatcher = KeyMatcher.keyEquals(JobKey.jobKey(QuartzTaskEnum.MQ_ACTIVITY_JOB_NAME.name(), QuartzTaskEnum.MQ_ACTIVITY_JOB_GROUP_NAME.name()));
//        scheduler.getListenerManager().addJobListener(new MyJobListener(), keyMatcher);
        scheduler.getListenerManager().addJobListener(new MyJobListener());
        return scheduler;
    }
}
