1
huangxiaoqiang
9 天以前 1cfc0c965c6d706548f7f685c456f7fc35a01be8
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs
@@ -25,6 +25,7 @@
using Newtonsoft.Json;
using Quartz;
using SqlSugar;
using System.ComponentModel.Design;
using System.Reflection;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Common;
@@ -132,7 +133,7 @@
                            }
                        }
                        if (childDeviceCode == "1670"||childDeviceCode=="1666"||childDeviceCode=="1548"||childDeviceCode=="1448")
                        if (childDeviceCode == "1670" || childDeviceCode == "1666" || childDeviceCode == "1548" || childDeviceCode == "1448")
                        {
                            Platform platform = _platFormRepository.QueryFirst(x => x.DeviceCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active");
                            if (platform != null)
@@ -211,15 +212,20 @@
                else
                {
                    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"))
                    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);
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                    _taskService.UpdateTaskStatusToNext(task);
                    //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                    if (sendFlag)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
            }
            catch (Exception ex)
@@ -249,9 +255,14 @@
                if (newTask != null)
                {
                    ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask);
                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                    _taskService.UpdateData(newTask);
                    //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                    if (sendFlag)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        _taskService.UpdateData(newTask);
                    }
                }
            }
        }
@@ -272,7 +283,7 @@
                if (content.Status)
                {
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState,Convert.ToInt16(1), childDeviceCode);
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                }
                Console.Out.WriteLine(content.Serialize());
@@ -292,13 +303,18 @@
            if (task != null)
            {
                ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
                conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                _taskService.UpdateTaskStatusToNext(task);
                if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray)
                bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                if (sendFlag)
                {
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                    _taskService.UpdateTaskStatusToNext(task);
                    if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray)
                    {
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
            }
        }
@@ -346,18 +362,28 @@
                    if (newTask != null)
                    {
                        ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask);
                        conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        _taskService.UpdateData(newTask);
                        //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                        if (sendFlag)
                        {
                            conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                            _taskService.UpdateData(newTask);
                        }
                    }
                }
                else
                {
                    ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                    taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode);
                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                    _taskService.UpdateTaskStatusToNext(task);
                    //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                    if (sendFlag)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
            }
        }
@@ -404,9 +430,13 @@
                    }
                }
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
                conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                content = _taskService.UpdateTaskStatusToNext(task);
                //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                if (sendFlag)
                {
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                    content = _taskService.UpdateTaskStatusToNext(task);
                }
            }
            else
            {
@@ -437,11 +467,16 @@
                        }
                    }
                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                    //conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    taskNext.ExceptionMessage = log;
                    content = _taskService.UpdateTaskStatusToNext(taskNext);
                    bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                    if (sendFlag)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode);
                        taskNext.ExceptionMessage = log;
                        content = _taskService.UpdateTaskStatusToNext(taskNext);
                    }
                }
            }
        }
@@ -524,7 +559,43 @@
            }
            return content;
        }
        public bool SendCommand(ConveyorLineTaskCommand_After taskCommand, CommonConveyorLine_GW conveyorLine, string childDeviceCode)
        {
            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(taskCommand.ConveyorLineTargetAddress), childDeviceCode);
            Thread.Sleep(100);
            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode);
            Thread.Sleep(100);
            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode);
            for (int i = 0; i < 6; i++)
            {
                ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode);
                if (command != null)
                {
                    if (command.ConveyorLineBarcode == taskCommand.ConveyorLineBarcode && command.ConveyorLineTaskNum == taskCommand.ConveyorLineTaskNum && command.ConveyorLineTargetAddress == taskCommand.ConveyorLineTargetAddress)
                    {
                        return true;
                    }
                    if (command.ConveyorLineTargetAddress != taskCommand.ConveyorLineTargetAddress)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(taskCommand.ConveyorLineTargetAddress), childDeviceCode);
                        Thread.Sleep(100);
                    }
                    if (command.ConveyorLineBarcode != taskCommand.ConveyorLineBarcode)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode);
                        Thread.Sleep(100);
                    }
                    if (command.ConveyorLineTaskNum != taskCommand.ConveyorLineTaskNum)
                    {
                        conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode); Thread.Sleep(100);
                    }
                }
            }
            WriteInfo(conveyorLine.DeviceName, $"写入任务失败任务号【{taskCommand.ConveyorLineTaskNum}】托盘号【{taskCommand.ConveyorLineBarcode}】目标地址【{taskCommand.ConveyorLineTargetAddress}】当前节点【{childDeviceCode}】");
            return false;
        }
    }
}
#endregion