From 8c6c9a5dc1e26890f2f4278842963bc6dcbd656e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?liming=20=E8=94=A1?= Date: Tue, 14 Jul 2026 17:13:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E6=88=90mes=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E8=AF=B7=E6=B1=82-=E5=93=8D=E5=BA=94-=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JY.Control/LogManagerControl.cs | 9 +++++++-- JY.Inspection/HomeForm.cs | 3 ++- JY.Inspection/HomeForm.designer.cs | 1 - JY.Inspection/HomeForm.resx | 2 +- JY.Inspection/Mes/MESDataCombin.cs | 8 ++++---- JY.MES/MESApiHelper.cs | 12 ++++++++++++ 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/JY.Control/LogManagerControl.cs b/JY.Control/LogManagerControl.cs index d3593b8..5f46441 100644 --- a/JY.Control/LogManagerControl.cs +++ b/JY.Control/LogManagerControl.cs @@ -95,6 +95,7 @@ namespace JYControl _manager.listView1.EndUpdate(); + string fileName = $"{DateTime.Now.ToString("yyyyMMdd")}.txt"; switch (logAddtype) { case LogAddtype.MES: @@ -102,7 +103,9 @@ namespace JYControl { Directory.CreateDirectory(logMesPath); } - using (StreamWriter sw = new StreamWriter(logMesPath+DateTime.Now.ToString("yyyyMMdd") + ".txt", true)) + + string logMesFilePath = Path.Combine(logMesPath, fileName); + using (StreamWriter sw = new StreamWriter(logMesFilePath, true)) { sw.WriteLine(strDate + " " + logType.ToString() + " " + strLog); } @@ -112,7 +115,9 @@ namespace JYControl { Directory.CreateDirectory(loglocalPath); } - using (StreamWriter sw = new StreamWriter(loglocalPath+DateTime.Now.ToString("yyyyMMdd") + ".txt", true)) + + string loglocalFilePath = Path.Combine(loglocalPath, fileName); + using (StreamWriter sw = new StreamWriter(loglocalFilePath, true)) { sw.WriteLine(strDate + " " + logType.ToString() + " " + strLog); } diff --git a/JY.Inspection/HomeForm.cs b/JY.Inspection/HomeForm.cs index 6a473a2..6a01323 100644 --- a/JY.Inspection/HomeForm.cs +++ b/JY.Inspection/HomeForm.cs @@ -2445,7 +2445,8 @@ namespace JY.Inspection } else { - LogManagerControl.AddLog("结果数据上传MES失败NG" + resMes.OriResponse.Message, LogAddtype.local, Logtype.Error); + string errMsg = resMes.OriResponse == null ? resMes.ErrorMessage : resMes.OriResponse.ToString(); + LogManagerControl.AddLog("结果数据上传MES失败NG," + errMsg, LogAddtype.local, Logtype.Error); } } #endregion diff --git a/JY.Inspection/HomeForm.designer.cs b/JY.Inspection/HomeForm.designer.cs index 1ec56a5..f6b8a56 100644 --- a/JY.Inspection/HomeForm.designer.cs +++ b/JY.Inspection/HomeForm.designer.cs @@ -2194,7 +2194,6 @@ namespace JY.Inspection this.button1.TabIndex = 51; this.button1.Text = "MEStest"; this.button1.UseVisualStyleBackColor = true; - this.button1.Visible = false; this.button1.Click += new System.EventHandler(this.button1_Click); // // contextMenuStrip1 diff --git a/JY.Inspection/HomeForm.resx b/JY.Inspection/HomeForm.resx index 0a08ad5..010d2f5 100644 --- a/JY.Inspection/HomeForm.resx +++ b/JY.Inspection/HomeForm.resx @@ -331,7 +331,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAE - CgAAAk1TRnQBSQFMAgEBAwEAAZABCAGQAQgBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + CgAAAk1TRnQBSQFMAgEBAwEAAZgBCAGYAQgBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA diff --git a/JY.Inspection/Mes/MESDataCombin.cs b/JY.Inspection/Mes/MESDataCombin.cs index c0177db..99da3cb 100644 --- a/JY.Inspection/Mes/MESDataCombin.cs +++ b/JY.Inspection/Mes/MESDataCombin.cs @@ -214,17 +214,17 @@ namespace JY.Inspection.Mes var sw = new Stopwatch(); sw.Start(); - var mesCallResult = MESApiHelper.HttpPostJsonAPI(Global.systemConfig.ResultProcessMesUrl, p, Global.systemConfig.MesRequestTime); + resp = MESApiHelper.HttpPostJsonAPI(Global.systemConfig.ResultProcessMesUrl, p, Global.systemConfig.MesRequestTime); sw.Stop(); - if (mesCallResult?.OriResponse?.Success != true) + if (resp?.OriResponse != null && resp?.OriResponse.Success != true) { resp.IsSuccess = false; resp.ErrorType = MesErrorType.BusinessError; - resp.ErrorMessage = mesCallResult?.OriResponse.Message ?? "MES业务处理失败"; + resp.ErrorMessage = resp?.OriResponse?.Message ?? "MES业务处理失败, 错误消息为空"; } - new MesLog().LogProductResult(nowTime, p, mesCallResult.OriRespJsonStr, sw.ElapsedMilliseconds); + new MesLog().LogProductResult(nowTime, p, resp.OriRespJsonStr, sw.ElapsedMilliseconds); } catch (Exception ex) { diff --git a/JY.MES/MESApiHelper.cs b/JY.MES/MESApiHelper.cs index 6aac187..da09573 100644 --- a/JY.MES/MESApiHelper.cs +++ b/JY.MES/MESApiHelper.cs @@ -57,6 +57,12 @@ namespace JY.MES result.OriResponse = mesResp; result.OriRespJsonStr = respJsonStr; } + catch (TaskCanceledException ex) + { + result.ErrorType = MesErrorType.NetworkTimeout; + result.ErrorMessage = $"MES请求超时: {ex.Message}"; + return result; + } catch (TimeoutException ex) { result.ErrorType = MesErrorType.NetworkTimeout; @@ -75,6 +81,12 @@ namespace JY.MES result.ErrorMessage = $"MES响应解析失败: {ex.Message}"; return result; } + catch (Exception ex) + { + result.ErrorType = MesErrorType.NetworkTimeout; + result.ErrorMessage = $"MES请求超时: {ex.Message}"; + return result; + } return result; }