package com.dy.pmsOther.dyFm; 
 | 
  
 | 
import com.dy.common.util.NumUtil; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.boot.context.event.ApplicationReadyEvent; 
 | 
import org.springframework.context.ApplicationListener; 
 | 
import org.springframework.core.env.Environment; 
 | 
import org.springframework.lang.NonNull; 
 | 
import org.springframework.stereotype.Component; 
 | 
  
 | 
@Component 
 | 
public class DyFmListener implements ApplicationListener<ApplicationReadyEvent> { 
 | 
  
 | 
    @Autowired 
 | 
    private Environment env; 
 | 
  
 | 
    public static DyFileSvConf.Group dyFileGroup = new DyFileSvConf.Group() ; 
 | 
  
 | 
    /** 
 | 
     * SpringBoot容器已经准备好了 
 | 
     * @param event 事件 
 | 
     */ 
 | 
    @Override 
 | 
    public void onApplicationEvent(@NonNull ApplicationReadyEvent event) { 
 | 
        try { 
 | 
            //等1秒,等待com.alibaba.druid.pool.DruidDataSource实始化完成 
 | 
            Thread.sleep(1000L); 
 | 
        } catch (InterruptedException e) { 
 | 
            e.printStackTrace(); 
 | 
        }finally { 
 | 
            try{ 
 | 
                parseConfig() ; 
 | 
            }catch(Exception e){ 
 | 
                e.printStackTrace(); 
 | 
                dyFileGroup = null ; 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
    private void parseConfig() throws Exception{ 
 | 
        String fmUrl = env.getProperty("dy.webFile.fmUrl"); 
 | 
        for(int i = 1 ; i <= 12 ; i++){ 
 | 
            String id = env.getProperty("dy.webFile.sv" + i + ".id"); 
 | 
            String absolutePath = env.getProperty("dy.webFile.sv" + i + ".absolutePath"); 
 | 
            String relativePath = env.getProperty("dy.webFile.sv" + i + ".relativePath"); 
 | 
            String hashStart = env.getProperty("dy.webFile.sv" + i + ".hashStart"); 
 | 
            String hashEnd = env.getProperty("dy.webFile.sv" + i + ".hashEnd"); 
 | 
            String restUrl = env.getProperty("dy.webFile.sv" + i + ".restUrl"); 
 | 
            String webUrl = env.getProperty("dy.webFile.sv" + i + ".webUrl"); 
 | 
            String webDownloadPath = env.getProperty("dy.webFile.sv" + i + ".webDownloadPath"); 
 | 
            if(!NumUtil.isPlusIntNumber(hashStart)){ 
 | 
                throw new Exception("配置dy.webFile.sv" + i + ".hashStart 不是整数") ; 
 | 
            } 
 | 
            if(!NumUtil.isPlusIntNumber(hashEnd)){ 
 | 
                throw new Exception("配置dy.webFile.sv" + i + ".hashEnd 不是整数") ; 
 | 
            } 
 | 
            dyFileGroup.add(new DyFileSvConf.Vo(id, 
 | 
                    absolutePath, 
 | 
                    relativePath, 
 | 
                    restUrl, 
 | 
                    webUrl, 
 | 
                    webDownloadPath, 
 | 
                    Integer.parseInt(hashStart), 
 | 
                    Integer.parseInt(hashEnd))) ; 
 | 
        } 
 | 
        dyFileGroup.check(); 
 | 
    } 
 | 
} 
 |