116 lines
4.0 KiB
C#
116 lines
4.0 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 ProductBarCodeService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<ProductBarCode> _rep;
|
|
public ProductBarCodeService(SqlSugarRepository<ProductBarCode> rep)
|
|
{
|
|
_rep = rep;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询产品条码
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "Page")]
|
|
public async Task<SqlSugarPagedList<ProductBarCodeOutput>> Page(ProductBarCodeInput input)
|
|
{
|
|
var query = _rep.AsQueryable()
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|
u.BarCode.Contains(input.SearchKey.Trim())
|
|
|| u.ParentCode.Contains(input.SearchKey.Trim())
|
|
|| u.BarCodeType.Contains(input.SearchKey.Trim())
|
|
|| u.MaterialName.Contains(input.SearchKey.Trim())
|
|
|| u.MaterialCode.Contains(input.SearchKey.Trim())
|
|
|| u.Unit.Contains(input.SearchKey.Trim())
|
|
)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BarCode), u => u.BarCode.Contains(input.BarCode.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ParentCode), u => u.ParentCode.Contains(input.ParentCode.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BarCodeType), u => u.BarCodeType.Contains(input.BarCodeType.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.MaterialName), u => u.MaterialName.Contains(input.MaterialName.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.MaterialCode), u => u.MaterialCode.Contains(input.MaterialCode.Trim()))
|
|
.Select<ProductBarCodeOutput>();
|
|
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(AddProductBarCodeInput input)
|
|
{
|
|
var entity = input.Adapt<ProductBarCode>();
|
|
await _rep.InsertAsync(entity);
|
|
return entity.Id;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除产品条码
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "Delete")]
|
|
public async Task Delete(DeleteProductBarCodeInput 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(UpdateProductBarCodeInput input)
|
|
{
|
|
var entity = input.Adapt<ProductBarCode>();
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取产品条码
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[ApiDescriptionSettings(Name = "Detail")]
|
|
public async Task<ProductBarCode> Detail([FromQuery] QueryByIdProductBarCodeInput 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<ProductBarCodeOutput>> List()
|
|
{
|
|
return await _rep.AsQueryable().Select<ProductBarCodeOutput>().ToListAsync();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|