|
|
@@ -1,22 +1,21 @@
|
|
|
package cn.reghao.autodop.dmaster.auth.controller;
|
|
|
|
|
|
-import cn.reghao.autodop.dmaster.auth.entity.po.GrantedAuthorityImpl;
|
|
|
+import cn.reghao.autodop.dmaster.auth.db.query.RoleQuery;
|
|
|
import cn.reghao.autodop.dmaster.auth.entity.po.Role;
|
|
|
import cn.reghao.autodop.dmaster.auth.entity.po.User;
|
|
|
-import cn.reghao.autodop.dmaster.auth.repository.RoleRepository;
|
|
|
-import cn.reghao.autodop.dmaster.auth.repository.UserRepository;
|
|
|
-import cn.reghao.autodop.dmaster.auth.service.RoleService;
|
|
|
+import cn.reghao.autodop.dmaster.auth.entity.vo.RoleVO;
|
|
|
import cn.reghao.autodop.dmaster.utils.db.PageList;
|
|
|
import cn.reghao.autodop.dmaster.utils.db.PageSort;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
@@ -26,61 +25,66 @@ import java.util.stream.Collectors;
|
|
|
@RequestMapping("/auth/role")
|
|
|
@Controller
|
|
|
public class RolePageController {
|
|
|
- private RoleService roleService;
|
|
|
- private UserRepository userRepository;
|
|
|
- private RoleRepository roleRepository;
|
|
|
+ private RoleQuery roleQuery;
|
|
|
|
|
|
- public RolePageController(RoleService roleService,
|
|
|
- UserRepository userRepository,
|
|
|
- RoleRepository roleRepository) {
|
|
|
- this.roleService = roleService;
|
|
|
- this.userRepository = userRepository;
|
|
|
- this.roleRepository = roleRepository;
|
|
|
+ public RolePageController(RoleQuery roleQuery) {
|
|
|
+ this.roleQuery = roleQuery;
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation("角色列表页面")
|
|
|
@GetMapping
|
|
|
- public String rolePage(Model model) {
|
|
|
- PageRequest pageRequest = PageSort.pageRequest();
|
|
|
- Page<Role> rolePage = roleRepository.findAll(pageRequest);
|
|
|
- PageList<Role> pageList = PageList.pageList(rolePage);
|
|
|
+ public String rolePage(@RequestParam(value = "name", required = false) String name, Model model) {
|
|
|
+ Page<RoleVO> page;
|
|
|
+ PageList<RoleVO> pageList;
|
|
|
+ if (name != null) {
|
|
|
+ List<RoleVO> list = roleQuery.queryByMatchName(name);
|
|
|
+ page = new PageImpl<>(list);
|
|
|
+ pageList = PageList.pageList(page);
|
|
|
+ } else {
|
|
|
+ PageRequest pageRequest = PageSort.pageRequest();
|
|
|
+ page = roleQuery.getRoleVOByPage(pageRequest);
|
|
|
+ pageList = PageList.pageList(page);
|
|
|
+ }
|
|
|
|
|
|
- model.addAttribute("page", rolePage);
|
|
|
+ model.addAttribute("page", page);
|
|
|
model.addAttribute("list", pageList.getList());
|
|
|
return "/auth/role/index";
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation("角色新增页面")
|
|
|
@GetMapping("/add")
|
|
|
public String addRolePage() {
|
|
|
return "/auth/role/add";
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation("角色编辑页面")
|
|
|
@GetMapping("/edit/{id}")
|
|
|
public String editRolePage(@PathVariable("id") int id, Model model) {
|
|
|
- Role role = roleService.findById(id);
|
|
|
- model.addAttribute("role", role);
|
|
|
+ RoleVO vo = roleQuery.getRoleVOById(id);
|
|
|
+ model.addAttribute("role", vo);
|
|
|
return "/auth/role/add";
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation("角色详细信息页面")
|
|
|
@GetMapping("/detail/{id}")
|
|
|
public String roleDetailPage(@PathVariable("id") int id, Model model) {
|
|
|
- Role role = roleService.findById(id);
|
|
|
- model.addAttribute("role", role);
|
|
|
+ RoleVO vo = roleQuery.getRoleVOById(id);
|
|
|
+ model.addAttribute("role", vo);
|
|
|
return "/auth/role/detail";
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/auth")
|
|
|
- public String authPage(@RequestParam(value = "ids") Long id, Model model){
|
|
|
+ @ApiOperation("设置角色可访问的资源页面")
|
|
|
+ @GetMapping("/menus/{id}")
|
|
|
+ public String menusPage(@PathVariable(value = "id") Integer id, Model model){
|
|
|
model.addAttribute("id", id);
|
|
|
- return "/auth/role/auth";
|
|
|
+ return "/auth/role/menus";
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/resource/{id}")
|
|
|
- public String userListWithRole(@PathVariable("id") Role role, Model model) {
|
|
|
- List<User> list = userRepository.findAll().stream()
|
|
|
- .filter(user -> user.getAuthorities().contains(new GrantedAuthorityImpl(role.getTitle())))
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
+ @ApiOperation("拥有角色的所有用户页面")
|
|
|
+ @GetMapping("/users/{id}")
|
|
|
+ public String userListWithRole(@PathVariable("id") Integer roleId, Model model) {
|
|
|
+ List<User> list = roleQuery.getUsersByRoleId(roleId);
|
|
|
model.addAttribute("list", list);
|
|
|
- return "/auth/role/resource";
|
|
|
+ return "/auth/role/users";
|
|
|
}
|
|
|
}
|