liulijun
21 小时以前 5270308151082506e0e6df2c72d278d2976ec860
ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_Tasks/³ÉÆ·²Ö/StackerCraneJob_CP.cs
@@ -1,5 +1,8 @@
using Microsoft.AspNetCore.Components.Routing;
using HslCommunication.WebSocket;
using Microsoft.AspNetCore.Components.Routing;
using Newtonsoft.Json;
using Quartz;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -7,6 +10,7 @@
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
@@ -15,14 +19,14 @@
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_Tasks.StackerCraneJob;
using WIDESEAWCS_Tasks;
using WIDESEAWCS_Core;
using SqlSugar.Extensions;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_Tasks;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
using WIDESEAWCS_Tasks.原料库;
namespace WIDESEAWCS_Tasks
{
@@ -35,8 +39,9 @@
        private readonly IRouterService _routerService;
        private readonly IRouterRepository _routerRepository;
        private readonly IStationMangerRepository _stationMangerRepository;
        private readonly WebSocketServer _webSocketServer;
        public StackerCraneJob_CP(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository,IRouterRepository routerRepository)
        public StackerCraneJob_CP(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository,IRouterRepository routerRepository, WebSocketServer webSocketServer)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
@@ -44,6 +49,7 @@
            _routerService = routerService;
            _stationMangerRepository = stationMangerRepository;
            _routerRepository = routerRepository;
            _webSocketServer = webSocketServer;
        }
        public Task Execute(IJobExecutionContext context)
@@ -57,8 +63,13 @@
                    {
                        commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
                    }
                    commonStackerCrane.CheckStackerCraneTaskCompleted();//防止任务完成事件监测超时,再手动触发一次
                    if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal && commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                    //commonStackerCrane.CheckStackerCraneTaskCompleted();//防止任务完成事件监测超时,再手动触发一次
                    if (commonStackerCrane.CurrentTaskNum > 0 && (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.WorkCompleted || commonStackerCrane.Communicator.Read<short>("DB1000.40.0") == 3))
                    {
                        StackerCraneTaskCompletedEventArgs e = new StackerCraneTaskCompletedEventArgs(commonStackerCrane.CurrentTaskNum);
                        CommonStackerCrane_StackerCraneTaskCompletedEventHandler(commonStackerCrane, e);
                    }
                    else if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal && commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                    {
                        short stackerError = commonStackerCrane.Communicator.Read<short>("DB1000.54.0");
                        if (stackerError == 0)
@@ -84,6 +95,44 @@
                            }
                        }
                    }
                    // è®¾ç½®è®¾å¤‡ç¼–号,前端用于识别堆垛机
                    YL_DB yL_DB = new YL_DB();
                    yL_DB.R_PP_Status = commonStackerCrane.DeviceCode;
                    // è®¾ç½®å †åž›æœºçŠ¶æ€
                    yL_DB.YL_Status = commonStackerCrane.StackerCraneStatusValue switch
                    {
                        StackerCraneStatus.Fault => 0,
                        StackerCraneStatus.Normal => 1,
                        StackerCraneStatus.EmergencyStop => 2,
                        StackerCraneStatus.Unkonw => 3,
                    };
                    yL_DB.YL_AutoStatus = commonStackerCrane.StackerCraneAutoStatusValue switch
                    {
                        StackerCraneAutoStatus.SemiAutomatic => 1,
                        StackerCraneAutoStatus.Maintenance => 2,
                        StackerCraneAutoStatus.Automatic => 3,
                        StackerCraneAutoStatus.Manual => 4,
                        StackerCraneAutoStatus.Unkonw => 5,
                    };
                    yL_DB.YL_WorkStatus = commonStackerCrane.StackerCraneWorkStatusValue switch
                    {
                        StackerCraneWorkStatus.Standby => 1,
                        StackerCraneWorkStatus.PickUpCompleted => 2,
                        StackerCraneWorkStatus.PickUp => 3,
                        StackerCraneWorkStatus.Putting => 5,
                        StackerCraneWorkStatus.WorkCompleted => 9,
                    };
                    yL_DB.YL_TaskNum = commonStackerCrane.CurrentTaskNum;
                    yL_DB.YL_WorkType = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType);
                    yL_DB.YL_Row = commonStackerCrane.Communicator.Read<short>("DB1000.46");
                    yL_DB.YL_Column = commonStackerCrane.Communicator.Read<short>("DB1000.48.0");
                    yL_DB.YL_Layer = commonStackerCrane.Communicator.Read<short>("DB1000.50.0");
                    // è¯»å–报警信息
                    short stackerError2 = commonStackerCrane.Communicator.Read<short>("DB1000.54.0");
                    yL_DB.StackerAlarm = stackerError2 == 0 ? "无" : $"报警代码: {stackerError2}";
                    // åºåˆ—化并发送数据
                    string ylDB = JsonConvert.SerializeObject(yL_DB);
                    _webSocketServer.PublishAllClientPayload(ylDB);
                }
            }
            catch (Exception ex)
@@ -121,7 +170,7 @@
                {
                    if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                    {
                        Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StackerCraneStationCode == task.NextAddress && x.StackerCraneCode==deviceCode);
                        Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress && x.StackerCraneCode==deviceCode);
                        if (stationManger == null)
                        {
                            _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"输送线出库站点未配置,{task.NextAddress}");
@@ -182,6 +231,13 @@
        /// <returns></returns>
        private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane)
        {
            //判断是否有正执行的任务,如果有则不下发
            Dt_Task? taskOld = _taskRepository.QueryFirst(x => x.DeviceCode == commonStackerCrane.DeviceCode && x.Roadway == commonStackerCrane.DeviceCode && x.TaskState == TaskStatusEnum.SC_Executing.ObjToInt());
            if (taskOld!=null)
            {
                return null;
            }
            Dt_Task task;
            if (commonStackerCrane.LastTaskType == null)
            {
@@ -249,11 +305,17 @@
                if (device != null)
                {
                    OtherDevice client = (OtherDevice)device;
                    if (client.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode)==3)//出库站台未被占用
                    short command = client.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
                    if (command==3)//出库站台未被占用
                    {
                        task.NextAddress = stationManger.StackerCraneStationCode;
                        _taskRepository.UpdateData(task);
                        //task.NextAddress = stationManger.StackerCraneStationCode;
                        //_taskRepository.UpdateData(task);
                        return task;
                    }
                    else
                    {
                        task.ExceptionMessage = "出库站台无法下发";
                        _taskRepository.UpdateData(task);
                    }
                }
                else
@@ -313,7 +375,8 @@
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)//判断是否是出库任务
            {
                string[] targetCodes = task.NextAddress.Split("-");
                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress && x.StackerCraneCode == task.DeviceCode);
                string[] targetCodes = stationManger.StackerCraneStationCode.Split("-");
                if (targetCodes.Length == 3)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);