liurunyu
2024-04-23 1300e2434cb457e7d4d06ea66d90a04492f6c4e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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 webDownloadUrl = env.getProperty("dy.webFile.sv" + i + ".webDownloadUrl");
            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,
                    webDownloadUrl,
                    Integer.parseInt(hashStart),
                    Integer.parseInt(hashEnd))) ;
        }
        dyFileGroup.check();
    }
}