wanshenmean
3 天以前 4b483d9d06bead231b88ca212fd799196668a057
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
@@ -88,7 +88,7 @@
        /// </summary>
        /// <remarks>
        /// </remarks>
        private static List<string> AddressToDeviceType = new List<string> { "11020", "11028", "2125" };
        private static List<string> AddressToDeviceType = new List<string> { "11020", "11028", "2125", "11062" };
        /// <summary>
        /// 托盘检查位置的最近执行时间(用于30秒间隔限制)
@@ -168,57 +168,57 @@
                            // ========== 检查特定位置是否有托盘 ==========
                            // 从配置中读取需要检查托盘的位置列表
                            var checkPalletPositions = App.Configuration.GetSection("CheckPalletPositions")
                                .Get<List<CheckPalletPosition>>() ?? new List<CheckPalletPosition>();
                            //var checkPalletPositions = App.Configuration.GetSection("CheckPalletPositions")
                            //    .Get<List<CheckPalletPosition>>() ?? new List<CheckPalletPosition>();
                            // 如果当前设备在检查列表中
                            if (checkPalletPositions.Any(x => x.Code == childDeviceCode))
                            {
                                // 30秒间隔限制
                                if (_lastPalletCheckTime.TryGetValue(childDeviceCode, out var lastTime) &&
                                    (DateTime.Now - lastTime).TotalSeconds < 30)
                                {
                                    continue;
                                }
                            //// 如果当前设备在检查列表中
                            //if (checkPalletPositions.Any(x => x.Code == childDeviceCode))
                            //{
                            //    // 30秒间隔限制
                            //    if (_lastPalletCheckTime.TryGetValue(childDeviceCode, out var lastTime) &&
                            //        (DateTime.Now - lastTime).TotalSeconds < 30)
                            //    {
                            //        continue;
                            //    }
                                // 检查输送线状态(是否有托盘)
                                if (command.CV_State == 2)
                                {
                                    // 检查该位置是否已有任务
                                    var existingTask = _taskService.Db.Queryable<Dt_Task>().Count(x => x.TargetAddress == childDeviceCode);
                                    if (existingTask < 5)
                                    {
                                        // 没有任务,向 WMS 请求出库托盘任务
                                        var position = checkPalletPositions.FirstOrDefault(x => x.Code == childDeviceCode);
                            //    // 检查输送线状态(是否有托盘)
                            //    if (command.CV_State == 2)
                            //    {
                            //        // 检查该位置是否已有任务
                            //        var existingTask = _taskService.Db.Queryable<Dt_Task>().Count(x => x.TargetAddress == childDeviceCode);
                            //        if (existingTask < 5)
                            //        {
                            //            // 没有任务,向 WMS 请求出库托盘任务
                            //            var position = checkPalletPositions.FirstOrDefault(x => x.Code == childDeviceCode);
                                        string configKey = "GetOutBoundTrayTaskAsync";
                                        string requestParam = new CreateTaskDto()
                                        {
                                            WarehouseId = position.WarehouseId,
                                            TargetAddress = childDeviceCode
                                        }.Serialize();
                                        DateTime startTime = DateTime.Now;
                            //            string configKey = "GetOutBoundTrayTaskAsync";
                            //            string requestParam = new CreateTaskDto()
                            //            {
                            //                WarehouseId = position.WarehouseId,
                            //                TargetAddress = childDeviceCode
                            //            }.Serialize();
                            //            DateTime startTime = DateTime.Now;
                                        var responseResult = _httpClientHelper.Post<WebResponseContent>(configKey, requestParam);
                            //            var responseResult = _httpClientHelper.Post<WebResponseContent>(configKey, requestParam);
                                        _lastPalletCheckTime[childDeviceCode] = DateTime.Now;
                            //            _lastPalletCheckTime[childDeviceCode] = DateTime.Now;
                                        // 如果请求成功,接收 WMS 返回的任务
                                        if (responseResult.IsSuccess && responseResult.Data.Status)
                                        {
                                            QuartzLogHelper.LogInfo(_logger, $"调用WMS接口成功,接口:【{configKey}】,请求参数:【{requestParam}】,响应数据:【{responseResult.Data?.Data}】,耗时:{(DateTime.Now - startTime).TotalMilliseconds}ms", conveyorLine.DeviceCode);
                                            var wmsTask = JsonConvert.DeserializeObject<WMSTaskDTO>(responseResult.Data.Data.ToString());
                                            List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO> { wmsTask };
                                            if (wmsTask != null)
                                                _taskService.ReceiveWMSTask(taskDTOs);
                                        }
                                        else
                                        {
                                            QuartzLogHelper.LogError(_logger, $"调用WMS接口失败,接口:【{configKey}】,请求参数:【{requestParam}】,错误信息:【{responseResult.Data?.Message}】", conveyorLine.DeviceCode);
                                        }
                                    }
                                }
                            }
                            //            // 如果请求成功,接收 WMS 返回的任务
                            //            if (responseResult.IsSuccess && responseResult.Data.Status)
                            //            {
                            //                QuartzLogHelper.LogInfo(_logger, $"调用WMS接口成功,接口:【{configKey}】,请求参数:【{requestParam}】,响应数据:【{responseResult.Data?.Data}】,耗时:{(DateTime.Now - startTime).TotalMilliseconds}ms", conveyorLine.DeviceCode);
                            //                var wmsTask = JsonConvert.DeserializeObject<WMSTaskDTO>(responseResult.Data.Data.ToString());
                            //                List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO> { wmsTask };
                            //                if (wmsTask != null)
                            //                    _taskService.ReceiveWMSTask(taskDTOs);
                            //            }
                            //            else
                            //            {
                            //                QuartzLogHelper.LogError(_logger, $"调用WMS接口失败,接口:【{configKey}】,请求参数:【{requestParam}】,错误信息:【{responseResult.Data?.Message}】", conveyorLine.DeviceCode);
                            //            }
                            //        }
                            //    }
                            //}
                            #endregion 检测是否需要空托盘
