顾挽-11月13日
This commit is contained in:
parent
fe76b12b8c
commit
b9d9722067
|
@ -6,6 +6,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,6 +132,13 @@ public class SystemMenu implements Serializable {
|
||||||
@TableField(value = "deleted")
|
@TableField(value = "deleted")
|
||||||
private Boolean deleted;
|
private Boolean deleted;
|
||||||
|
|
||||||
|
|
||||||
|
// 添加 children 属性,表示子菜单
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<SystemMenu> children = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.guwan.controller.login;
|
||||||
|
|
||||||
import com.guwan.RBAC.TempVo;
|
import com.guwan.RBAC.TempVo;
|
||||||
import com.guwan.common.R;
|
import com.guwan.common.R;
|
||||||
|
import com.guwan.service.SystemUsersService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
@ -12,13 +13,14 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
public class DemoController {
|
public class DemoController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private service.SystemUsersService systemUsersService;
|
private SystemUsersService systemUsersService;
|
||||||
|
|
||||||
@GetMapping("1")
|
@GetMapping("1")
|
||||||
public R test(){
|
public R test(){
|
||||||
systemUsersService.getRouterAsync();
|
// systemUsersService.getRouterAsync();
|
||||||
|
|
||||||
return R.ok().put("data", new TempVo().setName("1111"));
|
|
||||||
|
return R.ok().put("data", systemUsersService.getRouterAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package service;
|
package com.guwan.service;
|
||||||
|
|
||||||
import com.guwan.RBAC.SystemUsers;
|
import com.guwan.RBAC.SystemUsers;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
@ -11,6 +11,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
public interface SystemUsersService extends IService<SystemUsers> {
|
public interface SystemUsersService extends IService<SystemUsers> {
|
||||||
|
|
||||||
|
|
||||||
public void getRouterAsync();
|
public String getRouterAsync();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,17 @@ package com.guwan.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.guwan.RBAC.*;
|
import com.guwan.RBAC.*;
|
||||||
import com.guwan.mapper.*;
|
import com.guwan.mapper.*;
|
||||||
|
import com.guwan.service.SystemUsersService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import service.SystemUsersService;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +36,7 @@ public class SystemUsersServiceImpl extends ServiceImpl<SystemUsersMapper, Syste
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getRouterAsync() {
|
public String getRouterAsync() {
|
||||||
|
|
||||||
|
|
||||||
/* List<String> roleList = ;
|
/* List<String> roleList = ;
|
||||||
|
@ -98,12 +99,105 @@ public class SystemUsersServiceImpl extends ServiceImpl<SystemUsersMapper, Syste
|
||||||
|
|
||||||
}).distinct().toList();*/
|
}).distinct().toList();*/
|
||||||
|
|
||||||
System.out.println("systemMenus = " + buildMenuTree(systemMenus));
|
ArrayList<TempVo> tempVos = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
/* for (SystemMenu systemMenu : systemMenus) {
|
||||||
|
TempVo tempVo = new TempVo();
|
||||||
|
tempVo.setName(systemMenu.getName());
|
||||||
|
tempVo.setPath(systemMenu.getPath());
|
||||||
|
RouterMeta routerMeta = new RouterMeta();
|
||||||
|
routerMeta.setTitle("暂时没有");
|
||||||
|
ArrayList<String> strings1 = new ArrayList<>();
|
||||||
|
routerMeta.setAuths(strings1);
|
||||||
|
ArrayList<String> strings2 = new ArrayList<>();
|
||||||
|
routerMeta.setRoles(strings1);
|
||||||
|
tempVo.setMeta(routerMeta);
|
||||||
|
List<TempVo> list = new ArrayList<>(List.of(tempVo));
|
||||||
|
//tempVo.setChildren(list);
|
||||||
|
tempVos.add(tempVo);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("tempVos = " + tempVos);*/
|
||||||
|
|
||||||
|
ArrayList<Integer> integers = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
for (SystemMenu systemMenu : systemMenus) {
|
||||||
|
System.out.println("systemMenu = " + systemMenu);
|
||||||
|
Integer count = 1;
|
||||||
|
Long parentId = systemMenu.getParentId();
|
||||||
|
while (parentId != 0L){
|
||||||
|
List<Long> temp = systemMenuMapper.selectObjs(new LambdaQueryWrapper<SystemMenu>()
|
||||||
|
.eq(SystemMenu::getId, parentId).select(SystemMenu::getParentId));
|
||||||
|
if (temp.isEmpty()) {
|
||||||
|
// 如果找不到父菜单,跳出循环,避免死循环
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
parentId = temp.get(0);
|
||||||
|
|
||||||
|
count++;
|
||||||
|
};
|
||||||
|
integers.add(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("integers = " + integers);
|
||||||
|
|
||||||
|
System.out.println("max = " + Collections.max(integers));
|
||||||
|
|
||||||
|
System.out.println("integers = " + integers.size());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return "111";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// System.out.println("systemMenus = " + buildMenuTree(systemMenus));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 构建 JSON 数据结构
|
||||||
|
private static Map<String, Object> buildJson(List<SystemMenu> rootMenus) {
|
||||||
|
Map<String, Object> rootJson = new HashMap<>();
|
||||||
|
for (SystemMenu menu : rootMenus) {
|
||||||
|
Map<String, Object> menuJson = new HashMap<>();
|
||||||
|
menuJson.put("path", menu.getPath());
|
||||||
|
|
||||||
|
// 构建 meta 数据
|
||||||
|
Map<String, Object> meta = new HashMap<>();
|
||||||
|
meta.put("title", menu.getName()); // 使用菜单名称作为 title
|
||||||
|
meta.put("icon", menu.getIcon());
|
||||||
|
meta.put("rank", menu.getSort());
|
||||||
|
|
||||||
|
// 如果有子菜单,则继续构建
|
||||||
|
if (menu.getChildren() != null && !menu.getChildren().isEmpty()) {
|
||||||
|
menuJson.put("children", buildJson(menu.getChildren()));
|
||||||
|
}
|
||||||
|
|
||||||
|
menuJson.put("meta", meta);
|
||||||
|
rootJson.put(menu.getPath(), menuJson);
|
||||||
|
}
|
||||||
|
return rootJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 方法:将菜单列表构建为树形结构
|
// 方法:将菜单列表构建为树形结构
|
||||||
public static List<SystemMenu> buildMenuTree(List<SystemMenu> menuList) {
|
public static List<SystemMenu> buildMenuTree(List<SystemMenu> menuList) {
|
||||||
// 以 parentId 分组菜单
|
// 以 parentId 分组菜单
|
||||||
|
@ -118,10 +212,10 @@ public class SystemUsersServiceImpl extends ServiceImpl<SystemUsersMapper, Syste
|
||||||
private static List<SystemMenu> buildTree(Map<Long, List<SystemMenu>> parentIdMap, Long parentId) {
|
private static List<SystemMenu> buildTree(Map<Long, List<SystemMenu>> parentIdMap, Long parentId) {
|
||||||
List<SystemMenu> children = parentIdMap.getOrDefault(parentId, new ArrayList<>());
|
List<SystemMenu> children = parentIdMap.getOrDefault(parentId, new ArrayList<>());
|
||||||
|
|
||||||
for (SystemMenu menu : children) {
|
/* for (SystemMenu menu : children) {
|
||||||
// 递归设置子菜单
|
// 递归设置子菜单
|
||||||
menu.setChildren(buildTree(parentIdMap, menu.getId()));
|
menu.setChildren(buildTree(parentIdMap, menu.getId()));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue