Commit ece29de7 authored by 赵啸非's avatar 赵啸非

菜单权限分配与角色分配

parent e6d847b7
...@@ -733,30 +733,30 @@ msg|String|消息|- ...@@ -733,30 +733,30 @@ msg|String|消息|-
} }
``` ```
## 角色用户关联 ## 角色用户
### 查询角色用户关联列表 ### 分配用户到角色
**请求URL:** role/user/list **请求URL:** role/user/assignRoleToUser
**请求方式:** POST **请求方式:** POST
**内容类型:** application/json;charset=utf-8 **内容类型:** application/json;charset=utf-8
**简要描述:** 查询角色用户关联 **简要描述:** 分配用户到角色
**请求参数:** **请求参数:**
参数名称|类型|必填|描述 参数名称|类型|必填|描述
:---|:---|:---|:------ :---|:---|:---|:------
page|Integer|否|当前页 userId|Long|是|用户ID
size|Integer|否|每页条数,值为-1,查询所有记录 roleIdList|Arrays|否|角色ID列表,值为long
**请求样例:** **请求样例:**
``` ```
{ {
"page":1, "userId":1,
"size":10 "roleIdList":[1,2]
} }
``` ```
...@@ -786,315 +786,51 @@ dict|object|字典对象 ...@@ -786,315 +786,51 @@ dict|object|字典对象
} }
``` ```
### 查看角色用户关联
**请求URL:** role/user/info
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 查看角色用户关联,返回实例详细信息
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
id|Long|是|ID
**请求样例:**
```
http://localhost/role/user/info?id=549
```
**响应参数:**
参数名称 |参数类型|描述
:---|:---|:-------
code|Integer|结果码(-1.失败,1.成功)
msg|String|消息
data|object|数据对象
 id|Long|序号,主键,自增长
 roleId|Long|角色ID
 userId|Long|用户ID
dict|object|字典对象
**响应消息样例:**
```
{
"code": 1,
"data": {
"id":5721,
"roleId":1782,
"userId":9790
}
}
```
### 保存更新角色用户关联
**请求URL:** role/user/save
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 保存或更新角色用户关联:id为空时为新增保存,否则为更新提交
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:-------
roleId|Long|是|角色ID
userId|Long|是|用户ID
**请求样例:**
```
{
"roleId":2572,
"userId":3424
}
```
**响应参数:**
参数名称 |参数类型|描述
:---|:---|:------
code|Integer|结果码(-1.失败,1.成功)
msg|String|消息
data|object|数据对象
 id|Long|保存后主键id
 entity|object|保存更新实体
  id|Long|序号,主键,自增长
  roleId|Long|角色ID
  userId|Long|用户ID
