You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.4 KiB
112 lines
3.4 KiB
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Znyc.Admin.AspNetCore.Controllers;
|
|
using Znyc.Admin.AspNetCore.Entitys;
|
|
using Znyc.Admin.AspNetCore.Mvc;
|
|
using Znyc.Admin.Commons.Entitys;
|
|
using Znyc.Admin.Commons.Pages;
|
|
using Znyc.Admin.Security.Dtos;
|
|
using Znyc.Admin.Security.Entitys;
|
|
using Znyc.Admin.Security.IServices;
|
|
|
|
namespace Znyc.Admin.WebApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 用户
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/Security/[controller]")]
|
|
public class UserController : AreaApiController<User, UserOutputDto, DcUserInPutDto, IUserService, long>
|
|
{
|
|
private readonly IUserService _userServices;
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
public UserController(
|
|
IUserService userServices
|
|
) : base(userServices)
|
|
{
|
|
_userServices = userServices;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增前处理数据
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
protected override void OnBeforeInsert(User info)
|
|
{
|
|
info.Id = 0;
|
|
info.CreatedTime = DateTime.Now;
|
|
info.CreatedUserId = CurrentUser.UserId;
|
|
info.IsDeleted = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在更新数据前对数据的修改操作
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns></returns>
|
|
protected override void OnBeforeUpdate(User info)
|
|
{
|
|
info.CreatedUserId = CurrentUser.UserId;
|
|
info.ModifiedUserId = CurrentUser.UserId;
|
|
info.ModifiedTime = DateTime.Now;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在软删除数据前对数据的修改操作
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns></returns>
|
|
protected override void OnBeforeSoftDelete(User info)
|
|
{
|
|
info.IsDeleted = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步分页查询
|
|
/// </summary>
|
|
/// <param name="search"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("FindWithPagerSearchAsync")]
|
|
[FunctionAuthorize("List")]
|
|
[AllowAnonymous]
|
|
public async Task<IActionResult> FindWithPagerSearchAsync(SearchUserModel search)
|
|
{
|
|
CommonResult<PageResult<UserOutputDto>> result = new CommonResult<PageResult<UserOutputDto>>
|
|
{
|
|
ResData = await _userServices.FindWithPagerSearchAsync(search),
|
|
ErrCode = ErrCode.successCode
|
|
};
|
|
return ToJsonContent(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改用户状态
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="status"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("UpdateStatusAsync")]
|
|
[FunctionAuthorize("")]
|
|
public async Task<IActionResult> UpdateStatusAsync(long id, int status)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
result = await _userServices.UpdateStatusAsync(id, status);
|
|
if (result.Success)
|
|
{
|
|
result.ErrCode = ErrCode.successCode;
|
|
result.ErrMsg = ErrCode.err0;
|
|
}
|
|
else
|
|
{
|
|
result.ErrMsg = ErrCode.err43002;
|
|
result.ErrCode = "43002";
|
|
}
|
|
return ToJsonContent(result);
|
|
}
|
|
}
|
|
}
|