@@ -299,48 +299,48 @@
                                        conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
                                    }
                                }
                                else if (!command.Barcode.IsNullOrEmpty() && (childDeviceCode == "11001" || childDeviceCode == "11010"))
                                {
                                    var isWcsTask = _taskService.Db.Queryable<Dt_Task>().Any(x => x.PalletCode == command.Barcode && (x.TaskStatus == (int)TaskOutStatusEnum.OutNew || x.TaskStatus == (int)TaskInStatusEnum.InNew));
                                    var isRobotTask = _robotTaskService.Db.Queryable<Dt_RobotTask>().Any(x => x.RobotTargetAddressPalletCode == command.Barcode);
                                    if (isWcsTask || isRobotTask)
                                    {
                                        continue;
                                    }
                                //else if (!command.Barcode.IsNullOrEmpty() && (childDeviceCode == "11001" || childDeviceCode == "11010"))
                                //{
                                //    var isWcsTask = _taskService.Db.Queryable<Dt_Task>().Any(x => x.PalletCode == command.Barcode && (x.TaskStatus == (int)TaskOutStatusEnum.OutNew || x.TaskStatus == (int)TaskInStatusEnum.InNew));
                                //    var isRobotTask = _robotTaskService.Db.Queryable<Dt_RobotTask>().Any(x => x.RobotTargetAddressPalletCode == command.Barcode);
                                //    if (isWcsTask || isRobotTask)
                                //    {
                                //        continue;
                                //    }
                                    // 调用 WMS 创建空托盘入库任务
                                    string configKey = nameof(ConfigKey.CreateTaskInboundAsync);
                                    string requestParam = new CreateTaskDto()
                                    {
                                        PalletCode = command.Barcode,
                                        SourceAddress = childDeviceCode,
                                        TargetAddress = "GWSC1",  // 目标地址
                                        Roadway = "GWSC1",             // 巷道
                                        WarehouseId = 1,                   // 仓库 ID
                                        PalletType = 1,                             // 托盘类型(默认为1)
                                        TaskType = TaskTypeEnum.InEmpty.GetHashCode()                         // 任务类型(入库/空托盘入库)
                                    }.Serialize();
                                    DateTime startTime = DateTime.Now;
                                //    // 调用 WMS 创建空托盘入库任务
                                //    string configKey = nameof(ConfigKey.CreateTaskInboundAsync);
                                //    string requestParam = new CreateTaskDto()
                                //    {
                                //        PalletCode = command.Barcode,
                                //        SourceAddress = childDeviceCode,
                                //        TargetAddress = "GWSC1",  // 目标地址
                                //        Roadway = "GWSC1",             // 巷道
                                //        WarehouseId = 1,                   // 仓库 ID
                                //        PalletType = 1,                             // 托盘类型(默认为1)
                                //        TaskType = TaskTypeEnum.InEmpty.GetHashCode()                         // 任务类型(入库/空托盘入库)
                                //    }.Serialize();
                                //    DateTime startTime = DateTime.Now;
                                    var responseResult = _httpClientHelper.Post<WebResponseContent>(configKey, requestParam);
                                //    var responseResult = _httpClientHelper.Post<WebResponseContent>(configKey, requestParam);
                                    if (responseResult.IsSuccess && responseResult.Data.Status)
                                    {
                                        QuartzLogHelper.LogInfo(_logger, $"调用WMS接口成功,接口:【{configKey}】,请求参数:【{requestParam}】,响应数据:【{responseResult.Data?.Data}】,耗时:{(DateTime.Now - startTime).TotalMilliseconds}ms", conveyorLine.DeviceCode);
                                        var wmsTask = JsonConvert.DeserializeObject<WMSTaskDTO>(responseResult?.Data?.Data?.ToString());
                                        List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO> { wmsTask };
                                        if (wmsTask == null) continue;
                                //    if (responseResult.IsSuccess && responseResult.Data.Status)
                                //    {
                                //        QuartzLogHelper.LogInfo(_logger, $"调用WMS接口成功,接口:【{configKey}】,请求参数:【{requestParam}】,响应数据:【{responseResult.Data?.Data}】,耗时:{(DateTime.Now - startTime).TotalMilliseconds}ms", conveyorLine.DeviceCode);
                                //        var wmsTask = JsonConvert.DeserializeObject<WMSTaskDTO>(responseResult?.Data?.Data?.ToString());
                                //        List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO> { wmsTask };
                                //        if (wmsTask == null) continue;
                                        if (_taskService.ReceiveWMSTask(taskDTOs).Status)
                                        {
                                            conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
                                        }
                                    }
                                    else
                                    {
                                        QuartzLogHelper.LogError(_logger, $"调用WMS接口失败,接口:【{configKey}】,请求参数:【{requestParam}】,错误信息:【{responseResult.Data?.Message}】", conveyorLine.DeviceCode);
                                    }
                                }
                                //        if (_taskService.ReceiveWMSTask(taskDTOs).Status)
                                //        {
                                //            conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
                                //        }
                                //    }
                                //    else
                                //    {
                                //        QuartzLogHelper.LogError(_logger, $"调用WMS接口失败,接口:【{configKey}】,请求参数:【{requestParam}】,错误信息:【{responseResult.Data?.Message}】", conveyorLine.DeviceCode);
                                //    }
                                //}
                            }
                        }
                        catch (Exception innerEx)