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

This commit is contained in:
疯狂的狮子Li
2026-04-02 11:26:46 +08:00
parent 242f9608f1
commit abc9f160da
3 changed files with 56 additions and 2 deletions

View File

@@ -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);
/** /**
* 查询符合条件的流程分类列表 * 查询符合条件的流程分类列表
* *
@@ -92,4 +102,5 @@ public interface IFlwCategoryService {
* @return 是否删除成功 * @return 是否删除成功
*/ */
int deleteWithValidById(Long categoryId); int deleteWithValidById(Long categoryId);
} }

View File

@@ -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;
/** /**
* 流程分类名称翻译实现 * 流程分类名称翻译实现
* *
@@ -28,4 +33,26 @@ public class CategoryNameTranslationImpl implements TranslationInterface<String>
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));
}
} }

View File

@@ -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业务层处理
@@ -77,6 +76,23 @@ 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);
}
/** /**
* 查询符合条件的流程分类列表 * 查询符合条件的流程分类列表
* *