935090232@qq.com
2021-11-21 59634aeabb04aae0e819bd4c5fe909bb9cdbeb28
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package com.matrix.system.common.init;
 
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
 
import javax.servlet.ServletContext;
 
import com.matrix.core.exception.GlobleException;
import com.matrix.core.tools.LogUtil;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysCompany;
import com.matrix.system.common.service.SysCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.ServletContextAware;
 
import com.matrix.core.constance.MatrixConstance;
 
/**
 * 
 *  初始化web容器的类 一些网站启动需要加载的数据和方法在这里配置和执行
 * @author:姜友瑶
 * @date 2016年10月18日
 */
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class InitWebContainer   implements ApplicationRunner {
 
 
    private static final String TRUE = "true";
 
    static private final String LANGUAGE_ZH = "zh";
 
    static private final String LANGUAGE_US = "us";
 
 
 
    @Autowired
    private SysCompanyService sysCompanyService;
 
 
 
    /**
     * 是否为debug模式
     */
    @Value("${debug}")
    private String debug;
 
    @Value("${system_language}")
    private String systemLanguage;
 
    /**
     * 
     *  容器启动后加载数据
     * @author:姜友瑶
     * @date 2016年10月18日
     */
    @Override
    public void run(ApplicationArguments args) {
 
        // 初始化调试模式
        initDebug();
        // 初始化语言环境
        initLanguage();
        //初始化公司
        initParams();
        LogUtil.info("\r\n\r\n**********************************************\r\n"
                + "* =========== 成功 ===========\r\n"
                + "* DEBUG模式:" + debug+"*\r\n"
                + "* 语言环境:" + Locale.getDefault().getLanguage()+"\r\n"
             
                + "**********************************************\r\n");
    }
 
    private void initDebug() {
        if (TRUE.equals(debug)) {
            MatrixConstance.DEBUG = true;
        } else {
            MatrixConstance.DEBUG = false;
        }
    }
 
    /**
     * 初始化语言环境,默认为中文
     * 
     * @author JIANGYOUYAO
     * @email 935090232@qq.com
     * @date 2017年11月30日
     */
    private void initLanguage() {
        Locale language = Locale.CHINA;
        if (systemLanguage != null) {
            if (LANGUAGE_US.equals(systemLanguage)) {
                language = Locale.US;
            }
        } else {
            LogUtil.warn("没有找到语言环境配置信息,默认配置中文环境");
        }
        Locale.setDefault(language);
    }
 
 
    /**
     * 初始化网站的关键词和描述
     *
 
     */
    public  void initParams() {
 
        //初始化所有的公司
        List<SysCompany> company=sysCompanyService.findByModel(null);
        Map<String, SysCompany> companyMap=new HashMap<>();
        for (SysCompany sysCompany : company) {
            companyMap.put(sysCompany.getComCode(), sysCompany);
        }
        LocalCache.save("companyMap", companyMap);
    }
 
 
 
 
 
}