From 8a718d4a371257af9afa5816989791865f21f696 Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期四, 20 十一月 2025 18:23:23 +0800
Subject: [PATCH] 提交

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockSelectViewDTO.cs         |    2 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_WMSServer.csproj      |    2 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs |   84 ++++++++++++----------------
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs                    |   20 ++++++
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_BasicService/ErpApiService.cs           |    8 +-
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Jobs/ErpJob.cs                |   50 ++++++++++++++++
 6 files changed, 113 insertions(+), 53 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_BasicService/ErpApiService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_BasicService/ErpApiService.cs"
index 5ddfe87..83277ed 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_BasicService/ErpApiService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_BasicService/ErpApiService.cs"
@@ -226,10 +226,10 @@
                 }
                 else
                 {
-                    materialRequest.modifyDateStart = DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd") + " 00:00:01";
-                    materialRequest.modifyDateEnd = DateTime.Now.ToString("yyyy-MM-dd HH:mm") + ":01";
-                    materialRequest.pageNum = 1;
-                    materialRequest.pageSize = 5000;
+                    //materialRequest.modifyDateStart = DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd") + " 00:00:01";
+                    //materialRequest.modifyDateEnd = DateTime.Now.ToString("yyyy-MM-dd HH:mm") + ":01";
+                    //materialRequest.pageNum = 1;
+                    //materialRequest.pageSize = 5000;
 
                     var result = await PostAsync<MaterialRequest, MaterialResponse>("erp/getMaterialInfo", materialRequest, true, true);
                     if (result != null && result.data != null && result.data.Any())
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockSelectViewDTO.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockSelectViewDTO.cs"
index 6bffcc6..0ff3981 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockSelectViewDTO.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockSelectViewDTO.cs"
@@ -18,5 +18,7 @@
         public string PalletCode { get; set; }
 
         public string LocationCode { get; set; }
+
+        
     }
 }
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
index 2bd7d87..58c97a7 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
@@ -148,53 +148,41 @@
             List<Dt_OutboundOrderDetail>? orderDetails = null;
             List<Dt_OutStockLockInfo>? outStockLockInfos = null;
             List<Dt_LocationInfo>? locationInfos = null;
-            //if (outboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+
+            (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundOrderDetailService.AssignStockOutbound(outboundOrderDetails);
+            if (result.Item1 != null && result.Item1.Count > 0)
             {
-                (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundOrderDetailService.AssignStockOutbound(outboundOrderDetails);
-                if (result.Item1 != null && result.Item1.Count > 0)
+                Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId);
+                TaskTypeEnum typeEnum = outboundOrder.OrderType switch
                 {
-                    Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId);
-                    TaskTypeEnum typeEnum = outboundOrder.OrderType switch
-                    {
-                        (int)OutOrderTypeEnum.Issue => TaskTypeEnum.Outbound,
-                        (int)OutOrderTypeEnum.Allocate => TaskTypeEnum.OutAllocate,
-                        (int)OutOrderTypeEnum.Quality => TaskTypeEnum.OutQuality,
-                        _ =>   TaskTypeEnum.Outbound 
-                    };
-                    tasks = GetTasks(result.Item1, typeEnum, outStation);
-                    tasks.ForEach(x =>
-                    {
-                        x.OrderNo = outboundOrder.OrderNo;
-                    });
-                    result.Item2.ForEach(x =>
-                    {
-                        x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
-                    });
-                    result.Item3.ForEach(x =>
-                    {
-                        x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
-                    });
+                    (int)OutOrderTypeEnum.Issue => TaskTypeEnum.Outbound,
+                    (int)OutOrderTypeEnum.Allocate => TaskTypeEnum.OutAllocate,
+                    (int)OutOrderTypeEnum.Quality => TaskTypeEnum.OutQuality,
+                    _ => TaskTypeEnum.Outbound
+                };
+                tasks = GetTasks(result.Item1, typeEnum, outStation);
+                tasks.ForEach(x =>
+                {
+                    x.OrderNo = outboundOrder.OrderNo;
+                });
+                result.Item2.ForEach(x =>
+                {
+                    x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+                });
+                result.Item3.ForEach(x =>
+                {
+                    x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+                });
 
-                    stockInfos = result.Item1;
-                    orderDetails = result.Item2;
-                    outStockLockInfos = result.Item3;
-                    locationInfos = result.Item4;
-                }
-                else
-                {
-                    throw new Exception("鏃犲簱瀛�");
-                }
+                stockInfos = result.Item1;
+                orderDetails = result.Item2;
+                outStockLockInfos = result.Item3;
+                locationInfos = result.Item4;
             }
-            //else
-            //{
-            //    List<Dt_OutStockLockInfo> stockLockInfos = _outboundService.OutboundStockLockInfoService.GetByOrderDetailId(outboundOrderDetail.OrderId, OutLockStockStatusEnum.宸插垎閰�);
-            //    if (stockLockInfos != null && stockLockInfos.Count > 0)
-            //    {
-            //        List<Dt_StockInfo> stocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockLockInfos.Select(x => x.PalletCode).Distinct().ToList());
-            //        tasks = GetTasks(stocks);
-            //    }
-            //}
-
+            else
+            {
+                throw new Exception("鏃犲簱瀛�");
+            }    
             return (tasks, stockInfos, orderDetails, outStockLockInfos, locationInfos);
         }
 
