From aded48e0f32d28bf61479a3c50ac63946be6f469 Mon Sep 17 00:00:00 2001 From: xxyy <cathay_xy@163.com> Date: 星期四, 06 三月 2025 17:28:46 +0800 Subject: [PATCH] 修复空指针异常的潜在问题 --- Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/appsettings.json | 2 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs | 81 ++------------------ Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs | 4 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/Unbind/UnbindService.cs | 4 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs | 4 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/NotifyFinishTest.cs | 2 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/WIDESEA_StoragIntegrationServices.csproj | 1 /dev/null | 0 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/AgingInOrOutInput/AgingInOrOutInputService.cs | 4 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs | 95 +++++++++++------------ Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/MCSService.cs | 6 + Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/4a99214b-9f9f-4ab7-8ce9-83d07cd22a77 | 0 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs | 2 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs | 7 - 14 files changed, 73 insertions(+), 139 deletions(-) diff --git a/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/4a99214b-9f9f-4ab7-8ce9-83d07cd22a77 b/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/4a99214b-9f9f-4ab7-8ce9-83d07cd22a77 new file mode 100644 index 0000000..324b841 --- /dev/null +++ b/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/4a99214b-9f9f-4ab7-8ce9-83d07cd22a77 Binary files differ diff --git a/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/85d61362-b687-48eb-8099-932a817719a7 b/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/85d61362-b687-48eb-8099-932a817719a7 deleted file mode 100644 index 8fc9dc5..0000000 --- a/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/85d61362-b687-48eb-8099-932a817719a7 +++ /dev/null Binary files differ diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/MCSService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/MCSService.cs index d224489..33a5904 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/MCSService.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/MCSService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using WIDESEA_Cache; using WIDESEA_IBusinessesRepository; using WIDESEA_IServices; using WIDESEA_IStorageBasicRepository; @@ -22,9 +23,11 @@ private readonly ISys_ConfigService _configService; private readonly IDt_StationManagerRepository _stationManagerRepository; private readonly IDt_AreaInfoRepository _areaInfoRepository; + + private readonly ISimpleCacheService _simpleCacheService; private readonly LogFactory LogFactory = new LogFactory(); - public MCSService(ILocationInfoRepository locationRepository,IDt_TaskRepository taskRepository,IStockInfoRepository stockInfoRepository, ISys_ConfigService configService, IDt_StationManagerRepository stationManagerRepository,IDt_AreaInfoRepository dt_AreaInfoRepository) + public MCSService(ILocationInfoRepository locationRepository,IDt_TaskRepository taskRepository,IStockInfoRepository stockInfoRepository, ISys_ConfigService configService, IDt_StationManagerRepository stationManagerRepository,IDt_AreaInfoRepository dt_AreaInfoRepository, ISimpleCacheService simpleCacheService) { _locationRepository = locationRepository; _taskRepository = taskRepository; @@ -32,6 +35,7 @@ _configService = configService; _stationManagerRepository = stationManagerRepository; _areaInfoRepository = dt_AreaInfoRepository; + _simpleCacheService = simpleCacheService; } } } diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/NotifyFinishTest.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/NotifyFinishTest.cs index 3029cce..6aed71f 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/NotifyFinishTest.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/NotifyFinishTest.cs @@ -105,6 +105,8 @@ if (respone.Status) { var taskId = _taskRepository.AddData(task); + + //_simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { taskDTO.PalletCode }); } else diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/AgingInOrOutInput/AgingInOrOutInputService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/AgingInOrOutInput/AgingInOrOutInputService.cs index 67b5f60..3fa97ef 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/AgingInOrOutInput/AgingInOrOutInputService.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/AgingInOrOutInput/AgingInOrOutInputService.cs @@ -35,7 +35,7 @@ input.SessionId = Guid.NewGuid().ToString(); input.EmployeeNo = "MITest"; input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); - var inputJson = input.ToDictionary(); + var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); // Specify the namespace explicitly var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.AgingInput)?.ConfigValue; @@ -85,7 +85,7 @@ input.SessionId = Guid.NewGuid().ToString(); input.EmployeeNo = "MITest"; input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); - var inputJson = input.ToDictionary(); + var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); // Specify the namespace explicitly var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.AgingOutput)?.ConfigValue; diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs index 7c2baf4..fc3786d 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs @@ -42,7 +42,7 @@ input.SessionId = Guid.NewGuid().ToString(); input.EmployeeNo = "MITest"; input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); - var inputJson = input.ToDictionary(); + var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.CellState)?.ConfigValue; @@ -82,7 +82,7 @@ input.SessionId = Guid.NewGuid().ToString(); input.EmployeeNo = "MITest"; input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); - var inputJson = input.ToDictionary(); + var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.TrayCellsStatus)?.ConfigValue; diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs index 0725b0b..6cd1a81 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs @@ -47,7 +47,7 @@ input.SessionId = Guid.NewGuid().ToString(); input.EmployeeNo = "MITest"; input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); - var inputJson = input.ToDictionary(); + var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ProcessApply)?.ConfigValue; diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/Unbind/UnbindService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/Unbind/UnbindService.cs index 4225e41..b84189a 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/Unbind/UnbindService.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/Unbind/UnbindService.cs @@ -38,7 +38,7 @@ input.EquipmentCode = "24MEJQ08-1091"; input.EmployeeNo = "MITest"; input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); - var inputJson = input.ToDictionary(); + var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); LogFactory.GetLog("鎵樼洏鍗曠數鑺В缁�1").Info(true, JsonConvert.SerializeObject(inputJson)); var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; @@ -77,7 +77,7 @@ input.EquipmentCode = "24MEJQ08-1091"; input.EmployeeNo = "MITest"; input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); - var inputJson = input.ToDictionary(); + var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); Console.WriteLine(inputJson); var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/WIDESEA_StoragIntegrationServices.csproj b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/WIDESEA_StoragIntegrationServices.csproj index 0c382c9..aa0d93c 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/WIDESEA_StoragIntegrationServices.csproj +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/WIDESEA_StoragIntegrationServices.csproj @@ -8,6 +8,7 @@ <ItemGroup> <ProjectReference Include="..\LogLibrary\LogLibrary.csproj" /> + <ProjectReference Include="..\WIDESEA_Cache\WIDESEA_Cache.csproj" /> <ProjectReference Include="..\WIDESEA_Common\WIDESEA_Common.csproj" /> <ProjectReference Include="..\WIDESEA_IStoragIntegrationServices\WIDESEA_IStoragIntegrationServices.csproj" /> <ProjectReference Include="..\WIDESEA_Services\WIDESEA_Services.csproj" /> diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs index 3a75882..271e0af 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs @@ -36,7 +36,7 @@ public Task StartAsync(CancellationToken cancellationToken) { - _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(20)); + _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(5)); return Task.CompletedTask; } @@ -51,9 +51,8 @@ IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo); List<DtStockInfo> stockInfoList = stockInfos.Values.ToList(); - var stockInfo = stockInfoList.Where(x => x.AreaCode == area.AreaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) // 杩囨护鏉′欢 - .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID) // 杩囨护鏉′欢 + .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID) // 杩囨护鏉′欢 .OrderBy(x => x.OutboundTime) // 鎺掑簭 .ToList(); // 鑾峰彇绗竴涓厓绱� @@ -140,7 +139,7 @@ Creater = "System", // 淇鎷煎啓閿欒 CreateDate = DateTime.Now, TaskId = 0, - ProductionLine= stockInfo.ProductionLine, + ProductionLine = stockInfo.ProductionLine, ProcessCode = stockInfo.ProcessCode, }; } diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs index 9c82d44..e696df4 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs @@ -1,6 +1,5 @@ 锘縰sing Mapster; using Masuit.Tools; -using NewLife.Caching; using SqlSugar; using System.Text.RegularExpressions; using WIDESEA_Cache; @@ -216,6 +215,8 @@ await DeleteTaskAsync(task.TaskId); await AddTaskHtyAsync(taskHty); }); + + _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode }); return content.OK("浠诲姟瀹屾垚鎴愬姛", task.Remark); } @@ -451,6 +452,7 @@ { _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(locationInf, lastStatus, (int)StatusChangeTypeEnum.AutomaticStorage, task.TaskNum); + stock.StockInfoDetails = new List<DtStockInfoDetail>() { { stock.StockInfoDetails[0] } }; _simpleCacheService.HashAdd(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, stock.PalletCode, stock); content.OK("鍏ュ簱浠诲姟瀹屾垚鎴愬姛"); @@ -1286,67 +1288,6 @@ .OrderBy(x => x.OutboundTime) .FirstOrDefault(); - if (result != null) - { - stockInfoList = stockInfoList.Where(x => x != result).ToList(); - _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode }); - } - - return result; - - if (stockInfoList.IsNullOrEmpty()) - { - stockInfoList = await _stockInfoRepository.Db.Queryable<DtStockInfo>().IncludesAllFirstLayer().ToListAsync(); - - result = stockInfoList.Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) - .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine) - .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 杩囨护鏉′欢 - .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo)) - .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) - .OrderBy(x => x.OutboundTime) // 鎺掑簭 - .FirstOrDefault(); // 鑾峰彇绗竴涓厓绱� - - if (result != null) - { - // 鎺掗櫎 result 涓殑鍏冪礌 - stockInfoList = stockInfoList.Where(x => x != result).ToList(); - } - foreach (var item in stockInfoList) - { - _simpleCacheService.HashAdd(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, item.PalletCode, item); - } - } - else - { - result = stockInfoList.Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) - .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine) - .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 杩囨护鏉′欢 - .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo)) - .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) - .OrderBy(x => x.OutboundTime) // 鎺掑簭 - .FirstOrDefault(); // 鑾峰彇绗竴涓厓绱� - if (result != null) - { - // 鎺掗櫎 result 涓殑鍏冪礌 - stockInfoList = stockInfoList.Where(x => x != result).ToList(); - } - string[] xfasd = new string[] { result.PalletCode }; - _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode }); - } - - #region - //var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>() - // .Includes(x => x.LocationInfo) // 棰勫姞杞絃ocationInfo - // .Includes(x => x.StockInfoDetails) // 棰勫姞杞絊tockInfoDetails - // .Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) // 杩囨护鏉′欢 - // .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine) - // .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 杩囨护鏉′欢 - // .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo)) - // .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) - // .OrderBy(x => x.OutboundTime) // 鎺掑簭 - // .FirstAsync(); // 鑾峰彇绗竴涓厓绱� - #endregion 璇锋眰鍑哄簱锛堝疄鐩�&绌虹洏锛� - return result; } @@ -1393,12 +1334,6 @@ .OrderBy(x => x.OutboundTime) // 鎺掑簭 .FirstOrDefault(); // 鑾峰彇绗竴涓厓绱� - if (result != null) - { - stockInfoList = stockInfoList.Where(x => x != result).ToList(); - _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode }); - } - return result; } @@ -1431,11 +1366,11 @@ .OrderBy(x => x.CreateDate) // 鎺掑簭 .FirstOrDefault(); // 杞崲涓哄垪琛� - if (result != null) - { - stockInfoList = stockInfoList.Where(x => x != result).ToList(); - _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode }); - } + //if (result != null) + //{ + // stockInfoList = stockInfoList.Where(x => x != result).ToList(); + // _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode }); + //} return result; } diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs index a3180a9..6714028 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs @@ -542,12 +542,13 @@ { if (stationManager.stationType != 7) throw new Exception("閿欒鐨勮皟鍙�"); - var stockinfo = await _stockInfoRepository.Db.Queryable<DtStockInfo>() - .Includes(x => x.LocationInfo) - //.Includes(x=>x.StockInfoDetails) - .Where(x => !x.IsFull && x.LocationInfo.RoadwayNo == stationManager.Roadway) + // 浠庣紦瀛樹腑鑾峰彇搴撳瓨淇℃伅 + 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) - .FirstAsync(); + .FirstOrDefault(); if (stockinfo == null) return null; @@ -886,11 +887,34 @@ #region 甯告俯琛ョ┖鎵樼洏鑷冲垎瀹� + private static readonly Dictionary<string, (int Count, DateTime LastRequestTime)> requestTrackerToCW = new(); + public async Task<WebResponseContent> GetFROutTrayToCW(RequestTaskDto taskDTO) { 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("璇锋眰娆℃暟宸茶揪鍒伴檺鍒讹紝璇风◢鍚庡啀璇曘��"); + } + } + + // 鏇存柊璇锋眰璺熻釜淇℃伅 + 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); @@ -923,6 +947,8 @@ _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum); // 杩斿洖鎴愬姛鍝嶅簲 + requestTrackerToCW.Remove(requestKey); + return content.OK(data: wmsTask); } else @@ -960,17 +986,12 @@ var result = stockInfoList.Where(x => x.ProductionLine == productLine) .Where(x => x.AreaCode == areaCode && x.IsFull == false) - .Where(x => x.StockInfoDetails.Any(y => y.MaterielCode == "绌烘墭鐩�")) - .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 杩囨护鏉′欢 - .WhereIF(!deviceCode.IsNullOrEmpty(), x => deviceCode.Contains(x.LocationInfo.RoadwayNo)) + .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(); // 杞崲涓哄垪琛� - if (result != null) - { - stockInfoList = stockInfoList.Where(x => x != result).ToList(); - _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode }); - } return result; } @@ -991,28 +1012,6 @@ WebResponseContent content = new WebResponseContent(); try { - //string requestKey = JsonConvert.SerializeObject(json); - //// 妫�鏌ヨ姹傛鏁板拰鏃堕棿闄愬埗 - //if (requestTracker.TryGetValue(requestKey, out var requestInfo)) - //{ - // if (requestInfo.Count >= 9 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(5)) - // { - // // 濡傛灉璇锋眰娆℃暟瓒呰繃闄愬埗涓旀湭瓒呰繃10鍒嗛挓锛屾姏鍑哄紓甯� - // throw new InvalidOperationException("璇锋眰娆℃暟宸茶揪鍒伴檺鍒讹紝璇风◢鍚庡啀璇曘��"); - // } - //} - - //// 鏇存柊璇锋眰璺熻釜淇℃伅 - //if (requestTracker.ContainsKey(requestKey)) - //{ - // requestTracker[requestKey] = (requestInfo.Count + 1, DateTime.Now); - //} - //else - //{ - // requestTracker[requestKey] = (1, DateTime.Now); - //} - //LogFactory.GetLog("甯告俯3鍑哄簱鑷冲寘瑁�").Info(true, $"甯告俯3鍑哄簱鑷冲寘瑁呬紶鍏ュ弬鏁帮細" + JsonConvert.SerializeObject(json, Formatting.Indented)); - Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == json.Position && x.stationType == 12 && x.stationArea == "Call"); if (station == null) { throw new Exception($"鏈壘鍒板寘瑁呯珯鍙颁俊鎭紝璇锋鏌ヤ紶鍏ュ弬鏁皗json.Position}"); } @@ -1021,26 +1020,20 @@ .Where(x => x.DeviceCode.Contains("CWSC")) // 杩囨护鏉′欢 .ToList().Select(x => x.DeviceCode).ToList(); - // 浠庣紦瀛樹腑鑾峰彇搴撳瓨淇℃伅 IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo); List<DtStockInfo> stockInfoList = stockInfos.Values.ToList(); - - - var stockInfo = stockInfoList.Where(x => x.ProductionLine == station.productLine) - .Where(x => x.AreaCode == "CWSC3" && x.IsFull == true) // 杩囨护鏉′欢 - .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock) // 杩囨护鏉′欢 - .WhereIF(!deviceCode.IsNullOrEmpty(), x => deviceCode.Contains(x.LocationInfo.RoadwayNo)) - .OrderBy(x => x.OutboundTime) // 鎺掑簭 - .FirstOrDefault(); // 鑾峰彇绗竴涓厓绱� - - if (stockInfo != null) - { - stockInfoList = stockInfoList.Where(x => x != stockInfo).ToList(); - _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stockInfo.PalletCode }); - } - + // 淇敼鍚庣殑鏌ヨ浠g爜 + var stockInfo = stockInfoList + .Where(x => x.ProductionLine == station.productLine) + .Where(x => x.AreaCode == "CWSC3" && x.IsFull == true) + // 澧炲姞瀵� 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}鏃犳弧瓒虫潯浠剁殑搴撳瓨鍙嚭搴�"); diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs index 29a2d05..a1b8b78 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs @@ -201,11 +201,11 @@ redis.DelByPattern(CacheConst.Cache_Prefix); WIDESEA_Core.Helper.ConsoleHelper.WriteInfoLine("正在缓存库存信息"); - var stockInfoList = await SqlSugarHelper.DbWMS.Queryable<DtStockInfo>() - .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock).IncludesAllFirstLayer().ToListAsync(); + var stockInfoList = await SqlSugarHelper.DbWMS.Queryable<DtStockInfo>().IncludesAllFirstLayer().ToListAsync(); // 缓存库存信息 foreach (var item in stockInfoList) { + item.StockInfoDetails = new List<DtStockInfoDetail>() { { item.StockInfoDetails[0] } }; redis.HashAdd(CacheConst.Cache_DtStockInfo, item.PalletCode, item); } WIDESEA_Core.Helper.ConsoleHelper.WriteInfoLine("缓存库存信息完成"); diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/appsettings.json b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/appsettings.json index 8460061..db958e1 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/appsettings.json +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/appsettings.json @@ -15,7 +15,7 @@ //"ConnectionString": "Data Source=.\\LIULEI;Initial Catalog=WIDESEA_WMSDB_BBMain;User ID=sa;Password=123456;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", //"ConnectionString": "Data Source=192.168.20.251;Initial Catalog=WIDESEA_WMSDB;User ID=sa;Password=123456@gy;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", //"ConnectionStringWCS": "Data Source=192.168.5.251;Initial Catalog=WIDESEAWCS_TEST;User ID=sa;Password=P@ssw0rd;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", - "ConnectionStringWCS": "Data Source=127.0.0.1;Initial Catalog=WIDESEA_WCSDB;User ID=sa;Password=sa123456;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ConnectionStringWCS": "Data Source=127.0.0.1;Initial Catalog=WIDESEA_WCS2F09;User ID=sa;Password=P@ssw0rd;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", //璺ㄥ煙 "Cors": { "PolicyName": "CorsIpAccess", //绛栫暐鍚嶇О -- Gitblit v1.9.3