|
|
|
|
@ -1,11 +1,15 @@
|
|
|
|
|
package com.ruoyi.portal.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.ruoyi.portal.mapper.HwWebMenuMapper;
|
|
|
|
|
import com.ruoyi.portal.domain.HwWebMenu;
|
|
|
|
|
import com.ruoyi.portal.service.IHwWebMenuService;
|
|
|
|
|
import com.ruoyi.common.core.utils.StringUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* haiwei官网菜单Service业务层处理
|
|
|
|
|
@ -90,4 +94,62 @@ public class HwWebMenuServiceImpl implements IHwWebMenuService
|
|
|
|
|
{
|
|
|
|
|
return hwWebMenuMapper.deleteHwWebMenuByWebMenuId(webMenuId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构建前端所需要树结构(根据传入的平铺菜单列表构造树)
|
|
|
|
|
*
|
|
|
|
|
* @param menus 菜单列表
|
|
|
|
|
* @return 树结构列表
|
|
|
|
|
*/
|
|
|
|
|
public List<HwWebMenu> buildWebMenuTree(List<HwWebMenu> menus) {
|
|
|
|
|
List<HwWebMenu> returnList = new ArrayList<>();
|
|
|
|
|
List<Long> tempList = menus.stream().map(HwWebMenu::getWebMenuId).collect(Collectors.toList());
|
|
|
|
|
for (HwWebMenu menu : menus) {
|
|
|
|
|
// 如果是顶级节点(parent为null、0或者不在当前列表中), 遍历该父节点的所有子节点
|
|
|
|
|
if (menu.getParent() == null || menu.getParent() == 0L || !tempList.contains(menu.getParent())) {
|
|
|
|
|
recursionFn(menus, menu);
|
|
|
|
|
returnList.add(menu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (returnList.isEmpty()) {
|
|
|
|
|
returnList = menus;
|
|
|
|
|
}
|
|
|
|
|
return returnList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 递归设置子节点
|
|
|
|
|
*/
|
|
|
|
|
private void recursionFn(List<HwWebMenu> list, HwWebMenu t) {
|
|
|
|
|
// 得到子节点列表
|
|
|
|
|
List<HwWebMenu> childList = getChildList(list, t);
|
|
|
|
|
t.setChildren(childList);
|
|
|
|
|
for (HwWebMenu tChild : childList) {
|
|
|
|
|
if (hasChild(list, tChild)) {
|
|
|
|
|
recursionFn(list, tChild);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 得到子节点列表
|
|
|
|
|
*/
|
|
|
|
|
private List<HwWebMenu> getChildList(List<HwWebMenu> list, HwWebMenu t) {
|
|
|
|
|
List<HwWebMenu> tlist = new ArrayList<HwWebMenu>();
|
|
|
|
|
Iterator<HwWebMenu> it = list.iterator();
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
HwWebMenu n = it.next();
|
|
|
|
|
if (StringUtils.isNotNull(n.getParent()) && n.getParent().longValue() == t.getWebMenuId().longValue()) {
|
|
|
|
|
tlist.add(n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tlist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否有子节点
|
|
|
|
|
*/
|
|
|
|
|
private boolean hasChild(List<HwWebMenu> list, HwWebMenu t) {
|
|
|
|
|
return !getChildList(list, t).isEmpty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|