mirror of
https://github.com/dataease/dataease.git
synced 2026-05-14 21:12:33 +08:00
perf: 社区版语言切换
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
package io.dataease.substitute.permissions.user;
|
||||
|
||||
|
||||
import io.dataease.api.permissions.user.dto.LangSwitchRequest;
|
||||
import io.dataease.api.permissions.user.vo.CurIpVO;
|
||||
import io.dataease.api.permissions.user.vo.UserFormVO;
|
||||
import io.dataease.exception.DEException;
|
||||
import io.dataease.i18n.Lang;
|
||||
import io.dataease.utils.CacheUtils;
|
||||
import io.dataease.utils.IPUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.dataease.constant.CacheConstant.UserCacheConstant.USER_COMMUNITY_LANGUAGE;
|
||||
|
||||
@Component
|
||||
@ConditionalOnMissingBean(name = "userServer")
|
||||
@RestController
|
||||
@@ -26,6 +32,10 @@ public class SubstituteUserServer {
|
||||
result.put("name", "管理员");
|
||||
result.put("oid", "1");
|
||||
result.put("language", "zh-CN");
|
||||
Object langObj = CacheUtils.get(USER_COMMUNITY_LANGUAGE, "de");
|
||||
if (ObjectUtils.isNotEmpty(langObj) && StringUtils.isNotBlank(langObj.toString())) {
|
||||
result.put("language", langObj.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -49,4 +59,17 @@ public class SubstituteUserServer {
|
||||
curIpVO.setIp(IPUtils.get());
|
||||
return curIpVO;
|
||||
}
|
||||
|
||||
@PostMapping("/switchLanguage")
|
||||
public void switchLanguage(@RequestBody LangSwitchRequest request) {
|
||||
String lang = request.getLang();
|
||||
if (StringUtils.equalsIgnoreCase(Lang.zh_CN.getDesc(), lang)) {
|
||||
lang = Lang.zh_CN.getDesc();
|
||||
} else if (StringUtils.equalsAnyIgnoreCase(lang, "en", "tw")) {
|
||||
lang = lang.toLowerCase();
|
||||
} else {
|
||||
DEException.throwException("无效language");
|
||||
}
|
||||
CacheUtils.put(USER_COMMUNITY_LANGUAGE, "de", lang);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +98,10 @@
|
||||
<key-type>java.lang.String</key-type>
|
||||
<value-type>java.lang.Object</value-type>
|
||||
</cache>
|
||||
<cache alias="de_v2_user_community_language" uses-template="common-cache">
|
||||
<key-type>java.lang.String</key-type>
|
||||
<value-type>java.lang.Object</value-type>
|
||||
</cache>
|
||||
|
||||
<cache alias="de_v2_user_token_cache">
|
||||
<key-type>java.lang.String</key-type>
|
||||
|
||||
2
de-xpack
2
de-xpack
Submodule de-xpack updated: cb6d275109...b814bd2cbe
@@ -8,6 +8,7 @@ public class CacheConstant {
|
||||
public static final String USER_ROLES_CACHE = "de_v2_user_roles";
|
||||
public static final String USER_BUSI_PERS_CACHE = "de_v2_user_busi_pers";
|
||||
public static final String USER_BUSI_PERS_INTERACTIVE_CACHE = "de_v2_user_busi_pers_interactive";
|
||||
public static final String USER_COMMUNITY_LANGUAGE = "de_v2_user_community_language";
|
||||
}
|
||||
|
||||
public static class RoleCacheConstant {
|
||||
|
||||
Reference in New Issue
Block a user