From 9b567a8304c3d202ddd1f716cb63c2a4535b6417 Mon Sep 17 00:00:00 2001
From: 肖洋 <cathay_xy@163.com>
Date: 星期一, 09 十二月 2024 22:47:06 +0800
Subject: [PATCH] 高温出库堆垛机完成给线体写入托盘号

---
 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
index f350bdb..1375410 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -1,10 +1,14 @@
 锘縰sing Autofac.Core;
 using HslCommunication;
+using Mapster;
 using Newtonsoft.Json;
 using Quartz;
 using System.Diagnostics.CodeAnalysis;
+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_ITaskInfoRepository;
@@ -16,6 +20,8 @@
 using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Service;
 using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
+using WIDESEAWCS_SignalR;
+using WIDESEAWCS_Tasks.ConveyorLineJob;
 using WIDESEAWCS_Tasks.StackerCraneJob;
 
 namespace WIDESEAWCS_Tasks
@@ -28,14 +34,20 @@
         private readonly ITaskRepository _taskRepository;
         private readonly IRouterService _routerService;
         private readonly IProcessRepository _processRepository;
+        private readonly ICacheService _cacheService;
+        private readonly INoticeService _noticeService;
+        private readonly IDt_StationManagerRepository _stationManagerRepository;
 
-        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository)
+        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository)
         {
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
             _taskRepository = taskRepository;
             _routerService = routerService;
             _processRepository = processRepository;
+            _cacheService = cacheService;
+            _noticeService = noticeService;
+            _stationManagerRepository = stationManagerRepository;
         }
 
         public Task Execute(IJobExecutionContext context)
@@ -78,11 +90,37 @@
                             }
                         }
                     }
+
+                    #region 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
+
+                    var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
+                    if (tokenInfos == null || !tokenInfos.Any())
+                    {
+                        throw new Exception(commonStackerCrane.DeviceName + "缂撳瓨涓湭鎵惧埌Token缂撳瓨");
+                    }
+                    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 });
+
+                    #endregion 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
+
                 }
             }
             catch (Exception ex)
             {
                 WriteError("CommonConveyorLineJob", "test", ex);
+                ConsoleHelper.WriteErrorLine($"{ex.Message}");
                 //Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
             }
             //WriteDebug("CommonConveyorLineJob", "test");
@@ -103,6 +141,21 @@
                 {
                     //Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
                     ConsoleHelper.WriteColorLine($"銆恵commonStackerCrane.DeviceName}銆戜换鍔″畬鎴�,浠诲姟鍙凤細銆恵e.TaskNum}銆�", ConsoleColor.Blue);
+                    if (commonStackerCrane.DeviceCode.Contains("GW"))
+                    {
+                        var task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum);
+
+                        var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.TargetAddress);
+
+                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == station.stationPLC);
+                        if (device != null)
+                        {
+                            CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)device;
+                            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, task.PalletCode, task.TargetAddress);
+                        }
+                        else
+                            return;
+                    }
                     _taskService.StackCraneTaskCompleted(e.TaskNum);
                     commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                 }
@@ -117,6 +170,8 @@
         private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane)
         {
             Dt_Task task;
+            var taskRun = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting || x.TaskState == (int)TaskInStatusEnum.SC_InExecuting);
+            if (taskRun != null) { return null; }
             if (commonStackerCrane.LastTaskType == null)
             {
                 task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
@@ -192,7 +247,7 @@
                     if (device != null)
                     {
                         CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)device;
-                        if (conveyorLine.IsOccupied(task.NextAddress))//鍑哄簱绔欏彴鏈鍗犵敤
+                        if (conveyorLine.IsOccupied(task.TargetAddress))//鍑哄簱绔欏彴鏈鍗犵敤
                         {
                             return task;
                         }

--
Gitblit v1.9.3