|
@@ -0,0 +1,331 @@
|
|
|
|
+using EInk.Models;
|
|
|
|
+using EInk.Dtos;
|
|
|
|
+using SqlSugar;
|
|
|
|
+using System.ComponentModel;
|
|
|
|
+using Newtonsoft.Json;
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using EInk.Tools;
|
|
|
|
+using Microsoft.Extensions.FileSystemGlobbing.Internal;
|
|
|
|
+using System.Linq;
|
|
|
|
+
|
|
|
|
+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));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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();
|
|
|
|
+ string topic = _configuration.GetValue<string>("Topic");
|
|
|
|
+ List<string> patternlist = _configuration.GetValue<string>("PatternList").Split(",").ToList();
|
|
|
|
+ int product_startid = _configuration.GetValue<int>("ProductStartID");
|
|
|
|
+ ISqlSugarClient _db = (ISqlSugarClient)db;
|
|
|
|
+ ISqlSugarClient _local_db = (ISqlSugarClient)local_db;
|
|
|
|
+ while (true)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ int max_productid = _local_db.Ado.GetInt("select max(product_id) from lot2lot3_info");
|
|
|
|
+ List<InitLot2Model> read_list = new List<InitLot2Model>();
|
|
|
|
+ if (product_startid == 0)
|
|
|
|
+ {
|
|
|
|
+ read_list = _db.Queryable<InitLot2Model>().Where(x => x.id > max_productid).Where(x => (x.productno != null && x.station != null && x.pattern != null) && (x.result == "enOK" || x.result == "enNG")).OrderBy(x => x.id).Take(30).ToList();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ read_list = _db.Queryable<InitLot2Model>().Where(x => x.id >= product_startid).Where(x => x.id > max_productid).Where(x => (x.productno != null && x.station != null && x.pattern != null) && (x.result == "enOK" || x.result == "enNG")).Take(60).OrderBy(x => x.id).Take(30).ToList();
|
|
|
|
+ }
|
|
|
|
+ if (read_list != null && read_list.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ _local_db.Ado.BeginTran();
|
|
|
|
+ foreach (var read_lot2 in read_list)
|
|
|
|
+ {
|
|
|
|
+ if (string.IsNullOrEmpty(read_lot2.productno) || string.IsNullOrEmpty(read_lot2.station) || string.IsNullOrEmpty(read_lot2.result))
|
|
|
|
+ {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ List<InitLot2DetailDto> lot2JsonList = new List<InitLot2DetailDto>();
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ //校验json格式
|
|
|
|
+ lot2JsonList = JsonConvert.DeserializeObject<List<InitLot2DetailDto>>(read_lot2.detail);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ LogerHelper.RecordLogTxt("ReadLot2Task,read_lot2Json有误" + ex.Message + "," + JsonConvert.SerializeObject(read_lot2));
|
|
|
|
+ }
|
|
|
|
+ List<Lot2Lot3Model> Lot2ModelList = _local_db.Queryable<Lot2Lot3Model>().Where(x => x.product_no == read_lot2.productno).ToList();
|
|
|
|
+ if (Lot2ModelList == null || Lot2ModelList.Count == 0)
|
|
|
|
+ {
|
|
|
|
+ Lot2Lot3Dto lot2Detail = new()
|
|
|
|
+ {
|
|
|
|
+ id = new GuidDto().Id,
|
|
|
|
+ slidesNumber = read_lot2.productno.Split('_')[0],
|
|
|
|
+ topic = topic,
|
|
|
|
+ createTime = read_lot2.created_at.ToString(),
|
|
|
|
+ result = read_lot2.result == "enOK" ? "OK" : "NG",
|
|
|
|
+ itemCheckDatas = new List<itemCheckData>()
|
|
|
|
+ };
|
|
|
|
+ itemCheckData lot2item = new itemCheckData()
|
|
|
|
+ {
|
|
|
|
+ station = read_lot2.station,
|
|
|
|
+ method = "1",
|
|
|
|
+ pattern = read_lot2.pattern,
|
|
|
|
+ result = read_lot2.result == "enOK" ? "OK" : "NG",
|
|
|
|
+ details = new List<detail>()
|
|
|
|
+ };
|
|
|
|
+ if (lot2JsonList != null && lot2JsonList.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ foreach (var item in lot2JsonList)
|
|
|
|
+ {
|
|
|
|
+ string defectCode = "null";
|
|
|
|
+ string defectName = "null";
|
|
|
|
+ if (!string.IsNullOrEmpty(item.Classification.Trim()))
|
|
|
|
+ {
|
|
|
|
+ List<DefectModel> defectCodelist = _local_db.SqlQueryable<DefectModel>("SELECT * FROM public.defect_info where classification ~* '" + item.Classification + "'").ToList();
|
|
|
|
+ //List<DefectModel> defectCodelist = _local_db.Queryable<DefectModel>().Where(x => x.defect_name == item.Classification).ToList();
|
|
|
|
+ if (defectCodelist != null && defectCodelist.Count != 0)
|
|
|
|
+ {
|
|
|
|
+ foreach (var defect_info in defectCodelist)
|
|
|
|
+ {
|
|
|
|
+ foreach (var defect_classification in defect_info.classification.Split(','))
|
|
|
|
+ {
|
|
|
|
+ if (item.Classification == defect_classification)
|
|
|
|
+ {
|
|
|
|
+ defectCode = defect_info.defect_code;
|
|
|
|
+ defectName = defect_info.defect_name;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ lot2item.details.Add(new detail()
|
|
|
|
+ {
|
|
|
|
+ defectCode = defectCode,
|
|
|
|
+ defectName = defectName,
|
|
|
|
+ x = item.ContourRect_X,
|
|
|
|
+ y = item.ContourRect_Y,
|
|
|
|
+ width = item.ContourRect_Width,
|
|
|
|
+ height = item.ContourRect_Height,
|
|
|
|
+ area = item.ContourRect_Area
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ lot2Detail.itemCheckDatas.Add(lot2item);
|
|
|
|
+ Lot2Lot3Model lot2model = new()
|
|
|
|
+ {
|
|
|
|
+ lot_id = lot2Detail.id,
|
|
|
|
+ is_send = 2,
|
|
|
|
+ content = JsonConvert.SerializeObject(lot2Detail),
|
|
|
|
+ create_time = DateTime.Now,
|
|
|
|
+ product_no = read_lot2.productno,
|
|
|
|
+ product_id = read_lot2.id
|
|
|
|
+ };
|
|
|
|
+ _local_db.Insertable(lot2model).ExecuteCommand();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if (Lot2ModelList[0].is_send == 2)
|
|
|
|
+ {
|
|
|
|
+ Lot2ModelList[0].create_time = DateTime.Now;
|
|
|
|
+ Lot2Lot3Dto lot2Detail = new Lot2Lot3Dto();
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ lot2Detail = JsonConvert.DeserializeObject<Lot2Lot3Dto>(Lot2ModelList[0].content);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ LogerHelper.RecordLogTxt("ReadLot2Task,lot2DetailJson有误" + ex.Message + "," + JsonConvert.SerializeObject(Lot2ModelList[0].content));
|
|
|
|
+ }
|
|
|
|
+ //is_send:0、等待发送;1、已发送;2、等待补充信息;3、重复插入;
|
|
|
|
+ lot2Detail.createTime = read_lot2.created_at.ToString();
|
|
|
|
+ bool send_flag = true;
|
|
|
|
+ foreach (var item in patternlist)
|
|
|
|
+ {
|
|
|
|
+ bool flag = false;
|
|
|
|
+ if (item == read_lot2.pattern)
|
|
|
|
+ {
|
|
|
|
+ flag = true;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ foreach (var item1 in lot2Detail.itemCheckDatas)
|
|
|
|
+ {
|
|
|
|
+ if (item == item1.pattern)
|
|
|
|
+ {
|
|
|
|
+ flag = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ send_flag = send_flag & flag;
|
|
|
|
+ }
|
|
|
|
+ Lot2ModelList[0].is_send = send_flag ? 0 : 2;
|
|
|
|
+ Lot2ModelList[0].product_id = read_lot2.id;
|
|
|
|
+ if (read_lot2.result == "enNG")
|
|
|
|
+ {
|
|
|
|
+ lot2Detail.result = "NG";
|
|
|
|
+ }
|
|
|
|
+ itemCheckData lot2item = new itemCheckData()
|
|
|
|
+ {
|
|
|
|
+ station = read_lot2.station,
|
|
|
|
+ method = "1",
|
|
|
|
+ pattern = read_lot2.pattern,
|
|
|
|
+ result = read_lot2.result == "enOK" ? "OK" : "NG",
|
|
|
|
+ details = new List<detail>()
|
|
|
|
+ };
|
|
|
|
+ if (lot2JsonList != null && lot2JsonList.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ foreach (var item in lot2JsonList)
|
|
|
|
+ {
|
|
|
|
+ string defectCode = "null";
|
|
|
|
+ string defectName = "null";
|
|
|
|
+ if (!string.IsNullOrEmpty(item.Classification.Trim()))
|
|
|
|
+ {
|
|
|
|
+ List<DefectModel> defectCodelist = _local_db.SqlQueryable<DefectModel>("SELECT * FROM public.defect_info where classification ~* '" + item.Classification + "'").ToList();
|
|
|
|
+ //List<DefectModel> defectCodelist = _local_db.Queryable<DefectModel>().Where(x => x.defect_name == item.Classification).ToList();
|
|
|
|
+ if (defectCodelist != null && defectCodelist.Count != 0)
|
|
|
|
+ {
|
|
|
|
+ foreach (var defect_info in defectCodelist)
|
|
|
|
+ {
|
|
|
|
+ foreach (var defect_classification in defect_info.classification.Split(','))
|
|
|
|
+ {
|
|
|
|
+ if (item.Classification == defect_classification)
|
|
|
|
+ {
|
|
|
|
+ defectCode = defect_info.defect_code;
|
|
|
|
+ defectName = defect_info.defect_name;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ lot2item.details.Add(new detail()
|
|
|
|
+ {
|
|
|
|
+ defectCode = defectCode,
|
|
|
|
+ defectName = defectName,
|
|
|
|
+ x = item.ContourRect_X,
|
|
|
|
+ y = item.ContourRect_Y,
|
|
|
|
+ width = item.ContourRect_Width,
|
|
|
|
+ height = item.ContourRect_Height,
|
|
|
|
+ area = item.ContourRect_Area
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ lot2Detail.itemCheckDatas.Add(lot2item);
|
|
|
|
+ Lot2ModelList[0].content = JsonConvert.SerializeObject(lot2Detail);
|
|
|
|
+ _local_db.Updateable<Lot2Lot3Model>(Lot2ModelList[0]).WhereColumns(s => s.id).ExecuteCommand();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Lot2Lot3Dto lot2Detail = new()
|
|
|
|
+ {
|
|
|
|
+ id = new GuidDto().Id,
|
|
|
|
+ slidesNumber = read_lot2.productno.Split('_')[0],
|
|
|
|
+ topic = topic,
|
|
|
|
+ createTime = read_lot2.created_at.ToString(),
|
|
|
|
+ result = read_lot2.result == "enOK" ? "OK" : "NG",
|
|
|
|
+ itemCheckDatas = new List<itemCheckData>()
|
|
|
|
+ };
|
|
|
|
+ itemCheckData lot2item = new itemCheckData()
|
|
|
|
+ {
|
|
|
|
+ station = read_lot2.station,
|
|
|
|
+ method = "1",
|
|
|
|
+ pattern = read_lot2.pattern,
|
|
|
|
+ result = read_lot2.result == "enOK" ? "OK" : "NG",
|
|
|
|
+ details = new List<detail>()
|
|
|
|
+ };
|
|
|
|
+ if (lot2JsonList != null && lot2JsonList.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ foreach (var item in lot2JsonList)
|
|
|
|
+ {
|
|
|
|
+ string defectCode = "null";
|
|
|
|
+ string defectName = "null";
|
|
|
|
+ if (!string.IsNullOrEmpty(item.Classification.Trim()))
|
|
|
|
+ {
|
|
|
|
+ List<DefectModel> defectCodelist = _local_db.SqlQueryable<DefectModel>("SELECT * FROM public.defect_info where classification ~* '" + item.Classification + "'").ToList();
|
|
|
|
+ //List<DefectModel> defectCodelist = _local_db.Queryable<DefectModel>().Where(x => x.defect_name == item.Classification).ToList();
|
|
|
|
+ if (defectCodelist != null && defectCodelist.Count != 0)
|
|
|
|
+ {
|
|
|
|
+ foreach (var defect_info in defectCodelist)
|
|
|
|
+ {
|
|
|
|
+ foreach (var defect_classification in defect_info.classification.Split(','))
|
|
|
|
+ {
|
|
|
|
+ if (item.Classification == defect_classification)
|
|
|
|
+ {
|
|
|
|
+ defectCode = defect_info.defect_code;
|
|
|
|
+ defectName = defect_info.defect_name;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ lot2item.details.Add(new detail()
|
|
|
|
+ {
|
|
|
|
+ defectCode = defectCode,
|
|
|
|
+ defectName = defectName,
|
|
|
|
+ x = item.ContourRect_X,
|
|
|
|
+ y = item.ContourRect_Y,
|
|
|
|
+ width = item.ContourRect_Width,
|
|
|
|
+ height = item.ContourRect_Height,
|
|
|
|
+ area = item.ContourRect_Area
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ lot2Detail.itemCheckDatas.Add(lot2item);
|
|
|
|
+ Lot2Lot3Model lot2model = new()
|
|
|
|
+ {
|
|
|
|
+ lot_id = lot2Detail.id,
|
|
|
|
+ is_send = 3,
|
|
|
|
+ content = JsonConvert.SerializeObject(lot2Detail),
|
|
|
|
+ create_time = DateTime.Now,
|
|
|
|
+ product_no = read_lot2.productno,
|
|
|
|
+ product_id = read_lot2.id
|
|
|
|
+ };
|
|
|
|
+ _local_db.Insertable(lot2model).ExecuteCommand();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Thread.Sleep(500);
|
|
|
|
+ }
|
|
|
|
+ _local_db.Ado.CommitTran();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ LogerHelper.RecordLogTxt("ReadLot2Task[1]," + ex.Message);
|
|
|
|
+ _local_db.Ado.RollbackTran();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ LogerHelper.RecordLogTxt("ReadLot2Task[2]," + ex.Message);
|
|
|
|
+ }
|
|
|
|
+ finally
|
|
|
|
+ {
|
|
|
|
+ Thread.Sleep(5000);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|