package org.nl.acs.auto.initial;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

@Component
public class ApplicationAutoInitialExecuter {
    /**
     * 获取所有实现ApplicationAutoInitial接口的bean对象
     */
    @Autowired(required = false)
    List<ApplicationAutoInitial> applicationAutoInitial;
    //是否启动
    private final static boolean IS_AUTO_THREAD_CODE = true;

    public void init() throws Exception {
        if (!IS_AUTO_THREAD_CODE) {
            return;
        }

        List<ApplicationAutoInitial> services = ObjectUtil.isNotEmpty(applicationAutoInitial) ? this.applicationAutoInitial : new ArrayList();
        Iterator it = services.iterator();

        while (it.hasNext()) {
            ApplicationAutoInitial service = (ApplicationAutoInitial) it.next();
            service.autoInitial(); // 执行实现的autoInitial方法
        }


    }

}
