diff --git a/admin.net.pro/Admin.NET/Vistar.Application/SapService/Dto/SapEcnQueryInput.cs b/admin.net.pro/Admin.NET/Vistar.Application/SapService/Dto/SapEcnQueryInput.cs new file mode 100644 index 0000000..de1e122 --- /dev/null +++ b/admin.net.pro/Admin.NET/Vistar.Application/SapService/Dto/SapEcnQueryInput.cs @@ -0,0 +1,80 @@ +// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。 +// +// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。 +// +// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Vistar.Application.SapService.Dto; +public class SapEcnQueryInput +{ + /// + /// 接口唯一ID + /// + public string Reqkeyid { get; set; } + + /// + /// 业务唯一ID + /// + public string Businessid { get; set; } + + /// + /// 业务唯一ID + /// + public string Messageid { get; set; } + + /// + /// 发送方的合作伙伴编号 + /// + public string Sndprn { get; set; } + + /// + /// 接收方的合作伙伴编号 + /// + public string Rcvprn { get; set; } + + /// + /// 用户名 + /// + public string Requser { get; set; } + + /// + /// 备注 + /// + public string Note1 { get; set; } + + /// + /// 备注 + /// + public string Note2 { get; set; } + + /// + /// 备注 + /// + public string Note3 { get; set; } + + /// + /// 范围类型的行类型中的 SIGN 组件的类型 默认:I + /// + public string Sign { get; set; } + + /// + /// 范围类型的行类型中的 OPTION 组件的类型 选择单值的时候,这里输入EQ,LOW值作为单选值值,输入范围的时候,这里输入BT,LOW作为区间起点,HIGH作为区间终点 + /// + public string Option { get; set; } + + /// + /// 物料编号 + /// + public string Low { get; set; } + + /// + /// 物料编号 + /// + public string High { get; set; } +} diff --git a/admin.net.pro/Admin.NET/Vistar.Application/SapService/SapService.cs b/admin.net.pro/Admin.NET/Vistar.Application/SapService/SapService.cs index f1f5a0b..e37c20d 100644 --- a/admin.net.pro/Admin.NET/Vistar.Application/SapService/SapService.cs +++ b/admin.net.pro/Admin.NET/Vistar.Application/SapService/SapService.cs @@ -110,7 +110,7 @@ public class SapService : IDynamicApiController, ITransient content.Headers.ContentType = new MediaTypeHeaderValue("text/xml"); httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh"); // 设置 SAP Web 服务的 URL - var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zmmfm012/100/zmmfm012/zmmfm012"; + var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zmmfm012/800/zmmfm012/zmmfm012"; // 发起 POST 请求到 SAP Web 服务 var response = await httpClient.PostAsync(url, content); @@ -222,7 +222,7 @@ public class SapService : IDynamicApiController, ITransient content.Headers.ContentType = new MediaTypeHeaderValue("text/xml"); httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh"); // 设置 SAP Web 服务的 URL - var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zppfm001/100/zppfm001/zppfm001"; + var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zppfm001/800/zppfm001/zppfm001"; // 发起 POST 请求到 SAP Web 服务 var response = await httpClient.PostAsync(url, content); @@ -396,7 +396,7 @@ public class SapService : IDynamicApiController, ITransient content.Headers.ContentType = new MediaTypeHeaderValue("text/xml"); httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh"); // 设置 SAP Web 服务的 URL - var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zppfm003/100/zppfm003/zppfm003"; + var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zppfm003/800/zppfm003/zppfm003"; // 发起 POST 请求到 SAP Web 服务 var response = await httpClient.PostAsync(url, content); @@ -506,7 +506,7 @@ public class SapService : IDynamicApiController, ITransient content.Headers.ContentType = new MediaTypeHeaderValue("text/xml"); httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh"); // 设置 SAP Web 服务的 URL - var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zppfm004/100/zppfm004/zppfm004"; + var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zppfm004/800/zppfm004/zppfm004"; // 发起 POST 请求到 SAP Web 服务 var response = await httpClient.PostAsync(url, content); @@ -660,7 +660,7 @@ public class SapService : IDynamicApiController, ITransient content.Headers.ContentType = new MediaTypeHeaderValue("text/xml"); httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh"); // 设置 SAP Web 服务的 URL - var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zmmfm013/100/zmmfm013/zmmfm013"; + var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zmmfm013/800/zmmfm013/zmmfm013"; // 发起 POST 请求到 SAP Web 服务 var response = await httpClient.PostAsync(url, content); @@ -767,4 +767,128 @@ public class SapService : IDynamicApiController, ITransient return itemElements; } + + /// + /// SAP Ecn查询服务 + /// + /// + /// + public async Task SapEcnQueryApi(SapEcnQueryInput input) + { + // 创建SOAP XML请求 + var soapEnvelope = new XDocument( + new XDeclaration("1.0", "utf-8", "yes"), + new XElement(XName.Get("Envelope", "http://schemas.xmlsoap.org/soap/envelope/"), + new XElement(XName.Get("Header", "http://schemas.xmlsoap.org/soap/envelope/")), + new XElement(XName.Get("Body", "http://schemas.xmlsoap.org/soap/envelope/"), + new XElement(XName.Get("Zppfm005", "urn:sap-com:document:sap:soap:functions:mc-style"), + new XElement("IsInput", + new XElement("ItMatnr", + new XElement("item", + new XElement("Sign", input.Sign), + new XElement("Option", input.Option), + new XElement("Low", input.Low), + new XElement("High", input.High) + ) + ) + ), + new XElement("IsReq", + new XElement("Reqkeyid", input.Reqkeyid), + new XElement("Businessid", input.Businessid), + new XElement("Messageid", input.Messageid), + new XElement("Sndprn", input.Sndprn), + new XElement("Rcvprn", input.Rcvprn), + new XElement("Requser", input.Requser), + new XElement("Note1", input.Note1), + new XElement("Note2", input.Note2), + new XElement("Note3", input.Note3) + ) + ) + ) + ) + ); + var httpClientHandler = new HttpClientHandler + { + ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true, + ClientCertificateOptions = ClientCertificateOption.Manual + }; + try + { + using (var httpClient = new HttpClient(httpClientHandler)) + { + // 设置基本身份验证信息 + var username = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); + var password = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapPassword); + var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}")); + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials); + // 将 XML 内容转换为字符串并设置请求内容类型为 text/xml + var content = new StringContent(soapEnvelope.ToString(), Encoding.UTF8, "text/xml"); + content.Headers.ContentType = new MediaTypeHeaderValue("text/xml"); + httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh"); + // 设置 SAP Web 服务的 URL + var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/zppfm005/800/zppfm005/zppfm005"; + + // 发起 POST 请求到 SAP Web 服务 + var response = await httpClient.PostAsync(url, content); + + if (response.IsSuccessStatusCode) + { + var result = await response.Content.ReadAsStringAsync(); + XDocument doc = XDocument.Parse(result); + var esRet = doc.Descendants("EsRet").FirstOrDefault(); + var code = esRet?.Element("Code")?.Value; + + var item = doc.Descendants("item").FirstOrDefault(); + var matnr= item?.Element("Matnr")?.Value; + var werks = item?.Element("Werks")?.Value; + var bdmng = item?.Element("Bdmng")?.Value; + var labst = item?.Element("Labst")?.Value; + var zwqslPr = item?.Element("ZwqslPr")?.Value; + var zwqslPo = item?.Element("ZwqslPo")?.Value; + var meins = item?.Element("Meins")?.Value; + + + var output = new SapEcnQueryOutput() + { + Parameter = soapEnvelope.ToString(), + Code = code, + Matnr = matnr, + Werks = werks, + Bdmng = bdmng, + Labst = labst, + ZwqslPr = zwqslPr, + ZwqslPo = zwqslPo, + Meins = meins, + Result= result + }; + return output; + } + else + { + var result = await response.Content.ReadAsStringAsync(); + var output = new SapEcnQueryOutput() + { + Parameter = soapEnvelope.ToString(), + Code = "失败", + Result = result + }; + return output; + } + } + } + catch (Exception ex) + { + + // 记录错误日志 + Console.WriteLine("发生错误: " + ex.Message); + var output = new SapEcnQueryOutput() + { + Code = "失败", + Result = "发生错误" + ex + }; + return output; + } + + } + } \ No newline at end of file diff --git a/admin.net.pro/Admin.NET/Vistar.Application/Service/ChangeNoticeEcn/ChangeNoticeEcnService.cs b/admin.net.pro/Admin.NET/Vistar.Application/Service/ChangeNoticeEcn/ChangeNoticeEcnService.cs index 467f7de..effdeb5 100644 --- a/admin.net.pro/Admin.NET/Vistar.Application/Service/ChangeNoticeEcn/ChangeNoticeEcnService.cs +++ b/admin.net.pro/Admin.NET/Vistar.Application/Service/ChangeNoticeEcn/ChangeNoticeEcnService.cs @@ -168,7 +168,7 @@ public class ChangeNoticeEcnService : IDynamicApiController, ITransient Messageid = "", Sndprn = "PLM", Rcvprn = "SAP", - Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName), + Requser = Requser, Note1 = "", Note2 = "", Note3 = "", @@ -280,6 +280,7 @@ public class ChangeNoticeEcnService : IDynamicApiController, ITransient /// 生成ECN差异清单 /// /// + [AllowAnonymous] public async Task EcnVarianceList() { //获取符合条件的变更通知Ecn数据