1
huangxiaoqiang
4 天以前 ce8f204db035e6fb7147edb4440591502f5c8567
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/GWTask/RequestInbound.cs
@@ -1,5 +1,7 @@
using Masuit.Tools;
using Mapster;
using Masuit.Tools;
using Newtonsoft.Json;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
@@ -183,7 +185,7 @@
                    //    break;
                    //}
                    RequestWmsTask(conveyorLine, command, childDeviceCode,stationManager);
                    RequestWmsTask(conveyorLine, command, childDeviceCode, stationManager);
                    break;
            }
        }
@@ -238,34 +240,23 @@
        {
            if (command.ConveyorLineBarcode != "NoRead")
            {
                //var config = _sys_ConfigService.GetByConfigKey("SYS_BASE", "ISFRINTRAY");
                //if (config.ConfigValue == "1")
                //{
                //    Random random = new Random();
                //    var task = new Dt_Task()
                //    {
                //        CurrentAddress = childDeviceCode,
                //        Grade = 1,
                //        NextAddress = "2066",
                //        PalletCode = command.ConveyorLineBarcode,
                //        Roadway = "FR",
                //        SourceAddress = childDeviceCode,
                //        TargetAddress = "2066",
                //        TaskNum = random.Next(1,9999),
                //        TaskType = (int)TaskInboundTypeEnum.InTray,
                //        TaskState = (int)TaskInStatusEnum.Line_InExecuting,
                //        WMSId = 0
                //    };
                //    var taskCommand = MapTaskCommand(task, command);
                //    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                //}
                //else
                //{
                var taskDTO = CreateEmptyTrayTaskDto(command.ConveyorLineBarcode, childDeviceCode);
                if (_taskRepository.QueryFirst(x => x.PalletCode == taskDTO.PalletCode) != null)
                if (_taskRepository.QueryFirst(x => x.PalletCode == command.ConveyorLineBarcode) != null)
                {
                    WriteInfo(conveyorLine.DeviceName, "当前托盘存在任务");
                    List<string> strings = new List<string>() { "1743", "1739", "1837", "1841" };
                    var taskExecuting = _taskRepository.QueryFirst(x => x.PalletCode == command.ConveyorLineBarcode && x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting && strings.Contains(x.TargetAddress));
                    if (taskExecuting != null)
                    {
                        taskExecuting.ExceptionMessage = "未接收到线体完成信号系统内部自动完成";
                        _taskService.Delete(taskExecuting);
                    }
                    ConsoleHelper.WriteErrorLine($"当前托盘存在任务:【{command.ConveyorLineBarcode}】");
                    WriteInfo(conveyorLine.DeviceName, $"当前托盘存在任务{command.ConveyorLineBarcode}");
                    return;
                }
@@ -276,9 +267,13 @@
                    if (task != null)
                    {
                        var taskCommand = MapTaskCommand(task, command);
                        conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        //ConveyorLineSendFinish(conveyorLine, childDeviceCode, true);
                        _taskService.UpdateTaskStatusToNext(task);
                        //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                        if (sendFlag)
                        {
                            _taskService.UpdateTaskStatusToNext(task);
                        }
                    }
                }
                //}
@@ -320,43 +315,51 @@
        /// </summary>
        private async void RequestWmsTask(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, Dt_StationManager stationManager)
        {
            //var taskGW = _taskRepository.QueryFirst(x => x.TargetAddress == childDeviceCode && (x.TaskState == (int)TaskOutStatusEnum.OutFinish || x.TaskState == (int)TaskOutStatusEnum.OutPending));
            //if (taskGW != null)
            //    _taskRepository.DeleteData(taskGW);
            if (command.ConveyorLineBarcode.IsNullOrEmpty()) return;
            var content = await _taskService.RequestWMSTask(command.ConveyorLineBarcode, childDeviceCode);
            if (content.Status)
            try
            {
                var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode);
                if (task != null)
                if (command.ConveyorLineBarcode.IsNullOrEmpty()) return;
                var content = await _taskService.RequestWMSTask(command.ConveyorLineBarcode, childDeviceCode);
                if (content.Status)
                {
                    //conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, task.TaskNum, childDeviceCode);
                    //conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, task.NextAddress, childDeviceCode);
                    //conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, command.ConveyorLineBarcode, childDeviceCode);
                    var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList();
                    if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2"))
                    var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode);
                    if (task != null)
                    {
                        ConsoleHelper.WriteErrorLine($"托盘号:【{command.ConveyorLineBarcode}】高温二已存在【{GWTask.Count}】个任务大于2个任务不可下发");
                        return;
                    }
                    ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode);
                        var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList();
                        if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2"))
                        {
                            ConsoleHelper.WriteErrorLine($"托盘号:【{command.ConveyorLineBarcode}】高温二已存在【{GWTask.Count}】个任务大于2个任务不可下发");
                            return;
                        }
                        ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                        //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    _taskService.UpdateTaskStatusToNext(task);
                        bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                        if (sendFlag)
                        {
                            conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                            _taskService.UpdateTaskStatusToNext(task);
                        }
                    }
                }
                else
                {
                    if (content.Message != "请求过于频繁,请稍后再试" || content.Message != "无法获取目标地址")
                    {
                        WriteInfo(conveyorLine.DeviceName, content.Message);
                        conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, stationManager.stationNGChildCode, childDeviceCode);
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        ConsoleHelper.WriteErrorLine($"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】请求点位:【{childDeviceCode}】异常信息【{content.Message}】");
                        WriteInfo(conveyorLine.DeviceName, $"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】请求点位:【{childDeviceCode}】异常信息【{content.Message}】");
                    }
                    ConsoleHelper.WriteErrorLine($"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】请求点位:【{childDeviceCode}】异常信息【{content.Message}】");
                }
            }
            else
            catch (Exception ex)
            {
                if (content.Message != "请求过于频繁,请稍后再试")
                {
                    WriteInfo(conveyorLine.DeviceName, content.Message);
                    conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, stationManager.stationNGChildCode, childDeviceCode);
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode);
                    ConsoleHelper.WriteErrorLine($"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】请求点位:【{childDeviceCode}】异常信息【{content.Message}】");
                    WriteInfo(conveyorLine.DeviceName, $"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】请求点位:【{childDeviceCode}】异常信息【{content.Message}】");
                }
                WriteInfo(conveyorLine.DeviceName, $"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】请求点位:【{childDeviceCode}】异常信息【{ex.Message}】异常行【{ex.StackTrace}】");
            }
        }
        /// <summary>
@@ -399,7 +402,7 @@
            if (command.ConveyorLineBarcode.IsNullOrEmpty())
            {
                conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 2, childDeviceCode);
                conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                return;
            }
@@ -407,8 +410,8 @@
            if (conveyorLine.ReadValue(ConveyorLineDBName_After.InteractiveSignal, childDeviceCode).ObjToInt() == 0) //托盘正反信号
            {
            };
            }
            ;
            conveyorLine.ReadValue(ConveyorLineDBName_After.InteractiveSignal, childDeviceCode);  //托盘有无电芯信号
        }