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 b2a9a00..1523594 100644 --- a/admin.net.pro/Admin.NET/Vistar.Application/SapService/SapService.cs +++ b/admin.net.pro/Admin.NET/Vistar.Application/SapService/SapService.cs @@ -20,6 +20,7 @@ using System.Threading.Tasks; using System.Xml.Linq; using Vistar.Application.SapService.Dto; using Vistar.Application.Util; +using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinExpressIntracityUpdateStoreRequest.Types; namespace Vistar.Application.SapService; @@ -122,6 +123,7 @@ public class SapService : IDynamicApiController, ITransient var msg = item?.Element("Msg")?.Value; var output = new SapOutput() { + parameter = soapEnvelope.ToString(), code = code, msg = msg, result = result @@ -132,6 +134,7 @@ public class SapService : IDynamicApiController, ITransient var result = await response.Content.ReadAsStringAsync(); var output = new SapOutput() { + parameter= soapEnvelope.ToString(), code = "失败", msg = "调用失败,状态码:"+response.StatusCode, result = result @@ -233,6 +236,7 @@ public class SapService : IDynamicApiController, ITransient var ES_RETmsg = ES_RETItem?.Element("MSG")?.Value; var outputES_RET = new SapOutput() { + parameter = soapEnvelope.ToString(), code = ES_RETcode, msg = ES_RETmsg, result = result @@ -241,6 +245,7 @@ public class SapService : IDynamicApiController, ITransient } var output = new SapOutput() { + parameter = soapEnvelope.ToString(), code = code, msg = msg, result = result @@ -252,6 +257,7 @@ public class SapService : IDynamicApiController, ITransient var result = await response.Content.ReadAsStringAsync(); var output = new SapOutput() { + parameter = soapEnvelope.ToString(), code = "失败", msg = "调用失败,状态码: " + response.StatusCode, result = result diff --git a/admin.net.pro/Admin.NET/Vistar.Application/Service/MaterialManagement/ProductManagementService.cs b/admin.net.pro/Admin.NET/Vistar.Application/Service/MaterialManagement/ProductManagementService.cs index 2d91b97..dbaed07 100644 --- a/admin.net.pro/Admin.NET/Vistar.Application/Service/MaterialManagement/ProductManagementService.cs +++ b/admin.net.pro/Admin.NET/Vistar.Application/Service/MaterialManagement/ProductManagementService.cs @@ -37,6 +37,11 @@ using DocumentFormat.OpenXml.Office2010.ExcelAc; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using static COSXML.Model.Object.SelectObjectResult; using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; +using Vistar.Application.Common; +using static Elastic.Clients.Elasticsearch.JoinField; +using OfficeOpenXml.FormulaParsing.Logging; +using Furion.Logging; +using static Org.BouncyCastle.Math.Primes; @@ -52,8 +57,9 @@ public class ProductManagementService : IDynamicApiController, ITransient private readonly SqlSugarRepository _configurationsRep; private readonly SysConfigService _sysConfigService; private readonly SqlSugarRepository _configurationDataRep; - public SapService.SapService _sapBomService; + public SapService.SapService _sapService; public SqlSugarRepository _obj118Rep; + public Common.DataValidationService _dataValidationService; public ProductManagementService( SqlSugarRepository obj110Rep, @@ -61,7 +67,8 @@ public class ProductManagementService : IDynamicApiController, ITransient SysConfigService sysConfigService, SqlSugarRepository configurationDataRep, SapService.SapService sapBomService, - SqlSugarRepository obj118Rep + SqlSugarRepository obj118Rep, + DataValidationService dataValidationService ) { @@ -69,8 +76,9 @@ public class ProductManagementService : IDynamicApiController, ITransient _configurationsRep = configurationsRep; _sysConfigService = sysConfigService; _configurationDataRep = configurationDataRep; - _sapBomService = sapBomService; + _sapService = sapBomService; _obj118Rep = obj118Rep; + _dataValidationService = dataValidationService; } /// /// 分页查询产品管理 @@ -181,10 +189,10 @@ public class ProductManagementService : IDynamicApiController, ITransient Zbom = input.fld004698 }; - var apiOutput = await _sapBomService.SapMaterialApi(sapMaterialInput); + var apiOutput = await _sapService.SapMaterialApi(sapMaterialInput); string codeVal = apiOutput.code == "S" ? "成功" : "失败"; var msg = apiOutput.msg; - if (apiOutput.msg=="") + if (apiOutput.msg == "") { msg = "同步成功"; } @@ -201,6 +209,7 @@ public class ProductManagementService : IDynamicApiController, ITransient .ExecuteCommandAsync(); var output = new SapOutput() { + parameter = apiOutput.parameter, code = codeVal, msg = msg, result = apiOutput.result @@ -242,11 +251,15 @@ public class ProductManagementService : IDynamicApiController, ITransient ecn = EcnData._System_objNBS; } - var itemDataList = new List(); for (int i = 0; i < input.Count; i++) { + var Verification = await _dataValidationService.VerificationMaterial(input[i].ChildObjID, input[i].PartNumber, input[i].ChildGuid); + if (Verification == "不存在") + { + continue; + } int sun = i + 1; var itemData = new ItemData() { @@ -286,7 +299,7 @@ public class ProductManagementService : IDynamicApiController, ITransient Datuv = ParentData.fld004945.ToString(), ItemList = itemDataList }; - var apiOutput = await _sapBomService.SapBomApi(isreq); + var apiOutput = await _sapService.SapBomApi(isreq); string codeVal = apiOutput.code == "S" ? "成功" : "失败"; await _obj110Rep.AsUpdateable() .SetColumns(it => new Obj110 @@ -305,6 +318,7 @@ public class ProductManagementService : IDynamicApiController, ITransient } var output = new SapOutput() { + parameter = apiOutput.parameter, code = codeVal, msg = msg, result = apiOutput.result @@ -322,7 +336,7 @@ public class ProductManagementService : IDynamicApiController, ITransient { const string lengthError = "物料编码长度大于40,请检查!"; const string synchronized = "该物料编码已同步!"; - var SapOutputList=new List(); + var SapOutputList = new List(); var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); for (int i = 0; i < input.Count; i++) { @@ -348,7 +362,7 @@ public class ProductManagementService : IDynamicApiController, ITransient }); continue; } - if (input[i].fld004312=="N") + if (input[i].fld004312 == "N") { SapOutputList.Add(new SapOutput() { @@ -395,7 +409,7 @@ public class ProductManagementService : IDynamicApiController, ITransient Rgekz = input[i].fld004872, Zbom = input[i].fld004698 }; - var sapOutput = await _sapBomService.SapMaterialApi(sapMaterialInput); + var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput); string codeVal = sapOutput.code == "S" ? "成功" : "失败"; string msg = sapOutput.msg; @@ -415,6 +429,7 @@ public class ProductManagementService : IDynamicApiController, ITransient .ExecuteCommandAsync(); var output = new SapOutput() { + parameter = sapOutput.parameter, materialCode = input[0]._System_objNBS, code = codeVal, msg = msg, @@ -422,21 +437,21 @@ public class ProductManagementService : IDynamicApiController, ITransient }; SapOutputList.Add(output); } - + return SapOutputList; } /// /// 产品管理-定时同步到SAP /// /// - [ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpPost] + [ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpGet] [DisplayName("产品管理-定时同步到SAP")] [AllowAnonymous] public async Task> TimingSyncToSAP() { var input = await _obj110Rep.AsQueryable() - .Where(x => x.CheckedStatus == false && x.deleted == false && x.IsLatestVersion == true && x.fld004312!="N") - .ToListAsync(); + .Where(x => x.CheckedStatus == false && x.deleted == false && x.IsLatestVersion == true && (x.fld004312 == "A" || x.fld004312 == "M")) + .ToListAsync(); const string lengthError = "物料编码长度大于40,请检查!"; var SapOutputList = new List(); var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); @@ -464,7 +479,7 @@ public class ProductManagementService : IDynamicApiController, ITransient }); continue; } - + //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); var sapMaterialInput = new SapMaterialInput() @@ -501,7 +516,7 @@ public class ProductManagementService : IDynamicApiController, ITransient Rgekz = input[i].fld004872, Zbom = input[i].fld004698 }; - var sapOutput = await _sapBomService.SapMaterialApi(sapMaterialInput); + var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput); string codeVal = sapOutput.code == "S" ? "成功" : "失败"; string msg = sapOutput.msg; @@ -521,6 +536,7 @@ public class ProductManagementService : IDynamicApiController, ITransient .ExecuteCommandAsync(); var output = new SapOutput() { + parameter= sapOutput.parameter, materialCode = input[0]._System_objNBS, code = codeVal, msg = msg, @@ -531,7 +547,121 @@ public class ProductManagementService : IDynamicApiController, ITransient return SapOutputList; } + /// + /// 产品管理-定时同步 BOM 到 SAP + /// + /// + [ApiDescriptionSettings(Name = "TimingSyncToSAPBom"), HttpGet] + [DisplayName("产品管理-定时同步 Bom 到 SAP")] + [AllowAnonymous] + public async Task> TimingSyncToSAPBom() + { + var sapOutputList = new List(); + var sapUserName = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); + // 配置 + var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 110 && x.ConfigLabel == "mBOM").FirstAsync(); + var materialData = await _obj110Rep.AsQueryable() + .Where(x => x.CheckedStatus == false && x.deleted == false && x.IsLatestVersion == true &&x.fld004311=="成功" && (x.fld004316 == "A" || x.fld004316 == "M")) + .ToListAsync(); + var groupedData = materialData.GroupBy(item => item.RecordGuid) + .Select(group => group.OrderByDescending(item => item.VersionIndex).First()) + .ToList(); + foreach (var item in groupedData) + { + // 获取版本号 + var versionIndex = item.VersionIndex; + // 获取 ECN guid + var ecnGuid = item.fld004944_Rec; + // 查询 BOM + var bomData = await _configurationDataRep.AsQueryable() + .Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == item.RecordGuid && x.isDeleted == false && x.ParentVersion == versionIndex).ToListAsync(); + if (bomData.Count==0) + { + continue; + } + // 查询 ECN 编码 + var ecnData = await _obj118Rep.AsQueryable().Where(x => x.RecordGuid == ecnGuid && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync(); + var ecn = ecnData != null ? ecnData._System_objNBS : ""; + + var itemDataList = new List(); + foreach (var bomItem in bomData) + { + var verification = await _dataValidationService.VerificationMaterial(bomItem.ChildObjID, bomItem.PartNumber, bomItem.ChildGuid); + if (verification == "不存在") + { + continue; + } + + var itemData = new ItemData + { + POSNR = (bomData.IndexOf(bomItem) + 1).ToString(), + IDNRK = bomItem.PartNumber, + MENGE = bomItem.Quantity.ToString(), + SORTF = bomItem.fld004936, + ITISOB = bomItem.fld004937, + ALPGR = bomItem.fld004938, + ALPRF = bomItem.fld004939, + ZDELETE = bomItem.fld004940, + POSTP = bomItem.fld004492, + ZYFMK = bomItem.fld004941 + }; + itemDataList.Add(itemData); + + } + // 获取时间戳精确到毫秒,sap 要求每次调用生成不重复 guid + string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); + var isreq = new IS_REQ + { + ReqKeyId = "", + BusinessId = "", + MessageId = "", + SndPrn = "PLM", + RcvPrn = "SAP", + ReqUser = sapUserName, + Note1 = "", + Note2 = "", + Note3 = "", + Zwbid = millisecondTimestamp, + Matnr = item._System_objNBS, + Werks = item.fld004325, + Bmeng = item.fld004942.ToString(), + Aennr = ecn, + Datuv = item.fld004945.ToString(), + ItemList = itemDataList + }; + + var apiOutput = await _sapService.SapBomApi(isreq); + string codeVal = apiOutput.code == "S" ? "成功" : "失败"; + await _obj110Rep.AsUpdateable() + .SetColumns(it => new Obj110 + { + fld004631 = DateTime.Now, + fld004315 = codeVal, + fld004316 = "N", + fld004317 = apiOutput.msg + }) + .Where(it => it.idRecord == item.idRecord) + .ExecuteCommandAsync(); + + var msg = apiOutput.msg; + if (string.IsNullOrEmpty(msg)) + { + msg = "同步成功"; + } + + var output = new SapOutput + { + parameter= apiOutput.parameter, + materialCode = item._System_objNBS, + code = codeVal, + msg = msg, + result = apiOutput.result + }; + sapOutputList.Add(output); + } + return sapOutputList; + } } diff --git a/admin.net.pro/Admin.NET/Vistar.Application/Util/SapOutput.cs b/admin.net.pro/Admin.NET/Vistar.Application/Util/SapOutput.cs index cadbc1f..37daf0c 100644 --- a/admin.net.pro/Admin.NET/Vistar.Application/Util/SapOutput.cs +++ b/admin.net.pro/Admin.NET/Vistar.Application/Util/SapOutput.cs @@ -16,6 +16,7 @@ namespace Vistar.Application.Util; /// public class SapOutput { + public string parameter { get; set; } public string? materialCode { get; set; } public string code { get; set; } public string msg { get; set; } diff --git a/admin.net.pro/Web/src/views/materialManagement/productManagement/index.vue b/admin.net.pro/Web/src/views/materialManagement/productManagement/index.vue index 88b5f64..8b43ec6 100644 --- a/admin.net.pro/Web/src/views/materialManagement/productManagement/index.vue +++ b/admin.net.pro/Web/src/views/materialManagement/productManagement/index.vue @@ -49,7 +49,7 @@