瀏覽代碼

加入根据平台动态设置txt的编码

wangliang 2 年之前
父節點
當前提交
f1dff72eb3

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

@@ -241,6 +241,7 @@ public class SystemConstant {
     public static final String FTL_PREFIX = ".ftl";
     public static final String ZIP_PREFIX = ".zip";
     public static final String TXT_PREFIX = ".txt";
+    public static final String WINDOWS = "Windows";
 
     public static final String EXCEL_PREFIX = ".xlsx";
     public static final String JPG_PREFIX = ".jpg";

+ 8 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysConfigServiceImpl.java

@@ -14,6 +14,7 @@ import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * <p>
@@ -49,11 +50,18 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
     public List<SysConfig> selectAll() {
         List<SysConfig> sysConfigList = null;
         try {
+            String platform = System.getProperties().getProperty("os.name");
             QueryWrapper<SysConfig> sysConfigQueryWrapper = new QueryWrapper<>();
             sysConfigQueryWrapper.lambda().isNull(SysConfig::getSchoolId);
             sysConfigList = this.list(sysConfigQueryWrapper);
             if (!CollectionUtils.isEmpty(sysConfigList)) {
                 for (SysConfig s : sysConfigList) {
+                    if (s.getConfigKey().contains(SystemConstant.SYS_CONFIG_KEY_CHARSETS) && Objects.nonNull(platform) && platform.contains(SystemConstant.WINDOWS)) {
+                        if (!Objects.equals(s.getConfigValue(), SystemConstant.CHARSET_GBK)) {
+                            s.setConfigValue(SystemConstant.CHARSET_GBK);
+                            this.updateById(s);
+                        }
+                    }
                     commonCacheService.updateSysConfigCacheForDb(s.getConfigKey(), s);
                 }
             }