|
|
@@ -1,3 +1,4 @@
|
|
|
+using Cognex.VisionPro.QuickBuild.Implementation.Internal;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
using Prism.Events;
|
|
|
using Prism.Ioc;
|
|
|
@@ -640,6 +641,92 @@ namespace TeamAAS_VP.Services
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ public async Task<(bool IsSuccess, string Response)> SubmitGetExAsync(string sn, string comp, Dictionary<string, string> data, List<string> results, DateTime start_time, DateTime stop_time, CancellationToken cancellationToken = default)
|
|
|
+ {
|
|
|
+ // 如果已经释放,则抛出异常,防止在已释放资源上继续操作。
|
|
|
+ if (_disposed) throw new ObjectDisposedException(nameof(MesService));
|
|
|
+
|
|
|
+ var device = _configService.GetDeviceInfo();
|
|
|
+ if (device == null || !device.EnableMES)
|
|
|
+ {
|
|
|
+ return (true, "MES功能未启用!");
|
|
|
+ }
|
|
|
+ if (string.IsNullOrWhiteSpace(device.MesUrl))
|
|
|
+ return (false, "Missing MES submit URL");
|
|
|
+ if (device.F == "PTL")
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(device.comp))
|
|
|
+ {
|
|
|
+ return (false, "PTL模式下comp不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //string res = isSuccess ? "Pass" : "Fail";
|
|
|
+ string res = "Pass";
|
|
|
+ if (results.Count > 0)//如果有多个结果,则用逗号连接起来传给MES, MES端再解析
|
|
|
+ {
|
|
|
+ res = string.Join(",", results);
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (device.F == "PTL")
|
|
|
+ {
|
|
|
+ sb.Append($"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&f=PTL&comp={device.comp}:{comp}");
|
|
|
+ foreach (var item in data)
|
|
|
+ {
|
|
|
+ sb.Append($"&{item.Key}={item.Value}");
|
|
|
+ }
|
|
|
+ sb.Append($"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sb.Append($"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&f=PQC");
|
|
|
+ foreach (var item in data)
|
|
|
+ {
|
|
|
+ sb.Append($"&{item.Key}={item.Value}");
|
|
|
+ }
|
|
|
+ sb.Append($"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}");
|
|
|
+ }
|
|
|
+ string url = sb.ToString();
|
|
|
+
|
|
|
+ LogHelper.WriteLogMes($"【上传URL】{url}");
|
|
|
+ SendTaskMessage($"【上传URL】{url}", MessageLevel.Info);
|
|
|
+ (bool IsSuccess, string Response) result = (false, string.Empty);
|
|
|
+
|
|
|
+ for (int i = 0; i < 3; i++)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var rsp = await _httpClient.GetAsync(url, cancellationToken))
|
|
|
+ {
|
|
|
+ var text = await rsp.Content.ReadAsStringAsync();
|
|
|
+ LogHelper.WriteLogMes($"【HTTP接收】{text}");
|
|
|
+ SendTaskMessage($"【HTTP接收】{text}", MessageLevel.Info);
|
|
|
+ // "SFC_OK" 代表和 MES 连接成功
|
|
|
+ if (text.Contains("SFC_OK"))
|
|
|
+ {
|
|
|
+ // 如果有附加信息(多行),代表此 SN 数据有问题,视为失败并返回该文本
|
|
|
+ if (text.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Length > 1)
|
|
|
+ {
|
|
|
+ return (false, text);
|
|
|
+ }
|
|
|
+ return (true, text);
|
|
|
+ }
|
|
|
+ result = (false, text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (OperationCanceledException)
|
|
|
+ {
|
|
|
+ result = (false, "Canceled");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ result = (false, ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 向 MES 提交请求的超时重载,使用超时(秒)作为便捷参数。
|
|
|
/// </summary>
|