dengjunjie
2024-12-24 18d1f45193e34e00fc1b6f65b8596ddb29c5267d
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/HostedService/WarehouseHostedService.cs
@@ -1,12 +1,24 @@

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;
        public WarehouseHostedService(ICacheService cacheService, DBContext dbContext)
        {
            _cacheService = cacheService;
            _dbContext = dbContext;
        }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            string connStr = AppSettings.GetValue("WMSConnectionStrings");
@@ -14,14 +26,18 @@
            {
                throw new Exception("WMS连接字符串错误");
            }
            SqlSugarClient sugarClient = new SqlSugarClient(new ConnectionConfig()
            SqlSugarClient sugarClient = new(new ConnectionConfig()
            {
                ConnectionString = connStr,
                IsAutoCloseConnection = true,
                DbType = DbType.SqlServer
            });
            List<WarehouseDTO> warehouses = sugarClient.Queryable<WarehouseDTO>().ToList();
            List<Dt_Warehouse> warehouses = sugarClient.Queryable<Dt_Warehouse>().ToList();
            _dbContext.Db.Deleteable<Dt_Warehouse>().ExecuteCommand();
            _dbContext.Db.Insertable(warehouses).ExecuteCommand();
            return Task.CompletedTask;
        }