1
wangxinhui
2025-06-10 3443d00c1c23f84d8559e802a27eb9ba7ff0858a
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/°å²Ä²Ö/ConveyorLineJob_BC.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using Quartz;
using SqlSugar;
using System;
@@ -98,7 +99,21 @@
                        ConveyorLineSignal conveyorLineSignalRead = conveyorLineInfoRead.Signal.ByteToBoolObject<ConveyorLineSignal>();
                        ConveyorLineSignal conveyorLineSignalWrite = conveyorLineInfoWrite.Signal.ByteToBoolObject<ConveyorLineSignal>();
                        if (item.StationType == StationTypeEnum.StationType_PakcPallet.ObjToInt())
                        {
                            if (conveyorLineSignalRead.STB && !conveyorLineSignalWrite.ACK)
                            {
                                device.SetValue(W_ConveyorLineDB.TaskNum, 1, item.StationCode);
                                device.SetValue(W_ConveyorLineDB.StartPos, item.StationCode, item.StationCode);
                                device.SetValue(W_ConveyorLineDB.EndPos, 1102, item.StationCode);
                                device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode);
                                device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode);
                            }
                            else if(!conveyorLineSignalRead.STB && conveyorLineSignalWrite.ACK)
                            {
                                device.SetValue(W_ConveyorLineDB.ACK, false, item.StationCode);
                            }
                        }
                        if (item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt())
                        {
                            {
@@ -106,13 +121,16 @@
                                Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) /*&& x.DeviceCode == item.StationDeviceCode*/ && (x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.WarehouseId == warehouseDevice.WarehouseId);
                                if (task != null && conveyorLineInfoWrite.Spare2 == 0 && conveyorLineStatus.Goods)
                                {
                                    List<string> stations = _routerExtension.GetEndPoint(item.StationCode, TaskTypeEnum.Inbound.ObjToInt()).Select(x => x.NextPosi).ToList();
                                    WebResponseContent responseContent = _taskService.RequestWMSAssignRoadway(stations, task.TaskNum, conveyorLineInfoRead.Spare2);
                                    if (responseContent.Status)
                                    {
                                        device.SetValue(W_ConveyorLineDB.Spare2, 1, item.StationCode);
                                        _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, deviceCode: item.StationDeviceCode, roadwayNo: responseContent.Data.ToString() ?? "");
                                    }
                                    //List<string> stations = _routerExtension.GetEndPoint(item.StationCode, TaskTypeEnum.Inbound.ObjToInt()).Select(x => x.NextPosi).ToList();
                                    ////分配巷道
                                    //WebResponseContent responseContent = _taskService.RequestWMSAssignRoadway(stations, task.TaskNum, conveyorLineInfoRead.Spare2);
                                    //if (responseContent.Status)
                                    //{
                                    //    device.SetValue(W_ConveyorLineDB.Spare2, 1, item.StationCode);
                                    //    _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, deviceCode: item.StationDeviceCode, roadwayNo: responseContent.Data.ToString() ?? "");
                                    //}
                                    device.SetValue(W_ConveyorLineDB.Spare2, 1, item.StationCode);
                                    _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, deviceCode: item.StationDeviceCode);
                                }
                                else
                                {
@@ -132,6 +150,17 @@
                                    Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.DeviceCode == item.StationDeviceCode && (x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt()) && x.PalletCode == conveyorLineInfoRead.Barcode && x.WarehouseId == warehouseDevice.WarehouseId);
                                    if (task != null)
                                    {
                                        List<string> stations = _routerExtension.GetEndPoint(item.StationCode, TaskTypeEnum.Inbound.ObjToInt()).Select(x => x.NextPosi).ToList();
                                        //分配巷道
                                        if (stations.Count>1)
                                        {
                                            WebResponseContent responseContent = _taskService.RequestWMSAssignRoadway(stations, task.TaskNum, conveyorLineInfoRead.Spare2);
                                            if (responseContent.Status)
                                            {
                                                _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, roadwayNo: responseContent.Data.ToString() ?? "",heightType: conveyorLineInfoRead.Spare2);
                                            }
                                        }
                                        device.SetValue(W_ConveyorLineDB.Spare2, 0, item.StationCode);
                                        string currentAddress = task.CurrentAddress;
