1106 lines
47 KiB
C#
1106 lines
47 KiB
C#
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||
//
|
||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||
//
|
||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||
|
||
using Admin.NET.Core;
|
||
using Admin.NET.Core.Service;
|
||
using DocumentFormat.OpenXml.Wordprocessing;
|
||
using Furion.DependencyInjection;
|
||
using Furion.DynamicApiController;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using Vistar.Application.Common;
|
||
using Vistar.Application.Const;
|
||
using Vistar.Application.Entity;
|
||
using Vistar.Application.SapService.Dto;
|
||
using Vistar.Application.Service.ProductDesignLibrary.Dto;
|
||
using Vistar.Application.SolidWorksManageService.Dto;
|
||
using Vistar.Application.Util;
|
||
|
||
namespace Vistar.Application.Service.ProductDesignLibrary;
|
||
/// <summary>
|
||
/// 产品设计库服务
|
||
/// </summary>
|
||
[ApiDescriptionSettings(ApplicationConst.GroupName, Name = "ProductDesignLibrary", Order = 100)]
|
||
public class ProductDesignLibraryService : IDynamicApiController, ITransient
|
||
{
|
||
private readonly SqlSugarRepository<Obj137> _obj137Rep;
|
||
private readonly SysConfigService _sysConfigService;
|
||
public SapService.SapService _sapService;
|
||
private readonly SqlSugarRepository<Configurations> _configurationsRep;
|
||
private readonly SqlSugarRepository<ConfigurationData> _configurationDataRep;
|
||
public SqlSugarRepository<Obj118> _obj118Rep;
|
||
public Common.DataValidationService _dataValidationService;
|
||
public SqlSugarRepository<Obj122> _obj122Rep;
|
||
public SqlSugarRepository<Obj121> _obj121Rep;
|
||
public SolidWorksManageService.SolidWorksManageService _solidWorksManageService;
|
||
|
||
public ProductDesignLibraryService(
|
||
SqlSugarRepository<Obj137> obj137Rep,
|
||
SysConfigService sysConfigService,
|
||
SapService.SapService sapService,
|
||
SqlSugarRepository<Configurations> configurationsRep,
|
||
SqlSugarRepository<ConfigurationData> configurationDataRep,
|
||
SqlSugarRepository<Obj118> obj118Rep,
|
||
DataValidationService dataValidationService,
|
||
SqlSugarRepository<Obj122> obj122Rep,
|
||
SqlSugarRepository<Obj121> obj121Rep,
|
||
SolidWorksManageService.SolidWorksManageService solidWorksManageService
|
||
)
|
||
{
|
||
_obj137Rep = obj137Rep;
|
||
_sysConfigService = sysConfigService;
|
||
_sapService = sapService;
|
||
_configurationsRep = configurationsRep;
|
||
_configurationDataRep = configurationDataRep;
|
||
_obj118Rep = obj118Rep;
|
||
_dataValidationService = dataValidationService;
|
||
_obj122Rep = obj122Rep;
|
||
_obj121Rep = obj121Rep;
|
||
_solidWorksManageService = solidWorksManageService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 分页查询产品设计库
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "page", Description = "分页查询", Order = 1000), HttpPost]
|
||
[DisplayName("分页查询产品设计库")]
|
||
public async Task<SqlSugarPagedList<ProductDesignLibraryOutput>> Page(PageProductDesignLibraryInput input)
|
||
{
|
||
var query = await _obj137Rep.AsQueryable()
|
||
.Where(x => x.CheckedStatus == 0 && x.deleted == false && x.IsLatestVersion == true && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW"))
|
||
.WhereIF(!string.IsNullOrWhiteSpace(input._System_objNBS), u => u._System_objNBS.Contains(input._System_objNBS.Trim()))
|
||
.WhereIF(!string.IsNullOrWhiteSpace(input._SWPDM_1188_SAP___), u => u._SWPDM_1188_SAP___.Contains(input._SWPDM_1188_SAP___.Trim()))
|
||
.Select<ProductDesignLibraryOutput>()
|
||
.ToPagedListAsync(input.Page, input.PageSize);
|
||
return query;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 产品设计库-同步到 SAP
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "syncToSAP"), HttpPost]
|
||
[DisplayName("产品设计库-同步到 SAP")]
|
||
public async Task<SapOutput> SyncToSAP(ProductDesignLibraryInput input)
|
||
{
|
||
const string lengthError = "物料描述长度大于40,请检查!";
|
||
|
||
// 验证物料描述长度
|
||
if (input._SWPDM_1188_SAP___.Length > 40)
|
||
{
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005532 = DateTime.Now,
|
||
fld005530 = "N",
|
||
fld005531 = lengthError,
|
||
fld005529 = "失败"
|
||
})
|
||
.Where(it => it.idRecord == input.idRecord)
|
||
.ExecuteCommandAsync().ConfigureAwait(false);
|
||
|
||
return new SapOutput
|
||
{
|
||
code = "失败",
|
||
msg = lengthError,
|
||
result = lengthError
|
||
};
|
||
}
|
||
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
|
||
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._SWPDM_1185_SAP___,
|
||
Mtart = input._SWPDM_1186_SAP_____,
|
||
Maktx = input._SWPDM_1188_SAP___,
|
||
Meins = input._SWPDM_126_SW___,
|
||
Matkl = input._SWPDM_1203_SAP____,
|
||
Bismt = input._SWPDM_64_SW___,
|
||
Groes = input._SWPDM_125_SW___,
|
||
Normt = input._SWPDM_65_SW___,
|
||
Ferth = input._SWPDM_62_SW___,
|
||
Zeinr = input._SWPDM_61_SW_____,
|
||
Mstae = input._SWPDM_1209_SAP_____,
|
||
Raube = "",
|
||
Mhdrz = "",
|
||
Mhdhb = "",
|
||
Werks = input._SWPDM_1187_SAP___,
|
||
Beskz = input._SWPDM_1196_SAP_____,
|
||
Sobsl = input._SWPDM_1198_SAP_____,
|
||
Schgt = input._SWPDM_1197_SAP_____,
|
||
Rgekz = input._SWPDM_1199_SAP___,
|
||
Zbom = input._SWPDM_1208_SAP___BOM___
|
||
};
|
||
|
||
var apiOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
var msg = apiOutput.msg;
|
||
if (apiOutput.msg == "")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005532 = DateTime.Now,
|
||
fld005529 = codeVal,
|
||
fld005530 = "N",
|
||
fld005531 = msg
|
||
})
|
||
.Where(it => it.idRecord == input.idRecord)
|
||
.ExecuteCommandAsync();
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = apiOutput.parameter,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = apiOutput.result
|
||
};
|
||
return output;
|
||
}
|
||
/// <summary>
|
||
/// 获取BOM
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "GetBOM", Description = "获取BOM", Order = 1000), HttpPost]
|
||
[DisplayName("获取BOM")]
|
||
public async Task<SqlSugarPagedList<ProductDesignLibraryBomOutput>> GetBOM(BomPageProductDesignLibraryInput input)
|
||
{
|
||
var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 137 && x.ConfigSystemName == "SolidWorks").FirstAsync();
|
||
var parent = await _obj137Rep.AsQueryable()
|
||
.Where(x => x.RecordGuid == input.ParentGuid && x.deleted == false && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW"))
|
||
.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 && (x.fld005577 != "不包含" || x.fld005577 == null) && x.isSuppressed == false && x.inContext == false)
|
||
.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<ProductDesignLibraryBomOutput>().ToPagedListAsync(input.Page, input.PageSize);
|
||
return BomData;
|
||
}
|
||
/// <summary>
|
||
/// 产品设计库-Bom同步到SAP
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "SyncToSAPBom"), HttpPost]
|
||
[DisplayName("产品设计库-Bom同步到SAP")]
|
||
public async Task<SapOutput> SyncToSAPBom(List<BomPageProductDesignLibraryInput> input)
|
||
{
|
||
var ParentData = await _obj137Rep.AsQueryable().Where(x => x.RecordGuid == input[0].ParentGuid && x.deleted == false && x.VersionIndex == input[0].ParentVersion && (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null) && x.fld005530 == "N" && x.fld005529 == "成功" && (x.fld005534 == "A" || x.fld005534 == "M") && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW")).FirstAsync();
|
||
var EcnData = await _obj118Rep.AsQueryable().Where(x => x.RecordGuid == ParentData.fld005679_Rec && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync();
|
||
var ecn = "";
|
||
if (EcnData != null)
|
||
{
|
||
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()
|
||
{
|
||
POSNR = "",//组件序号 sun.ToString()
|
||
IDNRK = input[i].PartNumber,//组件物料号
|
||
MENGE = input[i].QtyManual.ToString(),//组件数量
|
||
SORTF = input[i].fld005541,
|
||
ITISOB = input[i].fld005542,
|
||
ALPGR = input[i].fld005543,
|
||
ALPRF = input[i].fld005544,
|
||
ZDELETE = input[i].fld005545,
|
||
POSTP = input[i].fld005546,
|
||
ZYFMK = input[i].fld005547
|
||
};
|
||
itemDataList.Add(itemData);
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(ParentData.fld005686))
|
||
{
|
||
var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 137 && x.ConfigSystemName == "SolidWorks").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.fld005686) && (x.fld005577 != "不包含" || x.fld005577 == null) && x.isSuppressed == false && x.inContext == false).ToListAsync();
|
||
for (int i = 0; i < BomData.Count; i++)
|
||
{
|
||
|
||
var itemList = itemDataList.Where(x => x.IDNRK == BomData[i].PartNumber).ToList();
|
||
if (itemList.Count == 0)
|
||
{
|
||
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].QtyManual.ToString(),//组件数量
|
||
SORTF = BomData[i].fld005541,
|
||
ITISOB = BomData[i].fld005542,
|
||
ALPGR = BomData[i].fld005543,
|
||
ALPRF = BomData[i].fld005544,
|
||
ZDELETE = "X",
|
||
POSTP = BomData[i].fld005546,
|
||
ZYFMK = BomData[i].fld005547
|
||
};
|
||
itemDataList.Add(itemData);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
var fld005678 = ParentData.fld005678 ?? 1;
|
||
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._SWPDM_1187_SAP___,//工厂
|
||
Bmeng = fld005678.ToString(),
|
||
Aennr = ecn,
|
||
Datuv = ParentData.fld005680.ToString(),
|
||
ItemList = itemDataList
|
||
};
|
||
var apiOutput = await _sapService.SapBomApi(isreq);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
if (codeVal == "成功")
|
||
{
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005539 = DateTime.Now,
|
||
fld005533 = codeVal,
|
||
fld005534 = "N",
|
||
fld005535 = apiOutput.msg,
|
||
fld005686 = input[0].ParentVersion.ToString()
|
||
})
|
||
.Where(it => it.idRecord == ParentData.idRecord)
|
||
.ExecuteCommandAsync();
|
||
}
|
||
else
|
||
{
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005539 = DateTime.Now,
|
||
fld005533 = codeVal,
|
||
fld005534 = "N",
|
||
fld005535 = 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;
|
||
}
|
||
/// <summary>
|
||
/// 产品设计库-批量同步到SAP
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "BatchSyncToSAP"), HttpPost]
|
||
[DisplayName("产品设计库-批量同步到SAP")]
|
||
public async Task<List<SapOutput>> BatchSyncToSAP(List<ProductDesignLibraryInput> input)
|
||
{
|
||
const string lengthError = "物料描述长度大于40,请检查!";
|
||
const string synchronized = "该物料编码已同步或已停用!";
|
||
var SapOutputList = new List<SapOutput>();
|
||
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
||
for (int i = 0; i < input.Count; i++)
|
||
{
|
||
// 验证物料描述长度
|
||
if (input[i]._SWPDM_1188_SAP___.Length > 40)
|
||
{
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005532 = DateTime.Now,
|
||
fld005530 = "N",
|
||
fld005531 = lengthError,
|
||
fld005529 = "失败"
|
||
})
|
||
.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].fld005530 == "N" || input[i].fld005530 == "D" || input[i].fld005530 == null)
|
||
{
|
||
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]._SWPDM_1185_SAP___,
|
||
Mtart = input[i]._SWPDM_1186_SAP_____,
|
||
Maktx = input[i]._SWPDM_1188_SAP___,
|
||
Meins = input[i]._SWPDM_126_SW___,
|
||
Matkl = input[i]._SWPDM_1203_SAP____,
|
||
Bismt = input[i]._SWPDM_64_SW___,
|
||
Groes = input[i]._SWPDM_125_SW___,
|
||
Normt = input[i]._SWPDM_65_SW___,
|
||
Ferth = input[i]._SWPDM_62_SW___,
|
||
Zeinr = input[i]._SWPDM_61_SW_____,
|
||
Mstae = input[i]._SWPDM_1209_SAP_____,
|
||
Raube = "",
|
||
Mhdrz = "",
|
||
Mhdhb = "",
|
||
Werks = input[i]._SWPDM_1187_SAP___,
|
||
Beskz = input[i]._SWPDM_1196_SAP_____,
|
||
Sobsl = input[i]._SWPDM_1198_SAP_____,
|
||
Schgt = input[i]._SWPDM_1197_SAP_____,
|
||
Rgekz = input[i]._SWPDM_1199_SAP___,
|
||
Zbom = input[i]._SWPDM_1208_SAP___BOM___
|
||
};
|
||
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
||
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
|
||
string msg = sapOutput.msg;
|
||
|
||
if (sapOutput.msg == "")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005532 = DateTime.Now,
|
||
fld005529 = codeVal,
|
||
fld005530 = "N",
|
||
fld005531 = msg
|
||
})
|
||
.Where(it => it.idRecord == input[i].idRecord)
|
||
.ExecuteCommandAsync();
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = sapOutput.parameter,
|
||
materialCode = input[0]._System_objNBS,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = sapOutput.result
|
||
};
|
||
SapOutputList.Add(output);
|
||
}
|
||
|
||
return SapOutputList;
|
||
}
|
||
/// <summary>
|
||
/// 产品设计库-定时同步到SAP
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpGet]
|
||
[DisplayName("产品设计库-定时同步到SAP")]
|
||
[AllowAnonymous]
|
||
public async Task<List<SapOutput>> TimingSyncToSAP()
|
||
{
|
||
var input = await _obj137Rep.AsQueryable()
|
||
.Where(x => x.CheckedStatus == 0 && x.deleted == false && x.IsLatestVersion == true && (x.fld005530 == "A" || x.fld005530 == "M") && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW"))
|
||
.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 (!string.IsNullOrEmpty(input[i]._SWPDM_1188_SAP___))
|
||
{
|
||
// 验证物料描述长度
|
||
if (input[i]._SWPDM_1188_SAP___.Length > 40)
|
||
{
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005532 = DateTime.Now,
|
||
fld005530 = "N",
|
||
fld005531 = lengthError,
|
||
fld005529 = "失败"
|
||
})
|
||
.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]._SWPDM_1185_SAP___,
|
||
Mtart = input[i]._SWPDM_1186_SAP_____,
|
||
Maktx = input[i]._SWPDM_1188_SAP___,
|
||
Meins = input[i]._SWPDM_126_SW___,
|
||
Matkl = input[i]._SWPDM_1203_SAP____,
|
||
Bismt = input[i]._SWPDM_64_SW___,
|
||
Groes = input[i]._SWPDM_125_SW___,
|
||
Normt = input[i]._SWPDM_65_SW___,
|
||
Ferth = input[i]._SWPDM_62_SW___,
|
||
Zeinr = input[i]._SWPDM_61_SW_____,
|
||
Mstae = input[i]._SWPDM_1209_SAP_____,
|
||
Raube = "",
|
||
Mhdrz = "",
|
||
Mhdhb = "",
|
||
Werks = input[i]._SWPDM_1187_SAP___,
|
||
Beskz = input[i]._SWPDM_1196_SAP_____,
|
||
Sobsl = input[i]._SWPDM_1198_SAP_____,
|
||
Schgt = input[i]._SWPDM_1197_SAP_____,
|
||
Rgekz = input[i]._SWPDM_1199_SAP___,
|
||
Zbom = input[i]._SWPDM_1208_SAP___BOM___
|
||
};
|
||
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
||
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
|
||
string msg = sapOutput.msg;
|
||
|
||
if (sapOutput.msg == "")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005532 = DateTime.Now,
|
||
fld005529 = codeVal,
|
||
fld005530 = "N",
|
||
fld005531 = msg
|
||
})
|
||
.Where(it => it.idRecord == input[i].idRecord)
|
||
.ExecuteCommandAsync();
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = sapOutput.parameter,
|
||
materialCode = input[0]._System_objNBS,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = sapOutput.result
|
||
};
|
||
SapOutputList.Add(output);
|
||
}
|
||
|
||
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 == 137 && x.ConfigSystemName == "SolidWorks").FirstAsync();
|
||
|
||
var materialData = await _obj137Rep.AsQueryable()
|
||
.Where(x => x.CheckedStatus == 0 && x.deleted == false && x.IsLatestVersion == true && (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null) && x.fld005530 == "N" && x.fld005529 == "成功" && (x.fld005534 == "A" || x.fld005534 == "M") && x._system_objConfigurationName == "默认" && !x.SWPDMFileName.Contains("SLDDRW"))
|
||
.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.fld005679_Rec;
|
||
// 查询 BOM
|
||
var bomData = await _configurationDataRep.AsQueryable()
|
||
.Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == item.RecordGuid && x.isDeleted == false && x.ParentVersion == versionIndex && (x.fld005577 != "不包含" || x.fld005577 == null) && x.isSuppressed == false && x.inContext == false).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.QtyManual.ToString(),
|
||
SORTF = bomItem.fld005541,
|
||
ITISOB = bomItem.fld005542,
|
||
ALPGR = bomItem.fld005543,
|
||
ALPRF = bomItem.fld005544,
|
||
ZDELETE = bomItem.fld004940,
|
||
POSTP = bomItem.fld005546,
|
||
ZYFMK = bomItem.fld005547
|
||
};
|
||
itemDataList.Add(itemData);
|
||
|
||
}
|
||
|
||
var ParentData = await _obj137Rep.AsQueryable().Where(x => x.RecordGuid == bomData[0].ParentGuid && x.deleted == false && x.VersionIndex == bomData[0].ParentVersion).FirstAsync();
|
||
|
||
if (!string.IsNullOrEmpty(ParentData.fld005686))
|
||
{
|
||
var configidold = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 137 && x.ConfigSystemName == "SolidWorks").FirstAsync();
|
||
var BomData = await _configurationDataRep.AsQueryable().Where(x => x.ConfigId == configidold.ConfigID && x.ParentGuid == bomData[0].ParentGuid && x.isDeleted == false && x.ParentVersion == Convert.ToInt32(ParentData.fld005686) && (x.fld005577 != "不包含" || x.fld005577 == null) && x.isSuppressed == false && x.inContext == false).ToListAsync();
|
||
for (int i = 0; i < BomData.Count; i++)
|
||
{
|
||
|
||
var itemList = itemDataList.Where(x => x.IDNRK == BomData[i].PartNumber).ToList();
|
||
if (itemList.Count == 0)
|
||
{
|
||
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].QtyManual.ToString(),//组件数量
|
||
SORTF = BomData[i].fld005541,
|
||
ITISOB = BomData[i].fld005542,
|
||
ALPGR = BomData[i].fld005543,
|
||
ALPRF = BomData[i].fld005544,
|
||
ZDELETE = "X",
|
||
POSTP = BomData[i].fld005546,
|
||
ZYFMK = BomData[i].fld005547
|
||
};
|
||
itemDataList.Add(itemData);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
// 获取时间戳精确到毫秒,sap 要求每次调用生成不重复 guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
|
||
var fld005678 = item.fld005678 ?? 1;
|
||
|
||
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._SWPDM_1187_SAP___,
|
||
Bmeng = fld005678.ToString(),
|
||
Aennr = ecn,
|
||
Datuv = item.fld005680.ToString(),
|
||
ItemList = itemDataList
|
||
};
|
||
|
||
var apiOutput = await _sapService.SapBomApi(isreq);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
|
||
if (codeVal == "成功")
|
||
{
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005539 = DateTime.Now,
|
||
fld005533 = codeVal,
|
||
fld005534 = "N",
|
||
fld005535 = apiOutput.msg,
|
||
fld005686 = versionIndex.ToString()
|
||
})
|
||
.Where(it => it.idRecord == item.idRecord)
|
||
.ExecuteCommandAsync();
|
||
}
|
||
else
|
||
{
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005539 = DateTime.Now,
|
||
fld005533 = codeVal,
|
||
fld005534 = "N",
|
||
fld005535 = 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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 产品设计库-获取工艺路线
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "GetProcessRoute", Description = "获取工艺路线", Order = 1000), HttpPost]
|
||
[DisplayName("获取工艺路线")]
|
||
public async Task<SqlSugarPagedList<ProductDesignLibraryBomOutput>> GetProcessRoute(BomPageProductDesignLibraryInput input)
|
||
{
|
||
var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 137 && x.ConfigSystemName == "pBOM").FirstAsync();
|
||
var parent = await _obj137Rep.AsQueryable()
|
||
.Where(x =>
|
||
x.RecordGuid == input.ParentGuid
|
||
&& x.CheckedStatus == 0
|
||
&& x.deleted == false
|
||
&& x._system_objConfigurationName == "默认"
|
||
&& !x.SWPDMFileName.Contains("SLDDRW")
|
||
&& (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null)
|
||
&& x.fld005530 == "N"
|
||
&& x.fld005529 == "成功"
|
||
&& (x.fld005537 == "A" || x.fld005537 == "M")
|
||
)
|
||
.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<ProductDesignLibraryBomOutput>().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<BomPageProductDesignLibraryInput> input)
|
||
{
|
||
var ParentData = await _obj137Rep.AsQueryable()
|
||
.Where(x =>
|
||
x.RecordGuid == input[0].ParentGuid
|
||
&& x.deleted == false
|
||
&& x.VersionIndex == input[0].ParentVersion
|
||
&& x._system_objConfigurationName == "默认"
|
||
&& !x.SWPDMFileName.Contains("SLDDRW")
|
||
&& x.CheckedStatus == 0
|
||
&& (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null)
|
||
&& x.fld005530 == "N"
|
||
&& x.fld005529 == "成功"
|
||
&& (x.fld005537 == "A" || x.fld005537 == "M")
|
||
)
|
||
.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].fld005571.ToString(),
|
||
VGE01 = input[i].fld005572,
|
||
STEUS = input[i].fld005573,
|
||
BMSCH = input[i].fld005575.ToString()
|
||
|
||
};
|
||
itemDataList.Add(itemData);
|
||
}
|
||
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
|
||
var Datuv = ParentData.fld005680.ToString();
|
||
if (!string.IsNullOrEmpty(Datuv))
|
||
{
|
||
Datuv = ParentData.fld005680.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._SWPDM_1187_SAP___,
|
||
Datuv = Datuv,
|
||
Plnal = "",
|
||
|
||
ItemList = itemDataList
|
||
};
|
||
var apiOutput = await _sapService.SapProcessRouteApi(isreq);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005540 = DateTime.Now,
|
||
fld005536 = codeVal,
|
||
fld005537 = "N",
|
||
fld005538 = 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;
|
||
}
|
||
|
||
/// <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 == 137 && x.ConfigSystemName == "pBOM").FirstAsync();
|
||
|
||
//查询需要同步的产品
|
||
var materialData = await _obj137Rep.AsQueryable()
|
||
.Where(x =>
|
||
x.CheckedStatus == 0
|
||
&& x.deleted == false
|
||
&& x.IsLatestVersion == true
|
||
&& x._system_objConfigurationName == "默认"
|
||
&& !x.SWPDMFileName.Contains("SLDDRW")
|
||
&& (x._SWPDM_1202_SW_____ != "不展开" || x._SWPDM_1202_SW_____ == null)
|
||
&& x.fld005530 == "N"
|
||
&& x.fld005529 == "成功"
|
||
&& (x.fld005537 == "A" || x.fld005537 == "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.fld005571.ToString(),
|
||
VGE01 = processRouteItem.fld005572,
|
||
STEUS = processRouteItem.fld005573,
|
||
BMSCH = processRouteItem.fld005575.ToString()
|
||
|
||
};
|
||
itemDataList.Add(itemData);
|
||
}
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
|
||
var Datuv = item.fld005680.ToString();
|
||
|
||
if (!string.IsNullOrEmpty(Datuv))
|
||
{
|
||
Datuv = item.fld005680.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._SWPDM_1187_SAP___,
|
||
Datuv = Datuv,
|
||
Plnal = "",
|
||
|
||
ItemList = itemDataList
|
||
};
|
||
|
||
var apiOutput = await _sapService.SapProcessRouteApi(isreq);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
await _obj137Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj137
|
||
{
|
||
fld005540 = DateTime.Now,
|
||
fld005536 = codeVal,
|
||
fld005537 = "N",
|
||
fld005538 = 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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建排版软件
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
public async Task<string> CreateLayout(CreateLayoutInput input)
|
||
{
|
||
string output = "";
|
||
if (string.IsNullOrEmpty(input.ParentCode))
|
||
{
|
||
return "请输入父项编码";
|
||
}
|
||
var parentData = await _obj137Rep.AsQueryable().Where(x => x._System_objNBS == input.ParentCode && x.deleted == false).OrderByDescending(x => x.idRecord).FirstAsync();
|
||
if (parentData != null)
|
||
{
|
||
return "未查询到父项编码";
|
||
}
|
||
int lineNumber = 0;
|
||
foreach (var item in input.Item)
|
||
{
|
||
lineNumber ++;
|
||
string lineNumberStr = (lineNumber * 10).ToString("0000");
|
||
var outputData = output+"子项编码"+item.ChildCode;
|
||
if (string.IsNullOrEmpty(item.ChildCode)|| string.IsNullOrEmpty(item.Quantity))
|
||
{
|
||
outputData = outputData + "未输入必填项编码";
|
||
continue;
|
||
}
|
||
var childData = await _obj122Rep.AsQueryable().Where(x => x._System_objNBS == item.ChildCode && x.deleted == false).OrderByDescending(x => x.idRecord).FirstAsync();
|
||
|
||
if (childData != null)
|
||
{
|
||
output = outputData + "未查询到子项编码;";
|
||
continue;
|
||
}
|
||
|
||
var configurationData = await _configurationDataRep.AsQueryable().Where(x=> x.RecordImage!=null && x.ChildObjID ==112).FirstAsync();
|
||
|
||
var bomData = new ConfigurationData
|
||
{
|
||
ParentGuid = parentData.RecordGuid,
|
||
ChildGuid = childData.RecordGuid,
|
||
ChildObjID = 112,
|
||
ConfigId = 8,
|
||
childVersion = childData.VersionIndex,
|
||
ParentVersion = (int)parentData.VersionIndex,
|
||
isDeleted = false,
|
||
ChildConfigID = 0,
|
||
CreatedUserID = 2,
|
||
ModifiedUserID = 2,
|
||
CreatedDate = DateTime.Now,
|
||
ModifiedDate = DateTime.Now,
|
||
Quantity = item.Quantity.ToDouble(),
|
||
Description = parentData._System_ObjDescription,
|
||
EffectiveFrom = DateTime.Now,
|
||
EffectiveTo = DateTime.Now.AddYears(100),
|
||
Revision = "",
|
||
Marker = lineNumberStr,
|
||
Type = "正常",
|
||
OrderIndex = lineNumber,
|
||
PartNumber = childData._System_objNBS,
|
||
RecordImage = configurationData.RecordImage,
|
||
Folder = configurationData.Folder,
|
||
ParentObjectID = 137,
|
||
ChildSwFileType = 0,
|
||
ParentSwFileType = 1,
|
||
isSuppressed = false,
|
||
isAddedFromSW = true,
|
||
QtyManual = item.Quantity.ToDouble(),
|
||
SwConfiguration = "",
|
||
inContext = false,
|
||
PrimaryFile = "",
|
||
bKeepQuantityInSync = true,
|
||
BOMGuid = await _dataValidationService.GetGuid(),
|
||
IsPDMReference=false
|
||
};
|
||
var addChildBomBom = await _configurationDataRep.AsInsertable(bomData).InsertColumns(x => new { x.ParentGuid, x.ChildGuid, x.ChildObjID, x.ConfigId,x.childVersion, x.ParentVersion, x.isDeleted, x.ChildConfigID, x.CreatedUserID, x.ModifiedUserID, x.CreatedDate, x.ModifiedDate, x.Quantity, x.Description, x.EffectiveFrom, x.EffectiveTo, x.Revision, x.Marker, x.Type, x.OrderIndex, x.PartNumber, x.RecordImage, x.Folder, x.ParentObjectID, x.ChildSwFileType, x.ParentSwFileType, x.isSuppressed, x.isAddedFromSW, x.QtyManual, x.SwConfiguration, x.inContext, x.PrimaryFile, x.bKeepQuantityInSync, x.BOMGuid, x.IsPDMReference }).ExecuteReturnEntityAsync();
|
||
|
||
//var message = AddItemsInBomOutput.Message;
|
||
//output = outputData + message+";";
|
||
}
|
||
return output;
|
||
}
|
||
}
|