baowei 7 місяців тому
батько
коміт
90699e76d8

+ 1 - 1
EInk.Lot3/Program.cs

@@ -11,7 +11,7 @@ builder.Services.AddControllers();
 builder.Services.AddEndpointsApiExplorer();
 builder.Services.AddSwaggerGen();
 builder.Services.AddSingleton<IStartupFilter, ReadLot2Filter>();
-builder.Services.AddSingleton<IStartupFilter, SendLot2Lot3Filter>();
+builder.Services.AddSingleton<IStartupFilter, SendDataFilter>();
 builder.Services.AddSingleton<IStartupFilter, DeleteDBRecordFilter>();
 builder.Services.AddSingleton<ISqlSugarClient>(s =>
 {

+ 8 - 2
EInk.Lot3/Startup.cs

@@ -37,7 +37,7 @@ namespace EInk.Lot2Lot3
         }
     }
 
-    public class SendLot2Lot3Filter : IStartupFilter
+    public class SendDataFilter : IStartupFilter
     {
         private readonly ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
         {
@@ -53,6 +53,12 @@ namespace EInk.Lot2Lot3
             {
                 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")
+            {
+                sendcolourcast.SendThreadStart();
+            }
             return app => next(app);
         }
     }
@@ -70,7 +76,7 @@ namespace EInk.Lot2Lot3
         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>("DeleteDBRecordhread") == "on")
+            if (new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue<string>("DeleteDBRecordThread") == "on")
             {
                 deleterecord.DeleteThreadStart();
             }

+ 1 - 1
EInk.Lot3/TaskThread/ReadLot2Thread.cs

@@ -311,7 +311,7 @@ namespace EInk.TaskThread
                                         _local_db.Insertable(lot2model).ExecuteCommand();
                                     }
                                 }
-                                Thread.Sleep(500);
+                                Thread.Sleep(1000);
                             }
                             _local_db.Ado.CommitTran();
                         }

+ 73 - 0
EInk.Lot3/TaskThread/SendColourCastThread.cs

@@ -0,0 +1,73 @@
+using EInk.Dtos;
+using EInk.Models;
+using EInk.Tools;
+using Newtonsoft.Json;
+using SqlSugar;
+
+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);
+        }
+
+        static void SendTask(Object db)
+        {
+            ISqlSugarClient _db = (ISqlSugarClient)db;
+            IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
+            while (true)
+            {
+                try
+                {
+                    List<ColourCastModel> unsend_list = _db.Queryable<ColourCastModel>().Where(x => x.is_send == 0).OrderBy(x => x.id).Take(120).ToList();
+                    if (unsend_list != null && unsend_list.Count > 0)
+                    {
+                        foreach (var unsend in unsend_list)
+                        {
+                            var (rt_bl, rt_str) = HttpHelper.Post(_configuration.GetValue<string>("MesUrl")+ "/MesApi/LotAoiUpLoad", unsend.content, _configuration.GetValue<int>("MesUrlTime"));
+                            if (rt_bl && !string.IsNullOrEmpty(rt_str))
+                            {
+                                ResultDto rt = JsonConvert.DeserializeObject<ResultDto>(rt_str);
+                                if (rt.Code == CodeEnum.Ok)
+                                {
+                                    unsend.is_send = 1;
+                                    unsend.send_time = DateTime.Now;
+                                    _db.Updateable<ColourCastModel>(unsend).WhereColumns(s => s.id).ExecuteCommand();
+                                }
+                                else
+                                {
+                                    LogerHelper.RecordLogTxt("SendColourCastTask,MesApi1," + rt.Code + "," + rt.Message + "," + unsend.content);
+                                } 
+                            }
+                            else
+                            {
+                                LogerHelper.RecordLogTxt("SendColourCastTask,MesApi2," + rt_bl+ "," + rt_str + "," + unsend.content);
+                            }
+                            Thread.Sleep(1000);
+                        }
+                    }
+                }
+                catch(Exception ex)
+                {
+                    LogerHelper.RecordLogTxt("SendLotTask," + ex.Message);
+                }
+                finally
+                {
+                    Thread.Sleep(5000);
+                }
+            }
+
+        }
+
+    }
+}

+ 2 - 2
EInk.Lot3/TaskThread/SendLot2Lot3Thread.cs

@@ -29,7 +29,7 @@ namespace EInk.TaskThread
             {
                 try
                 {
-                    List<Lot2Lot3Model> unsend_list = _db.Queryable<Lot2Lot3Model>().Where(x => x.is_send == 0).OrderBy(x => x.id).ToList();
+                    List<Lot2Lot3Model> unsend_list = _db.Queryable<Lot2Lot3Model>().Where(x => x.is_send == 0).OrderBy(x => x.id).Take(120).ToList();
                     if (unsend_list != null && unsend_list.Count > 0)
                     {
                         foreach (var unsend in unsend_list)
@@ -53,7 +53,7 @@ namespace EInk.TaskThread
                             {
                                 LogerHelper.RecordLogTxt("SendLotTask,MesApi2," + rt_bl+ "," + rt_str + "," + unsend.content);
                             }
-                            Thread.Sleep(5000);
+                            Thread.Sleep(1000);
                         }
                     }
                 }

+ 3 - 2
EInk.Lot3/appsettings.json

@@ -16,5 +16,6 @@
   "Topic": "LOT2AOIData#04#04-2AOI01",
   "ReadLot2Thread": "off",
   "SendLot2Lot3Thread": "off",
-  "DeleteDBRecordhread": "off"
-}
+  "SendColourCastThread": "off",
+  "DeleteDBRecordThread": "off"
+}