83 lines
3.2 KiB
Java
83 lines
3.2 KiB
Java
|
|
package com.zhangmeng.online.exam.controller;
|
||
|
|
|
||
|
|
import com.zhangmeng.online.exam.dao.PermissionDao;
|
||
|
|
import com.zhangmeng.online.exam.dao.RoleDao;
|
||
|
|
import com.zhangmeng.online.exam.dao.UserDao;
|
||
|
|
import com.zhangmeng.online.exam.dto.Result;
|
||
|
|
import com.zhangmeng.online.exam.entity.*;
|
||
|
|
import com.zhangmeng.online.exam.entity.User;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RestController;
|
||
|
|
|
||
|
|
import javax.persistence.EntityManager;
|
||
|
|
import javax.persistence.TypedQuery;
|
||
|
|
import java.util.*;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author zm
|
||
|
|
* @date 2025/3/5 15:45
|
||
|
|
* @version: 1.0
|
||
|
|
*/
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/user")
|
||
|
|
public class UserController {
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private UserDao userDao;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private RoleDao roleDao;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private PermissionDao permissionDao;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private EntityManager entityManager;
|
||
|
|
|
||
|
|
|
||
|
|
@GetMapping("/menu")
|
||
|
|
public Result menuList() {
|
||
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
||
|
|
|
||
|
|
TypedQuery<User> query = entityManager.createQuery("select obj from User obj where obj.id = 1", User.class);
|
||
|
|
User root = query.getResultList().get(0);
|
||
|
|
|
||
|
|
// Set<Role> roles = root.getRoles();
|
||
|
|
// for (Role role : roles) {
|
||
|
|
// Set<Permission> permissions = role.getPermissions();
|
||
|
|
// for (Permission permission : permissions) {
|
||
|
|
// if (permission.getParent() == null) {//一级菜单
|
||
|
|
// Map<String, Object> map = new HashMap<>();
|
||
|
|
// map.put("id", permission.getId());
|
||
|
|
// map.put("name", permission.getName());
|
||
|
|
// map.put("icon", permission.getIcon());
|
||
|
|
// map.put("url", permission.getUrl());
|
||
|
|
// map.put("description", permission.getDescription());
|
||
|
|
// map.put("sort", permission.getSort());
|
||
|
|
// map.put("children", new ArrayList<>());
|
||
|
|
// list.add(map);
|
||
|
|
// } else {
|
||
|
|
// if (list.isEmpty()) {
|
||
|
|
// continue;
|
||
|
|
// }
|
||
|
|
// for (Map<String, Object> map : list) {
|
||
|
|
// if (map.get("id").equals(permission.getParent().getId())) {
|
||
|
|
// List<Map<String, Object>> children = (List<Map<String, Object>>) map.get("children");
|
||
|
|
// Map<String, Object> childMap = new HashMap<>();
|
||
|
|
// childMap.put("id", permission.getId());
|
||
|
|
// childMap.put("name", permission.getName());
|
||
|
|
// childMap.put("icon", permission.getIcon());
|
||
|
|
// childMap.put("url", permission.getUrl());
|
||
|
|
// childMap.put("description", permission.getDescription());
|
||
|
|
// childMap.put("sort", permission.getSort());
|
||
|
|
// children.add(childMap);
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
return Result.success(list);
|
||
|
|
}
|
||
|
|
}
|