whycxzp
2020-12-18 e5c227d7992ca6171b998ed2b73b1f0cbaf1ccfe
src/main/java/com/whyc/controller/RoleController.java
@@ -1,21 +1,100 @@
package com.whyc.controller;
import com.whyc.pojo.*;
import com.whyc.service.RolePrivilegeService;
import com.whyc.service.RoleService;
import com.whyc.service.UserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@RequestMapping("role")
@RestController
@Slf4j
@Api(value ="role value",tags = "角色")
@Api(value ="role value",tags = "角色相关-用户,权限,菜单")
public class RoleController {
    @GetMapping
    @ApiOperation(value = "查询")
    public void get(){
    @Autowired
    private RoleService roleService;
    @Autowired
    private UserRoleService userRoleService;
    @Autowired
    private RolePrivilegeService rolePrivilegeService;
    @GetMapping("userWithNoRole")
    @ApiOperation(value = "查询未分配角色的用户")
    public List<User> getUserWithNoRole(){
        return userRoleService.getUserWithNoRole();
    }
    @GetMapping("userWithRole")
    @ApiOperation(value = "查询分配角色的用户")
    public List<UserRole> getUserWithRole(){
        return userRoleService.getUserWithRole();
    }
    @GetMapping("userWithRoleMap")
    @ApiOperation(value = "查询分配角色的用户Map")
    public Map<String,List<UserRole>> getUserWithRoleMap(){
        return userRoleService.getUserWithRoleMap();
    }
    @GetMapping("roleAll")
    @ApiOperation(value = "查询所有角色")
    public List<Role> getRoleAll(){
        return roleService.getAll();
    }
    @PostMapping
    @ApiOperation(value = "新增角色")
    public boolean add(@RequestBody Role role){
        return roleService.add(role);
    }
    @PostMapping("batch")
    @ApiOperation(value = "批量新增角色")
    public boolean addBatch(@RequestBody List<Role> roles){
        return roleService.addBatch(roles);
    }
    @PostMapping("bindingUserWithRole")
    @ApiOperation(value = "绑定用户和角色")
    public boolean bindingUserWithRole(@RequestParam int userId,int roleId){
        return userRoleService.bindingUserWithRole(userId,roleId);
    }
    @PostMapping("bindingUserWithRoleBatch")
    @ApiOperation(value = "批量绑定用户和角色",notes = "传入userId和roleId的数组")
    public boolean bindingUserWithRoleBatch(@RequestBody List<UserRole> userRoles){
        return userRoleService.bindingUserWithRoleBatch(userRoles);
    }
    @PostMapping("bindingRoleWithPrivilege")
    @ApiOperation(value = "绑定角色-权限")
    public boolean bindingRoleWithPrivilege(@RequestParam int roleId,int privilegeId){
        return rolePrivilegeService.bindingUserWithRole(roleId,privilegeId);
    }
    @PostMapping("bindingRoleWithPrivilegeBatch")
    @ApiOperation(value = "批量绑定角色-权限",notes = "传入roleId和privilegeId的数组")
    public boolean bindingRoleWithPrivilegeBatch(@RequestBody List<RolePrivilege> rolePrivileges){
        return rolePrivilegeService.bindingUserWithRoleBatch(rolePrivileges);
    }
    @GetMapping("privilege")
    @ApiOperation(value = "获取当前用户的权限")
    public List<Privilege> getPrivileges(HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("user");
        return rolePrivilegeService.getPrivileges(user.getId());
    }
}