**响应消息样例:**
```
{
"msg":"新增模块成功",
"code":1,
"data":{}
}
}
```
### 删除角色用户关联
**请求URL:** role/user/delete
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 删除角色用户关联
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
id|String|是|数组
**请求样例:**
```
http://localhost:8080/role/user/delete?id=1&id=2'
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
**响应消息样例:**
```
{
"code":1,
"msg":"成功"
}
```
## 角色菜单权限关联 ## 角色菜单权限关联
### 查询角色菜单权限关联列表 ### 分配菜单到角色
**请求URL:** role/auth/list **请求URL:** role/auth/assignMenuToRole
**请求方式:** POST **请求方式:** POST
**内容类型:** application/json;charset=utf-8 **内容类型:** application/json;charset=utf-8
**简要描述:** 查询角色菜单权限关联 **简要描述:** 分配菜单到角色
**请求参数:** **请求参数:**
参数名称|类型|必填|描述 参数名称|类型|必填|描述
:---|:---|:---|:------ :---|:---|:---|:------
page|Integer|否|当前页
size|Integer|否|每页条数,值为-1,查询所有记录
**请求样例:**
```
{
"page":1,
"size":10
}
```
**响应参数:**
参数名称|参数类型|描述
:---|:---|:------
code|Integer|结果码(-1.失败,1.成功)
msg|String|消息
data|object|数据对象
 per_page|Integer|每页条数
 total|Integer|总条数
 last_page|Integer|总页数
 current_page|Integer|当前页
 data|array|结果集列表|数组
  id|Long|序号,主键,自增长
  roleId|Long|角色ID
  menuId|Long|菜单ID
dict|object|字典对象
**响应消息样例:**
```
{
"code":1,
"data":{
}
}
```
### 查看角色菜单权限关联
**请求URL:** role/auth/info
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 查看角色菜单权限关联,返回实例详细信息
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
id|Long|是|ID
**请求样例:**
```
http://localhost/role/auth/info?id=549
```
**响应参数:**
参数名称 |参数类型|描述
:---|:---|:-------
code|Integer|结果码(-1.失败,1.成功)
msg|String|消息
data|object|数据对象
 id|Long|序号,主键,自增长
 roleId|Long|角色ID
 menuId|Long|菜单ID
dict|object|字典对象
**响应消息样例:**
```
{
"code": 1,
"data": {
"id":3015,
"roleId":8288,
"menuId":5161
}
}
```
### 保存更新角色菜单权限关联
**请求URL:** role/auth/save
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 保存或更新角色菜单权限关联:id为空时为新增保存,否则为更新提交
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:-------
roleId|Long|是|角色ID roleId|Long|是|角色ID
menuId|Long|是|菜单ID menuIdList|Arrays|否|菜单ID列表,值为long
**请求样例:** **请求样例:**
``` ```
{ {
"roleId":3061, "roleId":2,
"menuId":7805 "menuIdList":[2]
} }
``` ```
**响应参数:** **响应参数:**
参数名称 |参数类型|描述 参数名称|参数类型|描述
:---|:---|:------ :---|:---|:------
code|Integer|结果码(-1.失败,1.成功) code|Integer|结果码(-1.失败,1.成功)
msg|String|消息 msg|String|消息
data|object|数据对象 data|object|数据对象
 id|Long|保存后主键id
 entity|object|保存更新实体
  id|Long|序号,主键,自增长
  roleId|Long|角色ID
  menuId|Long|菜单ID
**响应消息样例:** **响应消息样例:**
``` ```
{ {
"msg":"新增模块成功",
"code":1, "code":1,
"data":{} "data":{
} }
} }
```
### 删除角色菜单权限关联
**请求URL:** role/auth/delete
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 删除角色菜单权限关联
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
id|String|是|数组
**请求样例:**
``` ```
http://localhost:8080/role/auth/delete?id=1&id=2'
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
**响应消息样例:**
```
{
"code":1,
"msg":"成功"
}
```
## 菜单信息业务 ## 菜单信息业务
### 查询菜单信息业务列表 ### 查询菜单信息业务列表
...@@ -1113,6 +849,7 @@ msg|String|消息|- ...@@ -1113,6 +849,7 @@ msg|String|消息|-
:---|:---|:---|:------ :---|:---|:---|:------
page|Integer|否|当前页 page|Integer|否|当前页
size|Integer|否|每页条数,值为-1,查询所有记录 size|Integer|否|每页条数,值为-1,查询所有记录
parentId|Integer|否|通过父id查询子集
**请求样例:** **请求样例:**
``` ```
...@@ -1393,19 +1130,18 @@ createUserName|String|是|创建用户名称 ...@@ -1393,19 +1130,18 @@ createUserName|String|是|创建用户名称
**请求样例:** **请求样例:**
``` ```
{ {
"name":"et5j3o", "name":"测试菜单2",
"url":"v2m86a", "url":"",
"parentId":9580, "parentId":-1,
"linkType":5726, "linkType":0,
"imgPath":"o42z3k", "imgPath":"7mqw6a",
"buttonImgPath":"fo569j", "buttonImgPath":"vcr5tv",
"imgCommPath":"vvt1wp", "imgCommPath":"qnglei",
"visible":6295, "visible":1,
"menuType":1691, "menuType":0,
"status":6170, "status":1,
"authType":1321, "authType":3,
"orderId":5749, "orderId":0
"createUserName":"kjjdbc"
} }
``` ```
...@@ -1481,6 +1217,72 @@ msg|String|消息|- ...@@ -1481,6 +1217,72 @@ msg|String|消息|-
} }
``` ```
### 查询所有可用菜单
**请求URL:** menu/findAll
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 查询菜单信息业务
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
**请求样例:**
```
```
**响应参数:**
参数名称|参数类型|描述
:---|:---|:------
code|Integer|结果码(-1.失败,1.成功)
msg|String|消息
data|object|数据对象
 per_page|Integer|每页条数
 total|Integer|总条数
 last_page|Integer|总页数
 current_page|Integer|当前页
 data|array|结果集列表|数组
  id|Long|菜单ID,主键,自增长
  name|String|菜单名称
  url|String|连接地址
  parentId|Long|父菜单ID,一级菜单的该字段值为-1
  linkType|Integer|链接方式,(0.普通,1.弹出,2.脚本)
  imgPath|String|主菜单图标,主菜单图标的css样式名
  buttonImgPath|String|按钮图标
  imgCommPath|String|常用菜单图标
  visible|Integer|菜单显示(0.隐藏,1.显示)
  menuType|Integer|菜单类型(0.目录,1.菜单,2.按钮)
  status|Integer|菜单状态(0.禁用,1.启用)
  authType|Integer|权限类型(0.无限制,1.无需登录查看,2.需要登录查看,3.需要角色权限查看)
  orderId|Integer|排序编号
  firstLevel|String|一级菜单
  secondLevel|String|二级菜单
  thirdLevel|String|三级菜单
  createTime|Date|创建时间
  createUserId|Long|创建用户
  createUserName|String|创建用户名称
dict|object|字典对象
 linkType|object|字典属性对象,详见附录
 visible|object|字典属性对象,详见附录
 menuType|object|字典属性对象,详见附录
 status|object|字典属性对象,详见附录
 authType|object|字典属性对象,详见附录
**响应消息样例:**
```
{
"code":1,
"data":{}
}
```
## 上传文件业务 ## 上传文件业务
### 查询上传文件业务列表 ### 查询上传文件业务列表
......
...@@ -110,5 +110,24 @@ public class MenuController extends BaseCRUDJsonBodyMappingController<MenuServic ...@@ -110,5 +110,24 @@ public class MenuController extends BaseCRUDJsonBodyMappingController<MenuServic
return ret.toJSONString(); return ret.toJSONString();
} }
/**
* 查询所有可用菜单(树)
*/
@PostMapping(value = "findAll")
public String findAll() {
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
try {
List<MenuEntity> menuEntityList = this.service.findAllEnable();
ret.put(KEY_RESULT_DATA,menuEntityList);
} catch (Exception e) {
log.error("更新错误", e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, e.getMessage());
}
return ret.toJSONString();
}
} }
\ No newline at end of file
...@@ -15,7 +15,7 @@ import com.mortals.xhx.module.role.model.RoleAuthQuery; ...@@ -15,7 +15,7 @@ import com.mortals.xhx.module.role.model.RoleAuthQuery;
public interface RoleAuthService extends ICRUDService<RoleAuthEntity, Long> { public interface RoleAuthService extends ICRUDService<RoleAuthEntity, Long> {
/** /**
* 角色分配资源 * 角色分配菜单资源
*/ */
void doDistributionSource(RoleAuthQuery query); void assignMenu(RoleAuthQuery query);
} }
\ No newline at end of file
...@@ -12,7 +12,10 @@ import com.mortals.xhx.module.role.model.RoleUserQuery; ...@@ -12,7 +12,10 @@ import com.mortals.xhx.module.role.model.RoleUserQuery;
* @date 2022-05-25 * @date 2022-05-25
*/ */
public interface RoleUserService extends ICRUDService<RoleUserEntity,Long>{ public interface RoleUserService extends ICRUDService<RoleUserEntity,Long>{
void doDistributionUser(RoleUserQuery query);
void doDistributionRole(RoleUserQuery query); /**
* 给用户分配角色
* @param query
*/
void assignRoleToUser(RoleUserQuery query);
} }
\ No newline at end of file
...@@ -3,37 +3,57 @@ package com.mortals.xhx.module.role.service.impl; ...@@ -3,37 +3,57 @@ package com.mortals.xhx.module.role.service.impl;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.menu.model.MenuEntity;
import com.mortals.xhx.module.menu.model.MenuQuery;
import com.mortals.xhx.module.menu.service.MenuService;
import com.mortals.xhx.module.role.dao.RoleAuthDao; import com.mortals.xhx.module.role.dao.RoleAuthDao;
import com.mortals.xhx.module.role.model.RoleAuthEntity; import com.mortals.xhx.module.role.model.RoleAuthEntity;
import com.mortals.xhx.module.role.model.RoleAuthQuery; import com.mortals.xhx.module.role.model.RoleAuthQuery;
import com.mortals.xhx.module.role.service.RoleAuthService; import com.mortals.xhx.module.role.service.RoleAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap; import java.util.stream.Collectors;
import java.util.List;
import java.util.Map;
@Service("roleAuthService") @Service("roleAuthService")
public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, RoleAuthEntity, Long> implements RoleAuthService { public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, RoleAuthEntity, Long> implements RoleAuthService {
@Autowired
private MenuService menuService;
@Override @Override
public void doDistributionSource(RoleAuthQuery query) { public void assignMenu(RoleAuthQuery query) {
// 删除角色资源老数据 Map<Long, MenuEntity> menuEntityMap = menuService.find(new MenuQuery()).stream().collect(Collectors.toMap(x -> x.getId(), y -> y));
// 删除角色菜单资源老数据
Long roleId = query.getRoleId(); Long roleId = query.getRoleId();
Map<String, Object> condition = new HashMap<>(); Map<String, Object> condition = new HashMap<>();
condition.put("roleId", roleId); condition.put("roleId", roleId);
this.dao.delete(condition); this.dao.delete(condition);
List<RoleAuthEntity> list = new ArrayList<>(); Set<Long> curSet = query.getMenuIdList().stream().collect(Collectors.toSet());
// for (Long sourceId : query.getResourceIdList()) { query.getMenuIdList().stream().forEach(item -> {
// RoleAuthEntity entity = new RoleAuthEntity(); buildMenus(curSet, menuEntityMap.get(item), menuEntityMap);
// entity.setRoleId(roleId); });
// entity.setResourceId(sourceId); List<RoleAuthEntity> list = curSet.stream().map(item -> {
// list.add(entity); RoleAuthEntity entity = new RoleAuthEntity();
// } entity.setRoleId(roleId);
this.dao.insertBatch(list); entity.setMenuId(item);
return entity;
}).collect(Collectors.toList());
this.save(list);
}
private void buildMenus(Set<Long> curSet, MenuEntity menuEntity, Map<Long, MenuEntity> menuEntityMap) {
if (!ObjectUtils.isEmpty(menuEntity)) {
if (!curSet.contains(menuEntity.getId())) {
curSet.add(menuEntity.getId());
}
if (!ObjectUtils.isEmpty(menuEntity.getParentId())) {
buildMenus(curSet, menuEntityMap.get(menuEntity.getParentId()), menuEntityMap);
}
}
} }
} }
\ No newline at end of file
...@@ -25,31 +25,14 @@ import java.util.Map; ...@@ -25,31 +25,14 @@ import java.util.Map;
public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, RoleUserEntity,Long> implements RoleUserService { public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, RoleUserEntity,Long> implements RoleUserService {
@Override @Override
public void doDistributionUser(RoleUserQuery query) { public void assignRoleToUser(RoleUserQuery query) {
Long roleId = query.getRoleId(); //删除当前用户所有关联角色
// 删除角色对应的用户信息
Map<String, Object> condition = new HashMap<>(1);
condition.put("roleId", roleId);
dao.delete(condition);
List<Long> userIdList = query.getUserIdList();
List<RoleUserEntity> list = new ArrayList<>();
for (Long userId : userIdList) {
RoleUserEntity rolseUser = new RoleUserEntity();
rolseUser.setRoleId(roleId);
rolseUser.setUserId(userId);
list.add(rolseUser);
}
this.dao.insertBatch(list);
}
@Override
public void doDistributionRole(RoleUserQuery query) {
// 删除角色对应的用户信息
Long userId = query.getUserId(); Long userId = query.getUserId();
Map<String, Object> condition = new HashMap<>(1); Map<String, Object> condition = new HashMap<>(1);
condition.put("userId", userId); condition.put("userId", userId);
dao.delete(condition); dao.delete(condition);
//新增用户角色
List<Long> roleIdList = query.getRoleIdList(); List<Long> roleIdList = query.getRoleIdList();
List<RoleUserEntity> list = new ArrayList<>(); List<RoleUserEntity> list = new ArrayList<>();
for (Long roleId : roleIdList) { for (Long roleId : roleIdList) {
...@@ -58,7 +41,7 @@ public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, Ro ...@@ -58,7 +41,7 @@ public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, Ro
rolseUser.setUserId(userId); rolseUser.setUserId(userId);
list.add(rolseUser); list.add(rolseUser);
} }
this.dao.insertBatch(list); this.save(list);
} }
} }
\ No newline at end of file
...@@ -38,12 +38,12 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu ...@@ -38,12 +38,12 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu
} }
/** /**
* 分配菜单 * 分配菜单到角色
*/ */
@PostMapping(value = "distributionSource") @PostMapping(value = "assignMenuToRole")
public String distributionUser(@RequestBody RoleAuthQuery query) { public String assignMenuToRole(@RequestBody RoleAuthQuery query) {
try { try {
service.doDistributionSource(query); service.assignMenu(query);
JSONObject ret = new JSONObject(); JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS); ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString(); return ret.toJSONString();
......
...@@ -55,4 +55,24 @@ public class RoleUserController extends BaseCRUDJsonBodyMappingController<RoleUs ...@@ -55,4 +55,24 @@ public class RoleUserController extends BaseCRUDJsonBodyMappingController<RoleUs
} }
/**
* 给用户分配角色
*/
@PostMapping(value = "assignRoleToUser")
public String assignRoleToUser(@RequestBody RoleUserQuery query) {
JSONObject ret = new JSONObject();
try {
this.service.assignRoleToUser(query);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "分配角色成功!");
recordSysLog(request, getCurUser(), "分配角色成功!");
return ret.toJSONString();
} catch (Exception e) {
log.error("分配角色错误", e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
} }
\ No newline at end of file
...@@ -48,6 +48,4 @@ public class UserVo extends BaseEntityLong { ...@@ -48,6 +48,4 @@ public class UserVo extends BaseEntityLong {
/** 查询条件 */ /** 查询条件 */
private String query; private String query;
/** 角色id */
private Long roleId;
} }
\ No newline at end of file
...@@ -6,7 +6,8 @@ Content-Type: application/json ...@@ -6,7 +6,8 @@ Content-Type: application/json
{ {
"page":1, "page":1,
"size":10 "size":10,
"parentId":2
} }
...@@ -47,5 +48,9 @@ Authorization: {{authToken}} ...@@ -47,5 +48,9 @@ Authorization: {{authToken}}
Accept: application/json Accept: application/json
###菜单信息业务列表
POST {{baseUrl}}/menu/findAll
Authorization: {{authToken}}
Content-Type: application/json
...@@ -10,6 +10,17 @@ Content-Type: application/json ...@@ -10,6 +10,17 @@ Content-Type: application/json
} }
###分配菜单到角色
POST {{baseUrl}}/role/auth/assignMenuToRole
Authorization: {{authToken}}
Content-Type: application/json
{
"roleId":2,
"menuIdList":[2]
}
###角色菜单权限关联更新与保存 ###角色菜单权限关联更新与保存
POST {{baseUrl}}/role/auth/save POST {{baseUrl}}/role/auth/save
Authorization: {{authToken}} Authorization: {{authToken}}
......
...@@ -10,6 +10,17 @@ Content-Type: application/json ...@@ -10,6 +10,17 @@ Content-Type: application/json
} }
###分配用户到角色
POST {{baseUrl}}/role/user/assignRoleToUser
Authorization: {{authToken}}
Content-Type: application/json
{
"userId":1,
"roleIdList":[1,2]
}
###角色用户关联更新与保存 ###角色用户关联更新与保存
POST {{baseUrl}}/role/user/save POST {{baseUrl}}/role/user/save
Authorization: {{authToken}} Authorization: {{authToken}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment