| | |
| | | } |
| | | else |
| | | { |
| | | for (int i = 0; i < stockInfos.Count; i++) |
| | | { |
| | | Dt_StockInfo stockInfo = stockInfos[i]; |
| | | float useableStockQuantity = stockInfo.Details.Where(x => x.MaterielCode == materielCode).Sum(x => x.StockQuantity - x.OutboundQuantity); |
| | | if (useableStockQuantity < needQuantity) |
| | | { |
| | | stockInfo.Details.ForEach(x => x.OutboundQuantity = x.StockQuantity); |
| | | needQuantity -= useableStockQuantity; |
| | | } |
| | | else |
| | | { |
| | | stockInfo.Details.ForEach(x => |
| | | { |
| | | if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode) |
| | | { |
| | | if (x.StockQuantity - x.OutboundQuantity >= needQuantity) |
| | | { |
| | | x.OutboundQuantity += needQuantity; |
| | | needQuantity = 0; |
| | | } |
| | | else |
| | | { |
| | | needQuantity -= (x.StockQuantity - x.OutboundQuantity); |
| | | x.OutboundQuantity = x.StockQuantity; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | outStocks.Add(stockInfo); |
| | | } |
| | | throw new Exception("åºåä¸è¶³"); |
| | | } |
| | | residueQuantity = needQuantity; |
| | | return outStocks; |
| | |
| | | return BaseDal.GetStockInfos(materielCode, batchNo, locationCodes); |
| | | } |
| | | |
| | | public WebResponseContent UpdateExpirationlabel() |
| | | { |
| | | try |
| | | { |
| | | var today = DateTime.Today; |
| | | int batchSize = 1000; // æ¹æ¬¡å¤çå¤§å° |
| | | |
| | | var query = BaseDal.Db.Queryable<Dt_StockInfoDetail>() |
| | | .InnerJoin<Dt_StockInfo>((detail, master) => detail.StockId == master.Id) |
| | | .Select((detail, master) => new |
| | | { |
| | | MasterId = master.Id, |
| | | master.WarehouseId, |
| | | detail.EffectiveDate, |
| | | CurrentExpirationlabel = master.Expirationlabel // ç¨äºå¤ææ¯å¦éè¦æ´æ° |
| | | }); |
| | | |
| | | // åæ¹å¤çï¼ä½¿ç¨TakeåSkipå®ç°å页 |
| | | var totalUpdated = 0; |
| | | int skipCount = 0; |
| | | |
| | | while (true) |
| | | { |
| | | // 使ç¨SkipåTakeå®ç°å页è·åæ°æ® |
| | | var batchData = query.Skip(skipCount).Take(batchSize).ToList(); |
| | | if (!batchData.Any()) break; // æ²¡ææ´å¤æ°æ®æ¶éåºå¾ªç¯ |
| | | |
| | | var updateDic = new Dictionary<long, int>(); |
| | | |
| | | foreach (var item in batchData) |
| | | { |
| | | if (!DateTime.TryParse(item.EffectiveDate, out DateTime effectiveDate)) |
| | | continue; |
| | | int newLabel; |
| | | if (effectiveDate < today) |
| | | { |
| | | newLabel = ExpirationlabelEnum.è¿æ.ObjToInt(); |
| | | } |
| | | else if (item.WarehouseId == 3) |
| | | { |
| | | int daysDiff = (effectiveDate - today).Days; |
| | | newLabel = daysDiff <= 60 ? ExpirationlabelEnum.临æé¢è¦.ObjToInt() : ExpirationlabelEnum.æªä¸´æ.ObjToInt(); |
| | | } |
| | | else |
| | | { |
| | | int daysDiff = (effectiveDate - today).Days; |
| | | newLabel = daysDiff <= 30 ? ExpirationlabelEnum.临æé¢è¦.ObjToInt() : ExpirationlabelEnum.æªä¸´æ.ObjToInt(); |
| | | } |
| | | |
| | | // åªæ´æ°æååçå¼ï¼å¹¶ä¸å»é |
| | | if (newLabel != item.CurrentExpirationlabel && !updateDic.ContainsKey(item.MasterId)) |
| | | { |
| | | updateDic[item.MasterId] = newLabel; |
| | | } |
| | | } |
| | | |
| | | if (updateDic.Any()) |
| | | { |
| | | // æå»ºæ¹éæ´æ°è¯å¥ |
| | | var updateBuilder = BaseDal.Db.Updateable<Dt_StockInfo>(); |
| | | foreach (var kvp in updateDic) |
| | | { |
| | | updateBuilder.SetColumns(m => m.Expirationlabel == kvp.Value) |
| | | .Where(m => m.Id == kvp.Key); |
| | | } |
| | | totalUpdated += updateBuilder.ExecuteCommand(); |
| | | } |
| | | skipCount += batchSize; // åå¤è·åä¸ä¸æ¹æ°æ® |
| | | } |
| | | return WebResponseContent.Instance.OK($"æ´æ°æåï¼å
±æ´æ° {totalUpdated} æ¡è®°å½"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error("æ´æ°å¤±è´¥ï¼è¯·è系管çå"); |
| | | } |
| | | } |
| | | } |
| | | } |