baowei hace 6 meses
padre
commit
0421bbfb73

+ 1 - 13
EInk.Lot3/Program.cs

@@ -10,9 +10,7 @@ builder.Services.AddControllers();
 // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
 builder.Services.AddEndpointsApiExplorer();
 builder.Services.AddSwaggerGen();
-builder.Services.AddSingleton<IStartupFilter, ReadLot2Filter>();
-builder.Services.AddSingleton<IStartupFilter, SendDataFilter>();
-builder.Services.AddSingleton<IStartupFilter, DeleteDBRecordFilter>();
+builder.Services.AddSingleton<IStartupFilter, TaskFilter>();
 builder.Services.AddSingleton<ISqlSugarClient>(s =>
 {
     SqlSugarScope sqlSugar = new(new ConnectionConfig()
@@ -35,19 +33,9 @@ builder.Services.AddSingleton<ISqlSugarClient>(s =>
 });
 
 var app = builder.Build();
-
-// Configure the HTTP request pipeline.
-//if (app.Environment.IsDevelopment())
-//{
-//    app.UseSwagger();
-//    app.UseSwaggerUI();
-//}
 app.UseSwagger();
 app.UseSwaggerUI();
 app.UseHttpsRedirection();
-
 app.UseAuthorization();
-
 app.MapControllers();
-
 app.Run();

+ 16 - 40
EInk.Lot3/Startup.cs

@@ -3,23 +3,26 @@ using Microsoft.AspNetCore.Builder;
 using SqlSugar;
 using EInk.Models;
 using EInk.Tools;
+using Microsoft.Extensions.Options;
 
 namespace EInk.Lot2Lot3
 {
     
-    public class ReadLot2Filter : IStartupFilter
+    public class TaskFilter : IStartupFilter
     {
+        private static IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
+
         private readonly ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
         {
             DbType = DbType.PostgreSQL,
-            ConnectionString = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue<string>("TargetDbConnectionString"),
+            ConnectionString = config.GetValue<string>("TargetDbConnectionString"),
             IsAutoCloseConnection = true
         });
 
         private readonly ISqlSugarClient _local_db = new SqlSugarClient(new ConnectionConfig()
         {
             DbType = DbType.PostgreSQL,
-            ConnectionString = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue<string>("LocalDbConnectionString"),
+            ConnectionString = config.GetValue<string>("LocalDbConnectionString"),
             IsAutoCloseConnection = true
         });
 
@@ -29,58 +32,31 @@ namespace EInk.Lot2Lot3
             _local_db.CodeFirst.InitTables(typeof(DefectModel));
             _local_db.CodeFirst.InitTables(typeof(Lot2Lot3Model));
             _local_db.CodeFirst.InitTables(typeof(ColourCastModel));
-            ReadLot2Thread readLot2 = new ReadLot2Thread(_db, _local_db);
-            if (new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue<string>("ReadLot2Thread") =="on")
+
+            if (config.GetValue<bool>("ReadLot2Thread") ==true)
             {
+                ReadLot2Thread readLot2 = new ReadLot2Thread(_db, _local_db);
                 readLot2.ReadThreadStart(); 
             }
-            return app => next(app);
-        }
-    }
-
-    public class SendDataFilter : IStartupFilter
-    {
-        private readonly ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
-        {
-            DbType = DbType.PostgreSQL,
-            ConnectionString = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue<string>("LocalDbConnectionString"),
-            IsAutoCloseConnection = true
-        });
 
-        public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
-        {
-            SendLot2Lot3Thread sendLot2Lot3 = new SendLot2Lot3Thread(_db);
-            if (new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue<string>("SendLot2Lot3Thread") == "on")
+            if (config.GetValue<bool>("SendLot2Lot3Thread") == true)
             {
+                SendLot2Lot3Thread sendLot2Lot3 = new SendLot2Lot3Thread(_db);
                 sendLot2Lot3.SendThreadStart();
             }
 
-            SendColourCastThread sendcolourcast = new SendColourCastThread(_db);
-            if (new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue<string>("SendColourCastThread") == "on")
+            if (config.GetValue<bool>("SendColourCastThread") == true)
             {
+                SendColourCastThread sendcolourcast = new SendColourCastThread(_db);
                 sendcolourcast.SendThreadStart();
             }
-            return app => next(app);
-        }
-    }
-
-
-    public class DeleteDBRecordFilter : IStartupFilter
-    {
-        private readonly ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
-        {
-            DbType = DbType.PostgreSQL,
-            ConnectionString = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue<string>("LocalDbConnectionString"),
-            IsAutoCloseConnection = true
-        });
 
-        public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
-        {
-            DeleteDBRecordThread deleterecord = new DeleteDBRecordThread(_db);
-            if (new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue<string>("DeleteDBRecordThread") == "on")
+            if (config.GetValue<bool>("DeleteDBRecordThread") == true)
             {
+                DeleteDBRecordThread deleterecord = new DeleteDBRecordThread(_db, config.GetValue<int>("DaysAgo"));
                 deleterecord.DeleteThreadStart();
             }
+
             return app => next(app);
         }
     }

+ 6 - 4
EInk.Lot3/TaskThread/DeleteDBRecordThread.cs

@@ -9,10 +9,12 @@ namespace EInk.TaskThread
     public class DeleteDBRecordThread
     {
         private readonly ISqlSugarClient _db;
+        private int daysago;
 
-        public DeleteDBRecordThread(ISqlSugarClient db)
+        public DeleteDBRecordThread(ISqlSugarClient db, int daysago)
         {
             _db = db;
+            this.daysago = daysago;
         }
 
         public void DeleteThreadStart()
@@ -29,9 +31,9 @@ namespace EInk.TaskThread
                 try
                 {
                     DateTime now = DateTime.Now;
-                    if (now.Hour==8)
+                    if (now.Hour==8 && now.Minute==0)
                     {
-                        _db.Deleteable<Lot2Lot3Model>().Where(x => x.create_time < now.AddMonths(-2)).ExecuteCommand();
+                        _db.Deleteable<Lot2Lot3Model>().Where(x => x.create_time < now.AddDays(-2)).ExecuteCommand();
                         LogerHelper.RecordLogTxt("DeleteTask");
                     }
 
@@ -42,7 +44,7 @@ namespace EInk.TaskThread
                 }
                 finally
                 {
-                    Thread.Sleep(1000 * 60 * 60);
+                    Thread.Sleep(1000 * 60);
                 }
             }
 

+ 6 - 6
EInk.Lot3/appsettings.json

@@ -9,9 +9,8 @@
   "Kestrel": {
     "EndPoints": {
       "Http": {
-        "Url": "http://localhost:8081"
+        "Url": "http://localhost:8080"
       }
-
       //"Https": {
       //  "Url": "https://localhost:8082"
       //}
@@ -23,10 +22,11 @@
   "ProductStartID": 0,
   "MesUrl": "http://eyzms.toc.eink.com:8088",
   "MesUrlTime": 30,
+  "DaysAgo": 100,
   "PatternList": "wht,dot",
   "Topic": "LOT2AOIData#04#04-2AOI01",
-  "ReadLot2Thread": "off",
-  "SendLot2Lot3Thread": "off",
-  "SendColourCastThread": "off",
-  "DeleteDBRecordThread": "off"
+  "ReadLot2Thread": false,
+  "SendLot2Lot3Thread": false,
+  "SendColourCastThread": false,
+  "DeleteDBRecordThread": true
 }