// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。 // // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。 // // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! using Admin.NET.Core; using Admin.NET.Core.Service; using Furion.DependencyInjection; using Furion.DynamicApiController; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using Vistar.Application.Common; using Vistar.Application.Const; using Vistar.Application.Entity; using Vistar.Application.SapService.Dto; using Vistar.Application.Service.ProductDesignLibrary.Dto; using Vistar.Application.Util; namespace Vistar.Application.Service.ProductDesignLibrary; /// /// 产品设计库服务 /// [ApiDescriptionSettings(ApplicationConst.GroupName, Name = "ProductDesignLibrary", Order = 100)] public class ProductDesignLibraryService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _obj137Rep; private readonly SysConfigService _sysConfigService; public SapService.SapService _sapService; private readonly SqlSugarRepository _configurationsRep; private readonly SqlSugarRepository _configurationDataRep; public SqlSugarRepository _obj118Rep; public Common.DataValidationService _dataValidationService; public SqlSugarRepository _obj122Rep; public SqlSugarRepository _obj121Rep; public ProductDesignLibraryService( SqlSugarRepository obj137Rep, SysConfigService sysConfigService, SapService.SapService sapService, SqlSugarRepository configurationsRep, SqlSugarRepository configurationDataRep, SqlSugarRepository obj118Rep, DataValidationService dataValidationService, SqlSugarRepository obj122Rep, SqlSugarRepository obj121Rep ) { _obj137Rep = obj137Rep; _sysConfigService = sysConfigService; _sapService = sapService; _configurationsRep = configurationsRep; _configurationDataRep = configurationDataRep; _obj118Rep = obj118Rep; _dataValidationService = dataValidationService; _obj122Rep = obj122Rep; _obj121Rep = obj121Rep; } /// /// 分页查询产品设计库 /// /// /// [ApiDescriptionSettings(Name = "page", Description = "分页查询", Order = 1000), HttpPost] [DisplayName("分页查询产品设计库")] public async Task> Page(PageProductDesignLibraryInput input) { var query = await _obj137Rep.AsQueryable() .Where(x => x.CheckedStatus == 0 && x.deleted == false && x.IsLatestVersion == true && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW")) .WhereIF(!string.IsNullOrWhiteSpace(input._System_objNBS), u => u._System_objNBS.Contains(input._System_objNBS.Trim())) .WhereIF(!string.IsNullOrWhiteSpace(input._SWPDM_1188_SAP___), u => u._SWPDM_1188_SAP___.Contains(input._SWPDM_1188_SAP___.Trim())) .Select() .ToPagedListAsync(input.Page, input.PageSize); return query; } /// /// 产品设计库-同步到 SAP /// /// [ApiDescriptionSettings(Name = "syncToSAP"), HttpPost] [DisplayName("产品设计库-同步到 SAP")] public async Task SyncToSAP(ProductDesignLibraryInput input) { const string lengthError = "物料描述长度大于40,请检查!"; // 验证物料描述长度 if (input._SWPDM_1188_SAP___.Length > 40) { await _obj137Rep.AsUpdateable() .SetColumns(it => new Obj137 { fld005532 = DateTime.Now, fld005530 = "N", fld005531 = lengthError, fld005529 = "失败" }) .Where(it => it.idRecord == input.idRecord) .ExecuteCommandAsync().ConfigureAwait(false); return new SapOutput { code = "失败", msg = lengthError, result = lengthError }; } //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); var sapMaterialInput = new SapMaterialInput() { Reqkeyid = "", Businessid = "", Messageid = "", Sndprn = "PLM", Rcvprn = "SAP", Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName), Note1 = "", Note2 = "", Note3 = "", Zwbid = millisecondTimestamp, Matnr = input._System_objNBS, Mbrsh = input._SWPDM_1185_SAP___, Mtart = input._SWPDM_1186_SAP_____, Maktx = input._SWPDM_1188_SAP___, Meins = input._SWPDM_126_SW___, Matkl = input._SWPDM_1203_SAP____, Bismt = input._SWPDM_64_SW___, Groes = input._SWPDM_125_SW___, Normt = input._SWPDM_65_SW___, Ferth = input._SWPDM_62_SW___, Zeinr = input._SWPDM_61_SW_____, Mstae = input._SWPDM_1209_SAP_____, Raube = "", Mhdrz = "", Mhdhb = "", Werks = input._SWPDM_1187_SAP___, Beskz = input._SWPDM_1196_SAP_____, Sobsl = input._SWPDM_1198_SAP_____, Schgt = input._SWPDM_1197_SAP_____, Rgekz = input._SWPDM_1199_SAP___, Zbom = input._SWPDM_1208_SAP___BOM___ }; var apiOutput = await _sapService.SapMaterialApi(sapMaterialInput); string codeVal = apiOutput.code == "S" ? "成功" : "失败"; var msg = apiOutput.msg; if (apiOutput.msg == "") { msg = "同步成功"; } await _obj137Rep.AsUpdateable() .SetColumns(it => new Obj137 { fld005532 = DateTime.Now, fld005529 = codeVal, fld005530 = "N", fld005531 = msg }) .Where(it => it.idRecord == input.idRecord) .ExecuteCommandAsync(); var output = new SapOutput() { parameter = apiOutput.parameter, code = codeVal, msg = msg, result = apiOutput.result }; return output; } /// /// 获取BOM /// /// /// [ApiDescriptionSettings(Name = "GetBOM", Description = "获取BOM", Order = 1000), HttpPost] [DisplayName("获取BOM")] public async Task> GetBOM(BomPageProductDesignLibraryInput input) { var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 137 && x.ConfigSystemName == "SolidWorks").FirstAsync(); var parent = await _obj137Rep.AsQueryable() .Where(x => x.RecordGuid == input.ParentGuid && x.deleted == false && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW")) .MaxAsync(x => x.VersionIndex); var BomData = await _configurationDataRep.AsQueryable() .Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == input.ParentGuid && x.isDeleted == false && x.ParentVersion == parent && (x.fld005577 != "不包含" || x.fld005577 == null)&&x.isSuppressed==false) .WhereIF(!string.IsNullOrWhiteSpace(input.Description), u => u.Description.Contains(input.Description.Trim())) .WhereIF(!string.IsNullOrWhiteSpace(input.PartNumber), u => u.PartNumber.Contains(input.PartNumber.Trim())) .Select().ToPagedListAsync(input.Page, input.PageSize); return BomData; } /// /// 产品设计库-Bom同步到SAP /// /// /// [ApiDescriptionSettings(Name = "SyncToSAPBom"), HttpPost] [DisplayName("产品设计库-Bom同步到SAP")] public async Task SyncToSAPBom(List input) { var ParentData = await _obj137Rep.AsQueryable().Where(x => x.RecordGuid == input[0].ParentGuid && x.deleted == false && x.VersionIndex == input[0].ParentVersion && (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null) && x.fld005530 == "N" && x.fld005529 == "成功" && (x.fld005534 == "A" || x.fld005534 == "M") && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW")).FirstAsync(); var EcnData = await _obj118Rep.AsQueryable().Where(x => x.RecordGuid == ParentData.fld005679_Rec && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync(); var ecn = ""; if (EcnData != null) { 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() { POSNR = "",//组件序号 sun.ToString() IDNRK = input[i].PartNumber,//组件物料号 MENGE = input[i].QtyManual.ToString(),//组件数量 SORTF = input[i].fld005541, ITISOB = input[i].fld005542, ALPGR = input[i].fld005543, ALPRF = input[i].fld005544, ZDELETE = input[i].fld005545, POSTP = input[i].fld005546, ZYFMK = input[i].fld005547 }; itemDataList.Add(itemData); } if (!string.IsNullOrEmpty(ParentData.fld005686)) { var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 137 && x.ConfigSystemName == "SolidWorks").FirstAsync(); var BomData = await _configurationDataRep.AsQueryable().Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == input[0].ParentGuid && x.isDeleted == false && x.ParentVersion == Convert.ToInt32(ParentData.fld005686) && (x.fld005577 != "不包含" || x.fld005577 == null) && x.isSuppressed == false).ToListAsync(); for (int i = 0; i < BomData.Count; i++) { var itemList = itemDataList.Where(x => x.IDNRK == BomData[i].PartNumber).ToList(); if (itemList.Count == 0) { var Verification = await _dataValidationService.VerificationMaterial(BomData[i].ChildObjID, BomData[i].PartNumber, BomData[i].ChildGuid); if (Verification == "不存在") { continue; } //int sun = i + 1; var itemData = new ItemData() { POSNR = "",//组件序号 sun.ToString() IDNRK = BomData[i].PartNumber,//组件物料号 MENGE = BomData[i].QtyManual.ToString(),//组件数量 SORTF = BomData[i].fld005541, ITISOB = BomData[i].fld005542, ALPGR = BomData[i].fld005543, ALPRF = BomData[i].fld005544, ZDELETE = "X", POSTP = BomData[i].fld005546, ZYFMK = BomData[i].fld005547 }; itemDataList.Add(itemData); } } } //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); var fld005678 = ParentData.fld005678 ?? 1; var isreq = new IS_REQ() { ReqKeyId = "", BusinessId = "", MessageId = "", SndPrn = "PLM", RcvPrn = "SAP", ReqUser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName), Note1 = "", Note2 = "", Note3 = "", Zwbid = millisecondTimestamp, Matnr = ParentData._System_objNBS,//父物料编码 Werks = ParentData._SWPDM_1187_SAP___,//工厂 Bmeng = fld005678.ToString(), Aennr = ecn, Datuv = ParentData.fld005680.ToString(), ItemList = itemDataList }; var apiOutput = await _sapService.SapBomApi(isreq); string codeVal = apiOutput.code == "S" ? "成功" : "失败"; await _obj137Rep.AsUpdateable() .SetColumns(it => new Obj137 { fld005539 = DateTime.Now, fld005533 = codeVal, fld005534 = "N", fld005535 = apiOutput.msg, fld005686 = input[0].ParentVersion.ToString() }) .Where(it => it.idRecord == ParentData.idRecord) .ExecuteCommandAsync(); var msg = apiOutput.msg; if (apiOutput.msg == "") { msg = "同步成功"; } var output = new SapOutput() { parameter = apiOutput.parameter, code = codeVal, msg = msg, result = apiOutput.result }; return output; } /// /// 产品设计库-批量同步到SAP /// /// /// [ApiDescriptionSettings(Name = "BatchSyncToSAP"), HttpPost] [DisplayName("产品设计库-批量同步到SAP")] public async Task> BatchSyncToSAP(List input) { const string lengthError = "物料描述长度大于40,请检查!"; const string synchronized = "该物料编码已同步或已停用!"; var SapOutputList = new List(); var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); for (int i = 0; i < input.Count; i++) { // 验证物料描述长度 if (input[i]._SWPDM_1188_SAP___.Length > 40) { await _obj137Rep.AsUpdateable() .SetColumns(it => new Obj137 { fld005532 = DateTime.Now, fld005530 = "N", fld005531 = lengthError, fld005529 = "失败" }) .Where(it => it.idRecord == input[i].idRecord) .ExecuteCommandAsync().ConfigureAwait(false); SapOutputList.Add(new SapOutput() { materialCode = input[i]._System_objNBS, code = "失败", msg = lengthError, result = lengthError }); continue; } if (input[i].fld005530 == "N" || input[i].fld005530=="D"|| input[i].fld005530 ==null) { SapOutputList.Add(new SapOutput() { materialCode = input[i]._System_objNBS, code = "失败", msg = synchronized, result = synchronized }); continue; } //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); var sapMaterialInput = new SapMaterialInput() { Reqkeyid = "", Businessid = "", Messageid = "", Sndprn = "PLM", Rcvprn = "SAP", Requser = Requser, Note1 = "", Note2 = "", Note3 = "", Zwbid = millisecondTimestamp, Matnr = input[i]._System_objNBS, Mbrsh = input[i]._SWPDM_1185_SAP___, Mtart = input[i]._SWPDM_1186_SAP_____, Maktx = input[i]._SWPDM_1188_SAP___, Meins = input[i]._SWPDM_126_SW___, Matkl = input[i]._SWPDM_1203_SAP____, Bismt = input[i]._SWPDM_64_SW___, Groes = input[i]._SWPDM_125_SW___, Normt = input[i]._SWPDM_65_SW___, Ferth = input[i]._SWPDM_62_SW___, Zeinr = input[i]._SWPDM_61_SW_____, Mstae = input[i]._SWPDM_1209_SAP_____, Raube = "", Mhdrz = "", Mhdhb = "", Werks = input[i]._SWPDM_1187_SAP___, Beskz = input[i]._SWPDM_1196_SAP_____, Sobsl = input[i]._SWPDM_1198_SAP_____, Schgt = input[i]._SWPDM_1197_SAP_____, Rgekz = input[i]._SWPDM_1199_SAP___, Zbom = input[i]._SWPDM_1208_SAP___BOM___ }; var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput); string codeVal = sapOutput.code == "S" ? "成功" : "失败"; string msg = sapOutput.msg; if (sapOutput.msg == "") { msg = "同步成功"; } await _obj137Rep.AsUpdateable() .SetColumns(it => new Obj137 { fld005532 = DateTime.Now, fld005529 = codeVal, fld005530 = "N", fld005531 = msg }) .Where(it => it.idRecord == input[i].idRecord) .ExecuteCommandAsync(); var output = new SapOutput() { parameter = sapOutput.parameter, materialCode = input[0]._System_objNBS, code = codeVal, msg = msg, result = sapOutput.result }; SapOutputList.Add(output); } return SapOutputList; } /// /// 产品设计库-定时同步到SAP /// /// [ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpGet] [DisplayName("产品设计库-定时同步到SAP")] [AllowAnonymous] public async Task> TimingSyncToSAP() { var input = await _obj137Rep.AsQueryable() .Where(x => x.CheckedStatus == 0 && x.deleted == false && x.IsLatestVersion == true && (x.fld005530 == "A" || x.fld005530 == "M") && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW")) .ToListAsync(); const string lengthError = "物料描述长度大于40,请检查!"; var SapOutputList = new List(); var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); for (int i = 0; i < input.Count; i++) { if (!string.IsNullOrEmpty(input[i]._SWPDM_1188_SAP___)) { // 验证物料描述长度 if (input[i]._SWPDM_1188_SAP___.Length > 40) { await _obj137Rep.AsUpdateable() .SetColumns(it => new Obj137 { fld005532 = DateTime.Now, fld005530 = "N", fld005531 = lengthError, fld005529 = "失败" }) .Where(it => it.idRecord == input[i].idRecord) .ExecuteCommandAsync().ConfigureAwait(false); SapOutputList.Add(new SapOutput() { materialCode = input[i]._System_objNBS, code = "失败", msg = lengthError, result = lengthError }); continue; } } //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); var sapMaterialInput = new SapMaterialInput() { Reqkeyid = "", Businessid = "", Messageid = "", Sndprn = "PLM", Rcvprn = "SAP", Requser = Requser, Note1 = "", Note2 = "", Note3 = "", Zwbid = millisecondTimestamp, Matnr = input[i]._System_objNBS, Mbrsh = input[i]._SWPDM_1185_SAP___, Mtart = input[i]._SWPDM_1186_SAP_____, Maktx = input[i]._SWPDM_1188_SAP___, Meins = input[i]._SWPDM_126_SW___, Matkl = input[i]._SWPDM_1203_SAP____, Bismt = input[i]._SWPDM_64_SW___, Groes = input[i]._SWPDM_125_SW___, Normt = input[i]._SWPDM_65_SW___, Ferth = input[i]._SWPDM_62_SW___, Zeinr = input[i]._SWPDM_61_SW_____, Mstae = input[i]._SWPDM_1209_SAP_____, Raube = "", Mhdrz = "", Mhdhb = "", Werks = input[i]._SWPDM_1187_SAP___, Beskz = input[i]._SWPDM_1196_SAP_____, Sobsl = input[i]._SWPDM_1198_SAP_____, Schgt = input[i]._SWPDM_1197_SAP_____, Rgekz = input[i]._SWPDM_1199_SAP___, Zbom = input[i]._SWPDM_1208_SAP___BOM___ }; var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput); string codeVal = sapOutput.code == "S" ? "成功" : "失败"; string msg = sapOutput.msg; if (sapOutput.msg == "") { msg = "同步成功"; } await _obj137Rep.AsUpdateable() .SetColumns(it => new Obj137 { fld005532 = DateTime.Now, fld005529 = codeVal, fld005530 = "N", fld005531 = msg }) .Where(it => it.idRecord == input[i].idRecord) .ExecuteCommandAsync(); var output = new SapOutput() { parameter = sapOutput.parameter, materialCode = input[0]._System_objNBS, code = codeVal, msg = msg, result = sapOutput.result }; SapOutputList.Add(output); } 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 == 137 && x.ConfigSystemName == "SolidWorks").FirstAsync(); var materialData = await _obj137Rep.AsQueryable() .Where(x => x.CheckedStatus == 0 && x.deleted == false && x.IsLatestVersion == true && (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null) && x.fld005530 == "N" && x.fld005529 == "成功" && (x.fld005534 == "A" || x.fld005534 == "M") && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW")) .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.fld005679_Rec; // 查询 BOM var bomData = await _configurationDataRep.AsQueryable() .Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == item.RecordGuid && x.isDeleted == false && x.ParentVersion == versionIndex && (x.fld005577 != "不包含" || x.fld005577 == null) && x.isSuppressed == false).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.QtyManual.ToString(), SORTF = bomItem.fld005541, ITISOB = bomItem.fld005542, ALPGR = bomItem.fld005543, ALPRF = bomItem.fld005544, ZDELETE = bomItem.fld004940, POSTP = bomItem.fld005546, ZYFMK = bomItem.fld005547 }; itemDataList.Add(itemData); } var ParentData = await _obj137Rep.AsQueryable().Where(x => x.RecordGuid == bomData[0].ParentGuid && x.deleted == false && x.VersionIndex == bomData[0].ParentVersion).FirstAsync(); if (!string.IsNullOrEmpty(ParentData.fld005686)) { var configidold = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 137 && x.ConfigSystemName == "SolidWorks").FirstAsync(); var BomData = await _configurationDataRep.AsQueryable().Where(x => x.ConfigId == configidold.ConfigID && x.ParentGuid == bomData[0].ParentGuid && x.isDeleted == false && x.ParentVersion == Convert.ToInt32(ParentData.fld005686) && (x.fld005577 != "不包含" || x.fld005577 == null) && x.isSuppressed == false).ToListAsync(); for (int i = 0; i < BomData.Count; i++) { var itemList = itemDataList.Where(x => x.IDNRK == BomData[i].PartNumber).ToList(); if (itemList.Count == 0) { var Verification = await _dataValidationService.VerificationMaterial(BomData[i].ChildObjID, BomData[i].PartNumber, BomData[i].ChildGuid); if (Verification == "不存在") { continue; } //int sun = i + 1; var itemData = new ItemData() { POSNR = "",//组件序号 sun.ToString() IDNRK = BomData[i].PartNumber,//组件物料号 MENGE = BomData[i].QtyManual.ToString(),//组件数量 SORTF = BomData[i].fld005541, ITISOB = BomData[i].fld005542, ALPGR = BomData[i].fld005543, ALPRF = BomData[i].fld005544, ZDELETE = "X", POSTP = BomData[i].fld005546, ZYFMK = BomData[i].fld005547 }; itemDataList.Add(itemData); } } } // 获取时间戳精确到毫秒,sap 要求每次调用生成不重复 guid string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); var fld005678 = item.fld005678 ?? 1; 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._SWPDM_1187_SAP___, Bmeng = fld005678.ToString(), Aennr = ecn, Datuv = item.fld005680.ToString(), ItemList = itemDataList }; var apiOutput = await _sapService.SapBomApi(isreq); string codeVal = apiOutput.code == "S" ? "成功" : "失败"; await _obj137Rep.AsUpdateable() .SetColumns(it => new Obj137 { fld005539 = DateTime.Now, fld005533 = codeVal, fld005534 = "N", fld005535 = apiOutput.msg, fld005686 = bomData[0].ParentVersion.ToString() }) .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; } /// /// 产品设计库-获取工艺路线 /// /// /// [ApiDescriptionSettings(Name = "GetProcessRoute", Description = "获取工艺路线", Order = 1000), HttpPost] [DisplayName("获取工艺路线")] public async Task> GetProcessRoute(BomPageProductDesignLibraryInput input) { var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 137 && x.ConfigSystemName == "pBOM").FirstAsync(); var parent = await _obj137Rep.AsQueryable() .Where(x => x.RecordGuid == input.ParentGuid && x.CheckedStatus == 0 && x.deleted == false && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW") && (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null) && x.fld005530 == "N" && x.fld005529 == "成功" && (x.fld005537 == "A" || x.fld005537 == "M") ) .MaxAsync(x => x.VersionIndex); var BomData = await _configurationDataRep.AsQueryable() .Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == input.ParentGuid && x.isDeleted == false && x.ParentVersion == parent) .WhereIF(!string.IsNullOrWhiteSpace(input.Description), u => u.Description.Contains(input.Description.Trim())) .WhereIF(!string.IsNullOrWhiteSpace(input.PartNumber), u => u.PartNumber.Contains(input.PartNumber.Trim())) .Select().ToPagedListAsync(input.Page, input.PageSize); return BomData; } /// /// 产品设计库-工艺路线同步到SAP /// /// /// [ApiDescriptionSettings(Name = "SyncToSAPProcessRoute"), HttpPost] [DisplayName("产品设计库-工艺路线同步到SAP")] public async Task SyncToSAPProcessRoute(List input) { var ParentData = await _obj137Rep.AsQueryable() .Where(x => x.RecordGuid == input[0].ParentGuid && x.deleted == false && x.VersionIndex == input[0].ParentVersion && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW") && x.CheckedStatus == 0 && (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null) && x.fld005530 == "N" && x.fld005529 == "成功" && (x.fld005537 == "A" || x.fld005537 == "M") ) .FirstAsync(); 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; } //获取工序描述 var procedureDescription = await _obj122Rep.AsQueryable().Where(x => x.RecordGuid == input[i].ChildGuid).ToListAsync(); //获取工作中心 var workCenter = await _obj121Rep.AsQueryable().Where(x => x.RecordGuid == procedureDescription[0].fld005059_Rec).ToListAsync(); //int sun = i + 1; var itemData = new SapProcessRouteItemData() { VORNR = input[i].Marker, LTXA1 = procedureDescription[0]._System_ObjDescription, ARBPL = workCenter[0]._System_objNBS, VGW01 = input[i].fld005571.ToString(), VGE01 = input[i].fld005572, STEUS = input[i].fld005573, BMSCH = input[i].fld005575.ToString() }; itemDataList.Add(itemData); } //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); var Datuv = ParentData.fld005680.ToString(); if (!string.IsNullOrEmpty(Datuv)) { Datuv = ParentData.fld005680.ToDateTime().ToString("yyyy-MM-dd"); } var isreq = new SapProcessRouteIS_REQ() { ReqKeyId = "", BusinessId = "", MessageId = "", SndPrn = "PLM", RcvPrn = "SAP", ReqUser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName), Note1 = "", Note2 = "", Note3 = "", Zwbid = millisecondTimestamp, Matnr = ParentData._System_objNBS, Werks = ParentData._SWPDM_1187_SAP___, Datuv = Datuv, Plnal = "", ItemList = itemDataList }; var apiOutput = await _sapService.SapProcessRouteApi(isreq); string codeVal = apiOutput.code == "S" ? "成功" : "失败"; await _obj137Rep.AsUpdateable() .SetColumns(it => new Obj137 { fld005540 = DateTime.Now, fld005536 = codeVal, fld005537 = "N", fld005538 = apiOutput.msg }) .Where(it => it.idRecord == ParentData.idRecord) .ExecuteCommandAsync(); var msg = apiOutput.msg; if (apiOutput.msg == "") { msg = "同步成功"; } var output = new SapOutput() { parameter = apiOutput.parameter, code = codeVal, msg = msg, result = apiOutput.result }; return output; } /// /// 产品设计库-定时同步工艺路线到SAP /// /// [ApiDescriptionSettings(Name = "TimingSyncToSAPProcessRoute"), HttpGet] [DisplayName("产品设计库-定时同步工艺路线到SAP")] [AllowAnonymous] public async Task> TimingSyncToSAPProcessRoute() { var sapOutputList = new List(); var sapUserName = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); // 配置 var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 137 && x.ConfigSystemName == "pBOM").FirstAsync(); //查询需要同步的产品 var materialData = await _obj137Rep.AsQueryable() .Where(x => x.CheckedStatus == 0 && x.deleted == false && x.IsLatestVersion == true && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW") && (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null) && x.fld005530 == "N" && x.fld005529 == "成功" && (x.fld005537 == "A" || x.fld005537 == "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; // 查询 BOM var processRouteData = await _configurationDataRep.AsQueryable() .Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == item.RecordGuid && x.isDeleted == false && x.ParentVersion == versionIndex).ToListAsync(); if (processRouteData.Count == 0) { continue; } var itemDataList = new List(); foreach (var processRouteItem in processRouteData) { var verification = await _dataValidationService.VerificationMaterial(processRouteItem.ChildObjID, processRouteItem.PartNumber, processRouteItem.ChildGuid); if (verification == "不存在") { continue; } //获取工序描述 var procedureDescription = await _obj122Rep.AsQueryable().Where(x => x.RecordGuid == processRouteItem.ChildGuid).ToListAsync(); //获取工作中心 var workCenter = await _obj121Rep.AsQueryable().Where(x => x.RecordGuid == procedureDescription[0].fld005059_Rec).ToListAsync(); var itemData = new SapProcessRouteItemData() { VORNR = processRouteItem.Marker, LTXA1 = procedureDescription[0]._System_ObjDescription, ARBPL = workCenter[0]._System_objNBS, VGW01 = processRouteItem.fld005571.ToString(), VGE01 = processRouteItem.fld005572, STEUS = processRouteItem.fld005573, BMSCH = processRouteItem.fld005575.ToString() }; itemDataList.Add(itemData); } //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); var Datuv = item.fld005680.ToString(); if (!string.IsNullOrEmpty(Datuv)) { Datuv = item.fld005680.ToDateTime().ToString("yyyy-MM-dd"); } var isreq = new SapProcessRouteIS_REQ() { ReqKeyId = "", BusinessId = "", MessageId = "", SndPrn = "PLM", RcvPrn = "SAP", ReqUser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName), Note1 = "", Note2 = "", Note3 = "", Zwbid = millisecondTimestamp, Matnr = item._System_objNBS, Werks = item._SWPDM_1187_SAP___, Datuv = Datuv, Plnal = "", ItemList = itemDataList }; var apiOutput = await _sapService.SapProcessRouteApi(isreq); string codeVal = apiOutput.code == "S" ? "成功" : "失败"; await _obj137Rep.AsUpdateable() .SetColumns(it => new Obj137 { fld005540 = DateTime.Now, fld005536 = codeVal, fld005537 = "N", fld005538 = apiOutput.msg }) .Where(it => it.idRecord == item.idRecord) .ExecuteCommandAsync(); var msg = apiOutput.msg; if (apiOutput.msg == "") { msg = "同步成功"; } var output = new SapOutput() { parameter = apiOutput.parameter, code = codeVal, msg = msg, result = apiOutput.result }; sapOutputList.Add(output); } return sapOutputList; } }