117 lines
3.8 KiB
C#
117 lines
3.8 KiB
C#
|
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 CustomService : IDynamicApiController, ITransient
|
|||
|
{
|
|||
|
private readonly SqlSugarRepository<Custom> _rep;
|
|||
|
public CustomService(SqlSugarRepository<Custom> rep)
|
|||
|
{
|
|||
|
_rep = rep;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分页查询客户
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
[ApiDescriptionSettings(Name = "Page")]
|
|||
|
public async Task<SqlSugarPagedList<CustomOutput>> Page(CustomInput input)
|
|||
|
{
|
|||
|
var query = _rep.AsQueryable()
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|||
|
u.Name.Contains(input.SearchKey.Trim())
|
|||
|
|| u.CodeNum.Contains(input.SearchKey.Trim())
|
|||
|
|| u.Brand.Contains(input.SearchKey.Trim())
|
|||
|
|| u.ExternalNumber.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.Classify>0, u => u.Classify == input.Classify)
|
|||
|
.WhereIF(input.Age>0, u => u.Age == input.Age)
|
|||
|
.WhereIF(input.ExpandField>0, u => u.ExpandField == input.ExpandField)
|
|||
|
.WhereIF(input.Contacts>0, u => u.Contacts == input.Contacts)
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Brand), u => u.Brand.Contains(input.Brand.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ExternalNumber), u => u.ExternalNumber.Contains(input.ExternalNumber.Trim()))
|
|||
|
.Select<CustomOutput>();
|
|||
|
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(AddCustomInput input)
|
|||
|
{
|
|||
|
var entity = input.Adapt<Custom>();
|
|||
|
await _rep.InsertAsync(entity);
|
|||
|
return entity.Id;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 删除客户
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
[ApiDescriptionSettings(Name = "Delete")]
|
|||
|
public async Task Delete(DeleteCustomInput 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(UpdateCustomInput input)
|
|||
|
{
|
|||
|
var entity = input.Adapt<Custom>();
|
|||
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取客户
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
[ApiDescriptionSettings(Name = "Detail")]
|
|||
|
public async Task<Custom> Detail([FromQuery] QueryByIdCustomInput 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<CustomOutput>> List()
|
|||
|
{
|
|||
|
return await _rep.AsQueryable().Select<CustomOutput>().ToListAsync();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|