Files
Yi.Admin/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs

72 lines
2.3 KiB
C#
Raw Normal View History

2021-10-17 18:37:07 +08:00
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
2021-10-11 21:50:50 +08:00
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
2022-04-26 01:31:14 +08:00
using Yi.Framework.DTOModel;
2021-10-11 21:50:50 +08:00
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
2022-04-06 18:05:00 +08:00
using Yi.Framework.Repository;
2021-10-13 16:44:15 +08:00
using Yi.Framework.WebCore;
2022-04-06 22:22:45 +08:00
using Yi.Framework.WebCore.AttributeExtend;
2022-01-11 16:40:15 +08:00
using Yi.Framework.WebCore.AuthorizationPolicy;
2021-10-11 21:50:50 +08:00
namespace Yi.Framework.ApiMicroservice.Controllers
{
2022-04-26 01:31:14 +08:00
/// <summary>
/// 用户管理
/// </summary>
2021-10-11 21:50:50 +08:00
[ApiController]
[Route("api/[controller]/[action]")]
2022-04-06 18:05:00 +08:00
public class UserController : BaseCrudController<UserEntity>
2021-10-11 21:50:50 +08:00
{
private IUserService _iUserService;
2022-04-06 18:05:00 +08:00
public UserController(ILogger<UserEntity> logger, IUserService iUserService) : base(logger, iUserService)
2021-10-11 21:50:50 +08:00
{
_iUserService = iUserService;
2021-10-11 21:50:50 +08:00
}
2022-04-26 01:31:14 +08:00
/// <summary>
/// 添加用户,去重,密码加密
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[Permission($"{nameof(UserEntity)}:add")]
[HttpPost]
public override async Task<Result> Add(UserEntity entity)
{
if (!await _iUserService.Exist(entity.UserName))
{
entity.BuildPassword();
return Result.Success().SetData(await _iUserService._repository.InsertReturnSnowflakeIdAsync(entity));
}
return Result.SuccessError("用户已存在");
}
2022-04-26 01:31:14 +08:00
/// <summary>
/// 给多用户设置多角色
/// </summary>
/// <param name="giveUserSetRoleDto"></param>
/// <returns></returns>
[HttpPut]
public async Task<Result> GiveUserSetRole(GiveUserSetRoleDto giveUserSetRoleDto)
{
return Result.Success().SetStatus(await _iUserService.GiveUserSetRole(giveUserSetRoleDto.UserIds, giveUserSetRoleDto.RoleIds));
}
/// <summary>
/// 通过用户id得到角色列表
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<Result> GetRoleListByUserId(long userId)
{
return Result.Success().SetData(await _iUserService.GetRoleListByUserId(userId));
2022-04-26 01:31:14 +08:00
}
2021-10-11 21:50:50 +08:00
}
}