DigitalFactory/Admin.NET/Admin.NET.Application/Service/Custom/CustonClassifyService.cs

107 lines
3.2 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 CustonClassifyService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<CustonClassify> _rep;
public CustonClassifyService(SqlSugarRepository<CustonClassify> rep)
{
_rep = rep;
}
/// <summary>
/// 分页查询客户分类
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task<SqlSugarPagedList<CustonClassifyOutput>> Page(CustonClassifyInput input)
{
var query = _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
u.Name.Contains(input.SearchKey.Trim())
)
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim()))
.Select<CustonClassifyOutput>();
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(AddCustonClassifyInput input)
{
var entity = input.Adapt<CustonClassify>();
await _rep.InsertAsync(entity);
return entity.Id;
}
/// <summary>
/// 删除客户分类
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Delete")]
public async Task Delete(DeleteCustonClassifyInput 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(UpdateCustonClassifyInput input)
{
var entity = input.Adapt<CustonClassify>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
/// <summary>
/// 获取客户分类
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task<CustonClassify> Detail([FromQuery] QueryByIdCustonClassifyInput 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<CustonClassifyOutput>> List()
{
return await _rep.AsQueryable().Select<CustonClassifyOutput>().ToListAsync();
}
}