DigitalFactory/Admin.NET/Admin.NET.Application/Service/PrintCodeDetail/PrintCodeDetailService.cs

169 lines
6.5 KiB
C#
Raw Normal View History

2024-05-25 10:46:26 +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 PrintCodeDetailService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<PrintCodeDetail> _rep;
public PrintCodeDetailService(SqlSugarRepository<PrintCodeDetail> rep)
{
_rep = rep;
}
/// <summary>
/// 分页查询打印条码详情
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task<SqlSugarPagedList<PrintCodeDetailOutput>> Page(PrintCodeDetailInput input)
{
var query = _rep.AsQueryable().Where(a => !a.IsDelete)
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
u.Code.Contains(input.SearchKey.Trim())
|| u.FatherCode.Contains(input.SearchKey.Trim())
|| u.CodeName.Contains(input.SearchKey.Trim())
|| u.Unit.Contains(input.SearchKey.Trim())
|| u.BaseUnit.Contains(input.SearchKey.Trim())
|| u.Remarks.Contains(input.SearchKey.Trim())
)
.WhereIF(!string.IsNullOrWhiteSpace(input.Code), u => u.Code.Contains(input.Code.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.FatherCode), u => u.FatherCode.Contains(input.FatherCode.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeName), u => u.CodeName.Contains(input.CodeName.Trim()))
.WhereIF(input.Count>0, u => u.Count == input.Count)
.WhereIF(!string.IsNullOrWhiteSpace(input.Unit), u => u.Unit.Contains(input.Unit.Trim()))
.WhereIF(input.BaseCount>0, u => u.BaseCount == input.BaseCount)
.WhereIF(!string.IsNullOrWhiteSpace(input.BaseUnit), u => u.BaseUnit.Contains(input.BaseUnit.Trim()))
.WhereIF(input.ChildCount>0, u => u.ChildCount == input.ChildCount)
.WhereIF(!string.IsNullOrWhiteSpace(input.Remarks), u => u.Remarks.Contains(input.Remarks.Trim()))
.Select<PrintCodeDetailOutput>();
if(input.PrintCodeTimeRange != null && input.PrintCodeTimeRange.Count >0)
{
DateTime? start= input.PrintCodeTimeRange[0];
query = query.WhereIF(start.HasValue, u => u.PrintCodeTime > start);
if (input.PrintCodeTimeRange.Count >1 && input.PrintCodeTimeRange[1].HasValue)
{
var end = input.PrintCodeTimeRange[1].Value.AddDays(1);
query = query.Where(u => u.PrintCodeTime < end);
}
}
if(input.ScanCodeTimeRange != null && input.ScanCodeTimeRange.Count >0)
{
DateTime? start= input.ScanCodeTimeRange[0];
query = query.WhereIF(start.HasValue, u => u.ScanCodeTime > start);
if (input.ScanCodeTimeRange.Count >1 && input.ScanCodeTimeRange[1].HasValue)
{
var end = input.ScanCodeTimeRange[1].Value.AddDays(1);
query = query.Where(u => u.ScanCodeTime < end);
}
}
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(AddPrintCodeDetailInput input)
{
var entity = input.Adapt<PrintCodeDetail>();
await _rep.InsertAsync(entity);
return entity.Id;
}
/// <summary>
/// 删除打印条码详情
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Delete")]
public async Task Delete(DeletePrintCodeDetailInput 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(UpdatePrintCodeDetailInput input)
{
var entity = input.Adapt<PrintCodeDetail>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
2024-05-30 10:18:10 +00:00
public async Task UpdateByEntity(PrintCodeDetail entity)
{
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
2024-05-25 10:46:26 +00:00
/// <summary>
/// 获取打印条码详情
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task<PrintCodeDetail> Detail([FromQuery] QueryByIdPrintCodeDetailInput input)
{
return await _rep.GetFirstAsync(u => u.Id == input.Id);
}
/// <summary>
/// 获取打印条码详情列表
/// </summary>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "List")]
public async Task<List<PrintCodeDetailOutput>> List()
{
return await _rep.AsQueryable().Where(a => !a.IsDelete).Select<PrintCodeDetailOutput>().ToListAsync();
}
2024-06-12 10:10:50 +00:00
/// <summary>
/// 获取打印条码详情列表
/// </summary>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "GetRepeat")]
public async Task<List<PrintCodeDetailOutput>> GetRepeat(List<PrintData> printDatas)
{
if (printDatas.Count<1)
{
return new List<PrintCodeDetailOutput>();
}
var codes = string.IsNullOrEmpty(printDatas[0].BarCode) ? printDatas.ConvertAll(a => a.QrCode) : printDatas.ConvertAll(a => a.BarCode);
return await _rep.AsQueryable().Where(a => !a.IsDelete && codes.Any(b => b == a.Code)).Select<PrintCodeDetailOutput>().ToListAsync();
}
2024-06-06 10:22:07 +00:00
/// <summary>
/// 获取打印条码详情
/// </summary>
/// <param name="productCode"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "GetByProductCode")]
public async Task<PrintCodeDetail> GetByProductCode(string? productCode)
{
return await _rep.GetFirstAsync(a => a.Code == productCode);
}
2024-07-02 03:23:29 +00:00
2024-05-25 10:46:26 +00:00
}