public IEnumerable <StockProductInfo> GetSelectProductListByStepName(int pageIndex, int pageSize, string stepName, object productId, object customerId, double qty) { var sqlWhere = new StringBuilder(100); if (EnumData.EnumStep.发货.ToString() == stepName) { sqlWhere.Append("and sp.Qty > 0 "); } else if (EnumData.EnumStep.拣货.ToString() == stepName) { sqlWhere.AppendFormat("and sp.FreezeQty > 0 and ProductId = '{0}' and CustomerId = '{1}' ", productId, customerId); } var spList = new List <StockProductInfo>(); var list = dal.GetListByJoin(pageIndex, pageSize, sqlWhere.ToString(), null); if (list != null && list.Count > 0) { var slBll = new StockLocation(); var slTemp = slBll.GetModelForTemp(); var slList = slBll.GetList(); foreach (var item in list) { var pslaList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(item.StockLocations); if (EnumData.EnumStep.发货.ToString() == stepName || EnumData.EnumStep.拣货.ToString() == stepName) { pslaList.RemoveAll(m => m.StockLocationId.Equals(slTemp.Id)); } foreach (var pslaItem in pslaList) { if (EnumData.EnumStep.发货.ToString() == stepName) { if (pslaItem.Qty <= 0) { continue; } } else if (EnumData.EnumStep.拣货.ToString() == stepName) { if (pslaItem.FreezeQty <= 0) { continue; } } var slInfo = slList.FirstOrDefault(m => m.Id.Equals(pslaItem.StockLocationId)); if (slInfo == null) { throw new ArgumentException(string.Format("{0}对应的库位数据不存在或已被删除", pslaItem.StockLocationId)); } var spInfo = new StockProductInfo(item.ProductId, item.CustomerId, item.Qty, item.UnQty, item.FreezeQty, item.StepCode, item.LastStepName, item.Status, item.StockLocations, "", item.LastUpdatedDate); spInfo.StockLocations = ""; spInfo.StockLocationId = slInfo.Id; spInfo.StockLocationCode = slInfo.Code; spInfo.StockLocationName = slInfo.Named; spInfo.LastUpdatedDate = pslaItem.LastUpdatedDate; spInfo.Qty = 0; spInfo.ProductCode = item.ProductCode; spInfo.ProductName = item.ProductName; spInfo.CustomerCode = item.CustomerCode; spInfo.CustomerName = item.CustomerName; if (EnumData.EnumStep.拣货.ToString() == stepName) { spInfo.MaxQty = pslaItem.FreezeQty; } else { spInfo.MaxQty = pslaItem.Qty; } spList.Add(spInfo); } } var q = spList.OrderBy(m => m.LastUpdatedDate); var totalQty = 0d; foreach (var item in q) { if (totalQty >= qty) { break; } item.IsBest = true; totalQty += item.MaxQty; } } return(spList); }
public IList <PandianProductInfo> GetPandianProductList(Guid pandianId, Guid userId, DateTime stockStartDate, DateTime stockEndDate, string customer, string zones, string stockLocations) { var list = new List <PandianProductInfo>(); var slBll = new StockLocation(); var slTempInfo = slBll.GetModelForTemp(); var zBll = new Zone(); var hasStartDate = (stockStartDate != DateTime.Parse("1754-01-01") && stockStartDate != DateTime.MinValue); var hasEndDate = (stockEndDate != DateTime.Parse("1754-01-01") && stockEndDate != DateTime.MinValue); string[] customers = null; if (!string.IsNullOrWhiteSpace(customer)) { customers = customer.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } if ((customers != null && customers.Length > 0) && (!hasStartDate && !hasEndDate && string.IsNullOrWhiteSpace(zones) && string.IsNullOrWhiteSpace(stockLocations))) { #region 获取只客户为条件的库存货品 StringBuilder sqlWhere = null; SqlParameter parm = null; if (customers.Length == 1) { sqlWhere = new StringBuilder(@"and sp.CustomerId = @CustomerId "); parm = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier); parm.Value = Guid.Parse(customers[0]); } else { sqlWhere = new StringBuilder(1200); var sqlIn = new StringBuilder(1000); foreach (var item in customers) { sqlIn.AppendFormat("'{0}',", item); } sqlWhere.AppendFormat("and sp.CustomerId in ({0})", sqlIn.ToString().Trim(',')); } var spList = dal.GetListByJoin(sqlWhere.ToString(), parm); if (spList != null && spList.Count > 0) { var zList = zBll.GetList(); var slList = slBll.GetList(); foreach (var item in spList) { var qty = 0d; var sZones = new List <string>(); var pslList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(item.StockLocations); if (pslList != null && pslList.Count > 0) { pslList.RemoveAll(m => m.StockLocationId.Equals(slTempInfo.Id)); if (pslList.Count > 0) { qty = pslList.Sum(m => (m.Qty + m.FreezeQty)); var minSlList = new List <MinStockLocationInfo>(); foreach (var pslInfo in pslList) { var slInfo = slList.FirstOrDefault(m => m.Id.Equals(pslInfo.StockLocationId)); if (slInfo != null) { var zInfo = zList.FirstOrDefault(m => m.Id.Equals(slInfo.ZoneId)); if (zInfo != null) { if (!sZones.Contains(zInfo.ZoneCode)) { sZones.Add(zInfo.ZoneCode); } } minSlList.Add(new MinStockLocationInfo(slInfo.Id, slInfo.Code, slInfo.Named, (pslInfo.Qty + pslInfo.FreezeQty))); } } qty = minSlList.Sum(m => m.Qty); list.Add(new PandianProductInfo(pandianId, userId, item.ProductId, item.CustomerId, string.Join(",", sZones), JsonConvert.SerializeObject(minSlList), qty, "", "", 0, 0, EnumData.EnumOrderStatus.新建.ToString(), "", DateTime.Now)); } } } } #endregion } else { #region 获取可能包含入库时间、库区、库位为条件的库存货品 var spList = dal.GetList(); if (spList != null && spList.Count > 0) { string[] slItems = null; if (!string.IsNullOrWhiteSpace(stockLocations)) { slItems = stockLocations.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } IList <StockLocationInfo> zslList = null; if (!string.IsNullOrWhiteSpace(zones) && (slItems == null || slItems.Length == 0)) { zslList = slBll.GetListInZoneIds(zones); } var zList = zBll.GetList(); var slList = slBll.GetList(); foreach (var item in spList) { var pslList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(item.StockLocations); if (pslList == null || pslList.Count == 0) { continue; } pslList.RemoveAll(m => m.StockLocationId.Equals(slTempInfo.Id)); if (pslList.Count == 0) { continue; } if (customers != null && customers.Length > 0 && pslList.Count > 0) { if (!customers.Contains(item.CustomerId.ToString())) { continue; } } if (hasStartDate) { pslList.RemoveAll(m => m.LastUpdatedDate < stockStartDate); } if (hasEndDate && pslList.Count > 0) { pslList.RemoveAll(m => m.LastUpdatedDate > stockStartDate); } if (slItems != null && slItems.Length > 0 && pslList.Count > 0) { pslList.RemoveAll(m => !slItems.Contains(m.StockLocationId.ToString())); } if (!string.IsNullOrWhiteSpace(zones) && (slItems != null && slItems.Length == 0) && pslList.Count > 0) { pslList.RemoveAll(m => !slList.Any(mm => mm.Id.Equals(m.StockLocationId))); } if (pslList.Count == 0) { continue; } var sZones = new List <string>(); var minSlList = new List <MinStockLocationInfo>(); foreach (var pslInfo in pslList) { var slInfo = slList.FirstOrDefault(m => m.Id.Equals(pslInfo.StockLocationId)); if (slInfo != null) { var zInfo = zList.FirstOrDefault(m => m.Id.Equals(slInfo.ZoneId)); if (zInfo != null) { if (!sZones.Contains(zInfo.ZoneCode)) { sZones.Add(zInfo.ZoneCode); } } minSlList.Add(new MinStockLocationInfo(slInfo.Id, slInfo.Code, slInfo.Named, (pslInfo.Qty + pslInfo.FreezeQty))); } } var qty = minSlList.Sum(m => m.Qty); list.Add(new PandianProductInfo(pandianId, userId, item.ProductId, item.CustomerId, string.Join(",", sZones), JsonConvert.SerializeObject(minSlList), qty, "", "", 0, 0, EnumData.EnumOrderStatus.新建.ToString(), "", DateTime.Now)); } } #endregion } return(list); }