|
|
@@ -2,13 +2,17 @@ package com.ningdatech.pmapi.sys.manage; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import com.ningdatech.basic.util.CollUtils; |
|
|
|
import com.ningdatech.pmapi.common.constant.BizConst; |
|
|
|
import com.ningdatech.pmapi.common.model.entity.MenuTreeEntity; |
|
|
|
import com.ningdatech.pmapi.common.util.TreeUtil; |
|
|
|
import com.ningdatech.pmapi.sys.model.entity.Menu; |
|
|
|
import com.ningdatech.pmapi.sys.model.vo.MenuRoleVO; |
|
|
|
import com.ningdatech.pmapi.sys.service.IMenuService; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
@@ -22,9 +26,40 @@ import java.util.List; |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class MenuManage { |
|
|
|
|
|
|
|
private final IMenuService menuService; |
|
|
|
|
|
|
|
public List<MenuRoleVO> buildUserMenu(List<Menu> list) { |
|
|
|
List<MenuRoleVO> menuRoles = CollUtils.convert(list, w -> BeanUtil.copyProperties(w, MenuRoleVO.class)); |
|
|
|
Set<Long> menuIds = new HashSet<>(); |
|
|
|
List<MenuRoleVO> menuRoles = CollUtils.convert(list, w -> { |
|
|
|
menuIds.add(w.getId()); |
|
|
|
return BeanUtil.copyProperties(w, MenuRoleVO.class); |
|
|
|
}); |
|
|
|
List<Long> pidList = menuRoles.stream() |
|
|
|
.map(MenuTreeEntity::getPid) |
|
|
|
.filter(pid -> !menuIds.contains(pid) && pid != BizConst.PARENT_ID) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
parentMenuCheck(pidList, menuRoles, menuIds); |
|
|
|
return TreeUtil.buildUserTree(menuRoles); |
|
|
|
} |
|
|
|
|
|
|
|
public void parentMenuCheck(List<Long> pidList, List<MenuRoleVO> menuRoles, Set<Long> menuIds) { |
|
|
|
List<Menu> menus = menuService.listByIds(pidList); |
|
|
|
if (menus.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
Set<Long> tmpSet = new HashSet<>(); |
|
|
|
menus.forEach(w -> { |
|
|
|
menuIds.add(w.getId()); |
|
|
|
tmpSet.add(w.getPid()); |
|
|
|
menuRoles.add(BeanUtil.copyProperties(w, MenuRoleVO.class)); |
|
|
|
}); |
|
|
|
List<Long> tmpPidList = tmpSet.stream() |
|
|
|
.filter(pid -> !menuIds.contains(pid) && pid != BizConst.PARENT_ID) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
if (tmpPidList.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
parentMenuCheck(tmpPidList, menuRoles, menuIds); |
|
|
|
} |
|
|
|
|
|
|
|
} |