From b772a961960f379377961fa8466994c7f82d1650 Mon Sep 17 00:00:00 2001 From: xuemingqiang Date: Sun, 13 Jul 2025 00:39:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=89=8D=E7=AB=AF=E7=9A=84?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E5=92=8C=E7=99=BB=E5=BD=95=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysRoleController.java | 72 +++++++------------ .../controller/system/SysUserController.java | 2 +- .../core/controller/BaseController.java | 20 +++--- .../ruoyi/common/core/domain/AjaxResult.java | 3 - ruoyi-ui/src/views/system/role/index.vue | 4 +- ruoyi-ui/src/views/system/user/index.vue | 14 ++-- 6 files changed, 46 insertions(+), 69 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 fae44e8a..59e5ac6d 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 @@ -35,13 +35,12 @@ import com.ruoyi.system.service.ISysUserService; /** * 角色信息 - * + * * @author ruoyi */ @RestController @RequestMapping("/system/role") -public class SysRoleController extends BaseController -{ +public class SysRoleController extends BaseController { @Autowired private ISysRoleService roleService; @@ -59,8 +58,7 @@ public class SysRoleController extends BaseController @PreAuthorize("@ss.hasPermi('system:role:list')") @GetMapping("/list") - public TableDataInfo list(SysRole role) - { + public TableDataInfo list(SysRole role) { startPage(); List list = roleService.selectRoleList(role); return getDataTable(list); @@ -69,8 +67,7 @@ public class SysRoleController extends BaseController @Log(title = "角色管理", businessType = BusinessType.EXPORT) @PreAuthorize("@ss.hasPermi('system:role:export')") @PostMapping("/export") - public void export(HttpServletResponse response, SysRole role) - { + public void export(HttpServletResponse response, SysRole role) { List list = roleService.selectRoleList(role); ExcelUtil util = new ExcelUtil(SysRole.class); util.exportExcel(response, list, "角色数据"); @@ -81,8 +78,7 @@ public class SysRoleController extends BaseController */ @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 success(roleService.selectRoleById(roleId)); } @@ -93,14 +89,10 @@ public class SysRoleController extends BaseController @PreAuthorize("@ss.hasPermi('system:role:add')") @Log(title = "角色管理", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@Validated @RequestBody SysRole role) - { - if (!roleService.checkRoleNameUnique(role)) - { + public AjaxResult add(@Validated @RequestBody SysRole role) { + if (!roleService.checkRoleNameUnique(role)) { return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在"); - } - else if (!roleService.checkRoleKeyUnique(role)) - { + } else if (!roleService.checkRoleKeyUnique(role)) { return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在"); } role.setCreateBy(getUsername()); @@ -114,26 +106,20 @@ public class SysRoleController extends BaseController @PreAuthorize("@ss.hasPermi('system:role:edit')") @Log(title = "角色管理", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@Validated @RequestBody SysRole role) - { + public AjaxResult edit(@Validated @RequestBody SysRole role) { roleService.checkRoleAllowed(role); roleService.checkRoleDataScope(role.getRoleId()); - if (!roleService.checkRoleNameUnique(role)) - { + if (!roleService.checkRoleNameUnique(role)) { return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在"); - } - else if (!roleService.checkRoleKeyUnique(role)) - { + } else if (!roleService.checkRoleKeyUnique(role)) { return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); } role.setUpdateBy(getUsername()); - - if (roleService.updateRole(role) > 0) - { + + if (roleService.updateRole(role) > 0) { // 更新缓存用户权限 LoginUser loginUser = getLoginUser(); - if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) - { + if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) { loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName())); loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); tokenService.setLoginUser(loginUser); @@ -149,8 +135,7 @@ public class SysRoleController extends BaseController @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 toAjax(roleService.authDataScope(role)); @@ -162,8 +147,7 @@ public class SysRoleController extends BaseController @PreAuthorize("@ss.hasPermi('system:role:edit')") @Log(title = "角色管理", businessType = BusinessType.UPDATE) @PutMapping("/changeStatus") - public AjaxResult changeStatus(@RequestBody SysRole role) - { + public AjaxResult changeStatus(@RequestBody SysRole role) { roleService.checkRoleAllowed(role); roleService.checkRoleDataScope(role.getRoleId()); role.setUpdateBy(getUsername()); @@ -176,8 +160,7 @@ public class SysRoleController extends BaseController @PreAuthorize("@ss.hasPermi('system:role:remove')") @Log(title = "角色管理", businessType = BusinessType.DELETE) @DeleteMapping("/{roleIds}") - public AjaxResult remove(@PathVariable Long[] roleIds) - { + public AjaxResult remove(@PathVariable Long[] roleIds) { return toAjax(roleService.deleteRoleByIds(roleIds)); } @@ -186,8 +169,7 @@ public class SysRoleController extends BaseController */ @PreAuthorize("@ss.hasPermi('system:role:query')") @GetMapping("/optionselect") - public AjaxResult optionselect() - { + public AjaxResult optionselect() { return success(roleService.selectRoleAll()); } @@ -196,8 +178,7 @@ public class SysRoleController extends BaseController */ @PreAuthorize("@ss.hasPermi('system:role:list')") @GetMapping("/authUser/allocatedList") - public TableDataInfo allocatedList(SysUser user) - { + public TableDataInfo allocatedList(SysUser user) { startPage(); List list = userService.selectAllocatedList(user); return getDataTable(list); @@ -208,8 +189,7 @@ public class SysRoleController extends BaseController */ @PreAuthorize("@ss.hasPermi('system:role:list')") @GetMapping("/authUser/unallocatedList") - public TableDataInfo unallocatedList(SysUser user) - { + public TableDataInfo unallocatedList(SysUser user) { startPage(); List list = userService.selectUnallocatedList(user); return getDataTable(list); @@ -221,8 +201,7 @@ public class SysRoleController extends BaseController @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 toAjax(roleService.deleteAuthUser(userRole)); } @@ -232,8 +211,7 @@ public class SysRoleController extends BaseController @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 toAjax(roleService.deleteAuthUsers(roleId, userIds)); } @@ -243,8 +221,7 @@ public class SysRoleController extends BaseController @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 toAjax(roleService.insertAuthUsers(roleId, userIds)); } @@ -254,8 +231,7 @@ public class SysRoleController extends BaseController */ @PreAuthorize("@ss.hasPermi('system:role:query')") @GetMapping(value = "/deptTree/{roleId}") - public AjaxResult deptTree(@PathVariable("roleId") Long roleId) - { + public AjaxResult deptTree(@PathVariable("roleId") Long roleId) { DeptTree deptTree = new DeptTree(); deptTree.setCheckedKeys(deptService.selectDeptListByRoleId(roleId)); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java index 3dafd32d..d5f913c7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java @@ -102,7 +102,7 @@ public class SysUserController extends BaseController * 根据用户编号获取详细信息 */ @PreAuthorize("@ss.hasPermi('system:user:query')") - @GetMapping(value = {"/{userId}" }) + @GetMapping(value = { "/", "/{userId}" }) public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) { diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java index c131bc47..455da769 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java @@ -26,7 +26,7 @@ import com.ruoyi.common.utils.sql.SqlUtil; * * @author ruoyi */ -public class BaseController +public class BaseController { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -80,7 +80,7 @@ public class BaseController * 响应请求分页数据 */ @SuppressWarnings({ "rawtypes", "unchecked" }) - protected TableDataInfo getDataTable(List list) + protected TableDataInfo getDataTable(List list) { TableDataInfo rspData = new TableDataInfo(); rspData.setCode(HttpStatus.SUCCESS); @@ -109,15 +109,15 @@ public class BaseController /** * 返回成功消息 */ - public AjaxResult success(String message) - { - return AjaxResult.success(message); - } +// public AjaxResult success(String message) +// { +// return AjaxResult.success(message); +// } /** * 返回成功消息 */ - public AjaxResult success(Object data) + public AjaxResult success(T data) { return AjaxResult.success(data); } @@ -125,7 +125,7 @@ public class BaseController /** * 返回失败消息 */ - public AjaxResult error(String message) + public AjaxResult error(String message) { return AjaxResult.error(message); } @@ -133,7 +133,7 @@ public class BaseController /** * 返回警告消息 */ - public AjaxResult warn(String message) + public AjaxResult warn(String message) { return AjaxResult.warn(message); } @@ -144,7 +144,7 @@ public class BaseController * @param rows 影响行数 * @return 操作结果 */ - protected AjaxResult toAjax(int rows) + protected AjaxResult toAjax(int rows) { return rows > 0 ? AjaxResult.success() : AjaxResult.error(); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java index 20d5f17e..c528e739 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java @@ -1,9 +1,6 @@ package com.ruoyi.common.core.domain; -import java.util.HashMap; -import java.util.Objects; import com.ruoyi.common.constant.HttpStatus; -import com.ruoyi.common.utils.StringUtils; /** * 操作消息提醒 diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue index 359890b6..070f66cc 100644 --- a/ruoyi-ui/src/views/system/role/index.vue +++ b/ruoyi-ui/src/views/system/role/index.vue @@ -382,14 +382,14 @@ export default { /** 根据角色ID查询菜单树结构 */ getRoleMenuTreeselect(roleId) { return roleMenuTreeselect(roleId).then(response => { - this.menuOptions = response.menus + this.menuOptions = response.data.menus return response }) }, /** 根据角色ID查询部门树结构 */ getDeptTree(roleId) { return deptTreeSelect(roleId).then(response => { - this.deptOptions = response.depts + this.deptOptions = response.data.depts return response }) }, diff --git a/ruoyi-ui/src/views/system/user/index.vue b/ruoyi-ui/src/views/system/user/index.vue index 2bc3b5ba..a87877bd 100644 --- a/ruoyi-ui/src/views/system/user/index.vue +++ b/ruoyi-ui/src/views/system/user/index.vue @@ -439,9 +439,12 @@ export default { /** 新增按钮操作 */ handleAdd() { this.reset() + console.log("userId:"+1111111) getUser().then(response => { - this.postOptions = response.posts - this.roleOptions = response.roles + console.log(response) + this.postOptions = response.data.posts + console.log(this.postOptions) + this.roleOptions = response.data.roles this.open = true this.title = "添加用户" this.form.password = this.initPassword @@ -451,10 +454,11 @@ export default { handleUpdate(row) { this.reset() const userId = row.userId || this.ids + console.log("userId:"+userId) getUser(userId).then(response => { - this.form = response.data - this.postOptions = response.posts - this.roleOptions = response.roles + this.form = response.data.user + this.postOptions = response.data.posts + this.roleOptions = response.data.roles this.$set(this.form, "postIds", response.postIds) this.$set(this.form, "roleIds", response.roleIds) this.open = true