| | |
| | | using WIDESEA_IStockRepository; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_StockRepository; |
| | | |
| | | namespace WIDESEA_StockService |
| | | { |
| | |
| | | throw new Exception($"æªæ¾å°åºåºåä¿¡æ¯"); |
| | | } |
| | | |
| | | List<string> locationCodes = _basicRepository.LocationInfoRepository.GetCanOutLocationCodes(outboundOrder.WarehouseId); |
| | | List<string> locationCodes = _basicRepository.LocationInfoRepository.PPGetCanOutLocationCodes(outboundOrder.WarehouseId); |
| | | |
| | | return BaseDal.QueryTabs<Dt_StockInfo, Dt_StockInfoDetail, StockSelectViewDTO>((a, b) => a.Id == b.StockId, (a, b) => new StockSelectViewDTO |
| | | { |
| | |
| | | return null; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ¥è¯¢è®¢åPPç«åºåºåè§å¾ |
| | | /// </summary> |
| | | /// <param name="orderId"></param> |
| | | /// <param name="materielCode"></param> |
| | | /// <returns></returns> |
| | | public List<PPStockSelectViewDTO> PPGetStockSelectViews(int orderId, string materielCode) |
| | | { |
| | | try |
| | | { |
| | | Dt_MesPPCutOutboundOrder mesPPCutOutboundOrder = _outboundRepository.MesPPCutOutboundOrderRepository.QueryFirst(x => x.Id == orderId); |
| | | if (mesPPCutOutboundOrder == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°åºåºåä¿¡æ¯"); |
| | | } |
| | | List<string> locationCodes = _basicRepository.LocationInfoRepository.PPGetCanOutLocationCodes(mesPPCutOutboundOrder.WarehouseId); |
| | | |
| | | return BaseDal.QueryTabs<Dt_StockInfo, Dt_StockInfoDetail, PPStockSelectViewDTO>((a, b) => a.Id == b.StockId, (a, b) => new PPStockSelectViewDTO |
| | | { |
| | | LocationCode = a.LocationCode, |
| | | MaterielCode = b.MaterielCode, |
| | | MaterielName = b.MaterielName, |
| | | PalletCode = a.PalletCode, |
| | | Unit = b.Unit, |
| | | CutedWidth = b.CutedWidth, |
| | | UseableQuantity = b.StockQuantity - b.OutboundQuantity |
| | | }, a => locationCodes.Contains(a.LocationCode), b => b.StockQuantity > b.OutboundQuantity && b.MaterielCode == materielCode, x => true).GroupBy(x => x.PalletCode).Select(x => new PPStockSelectViewDTO |
| | | { |
| | | LocationCode = x.FirstOrDefault()?.LocationCode ?? "", |
| | | MaterielCode = x.FirstOrDefault()?.MaterielCode ?? "", |
| | | MaterielName = x.FirstOrDefault()?.MaterielName ?? "", |
| | | Unit = x.FirstOrDefault()?.Unit ?? "", |
| | | CutedWidth = x.Sum(x => x.CutedWidth), |
| | | PalletCode = x.Key, |
| | | UseableQuantity = x.Sum(x => x.UseableQuantity) |
| | | }).ToList(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢è®¢åPPå¹³åºåºåè§å¾ |
| | | /// </summary> |
| | | /// <param name="orderId"></param> |
| | | /// <param name="materielCode"></param> |
| | | /// <returns></returns> |
| | | public List<PPStockSelectViewDTO> PPGetPKStockSelectViews(int orderId, string materielCode) |
| | | { |
| | | try |
| | | { |
| | | Dt_MesPPCutOutboundOrder outboundOrder = _outboundRepository.MesPPCutOutboundOrderRepository.QueryFirst(x => x.Id == orderId); |
| | | if (outboundOrder == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°åºåºåä¿¡æ¯"); |
| | | } |
| | | return BaseDal.QueryTabs<Dt_StockInfo, Dt_StockInfoDetail, PPStockSelectViewDTO>((a, b) => a.Id == b.StockId && a.WarehouseId == outboundOrder.WarehouseId, (a, b) => new PPStockSelectViewDTO |
| | | { |
| | | LocationCode = a.LocationCode, |
| | | MaterielCode = b.MaterielCode, |
| | | MaterielName = b.MaterielName, |
| | | PalletCode = a.PalletCode, |
| | | Unit = b.Unit, |
| | | CutedWidth = b.CutedWidth, |
| | | UseableQuantity = b.StockQuantity - b.OutboundQuantity |
| | | }, a => a.LocationCode.Contains("AGV_PP"), b => b.StockQuantity > b.OutboundQuantity && b.MaterielCode == materielCode, x => true).GroupBy(x => x.PalletCode).Select(x => new PPStockSelectViewDTO |
| | | { |
| | | LocationCode = x.FirstOrDefault()?.LocationCode ?? "", |
| | | MaterielCode = x.FirstOrDefault()?.MaterielCode ?? "", |
| | | MaterielName = x.FirstOrDefault()?.MaterielName ?? "", |
| | | Unit = x.FirstOrDefault()?.Unit ?? "", |
| | | CutedWidth = x.Sum(x => x.CutedWidth), |
| | | PalletCode = x.Key, |
| | | UseableQuantity = x.Sum(x => x.UseableQuantity) |
| | | }).ToList(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public WebResponseContent StockQueryData(SaveModel saveModel) |
| | | { |
| | |
| | | { |
| | | Dt_StockInfo stockInfo = stockInfos[index]; |
| | | float useableStockQuantity = stockInfo.Details.Where(x => x.MaterielCode == materielCode).Sum(x => x.StockQuantity - x.OutboundQuantity); |
| | | if (useableStockQuantity < needQuantity) |
| | | if (useableStockQuantity < needQuantity && useableStockQuantity>0) |
| | | { |
| | | stockInfo.Details.ForEach(x => x.OutboundQuantity = x.StockQuantity); |
| | | needQuantity -= useableStockQuantity; |
| | |
| | | } |
| | | 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 MatPicking(SaveModel saveModel) |
| | | |
| | | public List<Dt_StockInfo> GetUseableStocks(string materielCode, string batchNo, string palletcode, int warehoseId) |
| | | { |
| | | WebResponseContent content= new WebResponseContent(); |
| | | Dt_StockInfo stockInfo = BaseDal.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletcode && x.WarehouseId == warehoseId).Includes(x => x.Details).First(); |
| | | |
| | | List<string> locationCodes = _basicRepository.LocationInfoRepository.GetCanOutLocationCodes(stockInfo.LocationCode); |
| | | |
| | | 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) |
| | | { |
| | | content.Error(ex.Message); |
| | | return WebResponseContent.Instance.Error("æ´æ°å¤±è´¥ï¼è¯·è系管çå"); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |