Files
Yi.Admin/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs

120 lines
3.8 KiB
C#
Raw Normal View History

2021-10-26 00:59:06 +08:00
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
2021-10-13 23:08:42 +08:00
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
2021-10-31 17:18:57 +08:00
using System.IO;
2021-10-13 23:08:42 +08:00
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
2021-10-14 13:15:00 +08:00
using Yi.Framework.DTOModel;
2021-10-13 23:08:42 +08:00
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
2021-10-31 17:18:57 +08:00
using Yi.Framework.WebCore;
2021-10-13 23:08:42 +08:00
namespace Yi.Framework.ApiMicroservice.Controllers
{
2021-10-14 13:15:00 +08:00
[Route("api/[controller]/[action]")]
2021-10-13 23:08:42 +08:00
[ApiController]
2021-10-26 00:59:06 +08:00
[Authorize]
2021-10-13 23:08:42 +08:00
public class RoleController : ControllerBase
{
private IRoleService _roleService;
public RoleController(IRoleService roleService)
{
_roleService = roleService;
}
[HttpGet]
2021-10-14 13:15:00 +08:00
public async Task<Result> GetRole()
2021-10-31 17:18:57 +08:00
{
return Result.Success().SetData(await _roleService.GetAllEntitiesTrueAsync());
}
[HttpPost]
public async Task<IActionResult> GetRoleFlie()
2021-10-13 23:08:42 +08:00
{
2021-10-31 17:18:57 +08:00
var roleList = await _roleService.GetAllEntitiesTrueAsync();
Dictionary<string, string> dt = new();
dt.Add("输出", "文件");
var byteStream = Excel.ExportExcel(roleList.ToList(), dt).ToString();
MemoryStream s = new MemoryStream();
StreamWriter writer = new StreamWriter(s);
writer.Write(byteStream);
writer.Flush();
//stream.Read(byteStream, 0, byteStream.Length);
return new FileStreamResult(s, "application/vnd.ms-excel");
2021-10-13 23:08:42 +08:00
}
/// <summary>
/// 更
/// </summary>
/// <param name="_role"></param>
/// <returns></returns>
[HttpPut]
public async Task<Result> UpdateRole(role _role)
{
await _roleService.UpdateAsync(_role);
return Result.Success();
}
/// <summary>
/// 删
/// </summary>
/// <param name="_ids"></param>
/// <returns></returns>
[HttpDelete]
public async Task<Result> DelListRole(List<int> _ids)
{
await _roleService.DelListByUpdateAsync(_ids);
return Result.Success();
}
/// <summary>
/// 增
/// </summary>
/// <param name="_role"></param>
/// <returns></returns>
[HttpPost]
public async Task<Result> AddRole(role _role)
{
await _roleService.AddAsync(_role);
return Result.Success();
}
2021-10-14 13:15:00 +08:00
2021-10-29 23:23:32 +08:00
/// <summary>
/// 根据用户id得到该用户有哪些角色
/// 用于显示用户详情中的角色说明
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<Result> GetRolesByUserId(int userId)
{
return Result.Success().SetData(await _roleService.GetRolesByUserId(userId));
}
2021-10-14 13:15:00 +08:00
/// <summary>
/// 给角色设置菜单多个角色与多个菜单让每一个角色都设置ids1为角色ids2为菜单
2021-10-27 18:01:09 +08:00
/// 用于设置角色
2021-10-14 13:15:00 +08:00
/// </summary>
/// <param name="idsListDto"></param>
/// <returns></returns>
[HttpPost]
public async Task<Result> SetMenuByRole(IdsListDto<int> idsListDto)
2021-10-15 14:45:16 +08:00
{
2021-10-29 23:23:32 +08:00
await _roleService.SetMenusByRolesId(idsListDto.ids2, idsListDto.ids1);
return Result.Success();
2021-10-14 13:15:00 +08:00
}
2021-10-27 18:01:09 +08:00
/// <summary>
/// 用于给角色设置菜单的时候,点击一个角色,显示这个角色拥有的并列的菜单
/// </summary>
2021-10-31 17:18:57 +08:00
/// <param name="role"></param>
2021-10-27 18:01:09 +08:00
/// <returns></returns>
2021-10-19 18:30:56 +08:00
[HttpGet]
2021-10-31 17:18:57 +08:00
public async Task<Result> GetTopMenusByRoleId(role role)
2021-10-19 17:33:55 +08:00
{
2021-10-31 17:18:57 +08:00
return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(role.id) ); ;
2021-10-19 17:33:55 +08:00
}
2021-10-13 23:08:42 +08:00
}
}