using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; using Znyc.Recruitment.Admin.AspNetCore.Controllers; using Znyc.Recruitment.Admin.AspNetCore.Entitys; using Znyc.Recruitment.Admin.AspNetCore.Mvc; using Znyc.Recruitment.Admin.AspNetCore.Mvc.Filter; using Znyc.Recruitment.Admin.Commons.Entitys; using Znyc.Recruitment.Admin.Commons.Pages; using Znyc.Recruitment.Admin.Security.Dtos; using Znyc.Recruitment.Admin.Security.Entitys; using Znyc.Recruitment.Admin.Security.IServices; namespace Znyc.Recruitment.Admin.WebApi.Controllers { /// /// 用户接口 /// [ApiController] [AllowAnonymous] [NoPermissionRequired] [Route("api/Security/[controller]")] public class UserController : AreaApiController { private readonly IOrganizeService organizeService; private readonly IRoleService roleService; private readonly IAdminUserLogOnService userLogOnService; /// /// /// /// /// /// public UserController(IUserService service, IOrganizeService _organizeService, IRoleService _roleService, IAdminUserLogOnService _userLogOnService) : base(service) { _service = service; organizeService = _organizeService; roleService = _roleService; userLogOnService = _userLogOnService; } /// /// 新增前处理数据 /// /// protected override void OnBeforeInsert(UserEntity info) { info.Id = 0; info.CreatedTime = DateTime.Now; info.CreatedUserId = new AdminCurrentUser().UserId; info.IsDeleted = false; } /// /// 在更新数据前对数据的修改操作 /// /// /// protected override void OnBeforeUpdate(UserEntity info) { info.ModifiedUserId = new AdminCurrentUser().UserId; info.ModifiedTime = DateTime.Now; } /// /// 在软删除数据前对数据的修改操作 /// /// /// protected override void OnBeforeSoftDelete(UserEntity info) { info.IsDeleted = true; } /// /// 异步更新数据 /// /// /// [HttpPost("UpdateAsync")] [FunctionAuthorize("Edit")] public async Task UpdateAsync(UserInputDto tinfo) { CommonResult result = new CommonResult(); UserEntity info = _service.Get(tinfo.Id); info.UserName = tinfo.UserName; info.AvatarUrl = tinfo.AvatarUrl; info.Phone = tinfo.Phone; OnBeforeUpdate(info); bool bl = await _service.UpdateAsync(info, tinfo.Id).ConfigureAwait(false); if (bl) { result.ErrCode = ErrCode.successCode; result.ErrMsg = ErrCode.err0; } else { result.ErrMsg = ErrCode.err43002; result.ErrCode = "43002"; } return ToJsonContent(result); } /// /// 异步禁用/启用用户 /// /// /// 1-启用/99-禁用 /// [HttpPost("UpdateStatusAsync")] [FunctionAuthorize("Edit")] public async Task UpdateStatusAsync(int id, int status) { CommonResult result = new CommonResult(); result = await _service.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); } /// /// 异步分页查询 /// /// /// [HttpPost("FindWithPagerSearchAsync")] [FunctionAuthorize("List")] public async Task FindWithPagerSearchAsync(SearchUserModel search) { CommonResult> result = new CommonResult> { ResData = await _service.FindWithPagerSearchAsync(search), ErrCode = ErrCode.successCode }; return ToJsonContent(result); } } }