baowei 7 месяцев назад
Родитель
Сommit
693199274f

+ 91 - 8
EInk.Lot3/Controllers/Lot3Controller.cs

@@ -9,6 +9,8 @@ using System.Xml.Linq;
 using System;
 using System.Threading;
 using System.Text;
+using EInk.Dtos;
+using System.Reflection.Metadata;
 
 namespace EInk.Controllers
 {
@@ -22,8 +24,7 @@ namespace EInk.Controllers
             _db = db;
         }
 
-        // POST api/<Lot3Controller>
-        [HttpPost("AccessLot3")]
+        [HttpPost("UploadLot3")]
         public IActionResult Lot3Data(string Lot3Data)
         {
             try
@@ -49,16 +50,42 @@ namespace EInk.Controllers
                 {
                     return Ok(ResultDto.Fail(ex.Message));
                 }
-                //int id = _db.Ado.GetInt("select max(count) from lot2lot3_info");
                 Lot2Lot3Model lot3model = new()
                 {
-                    //id = id + 1,
                     lot_id = lot3Dto.id,
-                    //判断数据是否重复插入,重复插入is_send标记为3
-                    is_send = _db.Ado.GetInt(string.Format("select count(*) from lot2lot3_info where lot_id='{0}'", lot3Dto.id)) == 0 ? 0 : 3,
+                    is_send = 0,
+                    product_no = lot3Dto.slidesNumber,
                     content = Lot3Data,
                     create_time = DateTime.Now
                 };
+                //校验是否有id重复的数据
+                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;
+                        }
+                    }
+                }
                 _db.Insertable(lot3model).ExecuteCommand();
                 return Ok(ResultDto.Success());
             }
@@ -68,7 +95,63 @@ namespace EInk.Controllers
             }
         }
 
-        // POST api/<Lot3Controller>
+
+        [HttpPost("UploadColourCast")]
+        public IActionResult ColourCastData(string ColourCastData)
+        {
+            try
+            {
+                if (String.IsNullOrEmpty(ColourCastData))
+                {
+                    return Ok(ResultDto.Fail("Components is null"));
+                }
+                ColourCastDto colourcastDto = new ColourCastDto();
+                try
+                {
+                    colourcastDto = JsonConvert.DeserializeObject<ColourCastDto>(ColourCastData);
+                }
+                catch (Exception)
+                {
+                    return Ok(ResultDto.Fail("Incorrect Json format"));
+                }
+                try
+                {
+                    colourcastDto.Valid();
+                }
+                catch (Exception ex)
+                {
+                    return Ok(ResultDto.Fail(ex.Message));
+                };
+                ColourCastModel colourcastmodel = new()
+                {
+                    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)
+                {
+                    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());
+            }
+            catch (Exception ex)
+            {
+                return Ok(ResultDto.Fail("error:" + ex.Message));
+            }
+        }
+
+
         [HttpPost("UpdateDefectInfo")]
         public IActionResult UpdateDefectInfo(IFormFile file)
         {
@@ -100,7 +183,7 @@ namespace EInk.Controllers
                 }
                 _db.Ado.CommitTran();
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
                 _db.Ado.RollbackTran();
                 return Ok(ResultDto.Fail(ex.Message));

+ 65 - 0
EInk.Lot3/Dtos/ColourCastDto.cs

@@ -0,0 +1,65 @@
+using EInk.Dtos;
+
+namespace EInk.Dtos
+{
+    public class ColourCastDto
+    {
+        public string slidesNumber { get; set; }
+        public string createTime { get; set; }
+        public string topic { get; set; }
+        public string pattern { get; set; }
+        public string result { get; set; }
+        public List<int> values { get; set; } = new List<int>();
+        public int alarmLocation { get; set; }
+        public int threshold { get; set; }
+        public void Valid()
+        {
+            if (String.IsNullOrEmpty(slidesNumber.Trim()))
+            {
+                throw new Exception("Empty slidesNumber");
+            }
+
+            try
+            {
+                DateTime valid = Convert.ToDateTime(createTime);
+            }
+            catch
+            {
+                throw new Exception("Incorrect createTime");
+            }
+
+            if (String.IsNullOrEmpty(topic.Trim()))
+            {
+                throw new Exception("Empty topic");
+            }
+
+            if (String.IsNullOrEmpty(pattern.Trim()))
+            {
+                throw new Exception("Empty pattern");
+            }
+
+            if (result != "en" && result != "ok")
+            {
+                throw new Exception("Incorrect result");
+            }
+
+            try
+            {
+                int valid = Convert.ToInt32(alarmLocation);
+            }
+            catch
+            {
+                throw new Exception("Incorrect alarmLocation");
+            }
+
+            try
+            {
+                int valid = Convert.ToInt32(threshold);
+            }
+            catch
+            {
+                throw new Exception("Incorrect threshold");
+            }
+        }
+    }
+}

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

