wanshenmean
2 天以前 ff006f77f6267fc0d2c4ee810d897a85165f5b8f
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
@@ -1,16 +1,11 @@
using MapsterMapper;
using Masuit.Tools;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Quartz;
using Serilog;
using SqlSugar;
using WIDESEA_Core;
using WIDESEAWCS_Common.HttpEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
@@ -228,7 +223,11 @@
                            {
                                // 如果 WCS_ACK 为 1,先清除(表示处理过上一次请求)
                                if (command.WCS_ACK == 1)
                                    conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)0, childDeviceCode);
                                {
                                    conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (byte)0, childDeviceCode);
                                    //Thread.Sleep(300);
                                    //conveyorLine.SetValue(ConveyorLineDBNameNew.Target, (short)0, childDeviceCode);
                                }
                                // 处理手动入库任务(起点为线体点位的任务)
                                try
@@ -247,17 +246,36 @@
                                }
                                continue;
                            }
                            else
                            {
                                if (childDeviceCode == "2103" || childDeviceCode == "2101")
                                {
                                    try
                                    {
                                        var task = _taskService.QueryManualInboundTask(childDeviceCode);
                                        if (task != null)
                                        {
                                            QuartzLogHelper.LogInfo(_logger, $"获取到输送线开始任务,任务号:{task.TaskNum},状态: {task.TaskStatus},当前地址:{conveyorLine.DeviceCode}", conveyorLine.DeviceCode);
                                            var handler = new ManualInboundTaskHandler(_taskService, _logger);
                                            handler.WriteTaskToPlc(conveyorLine, childDeviceCode, task);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        QuartzLogHelper.LogError(_logger, ex, "处理手动入库任务异常", $"处理手动入库任务异常: {ex.Message}", "CommonConveyorLineNewJob");
                                    }
                                }
                            }
                            // ========== 处理无托盘条码的情况 ==========
                            // 无托盘条码时,请求出库任务
                            if (command.Barcode.IsNullOrEmpty() || command.Barcode.Replace("\0", "") == "")
                            // 如果 PLC_STB 为 1,但没有任务号,可能是新任务的开始,先请求出库任务(适用于无条码的情况)
                            if (command.TaskNo == 1000)
                            {
                                _conveyorLineDispatch.RequestOutbound(conveyorLine, command, childDeviceCode);
                                continue;
                            }
                            // ========== 处理已有任务号的情况 ==========
                            if (command.TaskNo > 0 && !command.Barcode.IsNullOrEmpty())
                            if (command.TaskNo > 0)
                            {
                                // 查询正在执行的任务
                                Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNo, childDeviceCode);
@@ -299,48 +317,6 @@
                                        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;
                                //    }
                                //    // 调用 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);
                                //    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);
                                //    }
                                //}
                            }
                        }
                        catch (Exception innerEx)