|  |  |  | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSe.SeRechargeProfile; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSe.SeWaterType; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.util.DistrictLevel; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.jdom2.Document; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.boot.context.event.ApplicationReadyEvent; | 
|---|
|  |  |  | 
|---|
|  |  |  | * Spring容器并没有创建完,而本类中用了Spring容器中的Bean,即distriDao, userDao。 | 
|---|
|  |  |  | * 所以采用了Spring事件监听器来实现 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | public class InitListener implements ApplicationListener<ApplicationReadyEvent> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onApplicationEvent(@NonNull ApplicationReadyEvent event) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //等1秒,等待com.alibaba.druid.pool.DruidDataSource实始化完成 | 
|---|
|  |  |  | //等1秒,等待com.alibaba.druid.pool.DruidDataSource初始化完成 | 
|---|
|  |  |  | Thread.sleep(1000L); | 
|---|
|  |  |  | } catch (InterruptedException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 实始化 | 
|---|
|  |  |  | * 初始化 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @SuppressWarnings("unused ") | 
|---|
|  |  |  | private void init(ApplicationReadyEvent event){ | 
|---|
|  |  |  | 
|---|
|  |  |  | Document doc = configXml.createDom(this.resourceLoader, "init-config.xml") ; | 
|---|
|  |  |  | this.doInit(configXml, doc); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | System.out.println("系统启动时,初始化配置出错 !"); | 
|---|
|  |  |  | System.out.println(e.getMessage()); | 
|---|
|  |  |  | log.error("系统启动时,初始化配置出错 !"); | 
|---|
|  |  |  | log.error(e.getMessage()); | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private void doInit(ConfigXml4Springboot configXml, Document doc) throws Exception{ | 
|---|
|  |  |  | //Check if configXml and doc are not null | 
|---|
|  |  |  | if(configXml != null && doc != null){ | 
|---|
|  |  |  | //Loop through 10000 orgs | 
|---|
|  |  |  | for(int num = 1; num <= 10000; num++){ | 
|---|
|  |  |  | //Check if the org exists | 
|---|
|  |  |  | if(configXml.existElement(doc, "config.orgs.org" + num)){ | 
|---|
|  |  |  | //Get the tag and enable value of the org | 
|---|
|  |  |  | String orgTag = configXml.getSetAttrTxt(doc, "config.orgs.org" + num,"tag", null, false, null) ; | 
|---|
|  |  |  | Boolean enable = configXml.getSetAttrBoolean(doc, "config.orgs.org" + num, "enable", null, null); | 
|---|
|  |  |  | //If the org is enabled | 
|---|
|  |  |  | if(enable != null && enable.booleanValue()){ | 
|---|
|  |  |  | //设置数据源 | 
|---|
|  |  |  | DataSourceContext.set(orgTag); | 
|---|