123 lines
3.9 KiB
C#
123 lines
3.9 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 CodeElementService : IDynamicApiController, ITransient
|
|||
|
{
|
|||
|
private readonly SqlSugarRepository<CodeElement> _rep;
|
|||
|
public CodeElementService(SqlSugarRepository<CodeElement> rep)
|
|||
|
{
|
|||
|
_rep = rep;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分页查询码元素
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
[ApiDescriptionSettings(Name = "Page")]
|
|||
|
public async Task<SqlSugarPagedList<CodeElementOutput>> Page(CodeElementInput input)
|
|||
|
{
|
|||
|
var query = _rep.AsQueryable()
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|||
|
u.CodeName.Contains(input.SearchKey.Trim())
|
|||
|
|| u.ExportFormatExample.Contains(input.SearchKey.Trim())
|
|||
|
)
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeName), u => u.CodeName.Contains(input.CodeName.Trim()))
|
|||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ExportFormatExample), u => u.ExportFormatExample.Contains(input.ExportFormatExample.Trim()))
|
|||
|
.Select<CodeElementOutput>();
|
|||
|
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(AddCodeElementInput input)
|
|||
|
{
|
|||
|
var entity = input.Adapt<CodeElement>();
|
|||
|
await _rep.InsertAsync(entity);
|
|||
|
return entity.Id;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 删除码元素
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
[ApiDescriptionSettings(Name = "Delete")]
|
|||
|
public async Task Delete(DeleteCodeElementInput input)
|
|||
|
{
|
|||
|
var entity = await _rep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
|
|||
|
//var entity = await _rep.GetFirstAsync(u => u.CodeLength == input.CodeLength) ?? 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(UpdateCodeElementInput input)
|
|||
|
{
|
|||
|
var entity = input.Adapt<CodeElement>();
|
|||
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取码元素
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
[ApiDescriptionSettings(Name = "Detail")]
|
|||
|
public async Task<CodeElement> Detail([FromQuery] QueryByIdCodeElementInput input)
|
|||
|
{
|
|||
|
return await _rep.GetFirstAsync(u => u.Id == input.Id);
|
|||
|
//return await _rep.GetFirstAsync(u => u.CodeLength == input.CodeLength);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取码元素
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
[ApiDescriptionSettings(Name = "ElementByName")]
|
|||
|
public async Task<CodeElement> GetElementByName([FromQuery] string input)
|
|||
|
{
|
|||
|
return await _rep.GetFirstAsync(u => u.CodeName == input);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取码元素列表
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
[ApiDescriptionSettings(Name = "List")]
|
|||
|
public async Task<List<CodeElementOutput>> List()
|
|||
|
{
|
|||
|
return await _rep.AsQueryable().Where(a => !a.IsDelete).Select<CodeElementOutput>().ToListAsync();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|