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 c92cb4d..b56dfbd 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 @@ -8,6 +8,7 @@ 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; @@ -120,5 +121,136 @@ public class ChangeNoticeEcnService : IDynamicApiController, ITransient return output; } + /// + /// 变更通知ECN-批量同步到SAP + /// + /// + /// + [ApiDescriptionSettings(Name = "BatchSyncToSAP"), HttpPost] + [DisplayName("变更通知ECN-批量同步到SAP")] + public async Task> BatchSyncToSAP(List input) + { + + var SapOutputList = new List(); + var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); + for (int i = 0; i < input.Count; i++) + { + //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid + string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); + + var sapEcnInput = new SapEcnInput() + { + Reqkeyid = "", + Businessid = "", + Messageid = "", + Sndprn = "PLM", + Rcvprn = "SAP", + Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName), + Note1 = "", + Note2 = "", + Note3 = "", + + Aennr = input[i]._System_objNBS, + Aetxt = input[i]._System_ObjDescription, + Datuv = input[i].fld004693.ToDateTime().ToString("yyyy-MM-dd"), + Lvorm = input[i].fld004694, + Matnr = await _dataValidationService.ChangeModuleMaterial(input[i].fld004638.ToLong(), input[i].fld004638_Rec) + }; + var apiOutput = await _sapService.SapEcnApi(sapEcnInput); + string codeVal = apiOutput.code == "S" ? "成功" : "失败"; + var msg = apiOutput.msg; + if (apiOutput.msg == "") + { + msg = "同步成功"; + } + await _obj118Rep.AsUpdateable() + .SetColumns(it => new Obj118 + { + fld005293 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + fld005294 = codeVal, + fld005292 = "N", + fld005295 = msg + }) + .Where(it => it.idRecord == input[i].idRecord) + .ExecuteCommandAsync(); + var output = new SapOutput() + { + parameter = apiOutput.parameter, + code = codeVal, + msg = msg, + result = apiOutput.result + }; + SapOutputList.Add(output); + } + + return SapOutputList; + } + + /// + /// 变更通知ECN-定时同步到SAP + /// + /// + [ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpGet] + [DisplayName("变更通知ECN-定时同步到SAP")] + [AllowAnonymous] + public async Task> TimingSyncToSAP() + { + var input = await _obj118Rep.AsQueryable() + .Where(x => (x.CheckedStatus == 1 || x.CheckedStatus == 0) && x.deleted == false && x.IsLatestVersion == true && (x.fld005292 == "A" || x.fld005292 == "M")) + .ToListAsync(); + var SapOutputList = new List(); + var Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName); + for (int i = 0; i < input.Count; i++) + { + //获取时间戳精确到毫秒,sap要求每次调用生成不重复guid + string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); + + var sapEcnInput = new SapEcnInput() + { + Reqkeyid = "", + Businessid = "", + Messageid = "", + Sndprn = "PLM", + Rcvprn = "SAP", + Requser = await _sysConfigService.GetConfigValueByCode(ConfigConst.SapUserName), + Note1 = "", + Note2 = "", + Note3 = "", + + Aennr = input[i]._System_objNBS, + Aetxt = input[i]._System_ObjDescription, + Datuv = input[i].fld004693.ToDateTime().ToString("yyyy-MM-dd"), + Lvorm = input[i].fld004694, + Matnr = await _dataValidationService.ChangeModuleMaterial(input[i].fld004638.ToLong(), input[i].fld004638_Rec) + }; + var apiOutput = await _sapService.SapEcnApi(sapEcnInput); + string codeVal = apiOutput.code == "S" ? "成功" : "失败"; + var msg = apiOutput.msg; + if (apiOutput.msg == "") + { + msg = "同步成功"; + } + await _obj118Rep.AsUpdateable() + .SetColumns(it => new Obj118 + { + fld005293 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + fld005294 = codeVal, + fld005292 = "N", + fld005295 = msg + }) + .Where(it => it.idRecord == input[i].idRecord) + .ExecuteCommandAsync(); + var output = new SapOutput() + { + parameter = apiOutput.parameter, + code = codeVal, + msg = msg, + result = apiOutput.result + }; + SapOutputList.Add(output); + } + + return SapOutputList; + } } diff --git a/admin.net.pro/Web/src/views/processManagement/changeNoticeEcn/index.vue b/admin.net.pro/Web/src/views/processManagement/changeNoticeEcn/index.vue index c3edb3b..2d727c0 100644 --- a/admin.net.pro/Web/src/views/processManagement/changeNoticeEcn/index.vue +++ b/admin.net.pro/Web/src/views/processManagement/changeNoticeEcn/index.vue @@ -181,4 +181,37 @@ const syncToSAP = async (row: any) => { }; +//ECN批量同步到SAP +const batchSyncToSAP = async () => { + options.loading = true; + var data = xGrid.value?.getCheckboxRecords(); + + ElMessageBox.confirm(`确定要批量同步ECN吗?`, '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + }) + .then(async () => { + var output = await BatchSyncToSAPChangeNoticeEcn(data); + 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; +} + \ No newline at end of file