😎新增产品管理-定时同步 BOM 到 SAP接口

This commit is contained in:
bairubing 2024-09-25 20:48:19 +08:00
parent 34170e347e
commit 174fb2b4f2
4 changed files with 155 additions and 18 deletions

View File

@ -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

View File

@ -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<Configurations> _configurationsRep;
private readonly SysConfigService _sysConfigService;
private readonly SqlSugarRepository<ConfigurationData> _configurationDataRep;
public SapService.SapService _sapBomService;
public SapService.SapService _sapService;
public SqlSugarRepository<Obj118> _obj118Rep;
public Common.DataValidationService _dataValidationService;
public ProductManagementService(
SqlSugarRepository<Obj110> obj110Rep,
@ -61,7 +67,8 @@ public class ProductManagementService : IDynamicApiController, ITransient
SysConfigService sysConfigService,
SqlSugarRepository<ConfigurationData> configurationDataRep,
SapService.SapService sapBomService,
SqlSugarRepository<Obj118> obj118Rep
SqlSugarRepository<Obj118> 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;
}
/// <summary>
/// 分页查询产品管理
@ -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<ItemData>();
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<SapOutput>();
var SapOutputList = new List<SapOutput>();
var Requser = await _sysConfigService.GetConfigValueByCode<string>(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;
}
/// <summary>
/// 产品管理-定时同步到SAP
/// </summary>
/// <returns></returns>
[ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpPost]
[ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpGet]
[DisplayName("产品管理-定时同步到SAP")]
[AllowAnonymous]
public async Task<List<SapOutput>> 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<SapOutput>();
var Requser = await _sysConfigService.GetConfigValueByCode<string>(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;
}
/// <summary>
/// 产品管理-定时同步 BOM 到 SAP
/// </summary>
/// <returns></returns>
[ApiDescriptionSettings(Name = "TimingSyncToSAPBom"), HttpGet]
[DisplayName("产品管理-定时同步 Bom 到 SAP")]
[AllowAnonymous]
public async Task<List<SapOutput>> TimingSyncToSAPBom()
{
var sapOutputList = new List<SapOutput>();
var sapUserName = await _sysConfigService.GetConfigValueByCode<string>(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<ItemData>();
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;
}
}

View File

@ -16,6 +16,7 @@ namespace Vistar.Application.Util;
/// </summary>
public class SapOutput
{
public string parameter { get; set; }
public string? materialCode { get; set; }
public string code { get; set; }
public string msg { get; set; }

View File

@ -49,7 +49,7 @@
<template #row_buttons="{ row }">
<el-tooltip content="查看BOM" placement="top">
<el-button icon="ele-MessageBox" size="small" text="" type="primary"
@click="showBomDrawer(row)" v-if="row.fld004316!='N'">
@click="showBomDrawer(row)" v-if="row.fld004316=='A'||row.fld004316=='M'">
查看BOM </el-button>
</el-tooltip>
<el-tooltip content="工艺路线" placement="top">
@ -60,7 +60,7 @@
<el-tooltip content="同步到ERP" placement="top">
<el-button icon="ele-Promotion" size="small" text="" type="success" @click="syncToSAP(row)"
v-auth="'productManagement/syncToSAP'" v-if="row.fld004312!='N'"> 同步到SAP </el-button>
v-auth="'productManagement/syncToSAP'" v-if="row.fld004312=='A'||row.fld004312=='M'"> 同步到SAP </el-button>
</el-tooltip>
</template>
</vxe-grid>