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.

98 lines
3.1 KiB

using GDZZ.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using GDZZ.Application.Entity;
namespace GDZZ.Application
{
/// <summary>
/// 基础用户服务
/// </summary>
[ApiDescriptionSettings("Application",Name = "BaseUser", Order = 1)]
public class BaseUserService : IBaseUserService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<BaseUser> _rep;
public BaseUserService(SqlSugarRepository<BaseUser> rep)
{
_rep = rep;
}
/// <summary>
/// 分页查询基础用户
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/BaseUser/page")]
public async Task<dynamic> Page([FromQuery] BaseUserInput input)
{
var entities = await _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.UserName), u => u.UserName.Contains(input.UserName.Trim()))
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
/// <summary>
/// 增加基础用户
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BaseUser/add")]
public async Task Add(AddBaseUserInput input)
{
var entity = input.Adapt<BaseUser>();
await _rep.InsertAsync(entity);
}
/// <summary>
/// 删除基础用户
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BaseUser/delete")]
public async Task Delete(DeleteBaseUserInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
/// <summary>
/// 更新基础用户
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BaseUser/edit")]
public async Task Update(UpdateBaseUserInput input)
{
var entity = input.Adapt<BaseUser>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommandAsync();
}
/// <summary>
/// 获取基础用户
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/BaseUser/detail")]
public async Task<BaseUser> Get([FromQuery] QueryeBaseUserInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
/// <summary>
/// 获取基础用户列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/BaseUser/list")]
public async Task<dynamic> List([FromQuery] BaseUserInput input)
{
return await _rep.ToListAsync();
}
}
}