【i18n】整理代码

pull/3/head
fengshuonan 2021-01-26 21:01:04 +08:00
parent 4632548c9f
commit 6e6e4251ad
3 changed files with 31 additions and 39 deletions

View File

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

View File

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

View File

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