DigitalFactory/Admin.NET/Admin.NET.Application/Service/SuppleInformation/SuppleInformationService.cs

111 lines
3.6 KiB
C#
Raw Normal View History

2024-03-20 02:37:36 +00:00
using Admin.NET.Core.Service;
using Admin.NET.Application.Const;
using Admin.NET.Application.Entity;
using Microsoft.AspNetCore.Http;
namespace Admin.NET.Application;
/// <summary>
/// 辅助资料服务
/// </summary>
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
public class SuppleInformationService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<SuppleInformation> _rep;
public SuppleInformationService(SqlSugarRepository<SuppleInformation> rep)
{
_rep = rep;
}
/// <summary>
/// 分页查询辅助资料
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task<SqlSugarPagedList<SuppleInformationOutput>> Page(SuppleInformationInput input)
{
2024-05-20 10:06:52 +00:00
var query = _rep.AsQueryable().Where(a => !a.IsDelete)
2024-03-20 02:37:36 +00:00
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
u.Name.Contains(input.SearchKey.Trim())
|| u.CodeNum.Contains(input.SearchKey.Trim())
|| u.Remarks.Contains(input.SearchKey.Trim())
)
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeNum), u => u.CodeNum.Contains(input.CodeNum.Trim()))
.WhereIF(input.Type>0, u => u.Type == input.Type)
.Select<SuppleInformationOutput>();
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
}
/// <summary>
/// 增加辅助资料
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Add")]
public async Task<long> Add(AddSuppleInformationInput input)
{
var entity = input.Adapt<SuppleInformation>();
await _rep.InsertAsync(entity);
return entity.Id;
}
/// <summary>
/// 删除辅助资料
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Delete")]
public async Task Delete(DeleteSuppleInformationInput input)
{
var entity = await _rep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
await _rep.FakeDeleteAsync(entity); //假删除
//await _rep.DeleteAsync(entity); //真删除
}
/// <summary>
/// 更新辅助资料
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Update")]
public async Task Update(UpdateSuppleInformationInput input)
{
var entity = input.Adapt<SuppleInformation>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
/// <summary>
/// 获取辅助资料
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task<SuppleInformation> Detail([FromQuery] QueryByIdSuppleInformationInput input)
{
return await _rep.GetFirstAsync(u => u.Id == input.Id);
}
/// <summary>
/// 获取辅助资料列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "List")]
public async Task<List<SuppleInformationOutput>> List()
{
2024-05-24 10:22:01 +00:00
return await _rep.AsQueryable().Where(a => !a.IsDelete).Select<SuppleInformationOutput>().ToListAsync();
2024-03-20 02:37:36 +00:00
}
}