|  |  | 
 |  |  | using Masuit.Tools; | 
 |  |  | using SqlSugar; | 
 |  |  | using WIDESEA_Common.CustomModels; | 
 |  |  |  | 
 |  |  | //using WIDESEA_Common.CustomModels; | 
 |  |  | using WIDESEA_Core.Const; | 
 |  |  | using WIDESEA_DTO.MOM; | 
 |  |  | using WIDESEA_DTO.WMS; | 
 |  |  | 
 |  |  |                     TaskState = (int)TaskInStatusEnum.Line_InFinish, | 
 |  |  |                     TaskType = (int)TaskOutboundTypeEnum.InToOut, | 
 |  |  |                     TaskNum = await BaseDal.GetTaskNo(), | 
 |  |  |                     Creater = "Systeam", | 
 |  |  |                     Creater = "System", | 
 |  |  |                     ProductionLine = result.ProductionLine, | 
 |  |  |                     ProcessCode = result.ProcessCode, | 
 |  |  |                 }; | 
 |  |  | 
 |  |  |                         TaskState = (int)TaskInStatusEnum.Line_InFinish, | 
 |  |  |                         TaskType = (int)TaskOutboundTypeEnum.InToOut, | 
 |  |  |                         TaskNum = await BaseDal.GetTaskNo(), | 
 |  |  |                         Creater = "Systeam" | 
 |  |  |                         Creater = "System" | 
 |  |  |                     }; | 
 |  |  |                     return taskNG; | 
 |  |  |                 } | 
 |  |  | 
 |  |  |                         TaskState = (int)TaskInStatusEnum.Line_InFinish, | 
 |  |  |                         TaskType = (int)TaskOutboundTypeEnum.InToOut, | 
 |  |  |                         TaskNum = await BaseDal.GetTaskNo(), | 
 |  |  |                         Creater = "Systeam", | 
 |  |  |                         Creater = "System", | 
 |  |  |                         ProductionLine = result.ProductionLine, | 
 |  |  |                         ProcessCode = result.ProcessCode, | 
 |  |  |                     }; | 
 |  |  | 
 |  |  |                 TaskState = (int)TaskInStatusEnum.Line_InFinish, | 
 |  |  |                 TaskType = (int)TaskOutboundTypeEnum.InToOut, | 
 |  |  |                 TaskNum = await BaseDal.GetTaskNo(), | 
 |  |  |                 Creater = "Systeam", | 
 |  |  |                 Creater = "System", | 
 |  |  |                 ProductionLine = result.ProductionLine, | 
 |  |  |                 ProcessCode = result.ProcessCode, | 
 |  |  |             }; | 
 |  |  | 
 |  |  |                     TaskState = (int)TaskInStatusEnum.Line_InFinish, | 
 |  |  |                     TaskType = (int)TaskOutboundTypeEnum.InToOut, | 
 |  |  |                     TaskNum = await BaseDal.GetTaskNo(), | 
 |  |  |                     Creater = "Systeam", | 
 |  |  |                     Creater = "System", | 
 |  |  |                     ProductionLine = result.ProductionLine, | 
 |  |  |                     ProcessCode = result.ProcessCode, | 
 |  |  |                 }; | 
 |  |  | 
 |  |  |             TaskState = (int)TaskInStatusEnum.Line_InFinish, | 
 |  |  |             TaskType = stationManager.stationType == 1 ? (int)TaskInboundTypeEnum.Inbound : (int)TaskInboundTypeEnum.InTray, | 
 |  |  |             TaskNum = await BaseDal.GetTaskNo(), | 
 |  |  |             Creater = "Systeam", | 
 |  |  |             Creater = "System", | 
 |  |  |             ProductionLine = result.ProductionLine, | 
 |  |  |             ProcessCode = result.ProcessCode, | 
 |  |  |         }; | 
 |  |  | 
 |  |  |             IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo); | 
 |  |  |             List<DtStockInfo> stockInfoList = stockInfos.Values.ToList(); | 
 |  |  |  | 
 |  |  |             var stockinfo = stockInfoList.Where(x => x.LocationInfo != null && !x.IsFull && x.LocationInfo.RoadwayNo == stationManager.Roadway) | 
 |  |  |                 .OrderBy(x => x.CreateDate) | 
 |  |  |             var stockinfo1 = stockInfoList.OrderBy(x => x.CreateDate) | 
 |  |  |                 .ToList(); | 
 |  |  |             var stockinfo = stockinfo1.Where(x => x.LocationInfo != null && !x.IsFull && x.LocationInfo.RoadwayNo == stationManager.Roadway) | 
 |  |  |                 .FirstOrDefault(); | 
 |  |  |  | 
 |  |  |             if (stockinfo == null) return null; | 
 |  |  | 
 |  |  |                 TaskState = (int)TaskOutStatusEnum.OutNew, | 
 |  |  |                 TaskType = (int)TaskOutboundTypeEnum.OutTray, | 
 |  |  |                 TaskNum = await BaseDal.GetTaskNo(), | 
 |  |  |                 Creater = "Systeam", | 
 |  |  |                 Creater = "System", | 
 |  |  |                 ProductionLine = stockinfo.ProductionLine, | 
 |  |  |             }; | 
 |  |  |  | 
 |  |  |             _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { task.PalletCode }); | 
 |  |  |             return task; | 
 |  |  |         } | 
 |  |  |         catch (Exception ex) | 
 |  |  | 
 |  |  |                     TaskState = (int)TaskInStatusEnum.Line_InFinish, | 
 |  |  |                     TaskType = (int)TaskInboundTypeEnum.InTray, | 
 |  |  |                     TaskNum = await BaseDal.GetTaskNo(), | 
 |  |  |                     Creater = "Systeam", | 
 |  |  |                     Creater = "System", | 
 |  |  |                     ProductionLine = result.ProductionLine, | 
 |  |  |                     ProcessCode = result.ProcessCode, | 
 |  |  |                 }; | 
 |  |  | 
 |  |  |                 TaskState = (int)TaskInStatusEnum.Line_InFinish, | 
 |  |  |                 TaskType = (int)TaskInboundTypeEnum.Inbound, | 
 |  |  |                 TaskNum = await BaseDal.GetTaskNo(), | 
 |  |  |                 Creater = "Systeam", | 
 |  |  |                 Creater = "System", | 
 |  |  |                 ProductionLine = result.ProductionLine, | 
 |  |  |                 ProcessCode = result.ProcessCode, | 
 |  |  |             }; | 
 |  |  | 
 |  |  |         WebResponseContent content = new WebResponseContent(); | 
 |  |  |         try | 
 |  |  |         { | 
 |  |  |             string requestKey = JsonConvert.SerializeObject(taskDTO); | 
 |  |  |             // 检查请求次数和时间限制 | 
 |  |  |             if (requestTrackerToCW.TryGetValue(requestKey, out var requestInfo)) | 
 |  |  |             { | 
 |  |  |                 if (requestInfo.Count > 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(2)) | 
 |  |  |                 { | 
 |  |  |                     // 如果请求次数超过限制且未超过10分钟,抛出异常 | 
 |  |  |                     throw new InvalidOperationException("请求次数已达到限制,请稍后再试。"); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             //string requestKey = JsonConvert.SerializeObject(taskDTO); | 
 |  |  |             //// 检查请求次数和时间限制 | 
 |  |  |             //if (requestTrackerToCW.TryGetValue(requestKey, out var requestInfo)) | 
 |  |  |             //{ | 
 |  |  |             //    if (requestInfo.Count > 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(2)) | 
 |  |  |             //    { | 
 |  |  |             //        // 如果请求次数超过限制且未超过10分钟,抛出异常 | 
 |  |  |             //        throw new InvalidOperationException("请求次数已达到限制,请稍后再试。"); | 
 |  |  |             //    } | 
 |  |  |             //} | 
 |  |  |  | 
 |  |  |             // 更新请求跟踪信息 | 
 |  |  |             if (requestTrackerToCW.ContainsKey(requestKey)) | 
 |  |  |             { | 
 |  |  |                 requestTrackerToCW[requestKey] = (requestInfo.Count + 1, DateTime.Now); | 
 |  |  |             } | 
 |  |  |             else | 
 |  |  |             { | 
 |  |  |                 requestTrackerToCW[requestKey] = (1, DateTime.Now); | 
 |  |  |             } | 
 |  |  |             //// 更新请求跟踪信息 | 
 |  |  |             //if (requestTrackerToCW.ContainsKey(requestKey)) | 
 |  |  |             //{ | 
 |  |  |             //    requestTrackerToCW[requestKey] = (requestInfo.Count + 1, DateTime.Now); | 
 |  |  |             //} | 
 |  |  |             //else | 
 |  |  |             //{ | 
 |  |  |             //    requestTrackerToCW[requestKey] = (1, DateTime.Now); | 
 |  |  |             //} | 
 |  |  |  | 
 |  |  |             var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == taskDTO.Position && x.stationStatus == "1"); | 
 |  |  |             var locations = _locationRepository.QueryData(x => x.RoadwayNo == station.Roadway && x.LocationStatus == (int)LocationEnum.Free && x.LocationType == 1); | 
 |  |  | 
 |  |  |                     _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum); | 
 |  |  |  | 
 |  |  |                     // 返回成功响应 | 
 |  |  |                     requestTrackerToCW.Remove(requestKey); | 
 |  |  |                     //requestTrackerToCW.Remove(requestKey); | 
 |  |  |  | 
 |  |  |                     return content.OK(data: wmsTask); | 
 |  |  |                 } | 
 |  |  | 
 |  |  |         IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo); | 
 |  |  |         List<DtStockInfo> stockInfoList = stockInfos.Values.ToList(); | 
 |  |  |  | 
 |  |  |         var result = stockInfoList.Where(x => x.ProductionLine == productLine) | 
 |  |  |         var result1 = stockInfoList.Where(x => x.ProductionLine == productLine) | 
 |  |  |             .Where(x => x.AreaCode == areaCode && x.IsFull == false) | 
 |  |  |             .Where(x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => y.MaterielCode == "空托盘")) | 
 |  |  |             .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 过滤条件 | 
 |  |  |             .WhereIF(!deviceCode.IsNullOrEmpty(), x => x.LocationInfo != null && deviceCode.Contains(x.LocationInfo.RoadwayNo)) | 
 |  |  |             .OrderBy(x => x.CreateDate) // 排序 | 
 |  |  |             .FirstOrDefault(); // 转换为列表 | 
 |  |  |             .ToList(); // 转换为列表 | 
 |  |  |  | 
 |  |  |         var result = result1.Where(x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => y.MaterielCode == "空托盘")) | 
 |  |  |             .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 过滤条件 | 
 |  |  |             .FirstOrDefault(); // 获取第一个元素 | 
 |  |  |  | 
 |  |  |         if (result != null) | 
 |  |  |             _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode }); | 
 |  |  |         else | 
 |  |  |             ConsoleHelper.WriteColorLine($"常温{productLine}空托盘库存不足", ConsoleColor.Red); | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  | 
 |  |  |             List<DtStockInfo> stockInfoList = stockInfos.Values.ToList(); | 
 |  |  |  | 
 |  |  |             // 修改后的查询代码 | 
 |  |  |             var stockInfo = stockInfoList | 
 |  |  |             var stockInfo1 = stockInfoList | 
 |  |  |                 .Where(x => x.ProductionLine == station.productLine) | 
 |  |  |                 .Where(x => x.AreaCode == "CWSC3" && x.IsFull == true) | 
 |  |  |                 .OrderBy(x => x.OutboundTime) | 
 |  |  |                 .ToList(); | 
 |  |  |  | 
 |  |  |             var stockInfo = stockInfo1 | 
 |  |  |                 // 增加对 LocationInfo 的空值检查 | 
 |  |  |                 .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock) | 
 |  |  |                 // 增加对 LocationInfo 的空值检查 | 
 |  |  |                 .WhereIF(!deviceCode.IsNullOrEmpty(), x => x.LocationInfo != null && deviceCode.Contains(x.LocationInfo.RoadwayNo)) | 
 |  |  |                 .OrderBy(x => x.OutboundTime) | 
 |  |  |                 .FirstOrDefault(); | 
 |  |  |  | 
 |  |  |             if (stockInfo == null) throw new Exception($"库内{station.productLine}无满足条件的库存可出库"); | 
 |  |  | 
 |  |  |                 TaskState = (int)TaskOutStatusEnum.OutNew, | 
 |  |  |                 TaskType = (int)TaskOutboundTypeEnum.Outbound, | 
 |  |  |                 TaskNum = await BaseDal.GetTaskNo(), | 
 |  |  |                 Creater = "Systeam", | 
 |  |  |                 Creater = "System", | 
 |  |  |                 ProductionLine = stockInfo.ProductionLine, | 
 |  |  |                 ProcessCode = stockInfo.ProcessCode, | 
 |  |  |             }; | 
 |  |  | 
 |  |  |             stockInfo.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable; | 
 |  |  |             _locationRepository.UpdateData(stockInfo.LocationInfo); | 
 |  |  |  | 
 |  |  |             _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { taskDTO.PalletCode }); | 
 |  |  |  | 
 |  |  |             _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(stockInfo.LocationInfo, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum); | 
 |  |  |  | 
 |  |  |             return content.OK(data: taskDTO); |