From 992a33ca68af405d08da512c46d7d59ec3ceaabc Mon Sep 17 00:00:00 2001 From: 肖洋 <cathay_xy@163.com> Date: 星期二, 11 二月 2025 14:33:47 +0800 Subject: [PATCH] 添加 ProductionLine 属性并优化任务处理逻辑 --- Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs | 186 +++++++++++++++++++++++++++++++++++---------- 1 files changed, 143 insertions(+), 43 deletions(-) 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 85c1e58..7e35a13 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 @@ -14,6 +14,7 @@ using WIDESEA_StorageTaskRepository; using WIDESEAWCS_BasicInfoRepository; using WIDESEAWCS_Model.Models; +using WIDESEAWCS_QuartzJob.Models; namespace WIDESEA_StorageTaskServices; @@ -39,18 +40,20 @@ //if (task.TaskState == (int)TaskInStatusEnum.InNew) { // 鍒涘缓WMS浠诲姟 - WMSTaskDTO taskDTO = new WMSTaskDTO() - { - TaskNum = task.TaskNum.Value, - Grade = 1, - PalletCode = task.PalletCode, - RoadWay = task.Roadway, - SourceAddress = task.SourceAddress, - TargetAddress = task.TargetAddress, - TaskState = task.TaskState.Value, - Id = 0, - TaskType = task.TaskType, - }; + //WMSTaskDTO taskDTO = new WMSTaskDTO() + //{ + // TaskNum = task.TaskNum.Value, + // Grade = 1, + // PalletCode = task.PalletCode, + // RoadWay = task.Roadway, + // SourceAddress = task.SourceAddress, + // TargetAddress = task.TargetAddress, + // TaskState = task.TaskState.Value, + // Id = 0, + // TaskType = task.TaskType, + // ProductionLine = task.ProductionLine, + //}; + WMSTaskDTO taskDTO = CreateTaskDTO(task); return content.OK(data: taskDTO); } } @@ -100,7 +103,7 @@ WMSTaskDTO taskDTO = new WMSTaskDTO() { TaskNum = task.TaskNum.Value, - Grade = 1, + Grade = task.Grade.Value, PalletCode = task.PalletCode, RoadWay = task.Roadway, SourceAddress = task.SourceAddress, @@ -108,6 +111,7 @@ TaskState = task.TaskState.Value, Id = 0, TaskType = task.TaskType, + ProductionLine = task.ProductionLine }; content.OK(data: taskDTO); } @@ -186,6 +190,30 @@ // 缁勭洏淇℃伅 // 灏哻ontent.Data杞崲涓篟esultTrayCellsStatus瀵硅薄 var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString()); + + if (!result.Success) + { + var taskNG = new Dt_Task + { + CurrentAddress = input.Position, + Grade = 1, + Roadway = input.Roadways, + TargetAddress = stationManager.stationNGLocation, + Dispatchertime = DateTime.Now, + MaterialNo = "", + NextAddress = stationManager.stationNGChildCode, + OrderNo = null, + PalletCode = input.PalletCode, + SourceAddress = stationManager.stationLocation, + TaskState = (int)TaskInStatusEnum.Line_InFinish, + TaskType = (int)TaskOutboundTypeEnum.InToOut, + TaskNum = await BaseDal.GetTaskNo(), + Creater = "Systeam", + ProductionLine = result.ProductionLine + }; + return taskNG; + } + if (result.SerialNos.Count <= 0) { ConsoleHelper.WriteErrorLine(result.MOMMessage); @@ -218,7 +246,7 @@ } // 澶勭悊寮傚父鐢佃姱鎯呭喌 - var serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1).ToList(); + var serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList(); if (serialNosError.Count > 0) { if (stationManager.stationType != 3) @@ -238,7 +266,8 @@ TaskState = (int)TaskInStatusEnum.Line_InFinish, TaskType = (int)TaskOutboundTypeEnum.InToOut, TaskNum = await BaseDal.GetTaskNo(), - Creater = "Systeam" + Creater = "Systeam", + ProductionLine = result.ProductionLine }; return taskNG; } @@ -270,7 +299,8 @@ TaskState = (int)TaskInStatusEnum.Line_InFinish, TaskType = (int)TaskOutboundTypeEnum.InToOut, TaskNum = await BaseDal.GetTaskNo(), - Creater = "Systeam" + Creater = "Systeam", + ProductionLine = result.ProductionLine }; return task; } @@ -301,25 +331,33 @@ if (locationInfo == null) throw new Exception("搴撲綅宸叉弧"); + // 鍒涘缓涓�涓猅rayCellsStatusDto瀵硅薄锛屽苟璧嬪�� + TrayCellsStatusDto trayCells = new TrayCellsStatusDto() + { + Software = "WMS", + TrayBarcode = input.PalletCode, + //EquipmentCode = "EQ_CWJZ01" + EquipmentCode = input.EquiCodeMOM + }; + + // 璋冪敤GetTrayCellStatusAsync鏂规硶锛岃幏鍙栨暣鐩樼數鑺� + WebResponseContent content = await GetTrayCellStatusAsync(trayCells); + // 濡傛灉鐘舵�佷负false锛屽垯杩斿洖content + if (!content.Status) throw new Exception(content.Message); + + // 灏哻ontent.Data杞崲涓篟esultTrayCellsStatus瀵硅薄 + var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString()); + + if (stationManager.stationType == 6 && result.ProductionLine.IsNullOrEmpty()) + { + ConsoleHelper.WriteErrorLine($"褰撳墠鎵樼洏鏃犱骇绾�,鑱旂郴MOM娣诲姞浜х嚎"); + throw new Exception("褰撳墠鎵樼洏鏃犱骇绾�,鑱旂郴MOM娣诲姞浜х嚎"); + } + if (stationManager.stationType == 1) { - // 鍒涘缓涓�涓猅rayCellsStatusDto瀵硅薄锛屽苟璧嬪�� - TrayCellsStatusDto trayCells = new TrayCellsStatusDto() - { - Software = "WMS", - TrayBarcode = input.PalletCode, - //EquipmentCode = "EQ_CWJZ01" - EquipmentCode = input.EquiCodeMOM - }; + #region - // 璋冪敤GetTrayCellStatusAsync鏂规硶锛岃幏鍙栨暣鐩樼數鑺� - WebResponseContent content = await GetTrayCellStatusAsync(trayCells); - // 濡傛灉鐘舵�佷负false锛屽垯杩斿洖content - if (!content.Status) throw new Exception(content.Message); - - // 娣诲姞缁勭洏淇℃伅 - // 灏哻ontent.Data杞崲涓篟esultTrayCellsStatus瀵硅薄 - var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString()); if (result.SerialNos.Count <= 0) { ConsoleHelper.WriteErrorLine(result.MOMMessage); @@ -338,7 +376,8 @@ TaskState = (int)TaskInStatusEnum.Line_InFinish, TaskType = (int)TaskOutboundTypeEnum.InToOut, TaskNum = await BaseDal.GetTaskNo(), - Creater = "Systeam" + Creater = "Systeam", + ProductionLine = result.ProductionLine }; return taskNG; } @@ -368,6 +407,7 @@ ////// 璋冪敤GetProcessResponseAsync鏂规硶锛岃幏鍙栧伐鑹哄搷搴� ////var processResponse = await GetProcessResponseAsync(process, input.Position); var isBox = await _boxingInfoRepository.AddDataNavAsync(boxing); + #endregion } var task = new Dt_Task @@ -385,12 +425,16 @@ TaskState = (int)TaskInStatusEnum.Line_InFinish, TaskType = stationManager.stationType == 1 ? (int)TaskInboundTypeEnum.Inbound : (int)TaskInboundTypeEnum.InTray, TaskNum = await BaseDal.GetTaskNo(), - Creater = "Systeam" + Creater = "Systeam", + ProductionLine = result.ProductionLine, }; - ConsoleHelper.WriteSuccessLine($"淇敼鍓嶏細" + locationInfo.LocationStatus.ToString()); + int lastStatus = locationInfo.LocationStatus; + ConsoleHelper.WriteSuccessLine($"淇敼鍓嶏細" + lastStatus.ToString()); locationInfo.LocationStatus = (int)LocationEnum.FreeDisable; ConsoleHelper.WriteSuccessLine($"淇敼鍚庯細" + locationInfo.LocationStatus.ToString()); await UpdateLocationAsync(locationInfo); + + _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(locationInfo, lastStatus, (int)StatusChangeTypeEnum.AutomaticStorage, task.TaskNum); return task; } @@ -504,7 +548,7 @@ var task = new Dt_Task { CurrentAddress = input.Position, - Grade = 1, + Grade = 2, Roadway = input.Roadways, TargetAddress = stationManager.stationLocation, Dispatchertime = DateTime.Now, @@ -516,7 +560,8 @@ TaskState = (int)TaskOutStatusEnum.OutNew, TaskType = (int)TaskOutboundTypeEnum.OutTray, TaskNum = await BaseDal.GetTaskNo(), - Creater = "Systeam" + Creater = "Systeam", + ProductionLine = stockinfo.ProductionLine, }; return task; @@ -607,7 +652,8 @@ TaskState = (int)TaskInStatusEnum.Line_InFinish, TaskType = (int)TaskInboundTypeEnum.InTray, TaskNum = await BaseDal.GetTaskNo(), - Creater = "Systeam" + Creater = "Systeam", + ProductionLine = result.ProductionLine, }; return Epmtytask; } @@ -667,15 +713,21 @@ TaskState = (int)TaskInStatusEnum.Line_InFinish, TaskType = (int)TaskInboundTypeEnum.Inbound, TaskNum = await BaseDal.GetTaskNo(), - Creater = "Systeam" + Creater = "Systeam", + ProductionLine = result.ProductionLine, }; var isBox = await _boxingInfoRepository.AddDataNavAsync(boxing); - ConsoleHelper.WriteSuccessLine($"淇敼鍓嶏細" + locationInfo.LocationStatus.ToString()); + int lastStatus = locationInfo.LocationStatus; + + ConsoleHelper.WriteSuccessLine($"淇敼鍓嶏細" + lastStatus.ToString()); locationInfo.LocationStatus = (int)LocationEnum.FreeDisable; ConsoleHelper.WriteSuccessLine($"淇敼鍚庯細" + locationInfo.LocationStatus.ToString()); await UpdateLocationAsync(locationInfo); + + _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(locationInfo, lastStatus, (int)StatusChangeTypeEnum.AutomaticStorage, task.TaskNum); + return task; } catch (Exception ex) @@ -784,10 +836,13 @@ var content = JsonConvert.DeserializeObject<WebResponseContent>(result); if (content.Status) { + int lastStatus = item.LocationInfo.LocationStatus; await BaseDal.AddDataAsync(task); // 鏇存柊搴撳瓨浣嶇疆鐘舵�佷负涓嶅彲鐢� item.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable; await _locationRepository.UpdateDataAsync(item.LocationInfo); + + _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(item.LocationInfo, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum); } } } @@ -823,7 +878,7 @@ var location = locations.OrderBy(x => x.Layer).ThenBy(x => x.Column).ThenBy(x => x.Row).FirstOrDefault(); - var stockInfo = await QueryStockInfoForEmptyTrayAsync("CWSC1"); + var stockInfo = await QueryStockInfoForEmptyTrayFRAsync("CWSC1", "10086", taskDTO.ProductionLine); if (stockInfo != null) { @@ -833,6 +888,7 @@ WMSTaskDTO wmsTask = CreateTaskDTO(task); // 鏇存柊搴撳瓨浣嶇疆鐘舵�佷负涓嶅彲鐢� + int lastStatus = location.LocationStatus; stockInfo.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable; location.LocationStatus = (int)LocationEnum.Distribute; await _unitOfWorkManage.UseTranAsync(async () => @@ -841,6 +897,8 @@ await _locationRepository.UpdateDataAsync(stockInfo.LocationInfo); await _locationRepository.UpdateDataAsync(location); }); + + _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum); // 杩斿洖鎴愬姛鍝嶅簲 return content.OK(data: wmsTask); @@ -856,6 +914,43 @@ return content; } + /// <summary> + /// 鏌ヨ绌虹洏搴撳瓨淇℃伅 + /// </summary> + private async Task<DtStockInfo> QueryStockInfoForEmptyTrayFRAsync(string areaCode, string position, string productLine) + { + var area = await _areaInfoRepository.QueryFirstAsync(x => x.AreaCode == areaCode); + + ConsoleHelper.WriteColorLine(position + "..." + areaCode, ConsoleColor.Magenta); + var station = await _stationManagerRepository.QueryFirstAsync(x => x.stationChildCode == position && x.stationType == 17); + + ConsoleHelper.WriteColorLine(station.Roadway, ConsoleColor.Magenta); + var stackers = station.Roadway.Split(',').ToList(); + + + var devices = SqlSugarHelper.DbWCS.Queryable<Dt_DeviceInfo>() + .Where(x => x.DeviceStatus == "1") + .Where(x => stackers.Contains(x.DeviceCode)) + .ToList(); + + var deviceCode = devices.Select(x => x.DeviceCode).ToList(); + + var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>() + .Includes(x => x.LocationInfo) // 棰勫姞杞絃ocationInfo + .Includes(x => x.StockInfoDetails) // 棰勫姞杞絊tockInfoDetails + .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)) + .OrderBy(x => x.CreateDate) // 鎺掑簭 + .FirstAsync(); // 杞崲涓哄垪琛� + + //var firstOrDefault = result[0]; // 鏌ユ壘绗竴涓尮閰嶇殑鍏冪礌 + //return firstOrDefault; + return result; + } + #endregion public async Task<WebResponseContent> RequestOutTaskToBZAsync(RequestTaskDto json) @@ -866,8 +961,8 @@ Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == json.Position && x.stationType == 12 && x.stationArea == "Call"); var stockInfo = _stockInfoRepository.Db.Queryable<DtStockInfo>() + .Where(x => x.ProductionLine == station.productLine) .Includes(x => x.LocationInfo) // 棰勫姞杞絃ocationInfo - .Includes(x => x.StockInfoDetails) // 棰勫姞杞絊tockInfoDetails .Where(x => x.AreaCode == "CWSC3" && x.IsFull == true) // 杩囨护鏉′欢 .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock) // 杩囨护鏉′欢 .OrderBy(x => x.OutboundTime) // 鎺掑簭 @@ -896,15 +991,20 @@ TaskState = (int)TaskOutStatusEnum.OutNew, TaskType = (int)TaskOutboundTypeEnum.Outbound, TaskNum = await BaseDal.GetTaskNo(), - Creater = "Systeam" + Creater = "Systeam", + ProductionLine = stockInfo.ProductionLine, }; WMSTaskDTO taskDTO = CreateTaskDTO(task); + int lastStatus = locationInfo.LocationStatus; + BaseDal.AddData(task); stockInfo.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable; _locationRepository.UpdateData(stockInfo.LocationInfo); + _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(stockInfo.LocationInfo, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum); + return content.OK(data: taskDTO); } catch (Exception ex) -- Gitblit v1.9.3