From 5d6156f20f01fc91a6718705773e71b9bc554833 Mon Sep 17 00:00:00 2001 From: bairubing Date: Wed, 25 Sep 2024 14:37:03 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=8E=E5=AE=8C=E6=88=90=E4=BA=A7?= =?UTF-8?q?=E5=93=81=E7=AE=A1=E7=90=86=E6=89=B9=E9=87=8F=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=88=B0SAP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configuration/Logging.json | 2 +- .../ProductManagementService.cs | 123 +++++++++++++++++- .../Vistar.Application/Util/SapOutput.cs | 1 + .../materialManagement/productManagement.ts | 9 +- .../productManagement/index.vue | 70 +++++++--- 5 files changed, 178 insertions(+), 27 deletions(-) diff --git a/admin.net.pro/Admin.NET/Vistar.Application/Configuration/Logging.json b/admin.net.pro/Admin.NET/Vistar.Application/Configuration/Logging.json index f3a10bb..a041706 100644 --- a/admin.net.pro/Admin.NET/Vistar.Application/Configuration/Logging.json +++ b/admin.net.pro/Admin.NET/Vistar.Application/Configuration/Logging.json @@ -38,7 +38,7 @@ "ExcludeOfMethods": [], // 排除特定方法,当GlobalEnabled=true有效 "BahLogLevel": "Information", // Oops.Oh 和 Oops.Bah 业务日志输出级别 "WithReturnValue": true, // 是否包含返回值,默认true - "ReturnValueThreshold": 500, // 返回值字符串阈值,默认0全量输出 + "ReturnValueThreshold": 0, // 返回值字符串阈值,默认0全量输出500 "JsonBehavior": "None", // 是否输出Json,默认None(OnlyJson、All) "JsonIndented": false, // 是否格式化Json "UseUtcTimestamp": false, // 时间格式UTC、LOCAL 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 582b454..adee95d 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 @@ -120,7 +120,6 @@ public class ProductManagementService : IDynamicApiController, ITransient [DisplayName("产品管理-同步到 SAP")] public async Task SyncToSAP(ProductManagementBaseInput input) { - const string lengthError = "物料编码长度大于40,请检查!"; // 验证物料描述长度 @@ -213,8 +212,8 @@ public class ProductManagementService : IDynamicApiController, ITransient /// /// /// - [ApiDescriptionSettings(Name = "GetBOM", Description = "分页查询", Order = 1000), HttpPost] - [DisplayName("分页查询产品管理")] + [ApiDescriptionSettings(Name = "GetBOM", Description = "获取BOM", Order = 1000), HttpPost] + [DisplayName("获取BOM")] public async Task> GetBOM(BomPageProductManagementInput input) { var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 110 && x.ConfigLabel == "mBOM").FirstAsync(); @@ -227,10 +226,12 @@ public class ProductManagementService : IDynamicApiController, ITransient return BomData; } /// - /// Bom同步到SAP + /// 产品管理-Bom同步到SAP /// /// /// + [ApiDescriptionSettings(Name = "SyncToSAPBom"), HttpPost] + [DisplayName("产品管理-Bom同步到SAP")] public async Task SyncToSAPBom(List input) { var ParentData = await _obj110Rep.AsQueryable().Where(x => x.RecordGuid == input[0].ParentGuid && x.deleted == false && x.VersionIndex == input[0].ParentVersion).FirstAsync(); @@ -310,5 +311,119 @@ public class ProductManagementService : IDynamicApiController, ITransient }; 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].fld004484.Length > 40) + { + await _obj110Rep.AsUpdateable() + .SetColumns(it => new Obj110 + { + fld004629 = DateTime.Now, + fld004312 = "N", + fld004313 = lengthError + }) + .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].fld004312=="N") + { + 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].fld004323, + Mtart = input[i].fld004324, + Maktx = input[i].fld004484, + Meins = input[i].fld004861, + Matkl = input[i].fld004485, + Bismt = input[i].fld004880, + Groes = input[i].fld004879, + Normt = input[i].fld004887, + Ferth = input[i].fld004882, + Zeinr = input[i].fld004881, + Mstae = input[i].fld004699, + Raube = input[i].fld004877, + Mhdrz = input[i].fld004876, + Mhdhb = input[i].fld004895, + Werks = input[i].fld004325, + Beskz = input[i].fld004490, + Sobsl = input[i].fld004491, + Schgt = input[i].fld004873, + Rgekz = input[i].fld004872, + Zbom = input[i].fld004698 + }; + var sapOutput = await _sapBomService.SapMaterialApi(sapMaterialInput); + string codeVal = sapOutput.code == "S" ? "成功" : "失败"; + string msg = sapOutput.msg; + + if (sapOutput.msg == "") + { + msg = "同步成功"; + } + await _obj110Rep.AsUpdateable() + .SetColumns(it => new Obj110 + { + fld004629 = DateTime.Now, + fld004311 = codeVal, + fld004312 = "N", + fld004313 = msg + }) + .Where(it => it.idRecord == input[i].idRecord) + .ExecuteCommandAsync(); + var output = new SapOutput() + { + materialCode = input[0]._System_objNBS, + code = codeVal, + msg = msg, + result = sapOutput.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 44355fd..cadbc1f 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? materialCode { get; set; } public string code { get; set; } public string msg { get; set; } public string result { get; set; } diff --git a/admin.net.pro/Web/src/api/materialManagement/productManagement.ts b/admin.net.pro/Web/src/api/materialManagement/productManagement.ts index a7772d5..5cca365 100644 --- a/admin.net.pro/Web/src/api/materialManagement/productManagement.ts +++ b/admin.net.pro/Web/src/api/materialManagement/productManagement.ts @@ -5,6 +5,7 @@ enum Api { SyncToSAPProductManagement = '/api/productManagement/SyncToSAP', GetetBOMProductManagement = '/api/productManagement/getBOM', SyncToSAPBomProductManagement = '/api/productManagement/syncToSAPBom', + BatchSyncToSAPProductManagement = '/api/productManagement/batchSyncToSAP' } // 分页查询产品管理 @@ -44,4 +45,10 @@ export const SyncToSAPBomProductManagement = (params?: any) => method: 'post', data: params, }); - +// 批量同步到SAP +export const BatchSyncToSAPProductManagement = (params?: any) => + request({ + url: Api.BatchSyncToSAPProductManagement, + method: 'post', + data: params, + }); 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 7014ed6..88b5f64 100644 --- a/admin.net.pro/Web/src/views/materialManagement/productManagement/index.vue +++ b/admin.net.pro/Web/src/views/materialManagement/productManagement/index.vue @@ -48,20 +48,20 @@ --> @@ -72,16 +72,16 @@ - - - + label-width="auto" style="flex: 1 1 0%" @submit.prevent="handleQueryBom"> + + + + BOM同步到SAP + + @@ -100,7 +100,8 @@ import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook'; import { Local } from '/@/utils/storage'; import { formatDate } from '/@/utils/formatTime'; -import { PageProductManagement, BomTypeProductManagement, SyncToSAPProductManagement, GetetBOMProductManagement,SyncToSAPBomProductManagement } from '/@/api/materialManagement/productManagement'; +import { PageProductManagement, BomTypeProductManagement, SyncToSAPProductManagement, GetetBOMProductManagement, SyncToSAPBomProductManagement, BatchSyncToSAPProductManagement } from '/@/api/materialManagement/productManagement'; +import { disable } from 'ol/rotationconstraint'; // 子窗口对象 const xGrid = ref(); @@ -141,7 +142,7 @@ const options = useVxeTable( id: 'productManagement', name: '产品管理', columns: [ - { type: 'checkbox', title: '', width: 60 }, + { type: 'checkbox', title: '', width: 60}, { type: 'seq', title: '序号', width: 60 }, { field: '_System_objNBS', title: '物料编码', minWidth: 100, showOverflow: 'tooltip', sortable: false }, { field: '_System_ObjDescription', title: '名称', minWidth: 100, showOverflow: 'tooltip', sortable: false }, @@ -258,7 +259,7 @@ const syncToSAP = async (row: any) => { const bomxGrid = ref(); // 查看BOM const showBomDrawer = async (row: any) => { - stateBom.queryParams.ParentGuid=row.recordGuid; + stateBom.queryParams.ParentGuid = row.recordGuid; showBom.value = true; await handleQueryBom(); }; @@ -326,9 +327,8 @@ const handleQueryBom = async (reset = false) => { //Bom同步到sap const syncToSAPBom = async () => { - //var data=bomxGrid.value?.getCheckboxRecords(); options.loading = true; - var data=bomxGrid.value?.getTableData().fullData; + var data = bomxGrid.value?.getTableData().fullData; ElMessageBox.confirm(`确定要同步BOM吗?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', @@ -347,9 +347,37 @@ const syncToSAPBom = async () => { options.loading = false; } //物料批量同步到SAP -const batchSyncToSAP = async () =>{ - var data=xGrid.value?.getCheckboxRecords(); - console.log("datadatadata",data) +const batchSyncToSAP = async () => { + options.loading = true; + var data = xGrid.value?.getCheckboxRecords(); + + ElMessageBox.confirm(`确定要批量同步物料吗?`, '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + }) + .then(async () => { + var output = await BatchSyncToSAPProductManagement(data); + console.log("ssssssssssssssssssssss", output) + await handleQuery(); + var succeed = 0; + var error = 0; + for (let i = 0; i < output.data.result.length; i++) { + var code = output.data.result[i].code + if (code == "成功") { + succeed++ + } else { + error++ + } + } + ElMessageBox.alert("同步成功:" + succeed + ";" + "同步失败:" + error, '批量同步结果', { + // 如果你想禁用它的自动对焦 + // autofocus: false, + confirmButtonText: 'OK' + }) + }) + .catch(() => { }); + options.loading = false; }