feat: 网页组件翻译导入接口支持自动创建组件功能

This commit is contained in:
曹鹏飞 2025-06-20 16:16:07 +08:00
parent 0a7d7ac9fd
commit d96de4b914
1 changed files with 25 additions and 8 deletions

View File

@ -18,6 +18,7 @@ import com.nflg.mobilebroken.common.pojo.request.WebComponentUpdateRequest;
import com.nflg.mobilebroken.common.pojo.vo.LanguageVO;
import com.nflg.mobilebroken.common.pojo.vo.WebComponentInfoVO;
import com.nflg.mobilebroken.common.pojo.vo.WebComponentVO;
import com.nflg.mobilebroken.common.util.AdminUserUtil;
import com.nflg.mobilebroken.common.util.EecExcelUtil;
import com.nflg.mobilebroken.common.util.ZipUtils;
import com.nflg.mobilebroken.repository.entity.Language;
@ -48,6 +49,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@ -210,12 +212,25 @@ public class MultilingualController extends ControllerBase {
String pageCode = (String) d.get("页面编号");
String componentCode = (String) d.get("组件编号");
log.info("模块编号:{},页面编号:{},组件编号:{}",moduleCode,pageCode,componentCode);
if (StrUtil.isNotBlank(moduleCode) && StrUtil.isNotBlank(pageCode) && StrUtil.isNotBlank(componentCode)){
WebComponent webComponent = webComponentService.lambdaQuery()
.eq(WebComponent::getModuleCode, moduleCode)
.eq(WebComponent::getPageCode, pageCode)
.eq(WebComponent::getComponentCode, componentCode)
.one();
if (Objects.nonNull(webComponent)) {
if (Objects.isNull(webComponent)){
webComponent = new WebComponent()
.setPageName((String) d.get("页面"))
.setPageCode(pageCode)
.setModuleName((String) d.get("模块"))
.setModuleCode(moduleCode)
.setComponentName((String) d.get("组件"))
.setComponentCode(componentCode)
.setCreateBy(AdminUserUtil.getUserId())
.setCreateTime(LocalDateTime.now());
webComponentService.save(webComponent);
}
int componentId = webComponent.getId();
d.remove("模块");
d.remove("模块编号");
d.remove("页面");
@ -223,13 +238,13 @@ public class MultilingualController extends ControllerBase {
d.remove("组件");
d.remove("组件编号");
webComponentTranslateService.remove(new LambdaQueryWrapper<WebComponentTranslate>()
.eq(WebComponentTranslate::getComponentId, webComponent.getId()));
.eq(WebComponentTranslate::getComponentId, componentId));
List<WebComponentTranslate> translates = new ArrayList<>();
d.forEach((k, v) -> {
Language language = languages.stream().filter(l -> l.getName().equals(k)).findFirst().orElse(null);
if (Objects.nonNull(language)) {
WebComponentTranslate webComponentTranslate = new WebComponentTranslate()
.setComponentId(webComponent.getId())
.setComponentId(componentId)
.setLanguageId(language.getId())
.setValue(v.toString());
translates.add(webComponentTranslate);
@ -238,6 +253,8 @@ public class MultilingualController extends ControllerBase {
if (CollectionUtil.isNotEmpty(translates)) {
webComponentTranslateService.saveBatch(translates);
}
}else {
log.error("模块编号,页面编号,组件编号都不能为空");
}
});
return ApiResult.success();