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 company=sysCompanyService.findByModel(null); Map companyMap=new HashMap<>(); for (SysCompany sysCompany : company) { companyMap.put(sysCompany.getComCode(), sysCompany); } LocalCache.save("companyMap", companyMap); } }