update: 添加字符串切分方法以解析Long列表,并移除冗余的解析逻辑

This commit is contained in:
AprilWind 2026-11-04 16:43:45 +08:00
parent 066280bbaa
commit 0a89e92626
4 changed files with 14 additions and 17 deletions

View File

@ -296,6 +296,16 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
return splitTo(str, separator, Convert::toStr);
}
/**
* 切分字符串,解析成Long列表(默认逗号分隔)
*
* @param str 被切分字符串
* @return 分割后的数据列表
*/
public static List<Long> splitLongList(String str) {
return splitTo(str, Convert::toLong);
}
/**
* 切分字符串自定义转换(分隔符默认逗号)
*

View File

@ -56,7 +56,7 @@ public interface TranslationInterface<T> {
Set<Long> result = new LinkedHashSet<>();
for (Object key : keys) {
if (key instanceof String ids) {
result.addAll(parseLongIds(ids));
result.addAll(StringUtils.splitLongList(ids));
} else if (key != null) {
result.add(Convert.toLong(key));
}
@ -64,19 +64,6 @@ public interface TranslationInterface<T> {
return result;
}
/**
* 解析逗号分隔的 Long ID 列表。
*
* @param ids 逗号分隔字符串
* @return Long 列表
*/
default List<Long> parseLongIds(String ids) {
return StreamUtils.toList(
StreamUtils.filter(Arrays.asList(ids.split(StringUtils.SEPARATOR)), StringUtils::isNotBlank),
value -> Convert.toLong(value.trim())
);
}
/**
* 按原始 ID 顺序拼接映射值。
*
@ -86,7 +73,7 @@ public interface TranslationInterface<T> {
* @return 拼接后的结果字符串
*/
default <E> String joinMappedValues(String ids, Function<Long, E> mapper) {
return StreamUtils.join(parseLongIds(ids), id -> {
return StreamUtils.join(StringUtils.splitLongList(ids), id -> {
E value = mapper.apply(id);
return value == null ? null : String.valueOf(value);
});

View File

@ -38,7 +38,6 @@ class TranslationInterfaceTest {
Set<Long> result = translation.collectLongIds(List.of("1, 2,1", 3L, " "));
assertEquals(new LinkedHashSet<>(List.of(1L, 2L, 3L)), result);
assertEquals(List.of(4L, 5L), translation.parseLongIds("4, 5"));
}
/**

View File

@ -5,6 +5,7 @@ import cn.hutool.core.convert.Convert;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.StreamUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.system.api.UserService;
import org.dromara.workflow.common.ConditionalOnEnable;
@ -39,7 +40,7 @@ public class TaskOpNotifyComponent extends NodeComponent {
userIdList.add(Convert.toLong(bo.getUserId()));
}
if (CollUtil.isNotEmpty(bo.getUserIds())) {
userIdList.addAll(bo.getUserIds().stream().map(Convert::toLong).toList());
userIdList.addAll(StreamUtils.toList(bo.getUserIds(), Convert::toLong));
}
if (CollUtil.isEmpty(userIdList)) {
return;