From 0ea4a390d09679425cf3ad217a38a9e717641c95 Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期一, 14 四月 2025 16:23:12 +0800
Subject: [PATCH] 增加串行库位任务下发机制防呆

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Core/Quartzjob/JobSetup.cs |   64 ++++++++++++++++++++++++++------
 1 files changed, 52 insertions(+), 12 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Quartzjob/JobSetup.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Quartzjob/JobSetup.cs"
index 09ed5c2..2d3aebf 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Quartzjob/JobSetup.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Quartzjob/JobSetup.cs"
@@ -10,39 +10,79 @@
 
 namespace WIDESEA_Core.QuartzJob
 {
-
     /// <summary>
     /// 浠诲姟璋冨害 鍚姩鏈嶅姟
     /// </summary>
     public static class JobSetup
     {
-        public static void AddJobSetup(this IServiceCollection services)
+        public static void AddJobSetup(this IServiceCollection services, Action<IServiceCollection> configureJobs = null)
         {
             if (services == null) throw new ArgumentNullException(nameof(services));
 
-            //灏咼obFactory娉ㄥ叆鍒版湇鍔′腑
+            // 灏咼obFactory娉ㄥ叆鍒版湇鍔′腑
             services.AddSingleton<IJobFactory, JobFactory>();
-            //灏哠chedulerCenterServer娉ㄥ叆鍒版湇鍔′腑
+            // 灏哠chedulerCenterServer娉ㄥ叆鍒版湇鍔′腑
             services.AddSingleton<ISchedulerCenter, SchedulerCenterServer>();
-            //浠诲姟娉ㄥ叆
+
+            // 浠诲姟娉ㄥ叆
             var baseType = typeof(IJob);
-            //鑾峰彇褰撳墠搴旂敤绋嬪簭鍩熺殑鐩稿鎼滅储璺緞
+            // 鑾峰彇褰撳墠搴旂敤绋嬪簭鍩熺殑鐩稿鎼滅储璺緞
             var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
-            //鑾峰彇鎸囧畾璺緞涓嬬殑鎵�鏈夌▼搴忛泦
+            // 鑾峰彇鎸囧畾璺緞涓嬬殑鎵�鏈夌▼搴忛泦
             var referencedAssemblies = System.IO.Directory.GetFiles(path, "WIDESEA_Tasks.dll").Select(Assembly.LoadFrom).ToArray();
-            //鑾峰彇鎵�鏈夊畾涔夌殑绫诲瀷
+            // 鑾峰彇鎵�鏈夊畾涔夌殑绫诲瀷
             var types = referencedAssemblies
                 .SelectMany(a => a.DefinedTypes)
                 .Select(type => type.AsType())
-                //绛涢�夊嚭缁ф壙鑷狪Job鐨勭被鍨�
+                // 绛涢�夊嚭缁ф壙鑷狪Job鐨勭被鍨�
                 .Where(x => x != baseType && baseType.IsAssignableFrom(x)).ToArray();
-            //鑾峰彇鎵�鏈夊疄鐜颁簡IJob鐨勭被鍨�
+            // 鑾峰彇鎵�鏈夊疄鐜颁簡IJob鐨勭被鍨�
             var implementTypes = types.Where(x => x.IsClass).ToArray();
-            //灏嗘墍鏈夊疄鐜颁簡IJob鐨勭被鍨嬫敞鍏ュ埌鏈嶅姟涓�
+            // 灏嗘墍鏈夊疄鐜颁簡IJob鐨勭被鍨嬫敞鍏ュ埌鏈嶅姟涓�
             foreach (var implementType in implementTypes)
             {
                 services.AddTransient(implementType);
             }
+
+            // 娣诲姞瀹氭椂鍚姩閰嶇疆
+            services.AddTransient<StartupJob>();
+            services.AddSingleton(new JobSchedule(
+                jobType: typeof(StartupJob),
+                cronExpression: "0 0 8 ? * *")); // 姣忓ぉ涓婂崍8鐐规墽琛�
         }
     }
-}
+
+    /// <summary>
+    /// 鍚姩浠诲姟
+    /// </summary>
+    public class StartupJob : IJob
+    {
+        private readonly ISchedulerCenter _schedulerCenter;
+
+        public StartupJob(ISchedulerCenter schedulerCenter)
+        {
+            _schedulerCenter = schedulerCenter;
+        }
+
+        public async Task Execute(IJobExecutionContext context)
+        {
+            // 鍦ㄨ繖閲屽惎鍔ㄦ墍鏈夐渶瑕佸畾鏃舵墽琛岀殑浠诲姟
+            await _schedulerCenter.StartScheduleAsync();
+        }
+    }
+
+    /// <summary>
+    /// 浠诲姟璋冨害閰嶇疆
+    /// </summary>
+    public class JobSchedule
+    {
+        public Type JobType { get; }
+        public string CronExpression { get; }
+
+        public JobSchedule(Type jobType, string cronExpression)
+        {
+            JobType = jobType;
+            CronExpression = cronExpression;
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3