From 3322022068ab818912d6f5d9e5eb31f51cc639c2 Mon Sep 17 00:00:00 2001 From: patrick.xu <patrick.xu@broconcentric.com> Date: 星期四, 24 二月 2022 09:12:30 +0800 Subject: [PATCH] 添加配置文件的DataShift2 --- src/Bro.M071.Process/M071Process_MES.cs | 130 ++++++++++++++++++++++++++++++++++++++---- 1 files changed, 116 insertions(+), 14 deletions(-) diff --git a/src/Bro.M071.Process/M071Process_MES.cs b/src/Bro.M071.Process/M071Process_MES.cs index a5277b3..3f61ec4 100644 --- a/src/Bro.M071.Process/M071Process_MES.cs +++ b/src/Bro.M071.Process/M071Process_MES.cs @@ -7,7 +7,9 @@ using System.Linq; using System.Reflection; using System.Text; +using System.Threading; using System.Threading.Tasks; +using System.Windows.Forms; namespace Bro.M071.Process { @@ -82,14 +84,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) @@ -138,14 +140,39 @@ //string paraStr = JsonConvert.SerializeObject(paras); //LogAsync(DateTime.Now, $"MES鍏ユ枡妫�娴� {url}", paraStr); - IncomingCheckMethod = InitialMESWebServiceMethod(IncomingCheckMethodName, out IncomingCheckObj); + //IncomingCheckMethod = InitialMESWebServiceMethod(IncomingCheckMethodName, out IncomingCheckObj); Stopwatch sw = new Stopwatch(); sw.Start(); //var result = _webApiHelper.dooPost(url, paraStr); - object[] paras = new object[] { barcode, Config.StationCode }; - var result = IncomingCheckMethod?.Invoke(IncomingCheckObj, paras).ToString(); + object[] paras = new object[] { barcode, Config.StationCode, Config.ProjectCode }; + + if (Config.IsEnableMESLog) + { + LogAsync(DateTime.Now, $"MES鍏ユ枡妫�娴�", JsonConvert.SerializeObject(paras)); + } + + string result = "-3"; + + int repeatTime = 3; + + do + { + try + { + result = IncomingCheckMethod?.Invoke(IncomingCheckObj, paras).ToString(); + repeatTime = -1; + } + catch (Exception ex) + { + LogAsync(DateTime.Now, $"{barcode}浜у搧鏉$爜妫�娴嬪紓甯�", ex.GetExceptionMessage()); + repeatTime--; + + Thread.Sleep(100); + result = "-3"; + } + } while (repeatTime > 0); var mesReturn = (MESIncomingCheckReturn)int.Parse(result); sw.Stop(); LogAsync(DateTime.Now, $"{barcode}浜у搧鏉$爜妫�娴嬶紝{result}|{mesReturn.ToString()}", $"鑰楁椂锛歿sw.ElapsedMilliseconds}ms"); @@ -178,7 +205,7 @@ //string paraStr = JsonConvert.SerializeObject(paras); //LogAsync(DateTime.Now, $"MES鏁版嵁涓婁紶 {url}", paraStr); - DataUploadMethod = InitialMESWebServiceMethod(DataUploadMethodName, out DataUploadObj); + //DataUploadMethod = InitialMESWebServiceMethod(DataUploadMethodName, out DataUploadObj); Stopwatch sw = new Stopwatch(); sw.Start(); @@ -190,32 +217,107 @@ Config.IsDisableMultipleCheckTimes, Config.ProjectCode, pMeasure.Barcode, - checkTime.ToString("yyyy-MM-dd HH:mm:ss"), + checkTime, Config.StationCode, 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, $"{pMeasure.Barcode}浜у搧妫�娴嬫暟鎹笂浼�", JsonConvert.SerializeObject(paras)); + } - var result = DataUploadMethod?.Invoke(DataUploadObj, paras).ToString(); + string result = "-1"; + + int repeatTime = 3; + do + { + try + { + result = DataUploadMethod?.Invoke(DataUploadObj, paras).ToString(); + repeatTime = -1; + } + catch (Exception ex) + { + LogAsync(DateTime.Now, $"{barcode}浜у搧妫�娴嬫暟鎹笂浼犲紓甯�", ex.GetExceptionMessage()); + repeatTime--; + + Thread.Sleep(100); + result = "-1"; + } + } while (repeatTime > 0); + var mesReturn = (MESUploadReturn)int.Parse(result); sw.Stop(); LogAsync(DateTime.Now, $"{barcode}浜у搧妫�娴嬫暟鎹笂浼狅紝{result}|{mesReturn.ToString()}", $"鑰楁椂锛歿sw.ElapsedMilliseconds}ms"); OnCheckHintUpload?.Invoke("妫�娴嬫暟鎹�" + mesReturn.ToString(), mesReturn != MESUploadReturn.涓婁紶鎴愬姛); + + if (mesReturn != MESUploadReturn.涓婁紶鎴愬姛) + { + MessageBox.Show($"{barcode}浜у搧鏁版嵁涓婁紶澶辫触,{mesReturn.ToString()}\r\n璇锋鏌ョ綉缁滆繛鎺ユ垨纭闂鍚庨噸鏂版娴�", "涓婁紶寮傚父", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } } 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