using Admin.NET.Core.Service; using Admin.NET.Application.Const; using Admin.NET.Application.Entity; using Microsoft.AspNetCore.Http; namespace Admin.NET.Application; /// /// 打印条码详情服务 /// [ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)] public class PrintCodeDetailService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _rep; public PrintCodeDetailService(SqlSugarRepository rep) { _rep = rep; } /// /// 分页查询打印条码详情 /// /// /// [HttpPost] [ApiDescriptionSettings(Name = "Page")] public async Task> 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(); 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); } /// /// 增加打印条码详情 /// /// /// [HttpPost] [ApiDescriptionSettings(Name = "Add")] public async Task Add(AddPrintCodeDetailInput input) { var entity = input.Adapt(); await _rep.InsertAsync(entity); return entity.Id; } /// /// 删除打印条码详情 /// /// /// [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); //真删除 } /// /// 更新打印条码详情 /// /// /// [HttpPost] [ApiDescriptionSettings(Name = "Update")] public async Task Update(UpdatePrintCodeDetailInput input) { var entity = input.Adapt(); await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } public async Task UpdateByEntity(PrintCodeDetail entity) { await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } /// /// 获取打印条码详情 /// /// /// [HttpGet] [ApiDescriptionSettings(Name = "Detail")] public async Task Detail([FromQuery] QueryByIdPrintCodeDetailInput input) { return await _rep.GetFirstAsync(u => u.Id == input.Id); } /// /// 获取打印条码详情列表 /// /// [HttpGet] [ApiDescriptionSettings(Name = "List")] public async Task> List() { return await _rep.AsQueryable().Where(a => !a.IsDelete).Select().ToListAsync(); } /// /// 获取打印条码详情列表 /// /// [HttpPost] [ApiDescriptionSettings(Name = "GetRepeat")] public async Task> GetRepeat(List printDatas) { if (printDatas.Count<1) { return new List(); } 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().ToListAsync(); } /// /// 获取打印条码详情 /// /// /// [HttpGet] [ApiDescriptionSettings(Name = "GetByProductCode")] public async Task GetByProductCode(string? productCode) { return await _rep.GetFirstAsync(a => a.Code == productCode); } /// /// 获取打印条码详情 /// /// /// [HttpGet] [ApiDescriptionSettings(Name = "GetByProductCodes")] public async Task> GetByProductCodes(string? productCode) { return await _rep.AsQueryable().Where(a => !a.IsDelete && a.Code.Contains(productCode)).ToListAsync(); } [HttpGet] [ApiDescriptionSettings(Name = "GetByProductCodes2")] public async Task> GetByProductCodes2(string? productCode) { return await _rep.AsQueryable().Where(a => !a.IsDelete && a.Code == productCode).ToListAsync(); } [HttpGet] [ApiDescriptionSettings(Name = "GetByReportTableId")] public async Task> GetByReportTableId(long? reportTableId) { return await _rep.AsQueryable().Where(a => !a.IsDelete && a.ReportTableId == reportTableId).ToListAsync(); } }