1
wangxinhui
2024-12-30 5732962e2fe146d81273b4b02faaec87c05f0417
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/²âÊԼܲÖ/GroundStationJob_CSJ.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
@@ -12,6 +13,7 @@
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_Tasks.HoisterJob;
namespace WIDESEAWCS_Tasks
{
@@ -44,42 +46,100 @@
                    WriteInfo(nameof(GroundStationJob_CSJ), "调度错误,设备对象传值为null");
                    return Task.CompletedTask;
                }
                List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).ToList();
                List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
                foreach (var item in stationMangers)
                foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
                {
                    bool isCanPut = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, item.StationCode);
                    bool isCanTake = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanTake, item.StationCode);
                    bool putRequest = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_PutRequest, item.StationCode);
                    bool putFinish = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_PutFinish, item.StationCode);
                    bool takeRequest = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_TakeRequest, item.StationCode);
                    bool takeFinish = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_TakeFinish, item.StationCode);
                    if (item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt())
                    try
                    {
                        Dt_Task task = _taskRepository.QueryFirst(x => x.DeviceCode == item.StackerCraneCode && x.TaskState == TaskStatusEnum.New.ObjToInt() && string.IsNullOrEmpty(x.NextAddress));
                        if (task != null && isCanPut && !isCanTake && !putRequest && !putFinish && !takeRequest && !takeFinish)
                        bool isCanPut = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, item.StationCode);
                        bool isCanTake = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanTake, item.StationCode);
                        bool putRequest = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_PutRequest, item.StationCode);
                        bool putFinish = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_PutFinish, item.StationCode);
                        bool takeRequest = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_TakeRequest, item.StationCode);
                        bool takeFinish = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_TakeFinish, item.StationCode);
                        if (item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt())
                        {
                            Dt_Task task = _taskRepository.QueryFirst(x => x.DeviceCode == item.StackerCraneCode && x.TaskState == TaskStatusEnum.SC_Execute.ObjToInt() && string.IsNullOrEmpty(x.NextAddress));
                            if (task != null && isCanPut && !isCanTake && !putRequest && !putFinish && !takeRequest && !takeFinish)
                            {
                                string oldAddress = task.NextAddress;
                                int oldStatus = task.TaskState;
                                task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
                                task.NextAddress = item.StationCode;
                                _taskRepository.UpdateData(task);
                                _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"系统自动流程,目标地址由{oldAddress}变更为{task.NextAddress},任务状态由{oldStatus}变更为{task.TaskState}");
                            }
                        }
                        if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt())
                        {
                            Dt_Task task = _taskRepository.QueryFirst(x => (x.TargetAddress == item.StackerCraneCode || string.IsNullOrEmpty(x.TargetAddress) || x.NextAddress == item.StackerCraneCode || string.IsNullOrEmpty(x.NextAddress)) && (x.TaskState == TaskStatusEnum.New.ObjToInt() || x.TaskState == TaskStatusEnum.SC_Execute.ObjToInt()) && x.SourceAddress == item.StationCode || x.CurrentAddress==item.AGVStationCode);
                            if (task != null)
                            {
                                string oldAddress = task.NextAddress;
                                int oldStatus = task.TaskState;
                                Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.StationCode);
                                if (stationManger == null)
                                {
                                    WriteInfo(item.StationName, $"未找到对应站台信息,设备编号:{item.StationCode},任务号:{task.TaskNum}");
                                    break;
                                }
                                string? locationCode = _taskService.RequestAssignLocation(task.TaskNum, stationManger.StackerCraneCode);
                                if (string.IsNullOrEmpty(locationCode))
                                {
                                    WriteInfo(item.StationName, $"请求分配货位返回信息错误,设备编号:{item.StationCode},任务号:{task.TaskNum}");
                                    break;
                                }
                                task.CurrentAddress = stationManger.StackerCraneStationCode;
                                task.TargetAddress = locationCode;
                                task.NextAddress = locationCode;
                                task.DeviceCode = stationManger.StackerCraneCode;
                                _taskRepository.UpdateData(task);
                                _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"系统自动流程,目标地址由{oldAddress}变更为{task.NextAddress},任务状态由{oldStatus}变更为{task.TaskState}");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteError(device.DeviceCode, $"{item}交互错误", ex);
                    }
                }
                foreach (var item in stationMangers.Where(x => !deviceStations.Contains(x.StationCode)))
                {
                    try
                    {
                        Dt_Task task = _taskRepository.QueryFirst(x => x.TaskState == TaskStatusEnum.New.ObjToInt() && x.SourceAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType));
                        if (task != null)
                        {
                            Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.StationCode);
                            if (stationManger == null)
                            {
                                WriteInfo(item.StationName, $"未找到对应站台信息,设备编号:{item.StationCode},任务号:{task.TaskNum}");
                                break;
                            }
                            string? locationCode = _taskService.RequestAssignLocation(task.TaskNum, stationManger.StackerCraneCode);
                            if (string.IsNullOrEmpty(locationCode))
                            {
                                WriteInfo(item.StationName, $"请求分配货位返回信息错误,设备编号:{item.StationCode},任务号:{task.TaskNum}");
                                break;
                            }
                            string oldAddress = task.NextAddress;
                            int oldStatus = task.TaskState;
                            task.CurrentAddress = stationManger.StackerCraneStationCode;
                            task.TargetAddress = locationCode;
                            task.NextAddress = locationCode;
                            task.DeviceCode = stationManger.StackerCraneCode;
                            task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
                            task.NextAddress = item.StationCode;
                            _taskRepository.UpdateData(task);
                            _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"系统自动流程,目标地址由{oldAddress}变更为{task.NextAddress},任务状态由{oldStatus}变更为{task.TaskState}");
                        }
                    }
                    else if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt())
                    catch (Exception ex)
                    {
                        Dt_Task task = _taskRepository.QueryFirst(x => x.TargetAddress == item.StackerCraneCode && x.TaskState == TaskStatusEnum.New.ObjToInt() && string.IsNullOrEmpty(x.NextAddress));
                        if (task != null && isCanPut && !isCanTake && !putRequest && !putFinish && !takeRequest && !takeFinish)
                        {
                            string oldAddress = task.NextAddress;
                            int oldStatus = task.TaskState;
                            task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
                            task.NextAddress = item.StationCode;
                            _taskRepository.UpdateData(task);
                            _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"系统自动流程,目标地址由{oldAddress}变更为{task.NextAddress},任务状态由{oldStatus}变更为{task.TaskState}");
                        }
                    }
                }
            }