2024-09-23 11:34:19 +08:00
|
|
|
|
using Admin.NET.Core;
|
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Vistar.Application.Const;
|
|
|
|
|
using Vistar.Application.Entity;
|
|
|
|
|
using Vistar.Application.Service.MaterialManagement.Dto;
|
|
|
|
|
using Admin.NET.Core.Service;
|
|
|
|
|
using Vistar.Application.Util;
|
2024-09-25 11:21:29 +08:00
|
|
|
|
using Vistar.Application.SapService.Dto;
|
2024-09-25 20:48:19 +08:00
|
|
|
|
using Vistar.Application.Common;
|
2024-10-14 13:38:05 +08:00
|
|
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
|
|
|
|
using static Elastic.Clients.Elasticsearch.JoinField;
|
2024-10-16 13:30:25 +08:00
|
|
|
|
using Qiniu.CDN;
|
2024-09-23 11:34:19 +08:00
|
|
|
|
|
|
|
|
|
namespace Vistar.Application.Service.MaterialManagement;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 产品管理服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Name = "ProductManagement", Order = 100)]
|
|
|
|
|
public class ProductManagementService : IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<Obj110> _obj110Rep;
|
|
|
|
|
private readonly SqlSugarRepository<Configurations> _configurationsRep;
|
|
|
|
|
private readonly SysConfigService _sysConfigService;
|
|
|
|
|
private readonly SqlSugarRepository<ConfigurationData> _configurationDataRep;
|
2024-09-25 20:48:19 +08:00
|
|
|
|
public SapService.SapService _sapService;
|
2024-09-25 11:21:29 +08:00
|
|
|
|
public SqlSugarRepository<Obj118> _obj118Rep;
|
2024-09-25 20:48:19 +08:00
|
|
|
|
public Common.DataValidationService _dataValidationService;
|
2024-10-14 13:38:05 +08:00
|
|
|
|
public SqlSugarRepository<Obj122> _obj122Rep;
|
|
|
|
|
public SqlSugarRepository<Obj121> _obj121Rep;
|
2024-09-23 11:34:19 +08:00
|
|
|
|
|
|
|
|
|
public ProductManagementService(
|
|
|
|
|
SqlSugarRepository<Obj110> obj110Rep,
|
|
|
|
|
SqlSugarRepository<Configurations> configurationsRep,
|
|
|
|
|
SysConfigService sysConfigService,
|
2024-09-25 11:21:29 +08:00
|
|
|
|
SqlSugarRepository<ConfigurationData> configurationDataRep,
|
2024-09-26 00:21:59 +08:00
|
|
|
|
SapService.SapService sapService,
|
2024-09-25 20:48:19 +08:00
|
|
|
|
SqlSugarRepository<Obj118> obj118Rep,
|
2024-10-14 13:38:05 +08:00
|
|
|
|
DataValidationService dataValidationService,
|
|
|
|
|
SqlSugarRepository<Obj122> obj122Rep,
|
|
|
|
|
SqlSugarRepository<Obj121> obj121Rep
|
2024-09-25 11:21:29 +08:00
|
|
|
|
|
|
|
|
|
)
|
2024-09-23 11:34:19 +08:00
|
|
|
|
{
|
|
|
|
|
_obj110Rep = obj110Rep;
|
|
|
|
|
_configurationsRep = configurationsRep;
|
|
|
|
|
_sysConfigService = sysConfigService;
|
|
|
|
|
_configurationDataRep = configurationDataRep;
|
2024-09-26 00:21:59 +08:00
|
|
|
|
_sapService = sapService;
|
2024-09-25 11:21:29 +08:00
|
|
|
|
_obj118Rep = obj118Rep;
|
2024-09-25 20:48:19 +08:00
|
|
|
|
_dataValidationService = dataValidationService;
|
2024-10-16 13:30:25 +08:00
|
|
|
|
_obj122Rep = obj122Rep;
|
|
|
|
|
_obj121Rep = obj121Rep;
|
2024-09-23 11:34:19 +08:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询产品管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "page", Description = "分页查询", Order = 1000), HttpPost]
|
|
|
|
|
[DisplayName("分页查询产品管理")]
|
|
|
|
|
//[Authorize(AuthenticationSchemes = SignatureAuthenticationDefaults.AuthenticationScheme)]
|
|
|
|
|
public async Task<SqlSugarPagedList<ProductManagementOutput>> Page(PageProductManagementInput input)
|
|
|
|
|
{
|
2024-09-25 11:21:29 +08:00
|
|
|
|
var query = await _obj110Rep.AsQueryable()
|
2024-09-23 11:34:19 +08:00
|
|
|
|
.Where(x => x.CheckedStatus == false && x.deleted == false && x.IsLatestVersion == true)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input._System_objNBS), u => u._System_objNBS.Contains(input._System_objNBS.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.fld004484), u => u.fld004484.Contains(input.fld004484.Trim()))
|
|
|
|
|
.WhereIF(input.fld004494Range != null && input.fld004494Range.Length == 2, u => u.fld004494 >= input.fld004494Range[0] && u.fld004494 <= input.fld004494Range[1])
|
2024-09-25 11:21:29 +08:00
|
|
|
|
.Select<ProductManagementOutput>()
|
|
|
|
|
.ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
|
return query;
|
2024-09-23 11:34:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 产品管理-同步到 SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "syncToSAP"), HttpPost]
|
|
|
|
|
[DisplayName("产品管理-同步到 SAP")]
|
2024-09-25 11:21:29 +08:00
|
|
|
|
public async Task<SapOutput> SyncToSAP(ProductManagementBaseInput input)
|
2024-09-23 11:34:19 +08:00
|
|
|
|
{
|
2024-09-26 00:21:59 +08:00
|
|
|
|
const string lengthError = "物料描述长度大于40,请检查!";
|
2024-09-23 11:34:19 +08:00
|
|
|
|
|
|
|
|
|
// 验证物料描述长度
|
|
|
|
|
if (input.fld004484.Length > 40)
|
|
|
|
|
{
|
|
|
|
|
await _obj110Rep.AsUpdateable()
|
|
|
|
|
.SetColumns(it => new Obj110
|
|
|
|
|
{
|
|
|
|
|
fld004629 = DateTime.Now,
|
|
|
|
|
fld004312 = "N",
|
2024-09-26 00:21:59 +08:00
|
|
|
|
fld004313 = lengthError,
|
2024-10-16 13:30:25 +08:00
|
|
|
|
fld004311 = "失败"
|
2024-09-23 11:34:19 +08:00
|
|
|
|
})
|
|
|
|
|
.Where(it => it.idRecord == input.idRecord)
|
|
|
|
|
.ExecuteCommandAsync().ConfigureAwait(false);
|
|
|
|
|
|
2024-09-25 11:21:29 +08:00
|
|
|
|
return new SapOutput
|
2024-09-23 11:34:19 +08:00
|
|
|
|
{
|
|
|
|
|
code = "失败",
|
|
|
|
|
msg = lengthError,
|
|
|
|
|
result = lengthError
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-25 11:21:29 +08:00
|
|
|
|
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
2024-09-23 11:34:19 +08:00
|
|
|
|
|
2024-09-25 11:21:29 +08:00
|
|
|
|
var sapMaterialInput = new SapMaterialInput()
|
|
|
|
|
{
|
|
|
|
|
Reqkeyid = "",
|
|
|
|
|
Businessid = "",
|
|
|
|
|
Messageid = "",
|
|
|
|
|
Sndprn = "PLM",
|
|
|
|
|
Rcvprn = "SAP",
|
|
|
|
|
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
Note1 = "",
|
|
|
|
|
Note2 = "",
|
|
|
|
|
Note3 = "",
|
|
|
|
|
Zwbid = millisecondTimestamp,
|
|
|
|
|
Matnr = input._System_objNBS,
|
|
|
|
|
Mbrsh = input.fld004323,
|
|
|
|
|
Mtart = input.fld004324,
|
|
|
|
|
Maktx = input.fld004484,
|
|
|
|
|
Meins = input.fld004861,
|
|
|
|
|
Matkl = input.fld004485,
|
|
|
|
|
Bismt = input.fld004880,
|
|
|
|
|
Groes = input.fld004879,
|
|
|
|
|
Normt = input.fld004887,
|
|
|
|
|
Ferth = input.fld004882,
|
|
|
|
|
Zeinr = input.fld004881,
|
|
|
|
|
Mstae = input.fld004699,
|
|
|
|
|
Raube = input.fld004877,
|
|
|
|
|
Mhdrz = input.fld004876,
|
2024-09-27 09:34:44 +08:00
|
|
|
|
Mhdhb = input.fld004895.ToString(),
|
2024-09-25 11:21:29 +08:00
|
|
|
|
Werks = input.fld004325,
|
|
|
|
|
Beskz = input.fld004490,
|
|
|
|
|
Sobsl = input.fld004491,
|
|
|
|
|
Schgt = input.fld004873,
|
|
|
|
|
Rgekz = input.fld004872,
|
|
|
|
|
Zbom = input.fld004698
|
|
|
|
|
};
|
2024-09-23 11:34:19 +08:00
|
|
|
|
|
2024-09-25 20:48:19 +08:00
|
|
|
|
var apiOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
2024-09-25 11:21:29 +08:00
|
|
|
|
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
var msg = apiOutput.msg;
|
2024-09-25 20:48:19 +08:00
|
|
|
|
if (apiOutput.msg == "")
|
2024-09-25 11:21:29 +08:00
|
|
|
|
{
|
|
|
|
|
msg = "同步成功";
|
|
|
|
|
}
|
2024-09-23 11:34:19 +08:00
|
|
|
|
|
2024-09-25 11:21:29 +08:00
|
|
|
|
await _obj110Rep.AsUpdateable()
|
|
|
|
|
.SetColumns(it => new Obj110
|
|
|
|
|
{
|
|
|
|
|
fld004629 = DateTime.Now,
|
|
|
|
|
fld004311 = codeVal,
|
|
|
|
|
fld004312 = "N",
|
|
|
|
|
fld004313 = msg
|
|
|
|
|
})
|
|
|
|
|
.Where(it => it.idRecord == input.idRecord)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
var output = new SapOutput()
|
|
|
|
|
{
|
2024-09-25 20:48:19 +08:00
|
|
|
|
parameter = apiOutput.parameter,
|
2024-09-25 11:21:29 +08:00
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = apiOutput.result
|
|
|
|
|
};
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取BOM
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-09-25 14:37:03 +08:00
|
|
|
|
[ApiDescriptionSettings(Name = "GetBOM", Description = "获取BOM", Order = 1000), HttpPost]
|
|
|
|
|
[DisplayName("获取BOM")]
|
2024-09-25 11:21:29 +08:00
|
|
|
|
public async Task<SqlSugarPagedList<ProductManagementBomOutput>> GetBOM(BomPageProductManagementInput input)
|
|
|
|
|
{
|
|
|
|
|
var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 110 && x.ConfigLabel == "mBOM").FirstAsync();
|
|
|
|
|
var parent = await _obj110Rep.AsQueryable().Where(x => x.RecordGuid == input.ParentGuid && x.deleted == false).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<ProductManagementBomOutput>().ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
|
return BomData;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2024-09-25 14:37:03 +08:00
|
|
|
|
/// 产品管理-Bom同步到SAP
|
2024-09-25 11:21:29 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-09-25 14:37:03 +08:00
|
|
|
|
[ApiDescriptionSettings(Name = "SyncToSAPBom"), HttpPost]
|
|
|
|
|
[DisplayName("产品管理-Bom同步到SAP")]
|
2024-09-25 11:21:29 +08:00
|
|
|
|
public async Task<SapOutput> SyncToSAPBom(List<BomPageProductManagementInput> input)
|
|
|
|
|
{
|
|
|
|
|
var ParentData = await _obj110Rep.AsQueryable().Where(x => x.RecordGuid == input[0].ParentGuid && x.deleted == false && x.VersionIndex == input[0].ParentVersion).FirstAsync();
|
|
|
|
|
var EcnData = await _obj118Rep.AsQueryable().Where(x => x.RecordGuid == ParentData.fld004944_Rec && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync();
|
|
|
|
|
var ecn = "";
|
|
|
|
|
if (EcnData != null)
|
|
|
|
|
{
|
|
|
|
|
ecn = EcnData._System_objNBS;
|
|
|
|
|
}
|
2024-09-23 11:34:19 +08:00
|
|
|
|
|
2024-09-25 11:21:29 +08:00
|
|
|
|
var itemDataList = new List<ItemData>();
|
2024-09-23 11:34:19 +08:00
|
|
|
|
|
2024-09-25 11:21:29 +08:00
|
|
|
|
for (int i = 0; i < input.Count; i++)
|
2024-09-23 11:34:19 +08:00
|
|
|
|
{
|
2024-09-25 20:48:19 +08:00
|
|
|
|
var Verification = await _dataValidationService.VerificationMaterial(input[i].ChildObjID, input[i].PartNumber, input[i].ChildGuid);
|
|
|
|
|
if (Verification == "不存在")
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-10-14 13:38:05 +08:00
|
|
|
|
//int sun = i + 1;
|
2024-09-25 11:21:29 +08:00
|
|
|
|
var itemData = new ItemData()
|
2024-09-23 11:34:19 +08:00
|
|
|
|
{
|
2024-10-14 13:38:05 +08:00
|
|
|
|
POSNR = "",//组件序号 sun.ToString()
|
2024-09-25 11:21:29 +08:00
|
|
|
|
IDNRK = input[i].PartNumber,//组件物料号
|
|
|
|
|
MENGE = input[i].Quantity.ToString(),//组件数量
|
|
|
|
|
SORTF = input[i].fld004936,
|
|
|
|
|
ITISOB = input[i].fld004937,
|
|
|
|
|
ALPGR = input[i].fld004938,
|
|
|
|
|
ALPRF = input[i].fld004939,
|
|
|
|
|
ZDELETE = input[i].fld004940,
|
|
|
|
|
POSTP = input[i].fld004492,
|
|
|
|
|
ZYFMK = input[i].fld004941
|
2024-09-23 11:34:19 +08:00
|
|
|
|
};
|
2024-09-25 11:21:29 +08:00
|
|
|
|
itemDataList.Add(itemData);
|
2024-09-23 11:34:19 +08:00
|
|
|
|
}
|
2024-09-25 11:21:29 +08:00
|
|
|
|
|
2024-10-16 13:30:25 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(ParentData.fld005288))
|
|
|
|
|
{
|
2024-10-14 13:38:05 +08:00
|
|
|
|
var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 110 && x.ConfigLabel == "mBOM").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.fld005288)).ToListAsync();
|
|
|
|
|
for (int i = 0; i < BomData.Count; i++)
|
|
|
|
|
{
|
2024-10-16 13:30:25 +08:00
|
|
|
|
|
|
|
|
|
var itemList = itemDataList.Where(x => x.IDNRK == BomData[i].PartNumber).ToList();
|
|
|
|
|
if (itemList.Count == 0)
|
|
|
|
|
{
|
2024-10-14 13:38:05 +08:00
|
|
|
|
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].Quantity.ToString(),//组件数量
|
|
|
|
|
SORTF = BomData[i].fld004936,
|
|
|
|
|
ITISOB = BomData[i].fld004937,
|
|
|
|
|
ALPGR = BomData[i].fld004938,
|
|
|
|
|
ALPRF = BomData[i].fld004939,
|
|
|
|
|
ZDELETE = "X",
|
|
|
|
|
POSTP = BomData[i].fld004492,
|
|
|
|
|
ZYFMK = BomData[i].fld004941
|
|
|
|
|
};
|
|
|
|
|
itemDataList.Add(itemData);
|
|
|
|
|
}
|
2024-10-16 13:30:25 +08:00
|
|
|
|
|
2024-10-14 13:38:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-25 11:21:29 +08:00
|
|
|
|
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
|
|
|
|
|
var isreq = new IS_REQ()
|
|
|
|
|
{
|
|
|
|
|
ReqKeyId = "",
|
|
|
|
|
BusinessId = "",
|
|
|
|
|
MessageId = "",
|
|
|
|
|
SndPrn = "PLM",
|
|
|
|
|
RcvPrn = "SAP",
|
|
|
|
|
ReqUser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
Note1 = "",
|
|
|
|
|
Note2 = "",
|
|
|
|
|
Note3 = "",
|
|
|
|
|
Zwbid = millisecondTimestamp,
|
|
|
|
|
Matnr = ParentData._System_objNBS,//父物料编码
|
|
|
|
|
Werks = ParentData.fld004325,//工厂
|
|
|
|
|
Bmeng = ParentData.fld004942.ToString(),
|
|
|
|
|
Aennr = ecn,
|
|
|
|
|
Datuv = ParentData.fld004945.ToString(),
|
|
|
|
|
ItemList = itemDataList
|
|
|
|
|
};
|
2024-09-25 20:48:19 +08:00
|
|
|
|
var apiOutput = await _sapService.SapBomApi(isreq);
|
2024-09-25 11:21:29 +08:00
|
|
|
|
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
await _obj110Rep.AsUpdateable()
|
|
|
|
|
.SetColumns(it => new Obj110
|
|
|
|
|
{
|
|
|
|
|
fld004631 = DateTime.Now,
|
|
|
|
|
fld004315 = codeVal,
|
|
|
|
|
fld004316 = "N",
|
2024-10-14 13:38:05 +08:00
|
|
|
|
fld004317 = apiOutput.msg,
|
2024-10-16 13:30:25 +08:00
|
|
|
|
fld005288 = input[0].ParentVersion.ToString()////////////////////////////////////////////////////////////xinixnixn
|
2024-09-25 11:21:29 +08:00
|
|
|
|
})
|
|
|
|
|
.Where(it => it.idRecord == ParentData.idRecord)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
var msg = apiOutput.msg;
|
|
|
|
|
if (apiOutput.msg == "")
|
|
|
|
|
{
|
|
|
|
|
msg = "同步成功";
|
|
|
|
|
}
|
|
|
|
|
var output = new SapOutput()
|
|
|
|
|
{
|
2024-09-25 20:48:19 +08:00
|
|
|
|
parameter = apiOutput.parameter,
|
2024-09-25 11:21:29 +08:00
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = apiOutput.result
|
|
|
|
|
};
|
|
|
|
|
return output;
|
2024-09-23 11:34:19 +08:00
|
|
|
|
}
|
2024-09-25 14:37:03 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 产品管理-批量同步到SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "BatchSyncToSAP"), HttpPost]
|
|
|
|
|
[DisplayName("产品管理-批量同步到SAP")]
|
|
|
|
|
public async Task<List<SapOutput>> BatchSyncToSAP(List<ProductManagementBaseInput> input)
|
|
|
|
|
{
|
2024-09-26 00:21:59 +08:00
|
|
|
|
const string lengthError = "物料描述长度大于40,请检查!";
|
2024-09-25 14:37:03 +08:00
|
|
|
|
const string synchronized = "该物料编码已同步!";
|
2024-09-25 20:48:19 +08:00
|
|
|
|
var SapOutputList = new List<SapOutput>();
|
2024-09-25 14:37:03 +08:00
|
|
|
|
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",
|
2024-09-26 00:21:59 +08:00
|
|
|
|
fld004313 = lengthError,
|
|
|
|
|
fld004311 = "失败"
|
2024-09-25 14:37:03 +08:00
|
|
|
|
})
|
|
|
|
|
.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;
|
|
|
|
|
}
|
2024-09-27 09:34:44 +08:00
|
|
|
|
if (input[i].fld004312 != "A" && input[i].fld004312 != "M")
|
2024-09-25 14:37:03 +08:00
|
|
|
|
{
|
|
|
|
|
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,
|
2024-09-27 09:34:44 +08:00
|
|
|
|
Mhdhb = input[i].fld004895.ToString(),
|
2024-09-25 14:37:03 +08:00
|
|
|
|
Werks = input[i].fld004325,
|
|
|
|
|
Beskz = input[i].fld004490,
|
|
|
|
|
Sobsl = input[i].fld004491,
|
|
|
|
|
Schgt = input[i].fld004873,
|
|
|
|
|
Rgekz = input[i].fld004872,
|
|
|
|
|
Zbom = input[i].fld004698
|
|
|
|
|
};
|
2024-09-25 20:48:19 +08:00
|
|
|
|
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
2024-09-25 14:37:03 +08:00
|
|
|
|
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()
|
|
|
|
|
{
|
2024-09-25 20:48:19 +08:00
|
|
|
|
parameter = sapOutput.parameter,
|
2024-09-25 14:37:03 +08:00
|
|
|
|
materialCode = input[0]._System_objNBS,
|
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = sapOutput.result
|
|
|
|
|
};
|
|
|
|
|
SapOutputList.Add(output);
|
|
|
|
|
}
|
2024-09-25 20:48:19 +08:00
|
|
|
|
|
2024-09-25 14:37:03 +08:00
|
|
|
|
return SapOutputList;
|
|
|
|
|
}
|
2024-09-25 15:00:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 产品管理-定时同步到SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-09-25 20:48:19 +08:00
|
|
|
|
[ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpGet]
|
2024-09-25 15:00:27 +08:00
|
|
|
|
[DisplayName("产品管理-定时同步到SAP")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<List<SapOutput>> TimingSyncToSAP()
|
|
|
|
|
{
|
|
|
|
|
var input = await _obj110Rep.AsQueryable()
|
2024-09-25 20:48:19 +08:00
|
|
|
|
.Where(x => x.CheckedStatus == false && x.deleted == false && x.IsLatestVersion == true && (x.fld004312 == "A" || x.fld004312 == "M"))
|
|
|
|
|
.ToListAsync();
|
2024-09-26 00:21:59 +08:00
|
|
|
|
const string lengthError = "物料描述长度大于40,请检查!";
|
2024-09-25 15:00:27 +08:00
|
|
|
|
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",
|
2024-09-26 00:21:59 +08:00
|
|
|
|
fld004313 = lengthError,
|
|
|
|
|
fld004311 = "失败"
|
2024-09-25 15:00:27 +08:00
|
|
|
|
})
|
|
|
|
|
.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;
|
|
|
|
|
}
|
2024-09-25 20:48:19 +08:00
|
|
|
|
|
2024-09-25 15:00:27 +08:00
|
|
|
|
//获取时间戳精确到毫秒,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
|
|
|
|
|
};
|
2024-09-25 20:48:19 +08:00
|
|
|
|
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
2024-09-25 15:00:27 +08:00
|
|
|
|
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()
|
|
|
|
|
{
|
2024-10-16 13:30:25 +08:00
|
|
|
|
parameter = sapOutput.parameter,
|
2024-09-25 15:00:27 +08:00
|
|
|
|
materialCode = input[0]._System_objNBS,
|
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = sapOutput.result
|
|
|
|
|
};
|
|
|
|
|
SapOutputList.Add(output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SapOutputList;
|
|
|
|
|
}
|
2024-09-25 20:48:19 +08:00
|
|
|
|
/// <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()
|
2024-10-16 13:30:25 +08:00
|
|
|
|
.Where(x => x.CheckedStatus == false && x.deleted == false && x.IsLatestVersion == true && x.fld004311 == "成功" && (x.fld004316 == "A" || x.fld004316 == "M"))
|
2024-09-25 20:48:19 +08:00
|
|
|
|
.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();
|
2024-10-16 13:30:25 +08:00
|
|
|
|
if (bomData.Count == 0)
|
2024-09-25 20:48:19 +08:00
|
|
|
|
{
|
|
|
|
|
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);
|
2024-10-16 13:30:25 +08:00
|
|
|
|
|
|
|
|
|
}
|
2024-09-25 20:48:19 +08:00
|
|
|
|
// 获取时间戳精确到毫秒,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
|
|
|
|
|
};
|
2024-09-25 15:00:27 +08:00
|
|
|
|
|
2024-09-25 20:48:19 +08:00
|
|
|
|
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 = "同步成功";
|
|
|
|
|
}
|
2024-09-25 15:00:27 +08:00
|
|
|
|
|
2024-09-25 20:48:19 +08:00
|
|
|
|
var output = new SapOutput
|
|
|
|
|
{
|
2024-10-16 13:30:25 +08:00
|
|
|
|
parameter = apiOutput.parameter,
|
2024-09-25 20:48:19 +08:00
|
|
|
|
materialCode = item._System_objNBS,
|
|
|
|
|
code = codeVal,
|
|
|
|
|
msg = msg,
|
|
|
|
|
result = apiOutput.result
|
|
|
|
|
};
|
|
|
|
|
sapOutputList.Add(output);
|
|
|
|
|
}
|
|
|
|
|
return sapOutputList;
|
|
|
|
|
}
|
2024-09-23 11:34:19 +08:00
|
|
|
|
|
2024-10-14 13:38:05 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 产品管理-获取工艺路线
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "GetProcessRoute", Description = "获取工艺路线", Order = 1000), HttpPost]
|
|
|
|
|
[DisplayName("获取工艺路线")]
|
|
|
|
|
public async Task<SqlSugarPagedList<ProductManagementBomOutput>> GetProcessRoute(BomPageProductManagementInput input)
|
|
|
|
|
{
|
|
|
|
|
var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 110 && x.ConfigLabel == "pBOM").FirstAsync();
|
|
|
|
|
var parent = await _obj110Rep.AsQueryable().Where(x => x.RecordGuid == input.ParentGuid && x.deleted == false).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<ProductManagementBomOutput>().ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
|
return BomData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 产品管理-工艺路线同步到SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "SyncToSAPProcessRoute"), HttpPost]
|
|
|
|
|
[DisplayName("产品管理-工艺路线同步到SAP")]
|
|
|
|
|
public async Task<SapOutput> SyncToSAPProcessRoute(List<BomPageProductManagementInput> input)
|
|
|
|
|
{
|
|
|
|
|
var ParentData = await _obj110Rep.AsQueryable().Where(x => x.RecordGuid == input[0].ParentGuid && x.deleted == false && x.VersionIndex == input[0].ParentVersion).FirstAsync();
|
|
|
|
|
|
|
|
|
|
var itemDataList = new List<SapProcessRouteItemData>();
|
|
|
|
|
|
|
|
|
|
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].fld004994.ToString(),
|
|
|
|
|
VGE01 = input[i].fld004995,
|
|
|
|
|
STEUS = input[i].fld004996,
|
|
|
|
|
BMSCH = input[i].fld005296.ToString()
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
itemDataList.Add(itemData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
|
|
|
|
|
var Datuv = ParentData.fld004945.ToString();
|
|
|
|
|
if (!string.IsNullOrEmpty(Datuv))
|
|
|
|
|
{
|
|
|
|
|
Datuv = ParentData.fld004945.ToDateTime().ToString("yyyy-MM-dd");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var isreq = new SapProcessRouteIS_REQ()
|
|
|
|
|
{
|
|
|
|
|
ReqKeyId = "",
|
|
|
|
|
BusinessId = "",
|
|
|
|
|
MessageId = "",
|
|
|
|
|
SndPrn = "PLM",
|
|
|
|
|
RcvPrn = "SAP",
|
|
|
|
|
ReqUser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
Note1 = "",
|
|
|
|
|
Note2 = "",
|
|
|
|
|
Note3 = "",
|
|
|
|
|
Zwbid = millisecondTimestamp,
|
|
|
|
|
Matnr = ParentData._System_objNBS,
|
|
|
|
|
Werks = ParentData.fld004325,
|
|
|
|
|
Datuv = Datuv,
|
|
|
|
|
Plnal = "",
|
|
|
|
|
|
|
|
|
|
ItemList = itemDataList
|
|
|
|
|
};
|
|
|
|
|
var apiOutput = await _sapService.SapProcessRouteApi(isreq);
|
|
|
|
|
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
await _obj110Rep.AsUpdateable()
|
|
|
|
|
.SetColumns(it => new Obj110
|
|
|
|
|
{
|
|
|
|
|
fld004632 = DateTime.Now,
|
|
|
|
|
fld004319 = codeVal,
|
|
|
|
|
fld004320 = "N",
|
|
|
|
|
fld004321 = 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;
|
|
|
|
|
}
|
2024-10-16 13:30:25 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 产品管理-定时同步工艺路线到SAP
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ApiDescriptionSettings(Name = "TimingSyncToSAPProcessRoute"), HttpGet]
|
|
|
|
|
[DisplayName("产品管理-定时同步工艺路线到SAP")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<List<SapOutput>> TimingSyncToSAPProcessRoute()
|
|
|
|
|
{
|
|
|
|
|
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 == "pBOM").FirstAsync();
|
|
|
|
|
|
|
|
|
|
//查询需要同步的产品
|
|
|
|
|
var materialData = await _obj110Rep.AsQueryable()
|
|
|
|
|
.Where(x => x.CheckedStatus == false && x.deleted == false && x.IsLatestVersion == true && x.fld004311 == "成功" && (x.fld004320 == "A" || x.fld004320 == "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<SapProcessRouteItemData>();
|
|
|
|
|
|
|
|
|
|
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.fld004994.ToString(),
|
|
|
|
|
VGE01 = processRouteItem.fld004995,
|
|
|
|
|
STEUS = processRouteItem.fld004996,
|
|
|
|
|
BMSCH = processRouteItem.fld005296.ToString()
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
itemDataList.Add(itemData);
|
|
|
|
|
}
|
|
|
|
|
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
|
|
|
|
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
|
|
|
|
|
|
|
var Datuv = item.fld004945.ToString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Datuv))
|
|
|
|
|
{
|
|
|
|
|
Datuv = item.fld004945.ToDateTime().ToString("yyyy-MM-dd");
|
|
|
|
|
}
|
|
|
|
|
var isreq = new SapProcessRouteIS_REQ()
|
|
|
|
|
{
|
|
|
|
|
ReqKeyId = "",
|
|
|
|
|
BusinessId = "",
|
|
|
|
|
MessageId = "",
|
|
|
|
|
SndPrn = "PLM",
|
|
|
|
|
RcvPrn = "SAP",
|
|
|
|
|
ReqUser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
|
|
|
|
Note1 = "",
|
|
|
|
|
Note2 = "",
|
|
|
|
|
Note3 = "",
|
|
|
|
|
Zwbid = millisecondTimestamp,
|
|
|
|
|
Matnr = item._System_objNBS,
|
|
|
|
|
Werks = item.fld004325,
|
|
|
|
|
Datuv = Datuv,
|
|
|
|
|
Plnal = "",
|
|
|
|
|
|
|
|
|
|
ItemList = itemDataList
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var apiOutput = await _sapService.SapProcessRouteApi(isreq);
|
|
|
|
|
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
|
|
|
|
await _obj110Rep.AsUpdateable()
|
|
|
|
|
.SetColumns(it => new Obj110
|
|
|
|
|
{
|
|
|
|
|
fld004632 = DateTime.Now,
|
|
|
|
|
fld004319 = codeVal,
|
|
|
|
|
fld004320 = "N",
|
|
|
|
|
fld004321 = 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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-23 11:34:19 +08:00
|
|
|
|
}
|