Merge pull request #13953 from dataease/pr@dev-v2@perf_community_language

perf: 社区版语言切换
This commit is contained in:
dataeaseShu 2024-12-11 09:51:21 +08:00 committed by GitHub
commit 6b6376e4bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 4 deletions

View File

@ -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);
}
}

View File

@ -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>

@ -1 +1 @@
Subproject commit cb6d275109949c33f1474054908d961f1e9f0e2d
Subproject commit b814bd2cbe6d8108875ea7df1cd7c45ff07c0634

View File

@ -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 {