刘磊
2024-11-23 222d2040c2a5e958b5fbd0b7047a8e802ec14288
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_After/CommonConveyorLine_AfterJob.cs
@@ -72,13 +72,9 @@
                if (conveyorLine != null)
                {
                    List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode);
                    List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
                    //List<Task> tasks = new List<Task>();
                    foreach (string childDeviceCode in childDeviceCodes)
                    foreach (var station in stationManagers)
                    {
                        ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode);
                        if (command.ConveyorLineBarcode.Trim().Contains("\0")) command.ConveyorLineBarcode = "";
                        ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(station.stationChildCode);
                        DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString());
                        if (deviceProtocolDetails != null)
@@ -86,16 +82,35 @@
                            MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType);
                            if (method != null)
                            {
                                method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode });
                                method.Invoke(this, new object[] { conveyorLine, command, station });
                            }
                        }
                    }
                    //Task.WaitAll(tasks.ToArray());
                    #region 路由方式
                    //List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
                    //foreach (string childDeviceCode in childDeviceCodes)
                    //{
                    //    ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode);
                    //    if (command.ConveyorLineBarcode.Trim().Contains("\0")) command.ConveyorLineBarcode = "";
                    //    DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString());
                    //    if (deviceProtocolDetails != null)
                    //    {
                    //        MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType);
                    //        if (method != null)
                    //        {
                    //            method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode });
                    //        }
                    //    }
                    //}
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
                Console.Out.WriteLine(nameof(CommonConveyorLine_AfterJob) + ":" + ex.ToString());
            }
            finally
            {
@@ -111,82 +126,66 @@
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestInbound(CommonConveyorLine_After conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        public void RequestInbound(CommonConveyorLine_After conveyorLine, ConveyorLineTaskCommand_After command, Dt_StationManager stationInfo)
        {
            var taskNew = _taskService.QueryCraneConveyorLineTask(command.ConveyorLineTaskNum.ObjToInt(), childDeviceCode);
            var taskNew = _taskService.QueryTaskByPalletCode(command.ConveyorLineBarcode, stationInfo.Roadway);
            if (taskNew == null)
            {
                string barcode = command.ConveyorLineBarcode.TrimEnd();
                if (_taskService.RequestWMSTask(command.ConveyorLineBarcode, childDeviceCode).Result.Status)
                if (_taskService.RequestTask(command.ConveyorLineBarcode, stationInfo).Result.Status)
                {
                    Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
                    if (task != null)
                    {
                        ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                        //taskCommand.InteractiveSignal = command.InteractiveSignal;
                        taskCommand.ResponState = 1;
                        taskCommand.ConveyorLineTaskNum = task.TaskNum;
                        taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(task.NextAddress);
                        conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
            }
            var inTask = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum.ObjToInt(), childDeviceCode);
            if (inTask != null)
            {
                ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(inTask);
                //taskCommand.InteractiveSignal = command.InteractiveSignal;
                taskCommand.ResponState = 1;
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
                _taskService.UpdateTaskStatusToNext(inTask);
            }
        }
        /// <summary>
        /// 输送线入库完成
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        /// <param name="ProtocalDetailValue">线体当前bool读取偏移地址</param>
        public void ConveyorLineInFinish(CommonConveyorLine_After conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode);
            if (task != null && task.TaskState != (int)TaskInStatusEnum.Line_InFinish)
            {
                //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                //conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
                Console.Out.WriteLine(content.Serialize());
            }
        }
        /// <summary>
        /// 输送线请求出信息
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestOutbound(CommonConveyorLine_After conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        {
            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
                    Dt_Task task = _taskService.QueryTaskByPalletCode(command.ConveyorLineBarcode, stationInfo.Roadway);
            if (task != null)
            {
                // ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                //taskCommand.InteractiveSignal = command.InteractiveSignal;
                        //taskCommand.ResponState = 1;
                        //taskCommand.ConveyorLineTaskNum = task.TaskNum;
                        //taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(task.NextAddress);
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, stationInfo.stationChildCode);
                        //conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, 1, task.NextAddress);
                        //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                    }
                }
            }
        }
        /// <summary>
        /// 输送线请求入库
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        //public void RequestInbound(CommonConveyorLine_After conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        //{
        //    var stationInfo = _stationManagerService.GetStationInfoByChildCode(childDeviceCode);
        //    if (stationInfo != null)
        //    {
        //        //_taskService.r
        //    }
        //    var taskNew = _taskService.QueryCraneConveyorLineTask(command.ConveyorLineTaskNum.ObjToInt(), childDeviceCode);
        //    if (taskNew == null)
        //    {
        //        string barcode = command.ConveyorLineBarcode.TrimEnd();
        //        if (_taskService.RequestWMSTask(command.ConveyorLineBarcode, childDeviceCode).Result.Status)
        //        {
        //            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
        //            if (task != null)
        //            {
        //                ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
        //                //taskCommand.InteractiveSignal = command.InteractiveSignal;
        //                taskCommand.ResponState = 1;
        //                taskCommand.ConveyorLineTaskNum = task.TaskNum;
        //                taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(task.NextAddress);
                // conveyorLine.SendCommand(taskCommand, childDeviceCode);
                _taskService.UpdateTaskStatusToNext(task);
            }
        }
        //                //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
        //                _taskService.UpdateTaskStatusToNext(task);
        //            }
        //        }
        //    }
        //}
    }
}
#endregion