update 优化 工作流类别翻译器支持批量翻译

This commit is contained in:
疯狂的狮子Li
2026-04-02 11:26:36 +08:00
parent 00a5d5c59f
commit f8ebeaa01a
3 changed files with 54 additions and 9 deletions

View File

@@ -5,6 +5,8 @@ import org.dromara.workflow.domain.bo.FlowCategoryBo;
import org.dromara.workflow.domain.vo.FlowCategoryVo;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 流程分类Service接口
@@ -29,6 +31,14 @@ public interface IFlwCategoryService {
*/
String selectCategoryNameById(Long categoryId);
/**
* 根据流程分类ID查询流程分类名称
*
* @param categoryIds 流程分类ID
* @return 流程分类名称
*/
Map<Long, String> selectCategoryNameByIds(Set<Long> categoryIds);
/**
* 查询符合条件的流程分类列表
*

View File

@@ -3,6 +3,7 @@ package org.dromara.workflow.service.impl;
import cn.hutool.core.convert.Convert;
import lombok.RequiredArgsConstructor;
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.core.TranslationInterface;
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.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;
/**
* 将流程分类 ID 翻译为分类名称。
*
* @param key 分类 ID
* @param other 额外参数
* @return 分类名称
*/
@Override
public String translation(Object key, String other) {
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));
}
}

View File

@@ -26,8 +26,7 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
/**
* 流程分类Service业务层处理
@@ -70,6 +69,22 @@ public class FlwCategoryServiceImpl implements IFlwCategoryService, CategoryServ
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);
}
/**
* 查询符合条件的流程分类列表
*