From b8f7e58b5c626987816335889c96a25a697bf7e9 Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Sun, 24 Oct 2021 00:16:16 +0800
Subject: [PATCH] Merge branch 'score_shop' into api_score_meger

---
 zq-erp/src/main/java/com/matrix/system/common/init/InitWebContainer.java |   85 +++++++++++++++++++++++++++++-------------
 1 files changed, 58 insertions(+), 27 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/system/common/init/InitWebContainer.java b/zq-erp/src/main/java/com/matrix/system/common/init/InitWebContainer.java
index 6f04363..29faf3a 100644
--- a/zq-erp/src/main/java/com/matrix/system/common/init/InitWebContainer.java
+++ b/zq-erp/src/main/java/com/matrix/system/common/init/InitWebContainer.java
@@ -1,32 +1,46 @@
 package com.matrix.system.common.init;
 
-import com.matrix.core.constance.MatrixConstance;
-import com.matrix.core.tools.LogUtil;
-import com.matrix.system.common.bean.SysCompany;
-import com.matrix.system.common.dao.SysCompanyDao;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.context.ServletContextAware;
-
-import javax.servlet.ServletContext;
 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日
  */
-@Controller
-public class InitWebContainer   implements ServletContextAware{
+@Component
+@Order(Ordered.HIGHEST_PRECEDENCE)
+public class InitWebContainer   implements ApplicationRunner {
+
+
+	private static ConcurrentMap<String,Object> localCache=new ConcurrentHashMap(60);
 
 	private static final String TRUE = "true";
-
-	private ServletContext servletContext;
 
 	static private final String LANGUAGE_ZH = "zh";
 
@@ -35,8 +49,7 @@
 
 
 	@Autowired
-	private SysCompanyDao sysCompanyDao;
-
+	private SysCompanyService sysCompanyService;
 
 
 
@@ -50,27 +63,25 @@
 	private String systemLanguage;
 
 	/**
-	 * 
+	 *
 	 *  容器启动后加载数据
 	 * @author:姜友瑶
-	 * @param sc
 	 * @date 2016年10月18日
 	 */
 	@Override
-	public void setServletContext(ServletContext sc) {
-		this.servletContext = sc;
+	public void run(ApplicationArguments args) {
 
 		// 初始化调试模式
 		initDebug();
 		// 初始化语言环境
 		initLanguage();
 		//初始化公司
-		//initParams();
+		initParams();
 		LogUtil.info("\r\n\r\n**********************************************\r\n"
-				+ "* =========== Matrix启动成功 ===========\r\n" 
+				+ "* =========== 成功 ===========\r\n"
 				+ "* DEBUG模式:" + debug+"*\r\n"
 				+ "* 语言环境:" + Locale.getDefault().getLanguage()+"\r\n"
-			 
+
 				+ "**********************************************\r\n");
 	}
 
@@ -84,7 +95,7 @@
 
 	/**
 	 * 初始化语言环境,默认为中文
-	 * 
+	 *
 	 * @author JIANGYOUYAO
 	 * @email 935090232@qq.com
 	 * @date 2017年11月30日
@@ -110,15 +121,35 @@
 	public  void initParams() {
 
 		//初始化所有的公司
-		List<SysCompany> company=sysCompanyDao.selectAll();
+		List<SysCompany> company=sysCompanyService.findByModel(null);
 		Map<String, SysCompany> companyMap=new HashMap<>();
 		for (SysCompany sysCompany : company) {
 			companyMap.put(sysCompany.getComWebUrl(), sysCompany);
 		}
-		servletContext.setAttribute("companyMap", companyMap);
+		saveLocalCache("companyMap", companyMap);
 	}
 
 
+	/**
+	 * 获取本地缓存
+	 * @param key
+	 * @param <T>
+	 * @return
+	 */
+	public static <T> T getLocalCache(String key){
+		return (T)localCache.get(key);
+	}
+
+	/**
+	 * 保存一个本地缓存
+	 * @param key
+	 * @param value
+	 */
+	public static void saveLocalCache(String key,Object value){
+		if(null!=localCache.put(key,value)){
+			LogUtil.debug("覆盖原有缓存{}",key);
+		}
+	}
 
 
 }

--
Gitblit v1.9.1