😎完成产品管理定时同步到SAP
This commit is contained in:
parent
5d6156f20f
commit
6ba3ffc125
@ -425,5 +425,113 @@ public class ProductManagementService : IDynamicApiController, ITransient
|
||||
|
||||
return SapOutputList;
|
||||
}
|
||||
/// <summary>
|
||||
/// 产品管理-定时同步到SAP
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpPost]
|
||||
[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();
|
||||
const string lengthError = "物料编码长度大于40,请检查!";
|
||||
var SapOutputList = new List<SapOutput>();
|
||||
var Requser = await _sysConfigService.GetConfigValueByCode<string>(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;
|
||||
}
|
||||
|
||||
//获取时间戳精确到毫秒,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.ToString(),
|
||||
Mhdhb = input[i].fld004895.ToString(),
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user