@@ -173,13 +202,22 @@
                                        else
                                        {
                                            //task.NextAddress可能是router.NextPosi
                                            device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode);
                                            nextAddress = router.NextPosi;
                                            device.SetValue(W_ConveyorLineDB.EndPos, router.NextPosi, item.StationCode);
                                        }
                                        device.SetValue(W_ConveyorLineDB.TaskNum, task.TaskNum, item.StationCode);
                                        device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress, item.StationCode);
                                        device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode);
                                        device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode);
                                        _taskService.UpdateTask(task, taskState, currentAddress: currentAddress, nextAddress: nextAddress, targetAddress: targetAddress, deviceCode: deviceCode);
                                        if (router.IsEnd)
                                        {
                                            _taskService.UpdateTask(task, taskState, currentAddress: currentAddress, nextAddress: nextAddress, targetAddress: targetAddress, deviceCode: deviceCode);
                                        }
                                        else
                                        {
                                            _taskService.UpdateTask(task, taskState, nextAddress: nextAddress);
                                        }
                                    }
                                    else
                                    {
@@ -187,10 +225,11 @@
                                    }
                                    #endregion
                                }
                                else//生产退库
                                else//生产退库 //换巷道入库
                                {
                                    #region ç”Ÿäº§é€€åº“,带任务号查询任务
                                    Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNum && x.NextAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.WarehouseId == warehouseDevice.WarehouseId); // å¸¦ä»»åŠ¡å·æŸ¥è¯¢ä»»åŠ¡
                                    Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNum && x.NextAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.WarehouseId == warehouseDevice.WarehouseId && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt()); // å¸¦ä»»åŠ¡å·æŸ¥è¯¢ä»»åŠ¡
                                    Dt_Task taskIn = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNum && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.DeviceCode == item.StationDeviceCode && x.NextAddress == item.StationCode && x.WarehouseId == warehouseDevice.WarehouseId && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt()); // å¸¦ä»»åŠ¡å·æŸ¥è¯¢ä»»åŠ¡
                                    if (task != null)
                                    {
                                        List<string> stations = _routerExtension.GetEndPoint(item.StationCode, TaskTypeEnum.Inbound.ObjToInt()).Select(x => x.NextPosi).ToList();
@@ -231,7 +270,8 @@
                                                    taskState = TaskStatusEnum.SC_Execute;
                                                    deviceCode = item.StackerCraneCode;
                                                    roadwayNo = responseContent.Data.ToString();
                                                    device.SetValue(W_ConveyorLineDB.EndPos, task.CurrentAddress, item.StationCode);
                                                    device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode);
                                                    device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress, item.StationCode);
                                                }
                                                else
                                                {
@@ -242,15 +282,63 @@
                                            else
                                            {
                                                //task.NextAddress可能是router.NextPosi
                                                device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode);
                                                roadwayNo = responseContent.Data.ToString();
                                                deviceCode = router.ChildPosiDeviceCode;
                                                currentAddress = router.StartPosi;
                                                nextAddress= router.NextPosi;
                                                device.SetValue(W_ConveyorLineDB.EndPos, router.NextPosi, item.StationCode);
                                                device.SetValue(W_ConveyorLineDB.StartPos, router.StartPosi, item.StationCode);
                                            }
                                            device.SetValue(W_ConveyorLineDB.TaskNum, task.TaskNum, item.StationCode);
                                            device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress, item.StationCode);
                                            device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode);
                                            device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode);
                                            _taskService.UpdateTask(task, taskState, currentAddress: currentAddress, nextAddress: nextAddress, targetAddress: targetAddress, deviceCode: deviceCode, roadwayNo: roadwayNo);
                                            _taskService.UpdateTask(task, taskState, currentAddress: currentAddress, nextAddress: nextAddress, targetAddress: targetAddress, deviceCode: deviceCode, roadwayNo: roadwayNo,heightType: conveyorLineInfoRead.Spare2);
                                        }
                                       
                                    }
                                    if (taskIn!=null)
                                    {
                                        string currentAddress = taskIn.CurrentAddress;
                                        string nextAddress = taskIn.NextAddress;
                                        string targetAddress = taskIn.TargetAddress;
                                        string deviceCode = taskIn.DeviceCode;
                                        TaskStatusEnum taskState = (TaskStatusEnum)taskIn.TaskState;
                                        List<Dt_Router> routers = _routerService.QueryNextRoutes(item.StationCode, taskIn.Roadway, taskIn.TaskType);
                                        Dt_Router? router = routers.FirstOrDefault();
                                        if (routers == null || routers.Count == 0 || router == null)
                                        {
                                            WriteError(item.StationName, $"未找到对应路由信息,设备编号:{item.StationCode},任务号:{taskIn.TaskNum}");
                                            continue;
                                        }
                                        if (routers.Count > 1)
                                        {
                                            WriteError(item.StationName, $"路由信息配置错误,设备编号:{item.StationCode},任务号:{taskIn.TaskNum}");
                                            continue;
                                        }
                                        if (router.IsEnd)
                                        {
                                            string? targetLoca = _taskService.RequestAssignLocationByHeight(taskIn.TaskNum, taskIn.Roadway, taskIn.HeightType);
                                            if (!string.IsNullOrEmpty(targetLoca))
                                            {
                                                currentAddress = item.StackerCraneStationCode;
                                                targetAddress = targetLoca;
                                                nextAddress = targetLoca;
                                                taskState = TaskStatusEnum.SC_Execute;
                                                deviceCode = item.StackerCraneCode;
                                                device.SetValue(W_ConveyorLineDB.EndPos, taskIn.CurrentAddress, item.StationCode);
                                            }
                                            else
                                            {
                                                WriteError(item.StationName, $"请求分配货位失败,设备编号:{item.StationCode},任务号:{task.TaskNum}");
                                                continue;
                                            }
                                        }
                                        device.SetValue(W_ConveyorLineDB.TaskNum, taskIn.TaskNum, item.StationCode);
                                        device.SetValue(W_ConveyorLineDB.StartPos, taskIn.CurrentAddress, item.StationCode);
                                        device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode);
                                        device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode);
                                        _taskService.UpdateTask(taskIn, taskState, currentAddress: currentAddress, nextAddress: nextAddress, targetAddress: targetAddress, deviceCode: deviceCode);
                                    }
                                    #endregion
                                }
@@ -272,6 +360,10 @@
                                    device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode);
                                    device.SetValue(W_ConveyorLineDB.STB, true, item.StationCode);
                                }
                                //else //调拨使用
                                //{
                                //    device.SetValue(W_ConveyorLineDB.STB, true, item.StationCode);
                                //}
                                //{
                                //    task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && string.IsNullOrEmpty(x.DeviceCode) && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.WarehouseId == warehouseDevice.WarehouseId);
                                //    if (task != null)