From 18475c9ceff517b7ba292b9f8b90933b0ce3fb78 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期三, 23 十二月 2020 16:38:53 +0800
Subject: [PATCH] 添加MES日志开关配置和详细数据日志

---
 src/Bro.M071.Process/M071Process_MES.cs |   73 ++++++++++++++++++++++++++++++++----
 1 files changed, 65 insertions(+), 8 deletions(-)

diff --git a/src/Bro.M071.Process/M071Process_MES.cs b/src/Bro.M071.Process/M071Process_MES.cs
index a5277b3..3b19a35 100644
--- a/src/Bro.M071.Process/M071Process_MES.cs
+++ b/src/Bro.M071.Process/M071Process_MES.cs
@@ -82,14 +82,14 @@
         {
             get
             {
-                if (incomingCheckMethod == null)
+                if (dataUploadMethod == null)
                 {
-                    incomingCheckMethod = InitialMESWebServiceMethod(DataUploadMethodName, out DataUploadObj);
+                    dataUploadMethod = InitialMESWebServiceMethod(DataUploadMethodName, out DataUploadObj);
                 }
 
-                return incomingCheckMethod;
+                return dataUploadMethod;
             }
-            set => incomingCheckMethod = value;
+            set => dataUploadMethod = value;
         }
 
         private MethodInfo InitialMESWebServiceMethod(string methodName, out object invokeClass)
@@ -145,6 +145,12 @@
             //var result = _webApiHelper.dooPost(url, paraStr);
 
             object[] paras = new object[] { barcode, Config.StationCode };
+
+            if (Config.IsEnableMESLog)
+            {
+                LogAsync(DateTime.Now, $"MES鍏ユ枡妫�娴�", JsonConvert.SerializeObject(paras));
+            }
+
             var result = IncomingCheckMethod?.Invoke(IncomingCheckObj, paras).ToString();
             var mesReturn = (MESIncomingCheckReturn)int.Parse(result);
             sw.Stop();
@@ -195,10 +201,14 @@
                 pMeasure.PResult == "OK" ? "PASS" : "FAIL",
                 Config.LineCode,
                 GetMESSlantData(pMeasure),
-                GetMESAlignmentData(pMeasure)
+                GetMESAlignmentData(pMeasure),
+                GetNGKeys(pMeasure)
             };
 
-            //LogAsync(DateTime.Now, $"{barcode}浜у搧妫�娴嬫暟鎹笂浼�", JsonConvert.SerializeObject(paras));
+            if (Config.IsEnableMESLog)
+            {
+                LogAsync(DateTime.Now, $"{barcode}浜у搧妫�娴嬫暟鎹笂浼�", JsonConvert.SerializeObject(paras));
+            }
 
             var result = DataUploadMethod?.Invoke(DataUploadObj, paras).ToString();
             var mesReturn = (MESUploadReturn)int.Parse(result);
@@ -210,12 +220,59 @@
 
         private string GetMESAlignmentData(ProductionMeasurement pMeasure)
         {
-            return string.Join(",", pMeasure.Measurements.Where(u => u.MeasureType == "Alignment").Select(u => $"{u.Name}:{u.Spec.ActualValue.Value.ToString(_precision)}"));
+            return string.Join(",", pMeasure.Measurements.Where(u => u.MeasureType.StartsWith("Alignment")).Select(u => $"{u.Name}:{u.Spec.ActualValue.Value.ToString(_precision)}"));
         }
 
         private string GetMESSlantData(ProductionMeasurement pMeasure)
         {
-            return string.Join(",", pMeasure.Measurements.Where(u => u.MeasureType == "Slant").Select(u => $"{u.Name}:{u.Spec.ActualValue.Value.ToString(_precision)}"));
+            return string.Join(",", pMeasure.Measurements.Where(u => u.MeasureType.StartsWith("Slant")).Select(u => $"{u.Name}:{u.Spec.ActualValue.Value.ToString(_precision)}"));
+        }
+
+        private string GetNGKeys(ProductionMeasurement pMeasure)
+        {
+            string ngCodes = "";
+            Dictionary<string, List<string>> ngCodeDict = new Dictionary<string, List<string>>();
+
+            var ngList = pMeasure.Measurements.Where(m => m.Spec.MeasureResult != true).ToList();
+            if (ngList.Count == 0)
+                return "";
+
+            ngList.GroupBy(m => m.MeasureType).ToList().ForEach(g =>
+                  {
+                      var mType = Config.MeasureTypeCollection.FirstOrDefault(u => u.Code == g.Key);
+                      if (mType != null)
+                      {
+                          if (!ngCodeDict.ContainsKey(mType.NGCode))
+                          {
+                              ngCodeDict[mType.NGCode] = new List<string>();
+                          }
+
+                          g.ToList().ForEach(k =>
+                          {
+                              k.KeyUnitCollection.Select(kk => kk.Key).ToList().ForEach(key =>
+                              {
+                                  string uploadKeyCode = key;
+                                  var keyCodeMap = Config.KeyCodeMappingCollection.FirstOrDefault(kcm => kcm.Key == key);
+                                  if (keyCodeMap != null)
+                                  {
+                                      uploadKeyCode = keyCodeMap.KeyCode;
+                                  }
+
+                                  if (!ngCodeDict[mType.NGCode].Contains(uploadKeyCode))
+                                  {
+                                      ngCodeDict[mType.NGCode].Add(uploadKeyCode);
+                                  }
+                              });
+                          });
+                      }
+                  });
+
+            if (ngCodeDict.Count > 0)
+            {
+                ngCodes = string.Join(";", ngCodeDict.ToList().Select(u => $"{u.Key}:{string.Join(",", u.Value)}"));
+            }
+
+            return ngCodes;
         }
     }
 

--
Gitblit v1.8.0