using SqlSugar; using WIDESEA_Common.StockEnum; using WIDESEA_Core; using WIDESEA_Core.BaseRepository; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Enums; using WIDESEA_Core.Helper; using WIDESEA_Core.HttpContextUser; using WIDESEA_DTO.Stock; using WIDESEA_IStockService; using WIDESEA_Model.Models; namespace WIDESEA_StockService { public partial class StockInfoDetailService : ServiceBase>, IStockInfoDetailService { public StockInfoDetailService(IRepository BaseDal, IRepository stockinfoRepository) : base(BaseDal) { _stockinfoRepository = stockinfoRepository; } public IRepository _stockinfoRepository; public IRepository Repository => BaseDal; public bool ExistBarcodes(string barcode) { return BaseDal.QueryFirst(x => x.Barcode == barcode) != null; } public bool ExistBarcodes(List barcodes) { return BaseDal.QueryFirst(x => !string.IsNullOrEmpty(x.Barcode) && barcodes.Contains(x.Barcode)) != null; } public PageGridData GetPageData2(PageDataOptions options) { string wheres = ValidatePageOptions(options); var sugarQueryable = Db.Queryable().InnerJoin((detail, item) => detail.StockId == item.Id) .Where((detail, item) =>item.StockStatus==StockStatusEmun.入库完成.ObjToInt()); Dictionary orderbyDic = GetPageDataSort(options, TProperties); List orderByModels = new List(); foreach (var item in orderbyDic) { if (item.Key.ToLower() == "id") { OrderByModel orderByModel = new() { FieldName = "detail."+item.Key, OrderByType = item.Value }; orderByModels.Add(orderByModel); } else { OrderByModel orderByModel = new() { FieldName = item.Key, OrderByType = item.Value }; orderByModels.Add(orderByModel); } } int totalCount = 0; List searchParametersList = new List(); if (!string.IsNullOrEmpty(options.Wheres)) { try { searchParametersList = options.Wheres.DeserializeObject>(); if (searchParametersList != null && searchParametersList.Any()) { foreach (var param in searchParametersList) { // 匹配托盘编号查询条件(小写字段名) if (param.Name.Equals(nameof(Dt_StockInfo.PalletCode).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(param.Value?.ToString())) { sugarQueryable = sugarQueryable.Where((detail, item) => item.PalletCode.Contains(param.Value)); } } } } catch (Exception ex) { } } var data = sugarQueryable .WhereIF(!wheres.IsNullOrEmpty(), wheres) .OrderBy(orderByModels) .Select((detail, item) => new StockInfoDetailWithPalletDto { Id = detail.Id, StockId = detail.StockId, MaterielCode = detail.MaterielCode, MaterielName = detail.MaterielName, OrderNo = detail.OrderNo, BatchNo = detail.BatchNo, ProductionDate = detail.ProductionDate, EffectiveDate = detail.EffectiveDate, SerialNumber = detail.SerialNumber, StockQuantity = detail.StockQuantity, OutboundQuantity = detail.OutboundQuantity, Status = detail.Status, Unit = detail.Unit, InboundOrderRowNo = detail.InboundOrderRowNo, SupplyCode = detail.SupplyCode, WarehouseCode = detail.WarehouseCode, Barcode = detail.Barcode, BusinessType = detail.BusinessType, Remark = detail.Remark, Creater = detail.Creater, CreateDate = detail.CreateDate, Modifier = detail.Modifier, ModifyDate = detail.ModifyDate, PalletCode = item.PalletCode }) .ToPageList(options.Page, options.Rows, ref totalCount); return new PageGridData(totalCount, data); } } }