From a97ac998301461e6284595b1cf2c7b40ce5b2459 Mon Sep 17 00:00:00 2001
From: kingno <30263@KINGNO>
Date: 星期四, 03 四月 2025 14:09:36 +0800
Subject: [PATCH] 优化数据库字段的json传输 新增打印机

---
 src/Bro.M141.Process/M141Process.cs |   94 +++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 78 insertions(+), 16 deletions(-)

diff --git a/src/Bro.M141.Process/M141Process.cs b/src/Bro.M141.Process/M141Process.cs
index 91e0e62..d92a3cf 100644
--- a/src/Bro.M141.Process/M141Process.cs
+++ b/src/Bro.M141.Process/M141Process.cs
@@ -72,11 +72,11 @@
         }
 
         public PLCBase Plc1;
+        PLCBase Plc2;
         Thread ThHeartPlc;
         public override void Open()
         {
             base.Open();
-
             ML = DeviceCollection.FirstOrDefault(u => u is MachineLearningBase) as MachineLearningBase;
             if (ML == null)
             {
@@ -97,6 +97,7 @@
             _positionCheckTimeDict.Clear();
             _positionSpecHeads.Clear();
 
+            mysqlhelper.IniDBIP(M141Config.IPforall);
 
             if (ThHeartPlc == null)
             {
@@ -144,7 +145,6 @@
                 Thread.Sleep(3000);
             }
         }
-
 
         /// <summary>
         /// 缃戠粶棰勭儹
@@ -263,6 +263,19 @@
 
             if (isSaveDB)
             {
+                if (M141Config.Isreadbasketcode)
+                {
+                    p.BasketCode = M141Config.basketcode;
+                }
+                else
+                {
+                    p.BasketCode = mysqlhelper.Getbasketcode(p.SEQUENCE);
+                    if ("NoRead".Equals(p.BasketCode))
+                    {
+                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{p.PID}_{p.SEQUENCE}鑾峰彇妗嗗叿鐮佸け璐� 璧嬪�糔oread");
+                    }
+                }
+
                 mysqlhelper.NewProduct(p);
             }
 
@@ -294,7 +307,7 @@
                     p.PID = p.PID + "_" + sequence.Split('_')[sequence.Split('_').Length - 1];
 
                     p.Initial(M141Config.StationCode, M141Config.WorkPositionCollection.Where(u => u.IsEnabled).Select(u => u.PositionName).ToList());
-                    //LogAsync(DateTime.Now, EnumHelper.LogLevel.Warning, $"鏈兘浠庢暟鎹簱鑾峰彇浜у搧瀵硅薄锛屼娇鐢ㄤ复鏃舵柊寤轰骇鍝佸璞�");
+                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Warning, $"鏈兘浠庢暟鎹簱鑾峰彇浜у搧瀵硅薄锛屼娇鐢ㄤ复鏃舵柊寤轰骇鍝佸璞�");
                 }
 
                 NewProductIntoList(p, false);
@@ -360,22 +373,16 @@
                                     var errorSpec = _errorSpec.Copy();
                                     errorSpec.Code = "妫�娴婽BD";
                                     errorSpec.ActualValue = -999;
-                                    DetectResult ngResult = new DetectResult() { Specs = new List<ISpec>() { errorSpec }, PID = u.Key };
+                                    DetectResult ngResult = new DetectResult() { Specs = new List<ISpec>() { errorSpec }, PID = u.Key ,Id=Guid.NewGuid().ToString()};
                                     ngResults.Add(ngResult);
                                 }
                             }
                         });
-
                         detectResults.AddRange(ngResults);
                         resultList.AddRange(detectResults);
-
-
                     }
-
-
                     RunCustomizedMethod(products, triggerText, triggerSource, imgSet, measureBind.CustomizedMonitorId, resultList);
                     RunCustomizedMethod(products, triggerText, triggerSource, imgSet, measureBind.CustomizedCombineMethodId, resultList);
-
                 }
                 catch (Exception ex)
                 {
@@ -704,6 +711,7 @@
             try
             {
                 ConcurrentDictionary<MeasureBind, IImageSet> imgSetDicts = new ConcurrentDictionary<MeasureBind, IImageSet>();
+                var positionSet = M141Config.WorkPositionCollection.Where(u => u.IsEnabled).FirstOrDefault(u => u.TriggerValue == triggerDatas[0]);
 
                 measureBinds.AsParallel().ForAll(b =>
                 {
@@ -715,6 +723,10 @@
                         try
                         {
                             imgSetDicts[b] = CollectHImage(camera, b.SnapshotOpConfig);
+                            if (positionSet.ispiccover)
+                            {
+                                Plc1.WriteSingleAddress(positionSet.plcover,1,out _);
+                            }
                         }
                         catch (Exception ea)
                         {
@@ -930,21 +942,24 @@
                         plcresult.Add(isOK);
                         List<string> specHeads = new List<string>();
                         string head = p.GetCSVHead(ref specHeads, positionName);
-                        if (!_positionSpecHeads.ContainsKey(positionName))
-                        {
-                            _positionSpecHeads[positionName] = specHeads;
-                        }
+
+                        _positionSpecHeads[positionName] = specHeads;
 
                         string data = p.GetCSVData(_positionSpecHeads[positionName], positionName);
                         CSVRecordAsync($"{positionName}_Record_{DateTime.Now.ToString("yyyyMMdd")}.csv", data, head);
 
                         //UpdatePositionResultToDB(detail);
-                        var seqData = p.SEQUENCE.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList();
+                        //var seqData = p.SEQUENCE.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList();
 
-
+                        mysqlhelper.UpdateProduct(p);
                         if (positionSet.IsLastPosition)
                         {
                             UpdateProductResultAsync(p);
+                            mysqlhelper.NewForAll(p, M141Config.StationCode);
+                            if (M141Config.IsfinDevice)
+                            {
+                                SummaryAllprodata(p);
+                            }
                         }
                     });
                     ReplyPlcData(positionSet, plcresult);
@@ -993,6 +1008,53 @@
         }
 
 
+
+
+
+        public void SummaryAllprodata(ProductModel p)
+        {
+            _taskFactory.StartNew(() =>
+            {
+                try
+                {
+
+                    ProductModel newp = new ProductModel();
+                    newp.SEQUENCE = p.SEQUENCE;
+                    newp.PID = p.PID;
+                    newp.BasketCode = p.BasketCode;
+                    newp.Result = p.Result;
+                    newp.SN = p.SN;
+                    newp.Details.AddRange(p.Details);
+
+                    var plist = mysqlhelper.GetProductList(p.SEQUENCE);
+
+                    if (plist != null)
+                    {
+                        foreach (var item in plist)
+                        {
+                            newp.Details.AddRange(item.Details);
+                        }
+                    }
+
+                    List<string> specHeadListforall = new List<string>();
+                    List<string> positionListforall = new List<string>();
+                    string csvHeadforall = p.GetCSVHead(ref specHeadListforall, ref positionListforall);
+                    CSVRecordAsync($"AllDeviceProductRecord.csv", p.GetCSVData(specHeadListforall, positionListforall), csvHeadforall);
+
+                }
+                catch(Exception exx)
+                {
+                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, "AllDeviceProductRecord鏁版嵁姹囨�诲紓甯�  " + exx.ToString());
+                }
+            });
+
+        }
+
+
+
+
+
+
         #endregion
     }
 

--
Gitblit v1.8.0