1
刘磊
2024-12-26 e5642daf4b6820d0706967e486b16e8d33a46d6d
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -1,21 +1,17 @@
using Autofac.Core;
using HslCommunication;
using Mapster;
using Mapster;
using Newtonsoft.Json;
using Quartz;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using System.Text;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.HttpContextUser;
using WIDESEAWCS_DTO.MOM;
using WIDESEAWCS_IProcessRepository;
using WIDESEAWCS_ITaskInfo_HtyRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
@@ -84,11 +80,31 @@
                                StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
                                if (stackerCraneTaskCommand != null)
                                {
                                    bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                    if (sendFlag)
                                    var taskNum = commonStackerCrane.GetValue<StackerCraneDBName, int>(StackerCraneDBName.TaskNum);
                                    var taskBarCode = commonStackerCrane.GetValue<StackerCraneDBName, string>(StackerCraneDBName.Barcode);
                                    ConsoleHelper.WriteColorLine($"【{commonStackerCrane.DeviceName}】堆垛机任务号:【{taskNum}】,堆垛机托盘号:【{taskBarCode}】,任务任务号:【{task.TaskNum}】任务托盘号:【{task.PalletCode}】", ConsoleColor.DarkBlue);
                                    if (taskNum == 0 && taskBarCode != task.PalletCode)
                                    {
                                        commonStackerCrane.LastTaskType = task.TaskType;
                                        _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                        ConsoleHelper.WriteColorLine($"【{commonStackerCrane.DeviceName}】任务号为【{0}】,托盘号不一致可以下发任务", ConsoleColor.DarkBlue);
                                        bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                        if (sendFlag)
                                        {
                                            StringBuilder builder = new StringBuilder();
                                            builder.AppendLine();
                                            builder.AppendLine($"【{commonStackerCrane.DeviceName}】堆垛机状态:【{commonStackerCrane.StackerCraneStatusDes}】,时间:【{DateTime.Now}】");
                                            builder.AppendLine($"【{commonStackerCrane.DeviceName}】手自动状态:【{commonStackerCrane.StackerCraneAutoStatusDes}】,时间:【{DateTime.Now}】");
                                            builder.AppendLine($"【{commonStackerCrane.DeviceName}】作业状态:【{commonStackerCrane.StackerCraneWorkStatusDes}】,时间:【{DateTime.Now}】");
                                            builder.AppendLine($"【{commonStackerCrane.DeviceName}】下发任务成功,【{JsonConvert.SerializeObject(stackerCraneTaskCommand, Formatting.Indented)}】");
                                            builder.AppendLine($"时间:【{DateTime.Now}】");
                                            builder.AppendLine();
                                            ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue);
                                            commonStackerCrane.LastTaskType = task.TaskType;
                                            _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                        }
                                    }
                                    else
                                    {
                                        ConsoleHelper.WriteColorLine($"【{commonStackerCrane.DeviceName}】任务号不为【{0}】,或者托盘号一致不可以下发任务", ConsoleColor.DarkBlue);
                                    }
                                }
                            }
@@ -98,28 +114,25 @@
                    #region 调用事件总线通知前端
                    var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
                    if (tokenInfos == null || !tokenInfos.Any())
                    if (tokenInfos != null && tokenInfos.Any())
                    {
                        //throw new Exception(commonStackerCrane.DeviceName + "缓存中未找到Token缓存");
                        return Task.CompletedTask;
                    }
                    var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList();
                    var userIds = tokenInfos?.Select(x => x.UserId).ToList();
                        var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList();
                        var userIds = tokenInfos?.Select(x => x.UserId).ToList();
                    object obj = new
                    {
                        commonStackerCrane.StackerCraneStatusDes,
                        commonStackerCrane.StackerCraneAutoStatusDes,
                        commonStackerCrane.StackerCraneWorkStatusDes,
                        commonStackerCrane.DeviceCode,
                        commonStackerCrane.DeviceName,
                        commonStackerCrane.CurrentTaskNum,
                        commonStackerCrane.LastTaskNum,
                    };
                    _noticeService.StackerData(userIds?.FirstOrDefault(), userTokenIds, new { commonStackerCrane.DeviceName, data = obj });
                        object obj = new
                        {
                            commonStackerCrane.StackerCraneStatusDes,
                            commonStackerCrane.StackerCraneAutoStatusDes,
                            commonStackerCrane.StackerCraneWorkStatusDes,
                            commonStackerCrane.DeviceCode,
                            commonStackerCrane.DeviceName,
                            commonStackerCrane.CurrentTaskNum,
                            commonStackerCrane.LastTaskNum,
                        };
                        _noticeService.StackerData(userIds?.FirstOrDefault(), userTokenIds, new { commonStackerCrane.DeviceName, data = obj });
                    }
                    #endregion 调用事件总线通知前端
                }
            }
            catch (Exception ex)
@@ -142,8 +155,7 @@
            CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane;
            if (commonStackerCrane != null)
            {
                //var x = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType);
                //if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
                if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
                {
                    //Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
                    ConsoleHelper.WriteColorLine($"【{commonStackerCrane.DeviceName}】任务完成,任务号:【{e.TaskNum}】", ConsoleColor.Blue);
@@ -291,7 +303,7 @@
                            _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{task.TargetAddress}】对应的通讯对象,无法判断出库站台是否被占用");
                        }
                    }
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到站台【{task.TargetAddress}】信息,无法校验站台");
                    //_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到站台【{task.TargetAddress}】信息,无法校验站台");
                }
            }
            else
@@ -303,7 +315,7 @@
                    if (device != null)
                    {
                        CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                        //if (conveyorLine.IsOccupied(router.ChildPosi))//出库站台未被占用
                        if (conveyorLine.IsOccupiedx(router.ChildPosi))//出库站台未被占用
                        {
                            return task;
                        }
@@ -320,7 +332,6 @@
            }
            return null;
        }
        /// <summary>
        /// 查找其他出库任务的辅助方法(排除指定任务ID的任务)
@@ -347,7 +358,7 @@
                {
                    return candidateTask;
                }
                ConsoleHelper.WriteErrorLine($"任务号:【{occupiedStation.TaskNum}】出库地址:【{occupiedStation.NextAddress}】不允许放货");
                ConsoleHelper.WriteErrorLine($"任务号:【{candidateTask.TaskNum}】出库地址:【{candidateTask.NextAddress}】不允许放货");
            }
            return null;
@@ -444,7 +455,6 @@
                }
                else
                {
                    if (task.TargetAddress == "002-021-001" && task.Roadway.Contains("JZ") && task.TaskType == (int)TaskOutboundTypeEnum.OutTray)
                    {
                        string[] endCodes = task.NextAddress.Split("-");
@@ -518,6 +528,5 @@
            }
            return stackerCraneTaskCommand;
        }
    }
}