From 5ab6b36c0c4bd80a31dcdd9f15cc835b7352c4e7 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期四, 16 一月 2025 11:08:02 +0800
Subject: [PATCH] 1

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/HostedService/WarehouseHostedService.cs |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 53 insertions(+), 2 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/HostedService/WarehouseHostedService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/HostedService/WarehouseHostedService.cs"
index e6305ee..67cb2a1 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/HostedService/WarehouseHostedService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/HostedService/WarehouseHostedService.cs"
@@ -1,16 +1,67 @@
 锘�
+using HslCommunication.WebSocket;
+using SqlSugar;
+using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_Core.Seed;
+using WIDESEAWCS_DTO.BasicInfo;
+using WIDESEAWCS_Model.Models;
+using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
+
 namespace WIDESEAWCS_Server.HostedService
 {
     public class WarehouseHostedService : IHostedService
     {
+        private readonly ICacheService _cacheService;
+        private readonly DBContext _dbContext;
+        //private readonly WebSocketServer _webSocketServer;
+
+        public WarehouseHostedService(ICacheService cacheService, DBContext dbContext/*, WebSocketServer webSocketServer*/)
+        {
+            _cacheService = cacheService;
+            _dbContext = dbContext;
+            //_webSocketServer = webSocketServer;
+        }
+
         public Task StartAsync(CancellationToken cancellationToken)
         {
-            throw new NotImplementedException();
+            try
+            {
+                string connStr = AppSettings.GetValue("WMSConnectionStrings");
+                if (string.IsNullOrEmpty(connStr))
+                {
+                    throw new Exception("WMS杩炴帴瀛楃涓查敊璇�");
+                }
+                SqlSugarClient sugarClient = new(new ConnectionConfig()
+                {
+                    ConnectionString = connStr,
+                    IsAutoCloseConnection = true,
+                    DbType = DbType.SqlServer
+                });
+
+                List<Dt_Warehouse> warehouses = sugarClient.Queryable<Dt_Warehouse>().ToList();
+
+                _dbContext.Db.Deleteable<Dt_Warehouse>().ExecuteCommand();
+
+                _dbContext.Db.Insertable(warehouses).ExecuteCommand();
+
+                List<Dt_ApiInfo> apiInfos = _dbContext.Db.Queryable<Dt_ApiInfo>().ToList();
+
+                List<Dt_WarehouseDevice> warehouseDevices = _dbContext.Db.Queryable<Dt_WarehouseDevice>().ToList();
+
+                _cacheService.AddOrUpdate(nameof(Dt_WarehouseDevice), warehouseDevices);
+
+                _cacheService.AddOrUpdate(nameof(apiInfos), apiInfos);
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+            }
+            return Task.CompletedTask;
         }
 
         public Task StopAsync(CancellationToken cancellationToken)
         {
-            throw new NotImplementedException();
+            return Task.CompletedTask;
         }
     }
 }

--
Gitblit v1.9.3