@@ -257,7 +245,7 @@
                     taskType = "carry",
                     taskGroupCode = "",
                     groupPriority = 0,
-                    tasks = new List<TasksType>()                   
+                    tasks = new List<TasksType>()
                 };
 
                 foreach (var task in tasks)
@@ -290,7 +278,7 @@
                 else
                 {
                     return WebResponseContent.Instance.Error("涓嬪彂鏈哄櫒浜轰换鍔″け璐ワ紒");
-                }                               
+                }
             }
             catch (Exception ex)
             {
@@ -331,7 +319,7 @@
                             // TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                             PalletType = stockInfo.PalletType,
                             WarehouseId = stockInfo.WarehouseId,
-                            
+
                         };
                         //if (taskType != TaskTypeEnum.OutEmpty)
                         //{
@@ -353,7 +341,7 @@
         /// </summary>
         /// <param name="keys">鍑哄簱鍗曟槑缁嗕富閿�</param>
         /// <returns></returns>
-        public async Task<WebResponseContent> GenerateOutboundTasksAsync(int[] keys,string outStation) 
+        public async Task<WebResponseContent> GenerateOutboundTasksAsync(int[] keys, string outStation)
         {
             try
             {
@@ -364,7 +352,7 @@
                 List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
                 List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
 
-                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(keys,outStation);
+                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(keys, outStation);
                 if (result.Item2 != null && result.Item2.Count > 0)
                 {
                     stockInfos.AddRange(result.Item2);
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Jobs/ErpJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Jobs/ErpJob.cs"
new file mode 100644
index 0000000..1fa8fd0
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Jobs/ErpJob.cs"
@@ -0,0 +1,50 @@
+锘縰sing Quartz;
+using SqlSugar;
+using WIDESEA_DTO.Basic;
+
+namespace WIDESEA_WMSServer.Jobs
+{
+    [DisallowConcurrentExecution]
+    public class ErpJob : IJob
+    {
+        private readonly ILogger<ErpJob> _logger;
+        private readonly ISqlSugarClient _db;
+        private readonly WIDESEA_IBasicService.IErpApiService _erpApiService;
+        // 閫氳繃鏋勯�犲嚱鏁扮洿鎺ユ敞鍏ヤ緷璧�
+        public ErpJob(ILogger<ErpJob> logger, ISqlSugarClient db, WIDESEA_IBasicService.IErpApiService erpApiService)
+        {
+            _logger = logger;
+            _db = db;
+            _erpApiService = erpApiService;
+        }
+
+        public async Task Execute(IJobExecutionContext context)
+        {
+            _logger.LogInformation($"瀹氭椂浠诲姟寮�濮嬫墽琛岋紝鏃堕棿锛歿DateTime.Now:yyyy-MM-dd HH:mm:ss}");
+
+            try
+            {
+                 await _erpApiService.GetSuppliersAsync();
+
+                await _erpApiService.GetMaterialUnitAsync();
+
+                var materialRequest = new MaterialRequest
+                {
+                    modifyDateStart = DateTime.Now.AddDays(-10).Date.ToString("yyyy-MM-dd") + " 00:00:01",
+                    modifyDateEnd = DateTime.Now.ToString("yyyy-MM-dd HH:mm") + ":01",
+                    pageNum = 1,
+                    pageSize = 5000
+                };
+
+                await _erpApiService.GetMaterialInfoAsync(materialRequest);
+
+                _logger.LogInformation($"瀹氭椂浠诲姟鎵ц鎴愬姛");
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError(ex, "瀹氭椂浠诲姟鎵ц澶辫触");
+            }
+        }
+ 
+    }
+}
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs"
index 9b4fc91..ef722e9 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs"
@@ -22,6 +22,8 @@
 //using WIDESEA_Core.HostedService;
 using WIDESEA_Core.Middlewares;
 using WIDESEA_WMSServer.Filter;
+using Quartz;
+using WIDESEA_WMSServer.Jobs;
 
 var builder = WebApplication.CreateBuilder(args);
 
@@ -146,10 +148,26 @@
     client.Timeout = TimeSpan.FromSeconds(30);
 
 });
+ 
+builder.Services.AddQuartz(q =>
+{
+    
+    var jobKey = new JobKey("ErpJob");
+    q.AddJob<ErpJob>(opts => opts.WithIdentity(jobKey));
 
+
+    // 添加触发器 - 每天10:00, 14:00, 20:00执行
+    q.AddTrigger(opts => opts
+        .ForJob(jobKey)
+        .WithIdentity("ErpJob-trigger")
+        .WithCronSchedule("0 0 10,14,20 * * ?"));
+});
+
+ 
+builder.Services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
 var app = builder.Build();
 
-// 3、配置中间件
+ 
 app.UseMiniProfiler();//性能分析器
 app.ConfigureApplication();//配置文件
 app.UseApplicationSetup();//启动配置
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_WMSServer.csproj" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_WMSServer.csproj"
index c567f89..96225ab 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_WMSServer.csproj"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_WMSServer.csproj"
@@ -47,6 +47,8 @@
 	</ItemGroup>
 	
 	<ItemGroup>
+	  <PackageReference Include="Quartz" Version="3.13.1" />
+	  <PackageReference Include="Quartz.Extensions.Hosting" Version="3.13.1" />
 	  <PackageReference Include="Serilog" Version="4.3.0" />
 	  <PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
 	  <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.7.3" />

--
Gitblit v1.9.3