Browse Source

feat:[系统管理] [角色管理] 按照原型进行界面调整

master
memorylkf 3 weeks ago
parent
commit
d2abbe4eba
7 changed files with 122 additions and 8 deletions
  1. +33
    -6
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java
  2. +34
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/form/RoleUserSaveForm.java
  3. +13
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/mapper/SysUserMapper.java
  4. +15
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/ISysUserService.java
  5. +11
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java
  6. +2
    -2
      hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysRoleMapper.xml
  7. +14
    -0
      hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysUserMapper.xml

+ 33
- 6
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysRoleController.java View File

@ -1,13 +1,17 @@
package com.hxhq.system.controller; package com.hxhq.system.controller;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.hxhq.system.domain.SysUserRole; import com.hxhq.system.domain.SysUserRole;
import com.hxhq.system.form.RoleUserSaveForm;
import com.hxhq.system.service.ISysDeptService; import com.hxhq.system.service.ISysDeptService;
import com.hxhq.system.service.ISysRoleService; import com.hxhq.system.service.ISysRoleService;
import com.hxhq.system.service.ISysUserService; import com.hxhq.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -91,7 +95,7 @@ public class SysRoleController extends BaseController
} }
else if (!roleService.checkRoleKeyUnique(role)) else if (!roleService.checkRoleKeyUnique(role))
{ {
return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
return error("新增角色'" + role.getRoleName() + "'失败,角色编码已存在");
} }
role.setCreateBy(SecurityUtils.getUsername()); role.setCreateBy(SecurityUtils.getUsername());
return toAjax(roleService.insertRole(role)); return toAjax(roleService.insertRole(role));
@ -114,7 +118,7 @@ public class SysRoleController extends BaseController
} }
else if (!roleService.checkRoleKeyUnique(role)) else if (!roleService.checkRoleKeyUnique(role))
{ {
return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
return error("修改角色'" + role.getRoleName() + "'失败,角色编码已存在");
} }
role.setUpdateBy(SecurityUtils.getUsername()); role.setUpdateBy(SecurityUtils.getUsername());
return toAjax(roleService.updateRole(role)); return toAjax(roleService.updateRole(role));
@ -172,11 +176,12 @@ public class SysRoleController extends BaseController
*/ */
@RequiresPermissions("system:role:list") @RequiresPermissions("system:role:list")
@GetMapping("/authUser/allocatedList") @GetMapping("/authUser/allocatedList")
public TableDataInfo allocatedList(SysUser user)
public AjaxResult allocatedList(Long roleId)
{ {
startPage();
List<SysUser> 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<Long> existsUserIds = userService.selectAllocatedListSimple(form.getRoleId());
List<Long> deleteIds = existsUserIds.stream().filter(o->!form.getUserIdList().contains(o)).collect(Collectors.toList());
List<Long> 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") @RequiresPermissions("system:role:query")

+ 34
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/form/RoleUserSaveForm.java View File

@ -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<Long> userIdList;
public Long getRoleId() {
return roleId;
}
public void setRoleId(Long roleId) {
this.roleId = roleId;
}
public List<Long> getUserIdList() {
return userIdList;
}
public void setUserIdList(List<Long> userIdList) {
this.userIdList = userIdList;
}
}

+ 13
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/mapper/SysUserMapper.java View File

@ -141,4 +141,17 @@ public interface SysUserMapper
* @return 结果 * @return 结果
*/ */
public SysUser checkEmailUnique(String email); public SysUser checkEmailUnique(String email);
/**
* 获取所有用户的简要信息
* @return
*/
List<SysUser> selectTransferAllList();
/**
* 获取角色已分配的用户id
* @param roleId
* @return
*/
List<Long> selectAllocatedListSimple(Long roleId);
} }

+ 15
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/ISysUserService.java View File

@ -1,6 +1,8 @@
package com.hxhq.system.service; package com.hxhq.system.service;
import java.util.List; import java.util.List;
import java.util.Map;
import com.hxhq.system.api.domain.SysUser; import com.hxhq.system.api.domain.SysUser;
/** /**
@ -211,4 +213,17 @@ public interface ISysUserService
* @return 结果 * @return 结果
*/ */
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName); public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
/**
* 获取角色下的用户id
* @param roleId
* @return
*/
List<Long> selectAllocatedListSimple(Long roleId);
/**
* 获取所有用户的简要信息
* @return
*/
List<SysUser> selectTransferAllList();
} }

+ 11
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java View File

@ -1,7 +1,9 @@
package com.hxhq.system.service.impl; package com.hxhq.system.service.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.validation.Validator; import javax.validation.Validator;
@ -562,4 +564,13 @@ public class SysUserServiceImpl implements ISysUserService
return successMsg.toString(); return successMsg.toString();
} }
@Override
public List<Long> selectAllocatedListSimple(Long roleId) {
return userMapper.selectAllocatedListSimple(roleId);
}
@Override
public List<SysUser> selectTransferAllList() {
return userMapper.selectTransferAllList();
}
} }

+ 2
- 2
hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysRoleMapper.xml View File

@ -32,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult"> <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult">
<include refid="selectRoleVo"/> <include refid="selectRoleVo"/>
where r.del_flag = '0'
where r.del_flag = '0' and r.role_id&lt;>1
<if test="roleId != null and roleId != 0"> <if test="roleId != null and roleId != 0">
AND r.role_id = #{roleId} AND r.role_id = #{roleId}
</if> </if>
@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
${params.dataScope} ${params.dataScope}
order by r.role_sort
order by r.role_id desc
</select> </select>
<select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult"> <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">

+ 14
- 0
hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysUserMapper.xml View File

@ -102,6 +102,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
${params.dataScope} ${params.dataScope}
</select> </select>
<select id="selectAllocatedListSimple" resultType="java.lang.Long">
select distinct u.user_id
from sys_user u
left join sys_user_role ur on u.user_id = ur.user_id
left join sys_role r on r.role_id = ur.role_id
where u.del_flag = '0' and u.user_id&lt;>1 and r.role_id = #{roleId}
</select>
<select id="selectTransferAllList" resultType="com.hxhq.system.api.domain.SysUser">
select u.user_id, u.user_name, u.nick_name, u.phonenumber
from sys_user u
where u.del_flag = '0' and u.user_id&lt;>1
</select>
<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult"> <select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time

Loading…
Cancel
Save