From a6ea79849f0142b5280f0c5d4b15ecc83f0d015a Mon Sep 17 00:00:00 2001
From: 刘磊 <1161824510@qq.com>
Date: 星期六, 21 十二月 2024 09:52:27 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/HuaYiZhongHeng/BaiBuLiKu

---
 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DispatchInfoService.cs |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 59 insertions(+), 1 deletions(-)

diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DispatchInfoService.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DispatchInfoService.cs
index 27a92be..858681c 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DispatchInfoService.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DispatchInfoService.cs
@@ -15,11 +15,15 @@
  *----------------------------------------------------------------*/
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
+using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
+using Quartz.Impl.Matchers;
+using Quartz;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseRepository;
 using WIDESEAWCS_Core.BaseServices;
 using WIDESEAWCS_Core.Helper;
@@ -28,6 +32,8 @@
 using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Repository;
+using Quartz.Impl;
+using System.Collections.Specialized;
 
 namespace WIDESEAWCS_QuartzJob.Service
 {
@@ -35,10 +41,12 @@
     {
         private readonly IUnitOfWorkManage _unitOfWorkManage;
         private readonly IDeviceInfoRepository _deviceInfoRepository;
-        public DispatchInfoService(IDispatchInfoRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IDeviceInfoRepository deviceInfoRepository) : base(BaseDal)
+        private readonly ISchedulerCenter _schedulerCenter;
+        public DispatchInfoService(IDispatchInfoRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IDeviceInfoRepository deviceInfoRepository, ISchedulerCenter schedulerCenter) : base(BaseDal)
         {
             _unitOfWorkManage = unitOfWorkManage;
             _deviceInfoRepository = deviceInfoRepository;
+            _schedulerCenter = schedulerCenter;
         }
 
         /// <summary>
@@ -66,5 +74,55 @@
                 DeviceType = b.DeviceType
             }).ToList();
         }
+
+        public async Task<WebResponseContent> GetDispatchInfosAsync()
+        {
+            WebResponseContent content = new WebResponseContent();
+            NameValueCollection collection = new NameValueCollection
+            {
+                { "quartz.serializer.type", "binary" },
+            };
+            StdSchedulerFactory factory = new StdSchedulerFactory(collection);
+            IScheduler scheduler = await factory.GetScheduler();
+            var jobKeys = await scheduler.GetJobKeys(GroupMatcher<JobKey>.AnyGroup());
+            foreach (var jobKey in jobKeys)
+            {
+                // 鍦ㄨ繖閲屽鐞嗘瘡涓狫obKey
+                IJobDetail jobDetail = await scheduler.GetJobDetail(jobKey);
+                if (jobDetail != null)
+                {
+                    // 鍙互鑾峰彇Job鐨勬弿杩颁俊鎭�
+                    string jobDescription = jobDetail.Description;
+                    // 浠ュ強Job鐨勬暟鎹槧灏勶紙JobDataMap锛�
+                    JobDataMap jobDataMap = jobDetail.JobDataMap;
+                }
+            }
+
+            var triggerKeys = await scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.AnyGroup());
+            foreach (var triggerKey in triggerKeys)
+            {
+                // 鍦ㄨ繖閲屽鐞嗘瘡涓猅riggerKey
+                ITrigger trigger = await scheduler.GetTrigger(triggerKey);
+                if (trigger != null)
+                {
+                    // 鑾峰彇涓嬩竴娆¤Е鍙戞椂闂达紙濡傛灉鏈夛級
+                    DateTimeOffset? nextFireTime = trigger.GetNextFireTimeUtc();
+                    // 鑾峰彇涓婃瑙﹀彂鏃堕棿锛堝鏋滄湁锛�
+                    DateTimeOffset? previousFireTime = trigger.GetPreviousFireTimeUtc();
+                    // 鑾峰彇瑙﹀彂绫诲瀷锛堝SimpleTrigger銆丆ronTrigger锛�
+                    string triggerType = trigger.GetType().Name;
+                    // 瀵逛簬CronTrigger锛岃繕鍙互鑾峰彇Cron琛ㄨ揪寮忥紙濡傛灉鏄級
+                    //if (trigger is CronTrigger cronTrigger)
+                    //{
+                    //    string cronExpression = cronTrigger.CronExpressionString;
+                    //}
+                    if (!previousFireTime.HasValue && nextFireTime.HasValue)
+                    {
+                        Console.WriteLine($"Job澶勪簬绛夊緟瑙﹀彂鐘舵�侊紝Trigger鍚嶇О: {triggerKey.Name}");
+                    }
+                }
+            }
+            return content;
+        }
     }
 }

--
Gitblit v1.9.3