From d2abbe4eba6fbc435ba1d3b07b716df11fb1fbdf Mon Sep 17 00:00:00 2001 From: memorylkf <312904636@qq.com> Date: Fri, 19 Dec 2025 10:09:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:[=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86]=20[?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E7=AE=A1=E7=90=86]=20=E6=8C=89=E7=85=A7?= =?UTF-8?q?=E5=8E=9F=E5=9E=8B=E8=BF=9B=E8=A1=8C=E7=95=8C=E9=9D=A2=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hxhq/system/controller/SysRoleController.java | 39 ++++++++++++++++++---- .../com/hxhq/system/form/RoleUserSaveForm.java | 34 +++++++++++++++++++ .../java/com/hxhq/system/mapper/SysUserMapper.java | 13 ++++++++ .../com/hxhq/system/service/ISysUserService.java | 15 +++++++++ .../system/service/impl/SysUserServiceImpl.java | 11 ++++++ .../main/resources/mapper/system/SysRoleMapper.xml | 4 +-- .../main/resources/mapper/system/SysUserMapper.xml | 14 ++++++++ 7 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/form/RoleUserSaveForm.java diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java index d18d697..78c08d2 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java @@ -1,13 +1,17 @@ package com.hxhq.system.controller; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; import com.hxhq.system.domain.SysUserRole; +import com.hxhq.system.form.RoleUserSaveForm; import com.hxhq.system.service.ISysDeptService; import com.hxhq.system.service.ISysRoleService; import com.hxhq.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -91,7 +95,7 @@ public class SysRoleController extends BaseController } else if (!roleService.checkRoleKeyUnique(role)) { - return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在"); + return error("新增角色'" + role.getRoleName() + "'失败,角色编码已存在"); } role.setCreateBy(SecurityUtils.getUsername()); return toAjax(roleService.insertRole(role)); @@ -114,7 +118,7 @@ public class SysRoleController extends BaseController } else if (!roleService.checkRoleKeyUnique(role)) { - return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); + return error("修改角色'" + role.getRoleName() + "'失败,角色编码已存在"); } role.setUpdateBy(SecurityUtils.getUsername()); return toAjax(roleService.updateRole(role)); @@ -172,11 +176,12 @@ public class SysRoleController extends BaseController */ @RequiresPermissions("system:role:list") @GetMapping("/authUser/allocatedList") - public TableDataInfo allocatedList(SysUser user) + public AjaxResult allocatedList(Long roleId) { - startPage(); - List list = userService.selectAllocatedList(user); - return getDataTable(list); + AjaxResult ajax = AjaxResult.success(); + ajax.put("selected", userService.selectAllocatedListSimple(roleId)); + ajax.put("list", userService.selectTransferAllList()); + return ajax; } /** @@ -226,6 +231,28 @@ public class SysRoleController extends BaseController } /** + * 批量设置角色的用户 + */ + @RequiresPermissions("system:role:edit") + @Log(title = "角色管理", businessType = BusinessType.GRANT) + @PostMapping("/authUser/setAll") + @Transactional + public AjaxResult setAll(@RequestBody RoleUserSaveForm form) + { + List existsUserIds = userService.selectAllocatedListSimple(form.getRoleId()); + List deleteIds = existsUserIds.stream().filter(o->!form.getUserIdList().contains(o)).collect(Collectors.toList()); + List addList = form.getUserIdList().stream().filter(o->!existsUserIds.contains(o)).collect(Collectors.toList()); + if(deleteIds.size()>0){ + roleService.deleteAuthUsers(form.getRoleId(), deleteIds.toArray(new Long[0])); + } + if(addList.size()>0){ + roleService.insertAuthUsers(form.getRoleId(), addList.toArray(new Long[0])); + } + + return AjaxResult.success("操作成功"); + } + + /** * 获取对应角色部门树列表 */ @RequiresPermissions("system:role:query") diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/form/RoleUserSaveForm.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/form/RoleUserSaveForm.java new file mode 100644 index 0000000..042f7da --- /dev/null +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/form/RoleUserSaveForm.java @@ -0,0 +1,34 @@ +package com.hxhq.system.form; + +import java.util.List; + +/** + * @author memory + */ +public class RoleUserSaveForm { + + /** + * 角色id + */ + private Long roleId; + /** + * 用户id + */ + private List userIdList; + + public Long getRoleId() { + return roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + + public List getUserIdList() { + return userIdList; + } + + public void setUserIdList(List userIdList) { + this.userIdList = userIdList; + } +} diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/mapper/SysUserMapper.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/mapper/SysUserMapper.java index 8d8fcf0..d8210d6 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/mapper/SysUserMapper.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/mapper/SysUserMapper.java @@ -141,4 +141,17 @@ public interface SysUserMapper * @return 结果 */ public SysUser checkEmailUnique(String email); + + /** + * 获取所有用户的简要信息 + * @return + */ + List selectTransferAllList(); + + /** + * 获取角色已分配的用户id + * @param roleId + * @return + */ + List selectAllocatedListSimple(Long roleId); } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/ISysUserService.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/ISysUserService.java index 6c1eec2..ebf59b4 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/ISysUserService.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/ISysUserService.java @@ -1,6 +1,8 @@ package com.hxhq.system.service; import java.util.List; +import java.util.Map; + import com.hxhq.system.api.domain.SysUser; /** @@ -211,4 +213,17 @@ public interface ISysUserService * @return 结果 */ public String importUser(List userList, Boolean isUpdateSupport, String operName); + + /** + * 获取角色下的用户id + * @param roleId + * @return + */ + List selectAllocatedListSimple(Long roleId); + + /** + * 获取所有用户的简要信息 + * @return + */ + List selectTransferAllList(); } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java index 338918e..10481ed 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java @@ -1,7 +1,9 @@ package com.hxhq.system.service.impl; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import javax.validation.Validator; @@ -562,4 +564,13 @@ public class SysUserServiceImpl implements ISysUserService return successMsg.toString(); } + @Override + public List selectAllocatedListSimple(Long roleId) { + return userMapper.selectAllocatedListSimple(roleId); + } + + @Override + public List selectTransferAllList() { + return userMapper.selectTransferAllList(); + } } diff --git a/hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysRoleMapper.xml b/hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysRoleMapper.xml index 17062dd..839c008 100644 --- a/hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysRoleMapper.xml +++ b/hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysRoleMapper.xml @@ -32,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + +