Browse Source

系统配置修改-新增删除版本时刷新缓存的版本信息

shenhao 2 năm trước cách đây
mục cha
commit
c94c7c01f9

+ 30 - 18
src/main/java/com/ssj/framework/basic/config/service/impl/ConfigServiceImpl.java

@@ -1,5 +1,7 @@
 package com.ssj.framework.basic.config.service.impl;
 
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.ssj.framework.basic.config.bean.Config;
 import com.ssj.framework.basic.config.bean.VersionConfig;
 import com.ssj.framework.basic.config.dao.ConfigDao;
@@ -9,6 +11,7 @@ import com.ssj.framework.core.persistence.DynamicSpecifications;
 import com.ssj.framework.core.persistence.SearchFilter;
 import com.ssj.framework.core.security.manager.TokenManager;
 import com.ssj.framework.core.util.SystemResourceLocator;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
@@ -17,6 +20,7 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.data.repository.PagingAndSortingRepository;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -37,18 +41,10 @@ public class ConfigServiceImpl extends BaseServiceImpl<Config, String> implement
 
     @Autowired
     private TokenManager tokenManager;
-    /**
-     * 数学
-     */
-    private static String versionKey1="VERSION_M";
-    /**
-     * 语文
-     */
-    private static String versionKey2="VERSION_C";
-    /**
-     * 英语
-     */
-    private static String versionKey3="VERSION_E";
+
+    private static String versionMKey="VERSION_M_*";
+    private static String versionCKey="VERSION_C_*";
+    private static String versionEKey="VERSION_E_*";
 
     @Override
     public PagingAndSortingRepository<Config, String> getDao() {
@@ -127,18 +123,34 @@ public class ConfigServiceImpl extends BaseServiceImpl<Config, String> implement
     @Override
     public void refushCache(String paramCode) {
         String courseName = getCourseName(paramCode);
-        Map<String,List<VersionConfig>> map = SystemResourceLocator.getVersionList(courseName);
-        List<VersionConfig> list = map.get(courseName);
-//        tokenManager.hset(courseName,courseName,list);
+        if(StringUtils.isNotBlank(courseName)){
+            Map<String,List<VersionConfig>> map = SystemResourceLocator.getVersionList(courseName);
+            List<VersionConfig> list = map.get(courseName);
+            String versionKey = courseName.equals("语文")?versionCKey:courseName.equals("数学")?versionMKey:versionEKey;
+            String cacheKey = versionKey.replace("*",courseName).replace("VERSION",courseName);
+            tokenManager.setString(cacheKey, JSONUtil.toJsonStr(list));
+        }
+
     }
 
     private String getCourseName(String paramCode){
-        if(paramCode.contains(versionKey2)){
+        if(paramCode.contains(versionCKey.replace("_*",""))){
             return "语文";
-        }else if(paramCode.contains(versionKey1)){
+        }else if(paramCode.contains(versionMKey.replace("_*",""))){
             return "数学";
-        }else{
+        }else if (paramCode.contains(versionEKey.replace("_*",""))){
             return "英语";
+        }else{
+            return "";
+        }
+    }
+    private String getCourseCode(String courseName){
+        if(courseName.contains("语文")){
+            return versionCKey;
+        }else if(courseName.contains("数学")){
+            return versionMKey;
+        }else{
+            return versionEKey;
         }
     }
 

+ 2 - 1
src/main/java/com/ssj/sys/controller/ConfigController.java

@@ -75,7 +75,8 @@ public class ConfigController extends BaseController {
     	config=configService.save(config);
     	configService.clearConfigCache();
 		SystemResourceLocator.setValue(config.getParamCode(),config.getParamVal(),true);
-    	response.success(config);
+		configService.refushCache(config.getParamCode());
+		response.success(config);
         return response;
     }