From 695cb6d76b838b1e4cb161bae335faa948dca12a Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 27 十月 2021 13:16:19 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into satoken --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java | 442 +++++++++++++++++++++++++----------------------------- 1 files changed, 203 insertions(+), 239 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java index 2870f66..f1d7e77 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java @@ -1,239 +1,203 @@ -package com.ruoyi.web.controller.system; - -import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -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.RestController; -import com.ruoyi.common.annotation.Log; -import com.ruoyi.common.constant.UserConstants; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.AjaxResult; -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.StringUtils; -import com.ruoyi.common.utils.poi.ExcelUtil; -import com.ruoyi.framework.web.service.SysPermissionService; -import com.ruoyi.framework.web.service.TokenService; -import com.ruoyi.system.domain.SysUserRole; -import com.ruoyi.system.service.ISysRoleService; -import com.ruoyi.system.service.ISysUserService; - -/** - * 瑙掕壊淇℃伅 - * - * @author ruoyi - */ -@RestController -@RequestMapping("/system/role") -public class SysRoleController extends BaseController -{ - @Autowired - private ISysRoleService roleService; - - @Autowired - private TokenService tokenService; - - @Autowired - private SysPermissionService permissionService; - - @Autowired - private ISysUserService userService; - - @PreAuthorize("@ss.hasPermi('system:role:list')") - @GetMapping("/list") - public TableDataInfo list(SysRole role) - { - startPage(); - List<SysRole> list = roleService.selectRoleList(role); - return getDataTable(list); - } - - @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.EXPORT) - @PreAuthorize("@ss.hasPermi('system:role:export')") - @GetMapping("/export") - public AjaxResult export(SysRole role) - { - List<SysRole> list = roleService.selectRoleList(role); - ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class); - return util.exportExcel(list, "瑙掕壊鏁版嵁"); - } - - /** - * 鏍规嵁瑙掕壊缂栧彿鑾峰彇璇︾粏淇℃伅 - */ - @PreAuthorize("@ss.hasPermi('system:role:query')") - @GetMapping(value = "/{roleId}") - public AjaxResult getInfo(@PathVariable Long roleId) - { - return AjaxResult.success(roleService.selectRoleById(roleId)); - } - - /** - * 鏂板瑙掕壊 - */ - @PreAuthorize("@ss.hasPermi('system:role:add')") - @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.INSERT) - @PostMapping - public AjaxResult add(@Validated @RequestBody SysRole role) - { - if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) - { - return AjaxResult.error("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹插悕绉板凡瀛樺湪"); - } - else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) - { - return AjaxResult.error("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪"); - } - role.setCreateBy(getUsername()); - return toAjax(roleService.insertRole(role)); - - } - - /** - * 淇敼淇濆瓨瑙掕壊 - */ - @PreAuthorize("@ss.hasPermi('system:role:edit')") - @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE) - @PutMapping - public AjaxResult edit(@Validated @RequestBody SysRole role) - { - roleService.checkRoleAllowed(role); - if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) - { - return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹插悕绉板凡瀛樺湪"); - } - else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) - { - return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪"); - } - role.setUpdateBy(getUsername()); - - if (roleService.updateRole(role) > 0) - { - // 鏇存柊缂撳瓨鐢ㄦ埛鏉冮檺 - LoginUser loginUser = getLoginUser(); - if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) - { - loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); - loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName())); - tokenService.setLoginUser(loginUser); - } - return AjaxResult.success(); - } - return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑱旂郴绠$悊鍛�"); - } - - /** - * 淇敼淇濆瓨鏁版嵁鏉冮檺 - */ - @PreAuthorize("@ss.hasPermi('system:role:edit')") - @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE) - @PutMapping("/dataScope") - public AjaxResult dataScope(@RequestBody SysRole role) - { - roleService.checkRoleAllowed(role); - return toAjax(roleService.authDataScope(role)); - } - - /** - * 鐘舵�佷慨鏀� - */ - @PreAuthorize("@ss.hasPermi('system:role:edit')") - @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE) - @PutMapping("/changeStatus") - public AjaxResult changeStatus(@RequestBody SysRole role) - { - roleService.checkRoleAllowed(role); - role.setUpdateBy(getUsername()); - return toAjax(roleService.updateRoleStatus(role)); - } - - /** - * 鍒犻櫎瑙掕壊 - */ - @PreAuthorize("@ss.hasPermi('system:role:remove')") - @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.DELETE) - @DeleteMapping("/{roleIds}") - public AjaxResult remove(@PathVariable Long[] roleIds) - { - return toAjax(roleService.deleteRoleByIds(roleIds)); - } - - /** - * 鑾峰彇瑙掕壊閫夋嫨妗嗗垪琛� - */ - @PreAuthorize("@ss.hasPermi('system:role:query')") - @GetMapping("/optionselect") - public AjaxResult optionselect() - { - return AjaxResult.success(roleService.selectRoleAll()); - } - - /** - * 鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛� - */ - @PreAuthorize("@ss.hasPermi('system:role:list')") - @GetMapping("/authUser/allocatedList") - 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) - { - 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) - { - return toAjax(roleService.deleteAuthUser(userRole)); - } - - /** - * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛 - */ - @PreAuthorize("@ss.hasPermi('system:role:edit')") - @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT) - @PutMapping("/authUser/cancelAll") - public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) - { - return toAjax(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) - { - return toAjax(roleService.insertAuthUsers(roleId, userIds)); - } -} +package com.ruoyi.web.controller.system; + +import cn.dev33.satoken.annotation.SaCheckPermission; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysRole; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.domain.SysUserRole; +import com.ruoyi.system.service.ISysRoleService; +import com.ruoyi.system.service.ISysUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 瑙掕壊淇℃伅 + * + * @author Lion Li + */ +@Validated +@Api(value = "瑙掕壊淇℃伅鎺у埗鍣�", tags = {"瑙掕壊淇℃伅绠$悊"}) +@RequiredArgsConstructor(onConstructor_ = @Autowired) +@RestController +@RequestMapping("/system/role") +public class SysRoleController extends BaseController { + + private final ISysRoleService roleService; + private final ISysUserService userService; + + @ApiOperation("鏌ヨ瑙掕壊淇℃伅鍒楄〃") + @SaCheckPermission("system:role:list") + @GetMapping("/list") + public TableDataInfo<SysRole> list(SysRole role) { + return roleService.selectPageRoleList(role); + } + + @ApiOperation("瀵煎嚭瑙掕壊淇℃伅鍒楄〃") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.EXPORT) + @SaCheckPermission("system:role:export") + @GetMapping("/export") + public void export(SysRole role, HttpServletResponse response) { + List<SysRole> list = roleService.selectRoleList(role); + ExcelUtil.exportExcel(list, "瑙掕壊鏁版嵁", SysRole.class, response); + } + + /** + * 鏍规嵁瑙掕壊缂栧彿鑾峰彇璇︾粏淇℃伅 + */ + @ApiOperation("鏍规嵁瑙掕壊缂栧彿鑾峰彇璇︾粏淇℃伅") + @SaCheckPermission("system:role:query") + @GetMapping(value = "/{roleId}") + public AjaxResult<SysRole> getInfo(@PathVariable Long roleId) { + roleService.checkRoleDataScope(roleId); + return AjaxResult.success(roleService.selectRoleById(roleId)); + } + + /** + * 鏂板瑙掕壊 + */ + @ApiOperation("鏂板瑙掕壊") + @SaCheckPermission("system:role:add") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult<Void> add(@Validated @RequestBody SysRole role) { + if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) { + return AjaxResult.error("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹插悕绉板凡瀛樺湪"); + } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) { + return AjaxResult.error("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪"); + } + return toAjax(roleService.insertRole(role)); + + } + + /** + * 淇敼淇濆瓨瑙掕壊 + */ + @ApiOperation("淇敼淇濆瓨瑙掕壊") + @SaCheckPermission("system:role:edit") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult<Void> edit(@Validated @RequestBody SysRole role) { + roleService.checkRoleAllowed(role); + if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) { + return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹插悕绉板凡瀛樺湪"); + } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) { + return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪"); + } + + if (roleService.updateRole(role) > 0) { + return AjaxResult.success(); + } + return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑱旂郴绠$悊鍛�"); + } + + /** + * 淇敼淇濆瓨鏁版嵁鏉冮檺 + */ + @ApiOperation("淇敼淇濆瓨鏁版嵁鏉冮檺") + @SaCheckPermission("system:role:edit") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE) + @PutMapping("/dataScope") + public AjaxResult<Void> dataScope(@RequestBody SysRole role) { + roleService.checkRoleAllowed(role); + return toAjax(roleService.authDataScope(role)); + } + + /** + * 鐘舵�佷慨鏀� + */ + @ApiOperation("鐘舵�佷慨鏀�") + @SaCheckPermission("system:role:edit") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE) + @PutMapping("/changeStatus") + public AjaxResult<Void> changeStatus(@RequestBody SysRole role) { + roleService.checkRoleAllowed(role); + return toAjax(roleService.updateRoleStatus(role)); + } + + /** + * 鍒犻櫎瑙掕壊 + */ + @ApiOperation("鍒犻櫎瑙掕壊") + @SaCheckPermission("system:role:remove") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.DELETE) + @DeleteMapping("/{roleIds}") + public AjaxResult<Void> remove(@PathVariable Long[] roleIds) { + return toAjax(roleService.deleteRoleByIds(roleIds)); + } + + /** + * 鑾峰彇瑙掕壊閫夋嫨妗嗗垪琛� + */ + @ApiOperation("鑾峰彇瑙掕壊閫夋嫨妗嗗垪琛�") + @SaCheckPermission("system:role:query") + @GetMapping("/optionselect") + public AjaxResult<List<SysRole>> optionselect() { + return AjaxResult.success(roleService.selectRoleAll()); + } + + /** + * 鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛� + */ + @ApiOperation("鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛�") + @SaCheckPermission("system:role:list") + @GetMapping("/authUser/allocatedList") + public TableDataInfo<SysUser> allocatedList(SysUser user) { + return userService.selectAllocatedList(user); + } + + /** + * 鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛� + */ + @ApiOperation("鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛�") + @SaCheckPermission("system:role:list") + @GetMapping("/authUser/unallocatedList") + public TableDataInfo<SysUser> unallocatedList(SysUser user) { + return userService.selectUnallocatedList(user); + } + + /** + * 鍙栨秷鎺堟潈鐢ㄦ埛 + */ + @ApiOperation("鍙栨秷鎺堟潈鐢ㄦ埛") + @SaCheckPermission("system:role:edit") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT) + @PutMapping("/authUser/cancel") + public AjaxResult<Void> cancelAuthUser(@RequestBody SysUserRole userRole) { + return toAjax(roleService.deleteAuthUser(userRole)); + } + + /** + * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛 + */ + @ApiOperation("鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛") + @SaCheckPermission("system:role:edit") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT) + @PutMapping("/authUser/cancelAll") + public AjaxResult<Void> cancelAuthUserAll(Long roleId, Long[] userIds) { + return toAjax(roleService.deleteAuthUsers(roleId, userIds)); + } + + /** + * 鎵归噺閫夋嫨鐢ㄦ埛鎺堟潈 + */ + @ApiOperation("鎵归噺閫夋嫨鐢ㄦ埛鎺堟潈") + @SaCheckPermission("system:role:edit") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT) + @PutMapping("/authUser/selectAll") + public AjaxResult<Void> selectAuthUserAll(Long roleId, Long[] userIds) { + return toAjax(roleService.insertAuthUsers(roleId, userIds)); + } +} -- Gitblit v1.9.3