@@ -0,0 +1,27 @@
+using SqlSugar;
+
+namespace EInk.Models
+{
+    [SugarTable("colourcast_info")]
+    public class ColourCastModel
+    {
+        [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
+        public long id { get; set; }
+
+        [SugarColumn(ColumnName = "slidesNumber", ColumnDataType = StaticConfig.CodeFirst_BigString)]
+        public string slidesNumber { get; set; }
+
+        [SugarColumn(ColumnName = "is_send")]
+        public int is_send { get; set; }
+
+        [SugarColumn(ColumnName = "create_time")]
+        public DateTime create_time { get; set; }
+
+        [SugarColumn(ColumnName = "send_time")]
+        public DateTime send_time { get; set; }
+
+        [SugarColumn(ColumnName = "content")]
+        public string content { get; set; }
+
+    }
+}

+ 3 - 3
EInk.Lot3/Models/DefectModel.cs

@@ -8,13 +8,13 @@ namespace EInk.Models
         [SugarColumn(ColumnName = "id", IsPrimaryKey = true)]
         public int id { get; set; }
 
-        [SugarColumn(ColumnName = "defect_code")]
+        [SugarColumn(ColumnName = "defect_code", ColumnDataType = StaticConfig.CodeFirst_BigString)]
         public string defect_code { get; set; }
 
-        [SugarColumn(ColumnName = "defect_name")]
+        [SugarColumn(ColumnName = "defect_name", ColumnDataType = StaticConfig.CodeFirst_BigString)]
         public string defect_name { get; set; }
 
-        [SugarColumn(ColumnName = "classification")]
+        [SugarColumn(ColumnName = "classification", ColumnDataType = StaticConfig.CodeFirst_BigString)]
         public string classification { get; set; }
 
     }

+ 10 - 10
EInk.Lot3/Models/Lot2Lot3Model.cs

@@ -6,27 +6,27 @@ namespace EInk.Models
     public class Lot2Lot3Model
     {
         [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
-        public int id { get; set; }
+        public long id { get; set; }
 
-        [SugarColumn(ColumnName = "lot_id")]
+        [SugarColumn(ColumnName = "lot_id", ColumnDataType = StaticConfig.CodeFirst_BigString)]
         public string lot_id { get; set; }
 
+        [SugarColumn(ColumnName = "product_no", ColumnDataType = StaticConfig.CodeFirst_BigString)]
+        public string product_no { get; set; }
+
+        [SugarColumn(ColumnName = "product_id")]
+        public long product_id { get; set; }
+
         [SugarColumn(ColumnName = "is_send")]
         public int is_send { get; set; }
 
-        [SugarColumn(ColumnName = "content")]
-        public string content { get; set; }
-
         [SugarColumn(ColumnName = "create_time")]
         public DateTime create_time { get; set; }
 
         [SugarColumn(ColumnName = "send_time")]
         public DateTime send_time { get; set; }
 
-        [SugarColumn(ColumnName = "product_no")]
-        public string product_no { get; set; }
-
-        [SugarColumn(ColumnName = "product_id")]
-        public int product_id { get; set; }
+        [SugarColumn(ColumnName = "content", ColumnDataType = StaticConfig.CodeFirst_BigString)]
+        public string content { get; set; }
     }
 }

+ 5 - 0
EInk.Lot3/Startup.cs

@@ -1,6 +1,7 @@
 using EInk.TaskThread;
 using Microsoft.AspNetCore.Builder;
 using SqlSugar;
+using EInk.Models;
 
 namespace EInk.Lot2Lot3
 {
@@ -23,6 +24,10 @@ namespace EInk.Lot2Lot3
 
         public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
         {
+            _local_db.DbMaintenance.CreateDatabase();
+            _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")
             {

+ 2 - 1
EInk.Lot3/TaskThread/DeleteDBRecordThread.cs

@@ -31,7 +31,8 @@ namespace EInk.TaskThread
                     DateTime now = DateTime.Now;
                     if (now.Hour==8)
                     {
-                        _db.Deleteable<Lot2Lot3Model>().Where(x => x.create_time < now.AddMonths(-2)).ExecuteCommand();  
+                        _db.Deleteable<Lot2Lot3Model>().Where(x => x.create_time < now.AddMonths(-2)).ExecuteCommand();
+                        LogerHelper.RecordLogTxt("DeleteTask");
                     }
 
                 }

+ 2 - 2
EInk.Lot3/appsettings.json

@@ -6,7 +6,7 @@
     }
   },
   "AllowedHosts": "*",
-  "LocalDbConnectionString": "Host=127.0.0.1;Port=5432;Database=localdb;Username=postgres;Password=eink;",
+  "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;",
   "ProductStartID": 0,
@@ -16,5 +16,5 @@
   "Topic": "LOT2AOIData#04#04-2AOI01",
   "ReadLot2Thread": "off",
   "SendLot2Lot3Thread": "off",
-  "DeleteDBRecordhread": "on"
+  "DeleteDBRecordhread": "off"
 }