mirror of https://gitee.com/stylefeng/roses
【i18n】整理代码
parent
4632548c9f
commit
6e6e4251ad
|
@ -85,7 +85,7 @@ public class TranslationController {
|
|||
*/
|
||||
@GetResource(name = "新增多语言配置", path = "/i18n/page")
|
||||
public ResponseData page(TranslationRequest translationRequest) {
|
||||
PageResult<Translation> page = this.translationService.getPage(translationRequest);
|
||||
PageResult<Translation> page = this.translationService.findPage(translationRequest);
|
||||
return new SuccessResponseData(page);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,15 +52,6 @@ public interface TranslationService extends IService<Translation>, TranslationPe
|
|||
*/
|
||||
Translation detail(TranslationRequest translationRequest);
|
||||
|
||||
/**
|
||||
* 查询-详情-按实体对象
|
||||
*
|
||||
* @param translationRequest 参数对象
|
||||
* @author chenjinlong
|
||||
* @date 2021/1/26 12:52
|
||||
*/
|
||||
Translation detailBy(TranslationRequest translationRequest);
|
||||
|
||||
/**
|
||||
* 查询-列表-按实体对象
|
||||
*
|
||||
|
@ -68,7 +59,7 @@ public interface TranslationService extends IService<Translation>, TranslationPe
|
|||
* @author chenjinlong
|
||||
* @date 2021/1/26 12:52
|
||||
*/
|
||||
List<Translation> listBy(TranslationRequest translationRequest);
|
||||
List<Translation> findList(TranslationRequest translationRequest);
|
||||
|
||||
/**
|
||||
* 查询-列表-分页-按实体对象
|
||||
|
@ -77,7 +68,6 @@ public interface TranslationService extends IService<Translation>, TranslationPe
|
|||
* @author chenjinlong
|
||||
* @date 2021/1/26 12:52
|
||||
*/
|
||||
PageResult<Translation> getPage(TranslationRequest translationRequest);
|
||||
|
||||
PageResult<Translation> findPage(TranslationRequest translationRequest);
|
||||
|
||||
}
|
||||
|
|
|
@ -37,50 +37,45 @@ public class TranslationServiceImpl extends ServiceImpl<TranslationMapper, Trans
|
|||
Translation translation = new Translation();
|
||||
BeanUtil.copyProperties(translationRequest, translation);
|
||||
this.save(translation);
|
||||
// 更新对应常量
|
||||
|
||||
// 更新翻译的缓存
|
||||
this.saveContext(translation);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void edit(TranslationRequest translationRequest) {
|
||||
Translation translation = this.queryTranslation(translationRequest);
|
||||
Translation translation = this.queryTranslationById(translationRequest);
|
||||
BeanUtil.copyProperties(translationRequest, translation);
|
||||
this.updateById(translation);
|
||||
// 更新对应常量
|
||||
|
||||
// 更新翻译的缓存
|
||||
this.saveContext(translation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void del(TranslationRequest translationRequest) {
|
||||
Translation translation = this.queryTranslation(translationRequest);
|
||||
Translation translation = this.queryTranslationById(translationRequest);
|
||||
this.removeById(translationRequest.getTranId());
|
||||
// 更新对应常量
|
||||
this.saveContext(translation);
|
||||
|
||||
// 删除对应缓存
|
||||
TranslationEnum translationEnum = TranslationEnum.valueOf(translation.getTranLanguageCode());
|
||||
TranslationContext.me().deleteTranslationDict(translationEnum, translation.getTranCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translation detail(TranslationRequest translationRequest) {
|
||||
return this.queryTranslation(translationRequest);
|
||||
LambdaQueryWrapper<Translation> queryWrapper = this.createWrapper(translationRequest);
|
||||
return this.getOne(queryWrapper, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translation detailBy(TranslationRequest translationRequest) {
|
||||
List<Translation> list = this.listBy(translationRequest);
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return list.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Translation> listBy(TranslationRequest translationRequest) {
|
||||
public List<Translation> findList(TranslationRequest translationRequest) {
|
||||
LambdaQueryWrapper<Translation> queryWrapper = this.createWrapper(translationRequest);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Translation> getPage(TranslationRequest translationRequest) {
|
||||
public PageResult<Translation> findPage(TranslationRequest translationRequest) {
|
||||
LambdaQueryWrapper<Translation> wrapper = createWrapper(translationRequest);
|
||||
Page<Translation> page = this.page(PageFactory.defaultPage(), wrapper);
|
||||
return PageResultFactory.createPageResult(page);
|
||||
|
@ -101,12 +96,10 @@ public class TranslationServiceImpl extends ServiceImpl<TranslationMapper, Trans
|
|||
/**
|
||||
* 根据主键id获取对象
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @author chenjinlong
|
||||
* @date 2021/1/26 13:28
|
||||
*/
|
||||
private Translation queryTranslation(TranslationRequest translationRequest) {
|
||||
private Translation queryTranslationById(TranslationRequest translationRequest) {
|
||||
Translation translation = this.getById(translationRequest.getTranId());
|
||||
if (ObjectUtil.isEmpty(translation)) {
|
||||
throw new TranslationException(TranslationExceptionEnum.NOT_EXISTED, translationRequest.getTranId());
|
||||
|
@ -123,29 +116,38 @@ public class TranslationServiceImpl extends ServiceImpl<TranslationMapper, Trans
|
|||
private LambdaQueryWrapper<Translation> createWrapper(TranslationRequest translationRequest) {
|
||||
LambdaQueryWrapper<Translation> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
Long tranId = translationRequest.getTranId();
|
||||
String tranCode = translationRequest.getTranCode();
|
||||
String tranName = translationRequest.getTranName();
|
||||
String tranLanguageCode = translationRequest.getTranLanguageCode();
|
||||
|
||||
// SQL条件拼接
|
||||
queryWrapper.eq(ObjectUtil.isNotEmpty(tranId), Translation::getTranId, tranId);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(tranCode), Translation::getTranCode, tranCode);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(tranName), Translation::getTranName, tranName);
|
||||
queryWrapper.eq(ObjectUtil.isNotEmpty(tranLanguageCode), Translation::getTranLanguageCode, tranLanguageCode);
|
||||
// 排序
|
||||
|
||||
// 按翻译编码倒序排列
|
||||
queryWrapper.orderByDesc(Translation::getTranCode);
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新对应常量
|
||||
* 更新翻译的缓存
|
||||
*
|
||||
* @param translation
|
||||
* @author chenjinlong
|
||||
* @date 2021/1/26 13:45
|
||||
*/
|
||||
private void saveContext(Translation translation) {
|
||||
|
||||
TranslationEnum translationEnum = TranslationEnum.getValue(translation.getTranLanguageCode());
|
||||
|
||||
// 没有对应的语种,不添加到context
|
||||
if (translationEnum == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TranslationDict translationDict = TranslationDictFactory.createTranslationDict(translationEnum, translation);
|
||||
TranslationContext.me().addTranslationDict(translationDict);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue