添加角色关联菜单功能
This commit is contained in:
@@ -254,6 +254,13 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.AddInfo(Yi.Framework.DTOModel.RoleInfoDto)">
|
||||
<summary>
|
||||
添加角色包含菜单
|
||||
</summary>
|
||||
<param name="roleDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.TestController">
|
||||
<summary>
|
||||
测试控制器
|
||||
|
||||
@@ -60,5 +60,17 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
return Result.Success().SetData(await _iRoleService.GetInMenuByRoleId(RoleId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色包含菜单
|
||||
/// </summary>
|
||||
/// <param name="roleDto"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPost]
|
||||
public async Task<Result> AddInfo(RoleInfoDto roleDto)
|
||||
{
|
||||
return Result.Success().SetData(await _iRoleService.AddInfo(roleDto));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
16
Yi.Framework.Net6/Yi.Framework.DTOModel/RoleInfoDto.cs
Normal file
16
Yi.Framework.Net6/Yi.Framework.DTOModel/RoleInfoDto.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class RoleInfoDto
|
||||
{
|
||||
public RoleEntity Role { get; set; }
|
||||
public List<long> DeptIds { get; set; }
|
||||
public List<long> MenuIds { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public UserEntity User { get; set; }
|
||||
public List<long> RoleIds { get; set; }
|
||||
public List<long> PostId { get; set; }
|
||||
public List<long> PostIds { get; set; }
|
||||
public long? DeptId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
@@ -36,5 +37,12 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
Task<PageModel<List<RoleEntity>>> SelctPageList(RoleEntity role, PageParModel page);
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色关联菜单
|
||||
/// </summary>
|
||||
/// <param name="roleDto"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> AddInfo(RoleInfoDto roleDto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
@@ -20,13 +22,13 @@ namespace Yi.Framework.Service
|
||||
var _repositoryRoleMenu= _repository.ChangeRepository<Repository<RoleMenuEntity>>();
|
||||
//多次操作,需要事务确保原子性
|
||||
return await _repositoryRoleMenu.UseTranAsync(async () =>
|
||||
{
|
||||
{ //删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||
await _repositoryRoleMenu.DeleteAsync(u => roleIds.Contains((long)u.RoleId) );
|
||||
|
||||
//遍历用户
|
||||
foreach (var roleId in roleIds)
|
||||
{
|
||||
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||
await _repositoryRoleMenu.DeleteAsync(u => u.RoleId==roleId);
|
||||
|
||||
|
||||
//添加新的关系
|
||||
List<RoleMenuEntity> roleMenuEntity = new();
|
||||
@@ -64,5 +66,14 @@ namespace Yi.Framework.Service
|
||||
|
||||
return new PageModel<List<RoleEntity>>(data, total);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<bool> AddInfo(RoleInfoDto roleDto)
|
||||
{
|
||||
var res1 = await _repository.InsertReturnSnowflakeIdAsync(roleDto.Role);
|
||||
var res2 = await GiveRoleSetMenu(new List<long> { res1 }, roleDto.MenuIds);
|
||||
return !0.Equals(res1) && res2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user