mirror of https://gitee.com/stylefeng/roses
【i18n】新增三个多语言接口
parent
a71a276c28
commit
29bb26b4f9
|
@ -98,8 +98,10 @@ public class LoginUser implements Serializable {
|
|||
* 当前用户语种的标识,例如:chinese,english
|
||||
* <p>
|
||||
* 这个值是根据字典获取,字典类型编码 languages
|
||||
* <p>
|
||||
* 默认语种是中文
|
||||
*/
|
||||
private String tranLanguageCode;
|
||||
private String tranLanguageCode = "chinese";
|
||||
|
||||
public String getWsUrl() {
|
||||
AtomicReference<String> returnUrl = new AtomicReference<>(StrUtil.EMPTY);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class TranslationRequest extends BaseRequest {
|
|||
/**
|
||||
* 语种字典
|
||||
*/
|
||||
@NotBlank(message = "tranLanguageCode不能为空", groups = {add.class, edit.class})
|
||||
@NotBlank(message = "tranLanguageCode不能为空", groups = {add.class, edit.class, changeUserLanguage.class})
|
||||
private String tranLanguageCode;
|
||||
|
||||
/**
|
||||
|
@ -49,4 +49,10 @@ public class TranslationRequest extends BaseRequest {
|
|||
@NotBlank(message = "tranValue不能为空", groups = {add.class, edit.class})
|
||||
private String tranValue;
|
||||
|
||||
/**
|
||||
* 改变当前用户多语言
|
||||
*/
|
||||
public @interface changeUserLanguage {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,14 @@
|
|||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--字典的api-->
|
||||
<!--多语言类型,存在于字典表-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>dict-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--资源api模块-->
|
||||
<!--用在资源控制器,资源扫描上-->
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.modular.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.auth.api.SessionManagerApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.dict.api.DictApi;
|
||||
import cn.stylefeng.roses.kernel.dict.api.constants.DictConstants;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.context.TranslationContext;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.pojo.request.TranslationRequest;
|
||||
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户多语言信息控制器
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/27 21:59
|
||||
*/
|
||||
@RestController
|
||||
@ApiResource(name = "用户多语言信息控制器")
|
||||
public class UserTranslationController {
|
||||
|
||||
@Resource
|
||||
private DictApi dictApi;
|
||||
|
||||
@Resource
|
||||
private SessionManagerApi sessionManagerApi;
|
||||
|
||||
/**
|
||||
* 获取所有的多语言类型编码
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:20
|
||||
*/
|
||||
@GetResource(name = "获取所有的多语言类型编码", path = "/i18n/getAllLanguages", requiredPermission = false)
|
||||
public ResponseData getAllLanguages() {
|
||||
List<SimpleDict> dictDetailsByDictTypeCode = dictApi.getDictDetailsByDictTypeCode(DictConstants.LANGUAGES_DICT_TYPE_CODE);
|
||||
return new SuccessResponseData(dictDetailsByDictTypeCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的多语言字典
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/27 22:00
|
||||
*/
|
||||
@GetResource(name = "获取当前用户的多语言字典", path = "/i18n/getUserTranslation", requiredPermission = false)
|
||||
public ResponseData getUserTranslation() {
|
||||
String tranLanguageCode = LoginContext.me().getLoginUser().getTranLanguageCode();
|
||||
Map<String, String> translationDictByLanguage = TranslationContext.me().getTranslationDictByLanguage(tranLanguageCode);
|
||||
return new SuccessResponseData(translationDictByLanguage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改当前用户的多语言配置
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/27 22:04
|
||||
*/
|
||||
@PostResource(name = "修改当前用户的多语言配置", path = "/i18n/changeUserTranslation", requiredPermission = false)
|
||||
public ResponseData changeUserTranslation(@RequestBody @Validated(TranslationRequest.changeUserLanguage.class) TranslationRequest translationRequest) {
|
||||
|
||||
String token = LoginContext.me().getToken();
|
||||
LoginUser loginUser = LoginContext.me().getLoginUser();
|
||||
|
||||
// 更新当前用户的多语言配置
|
||||
loginUser.setTranLanguageCode(translationRequest.getTranLanguageCode());
|
||||
sessionManagerApi.updateSession(token, loginUser);
|
||||
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
package cn.stylefeng.roses.kernel.dict.api;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典模块对外提供的api,方便其他模块直接调用
|
||||
*
|
||||
|
@ -20,11 +24,21 @@ public interface DictApi {
|
|||
* 通过字典类型编码和字典编码获取名称
|
||||
*
|
||||
* @param dictTypeCode 字典类型编码
|
||||
* @param dictCode 字典编码
|
||||
* @param dictCode 字典编码
|
||||
* @return 字典名称
|
||||
* @author liuhanqing
|
||||
* @date 2021/1/16 23:18
|
||||
*/
|
||||
String getDictName(String dictTypeCode, String dictCode);
|
||||
|
||||
/**
|
||||
* 根据字典类型编码获取所有的字典
|
||||
*
|
||||
* @param dictTypeCode 字典类型编码
|
||||
* @return 字典的集合
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/27 22:13
|
||||
*/
|
||||
List<SimpleDict> getDictDetailsByDictTypeCode(String dictTypeCode);
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
|||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.rule.factory.DefaultTreeBuildFactory;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.ztree.ZTreeNode;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
|
@ -333,6 +334,25 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SimpleDict> getDictDetailsByDictTypeCode(String dictTypeCode) {
|
||||
DictRequest dictRequest = new DictRequest();
|
||||
dictRequest.setDictTypeCode(dictTypeCode);
|
||||
LambdaQueryWrapper<SysDict> wrapper = createWrapper(dictRequest);
|
||||
List<SysDict> dictList = this.list(wrapper);
|
||||
if (dictList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
ArrayList<SimpleDict> simpleDictList = new ArrayList<>();
|
||||
for (SysDict sysDict : dictList) {
|
||||
SimpleDict simpleDict = new SimpleDict();
|
||||
simpleDict.setCode(sysDict.getDictCode());
|
||||
simpleDict.setName(sysDict.getDictName());
|
||||
simpleDictList.add(simpleDict);
|
||||
}
|
||||
return simpleDictList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改pids的请求
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue