baowei 7 meses atrás
pai
commit
960137d96c

+ 41 - 35
EInk.Lot3/Controllers/Lot3Controller.cs

@@ -58,34 +58,34 @@ namespace EInk.Controllers
                     content = Lot3Data,
                     create_time = DateTime.Now
                 };
-                //校验是否有id重复的数据
+                //根据guid查看是否为重复插入
                 if (_db.Ado.GetInt(string.Format("select count(*) from lot2lot3_info where lot_id='{0}'", lot3Dto.id)) > 0)
                 {
                     lot3model.is_send = 3;
                 }
-                else
-                {
-                    //校验是否有片号重复的数据
-                    List<Lot2Lot3Model> lot_list = _db.Queryable<Lot2Lot3Model>().Where(x => x.product_no == lot3Dto.slidesNumber).OrderByDescending(x => x.id).ToList();
-                    if (lot_list.Count > 0)
-                    {
-                        Lot2Lot3Dto lot3Dto_db = JsonConvert.DeserializeObject<Lot2Lot3Dto>(lot_list[0].content);
-                        if (Convert.ToDateTime(lot3Dto.createTime) > Convert.ToDateTime(lot3Dto_db.createTime))
-                        {
-                            if (lot3Dto_db.result == "NG") lot3Dto.result = "NG";
-                            foreach (var item in lot3Dto.itemCheckDatas)
-                            {
-                                lot3Dto_db.itemCheckDatas.Add(item);
-                            }
-                            lot3Dto.itemCheckDatas = lot3Dto_db.itemCheckDatas;
-                            lot3model.content = JsonConvert.SerializeObject(lot3Dto);
-                        }
-                        else
-                        {
-                            lot3model.is_send = 3;
-                        }
-                    }
-                }
+                //else
+                //{
+                //    //校验是否有片号重复的数据
+                //    List<Lot2Lot3Model> lot_list = _db.Queryable<Lot2Lot3Model>().Where(x => x.product_no == lot3Dto.slidesNumber).OrderByDescending(x => x.id).ToList();
+                //    if (lot_list.Count > 0)
+                //    {
+                //        Lot2Lot3Dto lot3Dto_db = JsonConvert.DeserializeObject<Lot2Lot3Dto>(lot_list[0].content);
+                //        if (Convert.ToDateTime(lot3Dto.createTime) > Convert.ToDateTime(lot3Dto_db.createTime))
+                //        {
+                //            if (lot3Dto_db.result == "NG") lot3Dto.result = "NG";
+                //            foreach (var item in lot3Dto.itemCheckDatas)
+                //            {
+                //                lot3Dto_db.itemCheckDatas.Add(item);
+                //            }
+                //            lot3Dto.itemCheckDatas = lot3Dto_db.itemCheckDatas;
+                //            lot3model.content = JsonConvert.SerializeObject(lot3Dto);
+                //        }
+                //        else
+                //        {
+                //            lot3model.is_send = 3;
+                //        }
+                //    }
+                //}
                 _db.Insertable(lot3model).ExecuteCommand();
                 return Ok(ResultDto.Success());
             }
@@ -124,24 +124,30 @@ namespace EInk.Controllers
                 };
                 ColourCastModel colourcastmodel = new()
                 {
+                    gid = colourcastDto.id,
                     slidesNumber = colourcastDto.slidesNumber,
                     is_send = 0,
                     content = ColourCastData,
                     create_time = DateTime.Now
                 };
-                List<ColourCastModel> colourcast_list = _db.Queryable<ColourCastModel>().Where(x => x.slidesNumber == colourcastDto.slidesNumber).OrderByDescending(x => x.id).ToList();
-                if (colourcast_list.Count > 0)
+                //根据guid查看是否为重复插入
+                if (_db.Ado.GetInt(string.Format("select count(*) from colourcast_info where gid='{0}'", colourcastDto.id)) > 0)
                 {
-                    ColourCastDto colourcastDto_db = JsonConvert.DeserializeObject<ColourCastDto>(colourcast_list[0].content);
-                    if (Convert.ToDateTime(colourcastDto.createTime) > Convert.ToDateTime(colourcastDto_db.createTime))
-                    {
-                        colourcastmodel.is_send = 0;
-                    }
-                    else
-                    {
-                        colourcastmodel.is_send = 3;
-                    }
+                    colourcastmodel.is_send = 3;
                 }
+                //List<ColourCastModel> colourcast_list = _db.Queryable<ColourCastModel>().Where(x => x.slidesNumber == colourcastDto.slidesNumber).OrderByDescending(x => x.id).ToList();
+                //if (colourcast_list.Count > 0)
+                //{
+                //    ColourCastDto colourcastDto_db = JsonConvert.DeserializeObject<ColourCastDto>(colourcast_list[0].content);
+                //    if (Convert.ToDateTime(colourcastDto.createTime) > Convert.ToDateTime(colourcastDto_db.createTime))
+                //    {
+                //        colourcastmodel.is_send = 0;
+                //    }
+                //    else
+                //    {
+                //        colourcastmodel.is_send = 3;
+                //    }
+                //}
                 _db.Insertable(colourcastmodel).ExecuteCommand();
                 return Ok(ResultDto.Success());
             }

+ 10 - 4
EInk.Lot3/Dtos/ColourCastDto.cs

@@ -4,6 +4,7 @@ namespace EInk.Dtos
 {
     public class ColourCastDto
     {
+        public string id { get; set; }
         public string slidesNumber { get; set; }
         public string createTime { get; set; }
         public string topic { get; set; }
@@ -14,7 +15,12 @@ namespace EInk.Dtos
         public int threshold { get; set; }
         public void Valid()
         {
-            if (String.IsNullOrEmpty(slidesNumber.Trim()))
+            if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(id.Trim()))
+            {
+                throw new Exception("Empty id");
+            }
+
+            if (String.IsNullOrEmpty(slidesNumber) || String.IsNullOrEmpty(slidesNumber.Trim()))
             {
                 throw new Exception("Empty slidesNumber");
             }
@@ -28,17 +34,17 @@ namespace EInk.Dtos
                 throw new Exception("Incorrect createTime");
             }
 
-            if (String.IsNullOrEmpty(topic.Trim()))
+            if (String.IsNullOrEmpty(topic) || String.IsNullOrEmpty(topic.Trim()))
             {
                 throw new Exception("Empty topic");
             }
 
-            if (String.IsNullOrEmpty(pattern.Trim()))
+            if (String.IsNullOrEmpty(pattern) || String.IsNullOrEmpty(pattern.Trim()))
             {
                 throw new Exception("Empty pattern");
             }
 
-            if (result != "en" && result != "ok")
+            if (String.IsNullOrEmpty(result) || (result != "NG" && result != "OK"))
             {
                 throw new Exception("Incorrect result");
             }

+ 28 - 27
EInk.Lot3/Dtos/Lot2Lot3Dto.cs

@@ -1,4 +1,5 @@
-using Microsoft.Extensions.FileSystemGlobbing.Internal;
+using EInk.Models;
+using Microsoft.Extensions.FileSystemGlobbing.Internal;
 using System.ComponentModel;
 using static System.Collections.Specialized.BitVector32;
 
@@ -57,19 +58,19 @@ namespace EInk.Dtos
         public List<detail> details { get; set; } = new List<detail>();
         public void Valid()
         {
-            if (String.IsNullOrEmpty(station.Trim()))
+            if (String.IsNullOrEmpty(station) || String.IsNullOrEmpty(station.Trim()))
             {
                 throw new Exception("Empty station");
             }
-            if (String.IsNullOrEmpty(method.Trim()))
+            if (String.IsNullOrEmpty(method) || String.IsNullOrEmpty(method.Trim()))
             {
                 throw new Exception("Empty method");
             }
-            if (String.IsNullOrEmpty(pattern.Trim()))
+            if (String.IsNullOrEmpty(pattern) || String.IsNullOrEmpty(pattern.Trim()))
             {
                 throw new Exception("Empty pattern");
             }
-            if (String.IsNullOrEmpty(result.Trim()))
+            if (String.IsNullOrEmpty(result) || String.IsNullOrEmpty(result.Trim()))
             {
                 throw new Exception("Empty result");
             }
@@ -95,34 +96,34 @@ namespace EInk.Dtos
         public string area { get; set; }
         public void Valid()
         {
-            if (String.IsNullOrEmpty(defectCode.Trim()))
+            if (String.IsNullOrEmpty(defectCode) || String.IsNullOrEmpty(defectCode.Trim()))
             {
                 throw new Exception("Empty defectCode");
             }
-            if (String.IsNullOrEmpty(defectName.Trim()))
+            if (String.IsNullOrEmpty(defectName) || String.IsNullOrEmpty(defectName.Trim()))
             {
                 throw new Exception("Empty defectName");
             }
-            if (String.IsNullOrEmpty(x.Trim()))
-            {
-                throw new Exception("Empty x");
-            }
-            if (String.IsNullOrEmpty(y.Trim()))
-            {
-                throw new Exception("Empty y");
-            }
-            if (String.IsNullOrEmpty(width.Trim()))
-            {
-                throw new Exception("Empty width");
-            }
-            if (String.IsNullOrEmpty(height.Trim()))
-            {
-                throw new Exception("Empty height");
-            }
-            if (String.IsNullOrEmpty(area.Trim()))
-            {
-                throw new Exception("Empty area");
-            }
+            //if (x == null || String.IsNullOrEmpty(x.Trim()))
+            //{
+            //    throw new Exception("Empty x");
+            //}
+            //if (y == null || String.IsNullOrEmpty(y.Trim()))
+            //{
+            //    throw new Exception("Empty y");
+            //}
+            //if (width == null || String.IsNullOrEmpty(width.Trim()))
+            //{
+            //    throw new Exception("Empty width");
+            //}
+            //if (height == null || String.IsNullOrEmpty(height.Trim()))
+            //{
+            //    throw new Exception("Empty height");
+            //}
+            //if (area == null || String.IsNullOrEmpty(area.Trim()))
+            //{
+            //    throw new Exception("Empty area");
+            //}
 
             //try
             //{

+ 3 - 0
EInk.Lot3/Models/ColourCastModel.cs

@@ -11,6 +11,9 @@ namespace EInk.Models
         [SugarColumn(ColumnName = "slidesNumber", ColumnDataType = StaticConfig.CodeFirst_BigString)]
         public string slidesNumber { get; set; }
 
+        [SugarColumn(ColumnName = "gid", ColumnDataType = StaticConfig.CodeFirst_BigString)]
+        public string gid { get; set; }
+
         [SugarColumn(ColumnName = "is_send")]
         public int is_send { get; set; }
 

+ 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 =>
 {

+ 9 - 2
EInk.Lot3/Startup.cs

@@ -2,6 +2,7 @@
 using Microsoft.AspNetCore.Builder;
 using SqlSugar;
 using EInk.Models;
+using EInk.Tools;
 
 namespace EInk.Lot2Lot3
 {
@@ -37,7 +38,7 @@ namespace EInk.Lot2Lot3
         }
     }
 
-    public class SendLot2Lot3Filter : IStartupFilter
+    public class SendDataFilter : IStartupFilter
     {
         private readonly ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
         {
@@ -53,6 +54,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 +77,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);
                         }
                     }
                 }

+ 14 - 2
EInk.Lot3/appsettings.json

@@ -6,6 +6,17 @@
     }
   },
   "AllowedHosts": "*",
+  "Kestrel": {
+    "EndPoints": {
+      "Http": {
+        "Url": "http://localhost:8081"
+      }
+
+      //"Https": {
+      //  "Url": "https://localhost:8082"
+      //}
+    }
+  },
   "LocalDbConnectionString": "Host=127.0.0.1;Port=5432;Database=Lot2Lot3;Username=postgres;Password=eink;",
   //"TargetDbConnectionString": "Host=127.0.0.1;Port=5432;Database=targetdb;Username=postgres;Password=eink;",
   "TargetDbConnectionString": "Host=192.168.1.108;Port=5432;Database=eink;Username=postgres;Password=eink;",
@@ -16,5 +27,6 @@
   "Topic": "LOT2AOIData#04#04-2AOI01",
   "ReadLot2Thread": "off",
   "SendLot2Lot3Thread": "off",
-  "DeleteDBRecordhread": "off"
-}
+  "SendColourCastThread": "off",
+  "DeleteDBRecordThread": "off"
+}

+ 18 - 0
EInk.Lot3/web.config

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <location path="." inheritInChildApplications="false">
+    <system.webServer>
+      <!--允许上传文件长度,单位字节-->
+      <handlers>
+        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
+      </handlers>
+      <aspNetCore processPath="dotnet" arguments=".\EInk.Lot2Lot3.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
+      <security>
+         <requestFiltering>
+           <requestLimits maxQueryString ="20971520"/>
+         </requestFiltering>
+      </security>
+    </system.webServer>
+  </location>
+</configuration>
+<!--ProjectGuid: 0c0961a1-494f-4ffc-82b9-1623aa58f174-->