| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.system.dto.SysRoleDTO; |
| | | import com.ruoyi.system.query.SysRoleQuery; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import com.ruoyi.system.vo.RoleInfoVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageDTO; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.BeanUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.SysPermissionService; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.domain.SysUserRole; |
| | | import com.ruoyi.system.dto.SysRoleDTO; |
| | | import com.ruoyi.system.query.SysRoleQuery; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import com.ruoyi.system.service.ISysRoleService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.vo.RoleInfoVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | /** |
| | | * 角色信息 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Api(tags = "角色信息") |
| | | @RestController |
| | | @RequestMapping("/system/role") |
| | | public class SysRoleController extends BaseController |
| | | { |
| | | public class SysRoleController extends BaseController { |
| | | |
| | | @Autowired |
| | | private ISysRoleService roleService; |
| | | |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:role:list')") |
| | | @ApiOperation(value = "角色列表") |
| | | @PostMapping("/list") |
| | | public AjaxResult list(@RequestBody SysRoleQuery query) |
| | | { |
| | | PageInfo<SysRole> list = roleService.selectList(query); |
| | | return AjaxResult.success(list); |
| | | public R<PageDTO<RoleInfoVO>> list(@RequestBody SysRoleQuery query) { |
| | | PageDTO<RoleInfoVO> sysRolePageDTO = roleService.selectList(query); |
| | | return R.ok(sysRolePageDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "角色列表不分页") |
| | | @PostMapping("/listNotPage") |
| | | public AjaxResult list() |
| | | { |
| | | public R<List<RoleInfoVO>> list() { |
| | | List<SysRole> list = roleService.selectRoleList(new SysRole()); |
| | | return AjaxResult.success(list); |
| | | List<RoleInfoVO> vos = BeanUtils.copyList(list, RoleInfoVO.class); |
| | | return R.ok(vos); |
| | | } |
| | | |
| | | @ApiOperation(value = "角色数量统计") |
| | | // @ApiOperation(value = "角色数量统计") |
| | | @PostMapping("/roleCount") |
| | | public AjaxResult roleCount() |
| | | { |
| | | public AjaxResult roleCount() { |
| | | int all = roleService.selectCount(null); |
| | | int normal = roleService.selectCount(0); |
| | | int stop = roleService.selectCount(1); |
| | | |
| | | Map<String,Integer> map = new HashMap<>(); |
| | | map.put("all",all); |
| | | map.put("normal",normal); |
| | | map.put("stop",stop); |
| | | Map<String, Integer> map = new HashMap<>(); |
| | | map.put("all", all); |
| | | map.put("normal", normal); |
| | | map.put("stop", stop); |
| | | return AjaxResult.success(map); |
| | | } |
| | | |
| | |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:role:query')") |
| | | @GetMapping(value = "/{roleId}") |
| | | public AjaxResult getInfo(@PathVariable Long roleId) |
| | | { |
| | | public AjaxResult getInfo(@PathVariable Long roleId) { |
| | | roleService.checkRoleDataScope(roleId); |
| | | return AjaxResult.success(roleService.selectRoleById(roleId)); |
| | | } |
| | |
| | | |
| | | @ApiOperation("角色详情") |
| | | @GetMapping("/roleInfo") |
| | | public AjaxResult roleInfo(@RequestParam Long roleId) |
| | | { |
| | | public R<RoleInfoVO> roleInfo(@RequestParam Long roleId) { |
| | | SysRole role = roleService.selectRoleById(roleId); |
| | | RoleInfoVO roleInfoVo = new RoleInfoVO(); |
| | | roleInfoVo.setRoleId(role.getRoleId()); |
| | |
| | | |
| | | // 获取当前角色的菜单列表 |
| | | List<SysMenu> menus = menuService.selectListByRoleId(roleId); |
| | | if(menus.size()==0){ |
| | | return AjaxResult.success(new ArrayList<>()); |
| | | if (menus.size() == 0) { |
| | | return R.ok(roleInfoVo); |
| | | } |
| | | List<Long> menusId = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList()); |
| | | |
| | |
| | | List<SysMenu> levelMenus = roleService.getMenuLevelList(menusId); |
| | | |
| | | roleInfoVo.setMenus(menusId); |
| | | return AjaxResult.success(roleInfoVo); |
| | | return R.ok(roleInfoVo); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("用户获取权限菜单") |
| | | @GetMapping("/roleInfoFromUserId") |
| | | public AjaxResult roleInfoFromUserId(@RequestParam Long userId) |
| | | { |
| | | public AjaxResult roleInfoFromUserId(@RequestParam Long userId) { |
| | | return AjaxResult.success(roleService.roleInfoFromUserId(userId)); |
| | | } |
| | | |
| | |
| | | @ApiOperation(value = "新增角色") |
| | | @Log(title = "角色信息-新增角色", businessType = BusinessType.INSERT) |
| | | @PostMapping("/add") |
| | | public AjaxResult add(@Validated @RequestBody SysRoleDTO dto) |
| | | { |
| | | Boolean flag= roleService.isExit(dto.getRoleId(),dto.getRoleName()); |
| | | if(flag){ |
| | | public AjaxResult add(@Validated @RequestBody SysRoleDTO dto) { |
| | | Boolean flag = roleService.isExit(dto.getRoleId(), dto.getRoleName()); |
| | | if (flag) { |
| | | return error("新增角色'" + dto.getRoleName() + "'失败,角色名称已存在"); |
| | | } |
| | | roleService.saveRole(dto); |
| | |
| | | @ApiOperation(value = "编辑角色") |
| | | @Log(title = "角色信息-编辑角色", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysRoleDTO dto) |
| | | { |
| | | Boolean flag= roleService.isExit(dto.getRoleId(),dto.getRoleName()); |
| | | if (flag){ |
| | | public AjaxResult edit(@Validated @RequestBody SysRoleDTO dto) { |
| | | Boolean flag = roleService.isExit(dto.getRoleId(), dto.getRoleName()); |
| | | if (flag) { |
| | | return error("修改角色'" + dto.getRoleName() + "'失败,角色名称已存在"); |
| | | } |
| | | if (roleService.editRole(dto) > 0) |
| | | { |
| | | if (roleService.editRole(dto) > 0) { |
| | | // 更新缓存用户权限 |
| | | LoginUser loginUser = getLoginUser(); |
| | | if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) |
| | | { |
| | | if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) { |
| | | loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); |
| | | loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName())); |
| | | loginUser.setUser( |
| | | userService.selectUserByUserName(loginUser.getUser().getUserName())); |
| | | tokenService.setLoginUser(loginUser); |
| | | } |
| | | return AjaxResult.success(); |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "角色管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/dataScope") |
| | | public AjaxResult dataScope(@RequestBody SysRole role) |
| | | { |
| | | public AjaxResult dataScope(@RequestBody SysRole role) { |
| | | roleService.checkRoleAllowed(role); |
| | | roleService.checkRoleDataScope(role.getRoleId()); |
| | | return AjaxResult.success(roleService.authDataScope(role)); |
| | |
| | | * 状态修改 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @ApiOperation(value = "状态修改") |
| | | // @ApiOperation(value = "状态修改") |
| | | @Log(title = "角色信息-角色状态修改", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody SysRole role) |
| | | { |
| | | public AjaxResult changeStatus(@RequestBody SysRole role) { |
| | | role.setUpdateBy(getUsername()); |
| | | roleService.updateStatus(role); |
| | | return AjaxResult.success(); |
| | |
| | | @ApiOperation(value = "删除角色") |
| | | @Log(title = "角色信息-角色删除角色", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/deleteById/{ids}") |
| | | public AjaxResult remove(@PathVariable String ids) |
| | | { |
| | | public AjaxResult remove(@PathVariable String ids) { |
| | | String[] split = ids.split(","); |
| | | List<Long> id = new ArrayList<>(); |
| | | for (String s : split) { |
| | |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:role:query')") |
| | | @GetMapping("/optionselect") |
| | | public AjaxResult optionselect() |
| | | { |
| | | public AjaxResult optionselect() { |
| | | return AjaxResult.success(roleService.selectRoleAll()); |
| | | } |
| | | |
| | |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:role:list')") |
| | | @GetMapping("/authUser/allocatedList") |
| | | public TableDataInfo allocatedList(SysUser user) |
| | | { |
| | | public TableDataInfo allocatedList(SysUser user) { |
| | | // startPage(); |
| | | List<SysUser> list = userService.selectAllocatedList(user); |
| | | return getDataTable(list); |
| | |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:role:list')") |
| | | @GetMapping("/authUser/unallocatedList") |
| | | public TableDataInfo unallocatedList(SysUser user) |
| | | { |
| | | public TableDataInfo unallocatedList(SysUser user) { |
| | | // startPage(); |
| | | List<SysUser> list = userService.selectUnallocatedList(user); |
| | | return getDataTable(list); |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "角色管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/cancel") |
| | | public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) |
| | | { |
| | | public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) { |
| | | return AjaxResult.success(roleService.deleteAuthUser(userRole)); |
| | | } |
| | | |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "角色管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/cancelAll") |
| | | public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) |
| | | { |
| | | public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) { |
| | | return AjaxResult.success(roleService.deleteAuthUsers(roleId, userIds)); |
| | | } |
| | | |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @Log(title = "角色管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/selectAll") |
| | | public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) |
| | | { |
| | | public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) { |
| | | roleService.checkRoleDataScope(roleId); |
| | | return AjaxResult.success(roleService.insertAuthUsers(roleId, userIds)); |
| | | } |
| | |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:role:query')") |
| | | @GetMapping(value = "/deptTree/{roleId}") |
| | | public AjaxResult deptTree(@PathVariable("roleId") Long roleId) |
| | | { |
| | | public AjaxResult deptTree(@PathVariable("roleId") Long roleId) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); |
| | | ajax.put("depts", deptService.selectDeptTreeList(new SysDept())); |