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.
 
 

178 lines
5.9 KiB

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