Преглед изворни кода

3.1.0-改txt编码为"gbk",浏览器访问不乱码,编码参数化,加入缓存

xiaof пре 2 година
родитељ
комит
fab71441d3

+ 4 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/GradeBatchServiceImpl.java

@@ -340,10 +340,10 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
 
                 JSONObject jsonObject = new JSONObject();
 
-                String charset = SystemConstant.CHARSET_GB2312;
-                SysConfigService sysConfigService = SpringContextHolder.getBean(SysConfigService.class);
-                if (sysConfigService != null) {
-                    SysConfig sysConfig = sysConfigService.getByKey("sys.txt.charset");
+                String charset = SystemConstant.CHARSET_GBK;
+                CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
+                if (commonCacheService != null) {
+                    SysConfig sysConfig = commonCacheService.txtCharsetCache();
                     if (sysConfig != null && StringUtils.isNotBlank(sysConfig.getConfigValue())) {
                         charset = sysConfig.getConfigValue();
                     }

+ 5 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/export/AsyncExportTaskTemplete.java

@@ -12,6 +12,7 @@ import com.qmth.teachcloud.common.entity.TBTask;
 import com.qmth.teachcloud.common.enums.TaskResultEnum;
 import com.qmth.teachcloud.common.enums.TaskStatusEnum;
 import com.qmth.teachcloud.common.enums.UploadFileEnum;
+import com.qmth.teachcloud.common.service.CommonCacheService;
 import com.qmth.teachcloud.common.service.SysConfigService;
 import com.qmth.teachcloud.common.service.TBTaskService;
 import com.qmth.teachcloud.common.util.FileStoreUtil;
@@ -98,10 +99,10 @@ public abstract class AsyncExportTaskTemplete {
             path = path.replaceAll("\\\\", "/");
             String type = (String) jsonObject.get(SystemConstant.TYPE);
 
-            String charset = SystemConstant.CHARSET_GB2312;
-            SysConfigService sysConfigService = SpringContextHolder.getBean(SysConfigService.class);
-            if (sysConfigService != null) {
-                SysConfig sysConfig = sysConfigService.getByKey("sys.txt.charset");
+            String charset = SystemConstant.CHARSET_GBK;
+            CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
+            if (commonCacheService != null) {
+                SysConfig sysConfig = commonCacheService.txtCharsetCache();
                 if (sysConfig != null && StringUtils.isNotBlank(sysConfig.getConfigValue())) {
                     charset = sysConfig.getConfigValue();
                 }

+ 5 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/importData/AsyncImportTaskTemplete.java

@@ -11,6 +11,7 @@ import com.qmth.teachcloud.common.enums.TaskResultEnum;
 import com.qmth.teachcloud.common.enums.TaskStatusEnum;
 import com.qmth.teachcloud.common.enums.TaskTypeEnum;
 import com.qmth.teachcloud.common.enums.UploadFileEnum;
+import com.qmth.teachcloud.common.service.CommonCacheService;
 import com.qmth.teachcloud.common.service.SysConfigService;
 import com.qmth.teachcloud.common.service.TBTaskService;
 import com.qmth.teachcloud.common.util.FileStoreUtil;
@@ -113,10 +114,10 @@ public abstract class AsyncImportTaskTemplete {
             path = path.replaceAll("\\\\", "/");
             String type = (String) jsonObject.get(SystemConstant.TYPE);
 
-            String charset = SystemConstant.CHARSET_GB2312;
-            SysConfigService sysConfigService = SpringContextHolder.getBean(SysConfigService.class);
-            if (sysConfigService != null) {
-                SysConfig sysConfig = sysConfigService.getByKey("sys.txt.charset");
+            String charset = SystemConstant.CHARSET_GBK;
+            CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
+            if (commonCacheService != null) {
+                SysConfig sysConfig = commonCacheService.txtCharsetCache();
                 if (sysConfig != null && StringUtils.isNotBlank(sysConfig.getConfigValue())) {
                     charset = sysConfig.getConfigValue();
                 }

+ 5 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/push/AsyncPushTaskTemplate.java

@@ -15,6 +15,7 @@ import com.qmth.teachcloud.common.enums.TaskResultEnum;
 import com.qmth.teachcloud.common.enums.TaskStatusEnum;
 import com.qmth.teachcloud.common.enums.TaskTypeEnum;
 import com.qmth.teachcloud.common.enums.UploadFileEnum;
+import com.qmth.teachcloud.common.service.CommonCacheService;
 import com.qmth.teachcloud.common.service.SysConfigService;
 import com.qmth.teachcloud.common.service.TBTaskService;
 import com.qmth.teachcloud.common.util.FileStoreUtil;
@@ -80,10 +81,10 @@ public abstract class AsyncPushTaskTemplate {
         ByteArrayOutputStream out = null;
         InputStream inputStream = null;
         try {
-            String charset = SystemConstant.CHARSET_GB2312;
-            SysConfigService sysConfigService = SpringContextHolder.getBean(SysConfigService.class);
-            if(sysConfigService != null) {
-                SysConfig sysConfig = sysConfigService.getByKey("sys.txt.charset");
+            String charset = SystemConstant.CHARSET_GBK;
+            CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
+            if(commonCacheService != null) {
+                SysConfig sysConfig = commonCacheService.txtCharsetCache();
                 if (sysConfig != null && StringUtils.isNotBlank(sysConfig.getConfigValue())) {
                     charset = sysConfig.getConfigValue();
                 }

+ 2 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -36,6 +36,7 @@ public class SystemConstant {
      */
     public static final String CHARSET_NAME = "UTF-8";
     public static final String CHARSET_GB2312= "gb2312";
+    public static final String CHARSET_GBK= "gbk";
     public static final Charset CHARSET = Charset.forName(CHARSET_NAME);
     public static final String MD5 = "MD5";
     public static final String SUCCESS = "success";
@@ -134,6 +135,7 @@ public class SystemConstant {
     public static final String PDF_CACHE = "pdf:cache";
     public static final String ROLE_CACHE = "role:cache";
     public static final String AUTH_INFO_CACHE = "auth:info:cache";
+    public static final String TXT_CHARSET_CACHE = "charset:txt:cache";
 
     /**
      * 报表缓存

+ 6 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/CommonCacheService.java

@@ -297,4 +297,10 @@ public interface CommonCacheService {
      * @param code
      */
     public void removeAuthInfoCache(String code);
+
+    /**
+     * 添加编码缓存
+     *
+     */
+    public SysConfig txtCharsetCache();
 }

+ 12 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/CommonCacheServiceImpl.java

@@ -53,6 +53,9 @@ public class CommonCacheServiceImpl implements CommonCacheService {
     @Resource
     SolarService solarService;
 
+    @Resource
+    SysConfigService sysConfigService;
+
     /**
      * 添加角色缓存
      *
@@ -470,4 +473,13 @@ public class CommonCacheServiceImpl implements CommonCacheService {
     public void removeAuthInfoCache(String code) {
 
     }
+
+    /**
+     * 添加编码缓存
+     */
+    @Override
+    @Cacheable(value = SystemConstant.TXT_CHARSET_CACHE)
+    public SysConfig txtCharsetCache() {
+        return sysConfigService.getByKey("sys.txt.charset");
+    }
 }