
package com.jeelowcode.core.framework.config.listener;

import com.jeelowcode.core.framework.service.IFormService;
import com.jeelowcode.core.framework.service.IReportService;
import com.jeelowcode.framework.utils.component.redis.JeeLowCodeRedisUtils;
import groovy.lang.GroovyClassLoader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


@Slf4j
@Order(value = 999)
@Component
public class JeeLowCodeListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    JeeLowCodeRedisUtils redisUtil;

    @Autowired
    private IFormService dbFormService;

    @Autowired
    private IReportService reportService;


    public GroovyClassLoader groovyClassLoader = new GroovyClassLoader();

    public GroovyClassLoader getGroovyClassLoader() {
        return groovyClassLoader;
    }
    
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        dbFormService.initConfigBtnCommand();
        log.info("1.初始化自定义按钮--->完成");
        dbFormService.cleanCache();
        log.info("2.清除框架缓存--->完成");
        dbFormService.initOnlineScript(groovyClassLoader);
        log.info("3.初始化在线脚本--->完成");
        dbFormService.initEnhancePluginManager();
        log.info("4.初始化增强--->完成");
        reportService.initEnhancePluginManager();
        log.info("5.初始化报表增强--->完成");
        dbFormService.initDataAuthTable();
        log.info("6.处理那些表需要做数据权限--->完成");
        dbFormService.initOtherDataSource();
        log.info("7.初始化动态数据源--->完成");
    }


}