소스 검색

202410111324

baowei 4 달 전
부모
커밋
bc343856d7

+ 4 - 4
EInk.Lot3/Startup.cs

@@ -36,28 +36,28 @@ namespace EInk.Lot2Lot3
             if (config.GetValue<bool>("ReadLot2Thread") ==true)
             {
                 LogerHelper.RecordLogTxt("Start ReadLot2Thread");
-                ReadLot2Thread readLot2 = new ReadLot2Thread(_db, _local_db);
+                ReadLot2Thread readLot2 = new ReadLot2Thread();
                 readLot2.ReadThreadStart(); 
             }
 
             if (config.GetValue<bool>("SendLot2Lot3Thread") == true)
             {
                 LogerHelper.RecordLogTxt("Start SendLot2Lot3Thread");
-                SendLot2Lot3Thread sendLot2Lot3 = new SendLot2Lot3Thread(_local_db);
+                SendLot2Lot3Thread sendLot2Lot3 = new SendLot2Lot3Thread();
                 sendLot2Lot3.SendThreadStart();
             }
 
             if (config.GetValue<bool>("SendColourCastThread") == true)
             {
                 LogerHelper.RecordLogTxt("Start SendColourCastThread");
-                SendColourCastThread sendcolourcast = new SendColourCastThread(_local_db);
+                SendColourCastThread sendcolourcast = new SendColourCastThread();
                 sendcolourcast.SendThreadStart();
             }
 
             if (config.GetValue<bool>("DeleteDBRecordThread") == true)
             {
                 LogerHelper.RecordLogTxt("Start DeleteDBRecordThread");
-                DeleteDBRecordThread deleterecord = new DeleteDBRecordThread(_local_db, config.GetValue<int>("DaysAgo"));
+                DeleteDBRecordThread deleterecord = new DeleteDBRecordThread(config.GetValue<int>("DaysAgo"));
                 deleterecord.DeleteThreadStart();
             }
 

+ 10 - 7
EInk.Lot3/TaskThread/DeleteDBRecordThread.cs

@@ -8,24 +8,28 @@ namespace EInk.TaskThread
 {
     public class DeleteDBRecordThread
     {
-        private readonly ISqlSugarClient _db;
         public static int daysago;
 
-        public DeleteDBRecordThread(ISqlSugarClient db, int daysago)
+        public DeleteDBRecordThread(int daysago)
         {
-            _db = db;
             DeleteDBRecordThread.daysago = daysago;
         }
 
         public void DeleteThreadStart()
         {
             Thread t = new Thread(DeleteTask);
-            t.Start(_db);
+            t.Start();
         }
 
-        static void DeleteTask(object db)
+        static void DeleteTask()
         {
-            ISqlSugarClient _db = (ISqlSugarClient)db;
+            IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
+            ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
+            {
+                DbType = DbType.PostgreSQL,
+                ConnectionString = _configuration.GetValue<string>("LocalDbConnectionString"),
+                IsAutoCloseConnection = true
+            });
             while (true)
             {
                 try
@@ -37,7 +41,6 @@ namespace EInk.TaskThread
                         LogerHelper.RecordLogTxt($"DeleteTask, DeleteLot2Lot3Data Before {now.AddDays(-DeleteDBRecordThread.daysago).ToString()}, {_db.Deleteable<Lot2Lot3Model>().Where(x => x.create_time < now.AddDays(-DeleteDBRecordThread.daysago)).ExecuteCommand()}");
                         LogerHelper.RecordLogTxt($"DeleteTask, DeleteColourCastData Before {now.AddDays(-DeleteDBRecordThread.daysago).ToString()},  {_db.Deleteable<ColourCastModel>().Where(x => x.create_time < now.AddDays(-DeleteDBRecordThread.daysago)).ExecuteCommand()}");
                     }
-
                 }
                 catch (Exception ex)
                 {

+ 16 - 11
EInk.Lot3/TaskThread/ReadLot2Thread.cs

@@ -12,25 +12,30 @@ namespace EInk.TaskThread
 {
     public class ReadLot2Thread
     {
-        private readonly ISqlSugarClient _db;
-        private readonly ISqlSugarClient _local_db;
-
-        public ReadLot2Thread(ISqlSugarClient db, ISqlSugarClient local_db)
-        {
-            _db = db;
-            _local_db = local_db;
-        }
-
         public void ReadThreadStart()
         {
             Thread t = new Thread(ReadTask);
-            t.Start((_db, _local_db));
+            t.Start();
         }
 
         static void ReadTask(Object dblist)
         {
-            var (db, local_db) = ((ISqlSugarClient, ISqlSugarClient))dblist;
             IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
+
+
+            var db = new SqlSugarClient(new ConnectionConfig()
+            {
+                DbType = DbType.PostgreSQL,
+                ConnectionString = _configuration.GetValue<string>("TargetDbConnectionString"),
+                IsAutoCloseConnection = true
+            });
+            var local_db = new SqlSugarClient(new ConnectionConfig()
+            {
+                DbType = DbType.PostgreSQL,
+                ConnectionString = _configuration.GetValue<string>("LocalDbConnectionString"),
+                IsAutoCloseConnection = true
+            });
+
             string topic = _configuration.GetValue<string>("Topic");
             List<string> patternlist = _configuration.GetValue<string>("PatternList").Split(",").ToList();
             int product_startid = _configuration.GetValue<int>("ProductStartID");

+ 8 - 10
EInk.Lot3/TaskThread/SendColourCastThread.cs

@@ -8,23 +8,21 @@ namespace EInk.TaskThread
 {
     public class SendColourCastThread
     {
-        private readonly ISqlSugarClient _db;
-
-        public SendColourCastThread(ISqlSugarClient db)
-        {
-            _db = db;
-        }
-
         public void SendThreadStart()
         {
             Thread t = new Thread(SendTask);
-            t.Start(_db);
+            t.Start();
         }
 
-        static void SendTask(Object db)
+        static void SendTask()
         {
-            ISqlSugarClient _db = (ISqlSugarClient)db;
             IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
+            ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
+            {
+                DbType = DbType.PostgreSQL,
+                ConnectionString = _configuration.GetValue<string>("LocalDbConnectionString"),
+                IsAutoCloseConnection = true
+            });
             while (true)
             {
                 try

+ 9 - 11
EInk.Lot3/TaskThread/SendLot2Lot3Thread.cs

@@ -8,23 +8,21 @@ namespace EInk.TaskThread
 {
     public class SendLot2Lot3Thread
     {
-        private readonly ISqlSugarClient _db;
-
-        public SendLot2Lot3Thread(ISqlSugarClient db)
-        {
-            _db = db;
-        }
-
         public void SendThreadStart()
         {
             Thread t = new Thread(SendTask);
-            t.Start(_db);
+            t.Start();
         }
 
-        static void SendTask(Object db)
+        static void SendTask()
         {
-            ISqlSugarClient _db = (ISqlSugarClient)db;
             IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
+            ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
+            {
+                DbType = DbType.PostgreSQL,
+                ConnectionString = _configuration.GetValue<string>("LocalDbConnectionString"),
+                IsAutoCloseConnection = true
+            });
             while (true)
             {
                 try
@@ -63,7 +61,7 @@ namespace EInk.TaskThread
                 }
                 finally
                 {
-                    Thread.Sleep(10000);
+                    Thread.Sleep(millisecondsTimeout: 10000);
                 }
             }