|
|
@@ -1,6 +1,7 @@
|
|
|
package com.cyksj.service.translations.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.cyksj.mapper.BackInfoTranslationsMapper;
|
|
|
import com.cyksj.model.dto.TranslationsDto;
|
|
|
@@ -28,7 +29,7 @@ public class BackInfoTranslationsServiceImpl extends ServiceImpl<BackInfoTransla
|
|
|
@Override
|
|
|
public void saveOrUpdateTranslations(TranslationsDto dto) {
|
|
|
List<BackInfoTranslations> fields = dto.getFields();
|
|
|
- if (CollUtil.isNotEmpty(fields)) {
|
|
|
+ if (CollUtil.isEmpty(fields)) {
|
|
|
return;
|
|
|
}
|
|
|
backInfoTranslationsMapper.batchInsertOrUpdate(dto.getFuncId(), dto.getType().ordinal(), dto.getFields(), dto.getLang());
|
|
|
@@ -42,15 +43,22 @@ public class BackInfoTranslationsServiceImpl extends ServiceImpl<BackInfoTransla
|
|
|
translationsDto.setFuncId(funcId);
|
|
|
List<BackInfoTranslations> fields = new ArrayList<>();
|
|
|
for (Field declaredField : obj.getClass().getDeclaredFields()) {
|
|
|
- BackInfoTranslations backInfoTranslations = new BackInfoTranslations();
|
|
|
- backInfoTranslations.setFieldName(declaredField.getName());
|
|
|
try {
|
|
|
declaredField.setAccessible(true);
|
|
|
- Optional.ofNullable(declaredField.get(obj)).ifPresent(val -> backInfoTranslations.setDesc(val.toString()));
|
|
|
- fields.add(backInfoTranslations);
|
|
|
+ Optional.ofNullable(declaredField.get(obj)).ifPresent(val -> {
|
|
|
+ BackInfoTranslations backInfoTranslations = new BackInfoTranslations();
|
|
|
+ backInfoTranslations.setFieldName(declaredField.getName());
|
|
|
+ backInfoTranslations.setDesp(val.toString());
|
|
|
+ fields.add(backInfoTranslations);
|
|
|
+ });
|
|
|
} catch (IllegalAccessException e) {
|
|
|
}
|
|
|
}
|
|
|
- saveOrUpdateTranslations(translationsDto);
|
|
|
+ if (CollUtil.isNotEmpty(fields)) {
|
|
|
+ translationsDto.setFields(fields);
|
|
|
+ saveOrUpdateTranslations(translationsDto);
|
|
|
+ } else {
|
|
|
+ backInfoTranslationsMapper.delete(Wrappers.lambdaQuery(BackInfoTranslations.class).eq(BackInfoTranslations::getType, type.ordinal()).eq(BackInfoTranslations::getFuncId, funcId).eq(BackInfoTranslations::getLang, lang));
|
|
|
+ }
|
|
|
}
|
|
|
}
|