|
@@ -0,0 +1,30 @@
|
|
|
+package com.fjhx.tenant.utils;
|
|
|
+
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
+import com.ruoyi.system.service.ISysDeptService;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.BiConsumer;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+public class DeptUtils {
|
|
|
+
|
|
|
+ private static final ISysDeptService sysDeptService = SpringUtil.getBean(ISysDeptService.class);
|
|
|
+
|
|
|
+ public static Map<Long, String> getDeptNameMap() {
|
|
|
+ List<SysDept> deptList = sysDeptService.list();
|
|
|
+ return deptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> void assignmentNickName(List<T> list, Function<T, Long> idMapper, BiConsumer<T, String> setNickNameMap) {
|
|
|
+ if (list == null || list.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, String> nickNameMapByIds = getDeptNameMap();
|
|
|
+ list.forEach(item -> setNickNameMap.accept(item, nickNameMapByIds.get(idMapper.apply(item))));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|