mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-04-04 01:33:23 +08:00
update 优化 工作流类别翻译器支持批量翻译
This commit is contained in:
@@ -5,6 +5,8 @@ import org.dromara.workflow.domain.bo.FlowCategoryBo;
|
|||||||
import org.dromara.workflow.domain.vo.FlowCategoryVo;
|
import org.dromara.workflow.domain.vo.FlowCategoryVo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流程分类Service接口
|
* 流程分类Service接口
|
||||||
@@ -29,6 +31,14 @@ public interface IFlwCategoryService {
|
|||||||
*/
|
*/
|
||||||
String selectCategoryNameById(Long categoryId);
|
String selectCategoryNameById(Long categoryId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据流程分类ID查询流程分类名称
|
||||||
|
*
|
||||||
|
* @param categoryIds 流程分类ID
|
||||||
|
* @return 流程分类名称
|
||||||
|
*/
|
||||||
|
Map<Long, String> selectCategoryNameByIds(Set<Long> categoryIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询符合条件的流程分类列表
|
* 查询符合条件的流程分类列表
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.dromara.workflow.service.impl;
|
|||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.dromara.common.translation.annotation.TranslationType;
|
import org.dromara.common.translation.annotation.TranslationType;
|
||||||
import org.dromara.common.translation.core.TranslationInterface;
|
import org.dromara.common.translation.core.TranslationInterface;
|
||||||
import org.dromara.workflow.common.ConditionalOnEnable;
|
import org.dromara.workflow.common.ConditionalOnEnable;
|
||||||
@@ -10,6 +11,10 @@ import org.dromara.workflow.common.constant.FlowConstant;
|
|||||||
import org.dromara.workflow.service.IFlwCategoryService;
|
import org.dromara.workflow.service.IFlwCategoryService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流程分类名称翻译实现
|
* 流程分类名称翻译实现
|
||||||
*
|
*
|
||||||
@@ -24,15 +29,30 @@ public class CategoryNameTranslationImpl implements TranslationInterface<String>
|
|||||||
|
|
||||||
private final IFlwCategoryService flwCategoryService;
|
private final IFlwCategoryService flwCategoryService;
|
||||||
|
|
||||||
/**
|
|
||||||
* 将流程分类 ID 翻译为分类名称。
|
|
||||||
*
|
|
||||||
* @param key 分类 ID
|
|
||||||
* @param other 额外参数
|
|
||||||
* @return 分类名称
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public String translation(Object key, String other) {
|
public String translation(Object key, String other) {
|
||||||
return flwCategoryService.selectCategoryNameById(Convert.toLong(key));
|
return flwCategoryService.selectCategoryNameById(Convert.toLong(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Object, String> translationBatch(Set<Object> keys, String other) {
|
||||||
|
Set<Long> categoryIds = collectLongIds(keys);
|
||||||
|
if (categoryIds.isEmpty()) {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
Map<Long, String> categoryNames = flwCategoryService.selectCategoryNameByIds(categoryIds);
|
||||||
|
Map<Object, String> result = new LinkedHashMap<>(keys.size());
|
||||||
|
for (Object key : keys) {
|
||||||
|
result.put(key, buildValue(key, categoryNames));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildValue(Object source, Map<Long, String> categoryNames) {
|
||||||
|
if (source instanceof String ids) {
|
||||||
|
return joinMappedValues(ids, categoryNames::get);
|
||||||
|
}
|
||||||
|
return source == null ? null : categoryNames.get(Convert.toLong(source));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ import org.springframework.cache.annotation.Cacheable;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流程分类Service业务层处理
|
* 流程分类Service业务层处理
|
||||||
@@ -70,6 +69,22 @@ public class FlwCategoryServiceImpl implements IFlwCategoryService, CategoryServ
|
|||||||
return ObjectUtils.notNullGetter(category, FlowCategory::getCategoryName);
|
return ObjectUtils.notNullGetter(category, FlowCategory::getCategoryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据流程分类ID查询流程分类名称
|
||||||
|
*
|
||||||
|
* @param categoryIds 流程分类ID
|
||||||
|
* @return 流程分类名称
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<Long, String> selectCategoryNameByIds(Set<Long> categoryIds) {
|
||||||
|
if (CollUtil.isEmpty(categoryIds)) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
List<FlowCategory> list = baseMapper.selectList(new LambdaQueryWrapper<FlowCategory>()
|
||||||
|
.select(FlowCategory::getCategoryName).in(FlowCategory::getCategoryId, categoryIds));
|
||||||
|
return StreamUtils.toMap(list, FlowCategory::getCategoryId, FlowCategory::getCategoryName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询符合条件的流程分类列表
|
* 查询符合条件的流程分类列表
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user