😎新增sap查询价格服务

This commit is contained in:
bairubing 2025-02-14 16:41:25 +08:00
parent f081772d40
commit 9202fa9e56
4 changed files with 183 additions and 3 deletions

View File

@ -120,4 +120,8 @@ public class ItemData
/// 研发模块 /// 研发模块
/// </summary> /// </summary>
public string ZYFMK { get; set; } public string ZYFMK { get; set; }
/// <summary>
/// 子件guid
/// </summary>
public string? ChildGuid { get; set; }
} }

View File

@ -0,0 +1,16 @@
// 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 SapPriceQueryInput: SapEcnQueryInput
{
}

View File

@ -11,6 +11,7 @@ using DocumentFormat.OpenXml.Spreadsheet;
using Furion.DependencyInjection; using Furion.DependencyInjection;
using Furion.DynamicApiController; using Furion.DynamicApiController;
using MailKit; using MailKit;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OnceMi.AspNetCore.OSS; using OnceMi.AspNetCore.OSS;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -1218,4 +1219,128 @@ public class SapService : IDynamicApiController, ITransient
} }
/// <summary>
/// SAP 成本查询服务
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<SapPriceQueryOutput> SapPriceQueryApi(SapPriceQueryInput input)
{
// 创建命名空间
XNamespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace urn = "urn:sap-com:document:sap:rfc:functions";
// 创建 SOAP XML 请求
var soapEnvelope = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(soapenv + "Envelope",
new XAttribute(XNamespace.Xmlns + "soapenv", soapenv.NamespaceName),
new XAttribute(XNamespace.Xmlns + "urn", urn.NamespaceName),
new XElement(soapenv + "Header"),
new XElement(soapenv + "Body",
new XElement(urn + "ZFIFM006",
new XElement("IS_DATA",
new XElement("IT_MATNR",
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("IS_REQ",
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<string>(ConfigConst.SapUserName);
var password = await _sysConfigService.GetConfigValueByCode<string>(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
//sap正式地址
var url = "https://vhjqeps4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/ZFIFM006/800/ZFIFM006/ZFIFM006";
//sap测试地址
//var url = "https://vhjqeds4ci.sap.vistar-eq.com:44300/sap/bc/srt/rfc/sap/ZFIFM006/130/ZFIFM006/ZFIFM006";
// 发起 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("ES_RET").FirstOrDefault();
var code = esRet?.Element("CODE")?.Value;
var item = doc.Descendants("item").FirstOrDefault();
var bwkey = item?.Element("BWKEY")?.Value;
var matnr = item?.Element("MATNR")?.Value;
var verpr = item?.Element("VERPR")?.Value;
var output = new SapPriceQueryOutput()
{
Parameter = soapEnvelope.ToString(),
Code = code,
Matnr = matnr,
Bwkey = bwkey,
Verpr = verpr,
Result = result
};
return output;
}
else
{
var result = await response.Content.ReadAsStringAsync();
var output = new SapPriceQueryOutput()
{
Parameter = soapEnvelope.ToString(),
Code = "失败",
Result = result
};
return output;
}
}
}
catch (Exception ex)
{
// 记录错误日志
Console.WriteLine("发生错误: " + ex.Message);
var output = new SapPriceQueryOutput()
{
Code = "失败",
Result = "发生错误" + ex
};
return output;
}
}
} }

View File

@ -79,7 +79,42 @@ public class SapEcnQueryOutput
/// 更新日期 /// 更新日期
/// </summary> /// </summary>
public DateTime DateUpdated { get; set; } public DateTime DateUpdated { get; set; }
}
public class SapPriceQueryOutput
{
/// <summary>
/// sap入参
/// </summary>
public string Parameter { get; set; }
/// <summary>
/// 消息类型
/// </summary>
public string Code { get; set; }
/// <summary>
/// 物料编码
/// </summary>
public string Matnr { get; set; }
/// <summary>
/// 工厂
/// </summary>
public string Bwkey { get; set; }
/// <summary>
/// 价格
/// </summary>
public string Verpr { get; set; }
/// <summary>
/// sap出参
/// </summary>
public string Result { get; set; }
/// <summary>
/// 更新日期
/// </summary>
public DateTime DateUpdated { get; set; }
} }