|
@ -492,200 +492,201 @@ SELECT top 1 v.Id |
|
|
[DisableRequestSizeLimit] |
|
|
[DisableRequestSizeLimit] |
|
|
public virtual async Task<ObjectResultDto<string>> ImportErpAssemblyAsync([FromForm] IFormFileCollection files) |
|
|
public virtual async Task<ObjectResultDto<string>> ImportErpAssemblyAsync([FromForm] IFormFileCollection files) |
|
|
{ |
|
|
{ |
|
|
_logger.LogDebug(_errorMessagePrefix + "ImportErpAssemblyAsync 进入"); |
|
|
throw new NotImplementedException(); |
|
|
ObjectResultDto<string> ret = new ObjectResultDto<string>(); |
|
|
//_logger.LogDebug(_errorMessagePrefix + "ImportErpAssemblyAsync 进入");
|
|
|
try |
|
|
//ObjectResultDto<string> ret = new ObjectResultDto<string>();
|
|
|
{ |
|
|
//try
|
|
|
List<MaterialExt> material3Lst = await _materialExtRepository.Where(itm => itm.MaterialType == "3").ToListAsync(); |
|
|
//{
|
|
|
List<PartCfg> partCfgLst = await _partCfgRepository.GetListAsync(); //取结算件信息列表
|
|
|
// List<MaterialExt> material3Lst = await _materialExtRepository.Where(itm => itm.MaterialType == "3").ToListAsync();
|
|
|
List<ErpAssemblyInfo2Part> ass2partLst = new List<ErpAssemblyInfo2Part>(); |
|
|
// List<PartCfg> partCfgLst = await _partCfgRepository.GetListAsync(); //取结算件信息列表
|
|
|
using (var memoryStream = new MemoryStream()) |
|
|
// List<ErpAssemblyInfo2Part> ass2partLst = new List<ErpAssemblyInfo2Part>();
|
|
|
{ |
|
|
// using (var memoryStream = new MemoryStream())
|
|
|
//保存到内存流
|
|
|
// {
|
|
|
IFormFile file = files[0]; |
|
|
// //保存到内存流
|
|
|
await file.CopyToAsync(memoryStream); |
|
|
// IFormFile file = files[0];
|
|
|
memoryStream.Seek(0, SeekOrigin.Begin); |
|
|
// await file.CopyToAsync(memoryStream);
|
|
|
StreamReader sr = new StreamReader(memoryStream, Encoding.Default); |
|
|
// memoryStream.Seek(0, SeekOrigin.Begin);
|
|
|
string strLine = ""; //记录每次读取的一行记录
|
|
|
// StreamReader sr = new StreamReader(memoryStream, Encoding.Default);
|
|
|
string[] aryLine = null; //记录每行记录中的各字段内容
|
|
|
// string strLine = ""; //记录每次读取的一行记录
|
|
|
int columnCount = 0; //标示列数
|
|
|
// string[] aryLine = null; //记录每行记录中的各字段内容
|
|
|
//遍历文件行
|
|
|
// int columnCount = 0; //标示列数
|
|
|
while ((strLine = sr.ReadLine()) != null) |
|
|
// //遍历文件行
|
|
|
{ |
|
|
// while ((strLine = sr.ReadLine()) != null)
|
|
|
if (strLine.IsNullOrEmpty()) |
|
|
// {
|
|
|
{ |
|
|
// if (strLine.IsNullOrEmpty())
|
|
|
continue; |
|
|
// {
|
|
|
} |
|
|
// continue;
|
|
|
if (strLine.Contains('�')) |
|
|
// }
|
|
|
{ |
|
|
// if (strLine.Contains('�'))
|
|
|
ret.Message = "导入文件的格式不对,请将其转换成utf-8格式后再导入"; |
|
|
// {
|
|
|
ret.Status = false; |
|
|
// ret.Message = "导入文件的格式不对,请将其转换成utf-8格式后再导入";
|
|
|
return ret; |
|
|
// ret.Status = false;
|
|
|
} |
|
|
// return ret;
|
|
|
|
|
|
// }
|
|
|
aryLine = strLine.Split(" "); |
|
|
|
|
|
columnCount = aryLine.Count(); |
|
|
// aryLine = strLine.Split(" ");
|
|
|
if (columnCount == 0) |
|
|
// columnCount = aryLine.Count();
|
|
|
{ |
|
|
// if (columnCount == 0)
|
|
|
continue; |
|
|
// {
|
|
|
} |
|
|
// continue;
|
|
|
if (columnCount < 14) |
|
|
// }
|
|
|
{ |
|
|
// if (columnCount < 14)
|
|
|
ret.Message = "当前行的列数小于14,行号:" + aryLine[0]; |
|
|
// {
|
|
|
ret.Status = false; |
|
|
// ret.Message = "当前行的列数小于14,行号:" + aryLine[0];
|
|
|
return ret; |
|
|
// ret.Status = false;
|
|
|
} |
|
|
// return ret;
|
|
|
ErpAssemblyInfo2Part ass2partObj = new ErpAssemblyInfo2Part(); |
|
|
// }
|
|
|
ass2partObj.ErpAssemblyCode = aryLine[1].Trim(); |
|
|
// ErpAssemblyInfo2Part ass2partObj = new ErpAssemblyInfo2Part();
|
|
|
ass2partObj.ErpAssemblyName = aryLine[2].Trim(); |
|
|
// ass2partObj.ErpAssemblyCode = aryLine[1].Trim();
|
|
|
//从物料表取车型,操作员导入BOM时已经在SAP中录入物料了
|
|
|
// ass2partObj.ErpAssemblyName = aryLine[2].Trim();
|
|
|
MaterialExt materialObj = material3Lst.FirstOrDefault(itm => itm.MaterialNum == ass2partObj.ErpAssemblyCode); |
|
|
// //从物料表取车型,操作员导入BOM时已经在SAP中录入物料了
|
|
|
if (materialObj != null) |
|
|
// MaterialExt materialObj = material3Lst.FirstOrDefault(itm => itm.MaterialNum == ass2partObj.ErpAssemblyCode);
|
|
|
{ |
|
|
// if (materialObj != null)
|
|
|
ass2partObj.VehicleModel = materialObj.VehicleModel; |
|
|
// {
|
|
|
ass2partObj.MaterialMemo = materialObj.MaterialMemo?.Replace(" ",""); //SAP分组
|
|
|
// ass2partObj.VehicleModel = materialObj.VehicleModel;
|
|
|
} |
|
|
// ass2partObj.MaterialMemo = materialObj.MaterialMemo?.Replace(" ",""); //SAP分组
|
|
|
|
|
|
// }
|
|
|
//将模板中的SAP物料号转换成客户零件号
|
|
|
|
|
|
string sapMaterialNum = aryLine[11].Trim().Replace(" "," "); //取派格SAP物料号
|
|
|
// //将模板中的SAP物料号转换成客户零件号
|
|
|
var partCfgObj = partCfgLst.FirstOrDefault(itm => itm.RelationKey == sapMaterialNum); |
|
|
// string sapMaterialNum = aryLine[11].Trim().Replace(" "," "); //取派格SAP物料号
|
|
|
if (partCfgObj != null) |
|
|
// var partCfgObj = partCfgLst.FirstOrDefault(itm => itm.RelationKey == sapMaterialNum);
|
|
|
{ |
|
|
// if (partCfgObj != null)
|
|
|
ass2partObj.PartCode = partCfgObj.PartCode; |
|
|
// {
|
|
|
ass2partObj.PartCode2 = sapMaterialNum; |
|
|
// ass2partObj.PartCode = partCfgObj.PartCode;
|
|
|
} |
|
|
// ass2partObj.PartCode2 = sapMaterialNum;
|
|
|
else |
|
|
// }
|
|
|
{ |
|
|
// else
|
|
|
ret.Message = $"当前行的SAP物料号在零件信息表没有匹配的客户零件号,行号:{aryLine[0]},SAP物料号:{sapMaterialNum}"; |
|
|
// {
|
|
|
ret.Status = false; |
|
|
// ret.Message = $"当前行的SAP物料号在零件信息表没有匹配的客户零件号,行号:{aryLine[0]},SAP物料号:{sapMaterialNum}";
|
|
|
return ret; |
|
|
// ret.Status = false;
|
|
|
} |
|
|
// return ret;
|
|
|
ass2partObj.PartNum = aryLine[13].TryToDouble(); |
|
|
// }
|
|
|
|
|
|
// ass2partObj.PartNum = aryLine[13].TryToDouble();
|
|
|
//数据校验
|
|
|
|
|
|
if (ass2partObj.ErpAssemblyCode == null || ass2partObj.ErpAssemblyCode.Trim() == "") |
|
|
// //数据校验
|
|
|
{ |
|
|
// if (ass2partObj.ErpAssemblyCode == null || ass2partObj.ErpAssemblyCode.Trim() == "")
|
|
|
ret.Message = "当前行的ERP总成代码列是空,行号:" + aryLine[0]; |
|
|
// {
|
|
|
ret.Status = false; |
|
|
// ret.Message = "当前行的ERP总成代码列是空,行号:" + aryLine[0];
|
|
|
return ret; |
|
|
// ret.Status = false;
|
|
|
} |
|
|
// return ret;
|
|
|
if (ass2partObj.PartCode == null || ass2partObj.PartCode.Trim() == "") |
|
|
// }
|
|
|
{ |
|
|
// if (ass2partObj.PartCode == null || ass2partObj.PartCode.Trim() == "")
|
|
|
if (partCfgObj.IsDisable == true) //不参与解析的也进入BOM, 报文解析时排除
|
|
|
// {
|
|
|
{ |
|
|
// if (partCfgObj.IsDisable == true) //不参与解析的也进入BOM, 报文解析时排除
|
|
|
} |
|
|
// {
|
|
|
else |
|
|
// }
|
|
|
{ |
|
|
// else
|
|
|
ret.Message = "当前行的零件代码列是空,行号:" + aryLine[0] + "对应SAP零件号:" + sapMaterialNum; |
|
|
// {
|
|
|
ret.Status = false; |
|
|
// ret.Message = "当前行的零件代码列是空,行号:" + aryLine[0] + "对应SAP零件号:" + sapMaterialNum;
|
|
|
return ret; |
|
|
// ret.Status = false;
|
|
|
} |
|
|
// return ret;
|
|
|
} |
|
|
// }
|
|
|
if (ass2partObj.PartNum == null || ass2partObj.PartNum == 0) |
|
|
// }
|
|
|
{ |
|
|
// if (ass2partObj.PartNum == null || ass2partObj.PartNum == 0)
|
|
|
ret.Message = "当前行的零件数量列是空或零,行号:" + aryLine[0]; |
|
|
// {
|
|
|
ret.Status = false; |
|
|
// ret.Message = "当前行的零件数量列是空或零,行号:" + aryLine[0];
|
|
|
return ret; |
|
|
// ret.Status = false;
|
|
|
} |
|
|
// return ret;
|
|
|
ass2partLst.Add(ass2partObj); |
|
|
// }
|
|
|
} |
|
|
// ass2partLst.Add(ass2partObj);
|
|
|
} |
|
|
// }
|
|
|
//取Erp总成
|
|
|
// }
|
|
|
List<AssemblyCfgErp> erpDataLst = await _assemblyCfgErpRepository.GetListAsync(itm => itm.NewVersionId == null, true); |
|
|
// //取Erp总成
|
|
|
|
|
|
// List<AssemblyCfgErp> erpDataLst = await _assemblyCfgErpRepository.GetListAsync(itm => itm.NewVersionId == null, true);
|
|
|
//总成编码去重
|
|
|
|
|
|
List<string> erpAssemblyCodeLst = ass2partLst |
|
|
// //总成编码去重
|
|
|
.Where(itm => string.IsNullOrEmpty(itm.ErpAssemblyCode) == false) |
|
|
// List<string> erpAssemblyCodeLst = ass2partLst
|
|
|
.Select(itm => itm.ErpAssemblyCode) |
|
|
// .Where(itm => string.IsNullOrEmpty(itm.ErpAssemblyCode) == false)
|
|
|
.Distinct() |
|
|
// .Select(itm => itm.ErpAssemblyCode)
|
|
|
.ToList(); |
|
|
// .Distinct()
|
|
|
//校验导入
|
|
|
// .ToList();
|
|
|
string repeatMsg = ""; |
|
|
// //校验导入
|
|
|
foreach (var erpAssemblyCode in erpAssemblyCodeLst) |
|
|
// string repeatMsg = "";
|
|
|
{ |
|
|
// foreach (var erpAssemblyCode in erpAssemblyCodeLst)
|
|
|
var partLst = ass2partLst.Where(itm => itm.ErpAssemblyCode == erpAssemblyCode).ToList(); |
|
|
// {
|
|
|
if (partLst.Count() > 0) |
|
|
// var partLst = ass2partLst.Where(itm => itm.ErpAssemblyCode == erpAssemblyCode).ToList();
|
|
|
{ |
|
|
// if (partLst.Count() > 0)
|
|
|
string erpAssCode = partLst[0].ErpAssemblyCode; |
|
|
// {
|
|
|
string erpAssName = partLst[0].ErpAssemblyName; |
|
|
// string erpAssCode = partLst[0].ErpAssemblyCode;
|
|
|
string vehicleModel = partLst[0].VehicleModel; |
|
|
// string erpAssName = partLst[0].ErpAssemblyName;
|
|
|
AssemblyCfgErp erpObj = new AssemblyCfgErp( |
|
|
// string vehicleModel = partLst[0].VehicleModel;
|
|
|
GuidGenerator.Create(), |
|
|
// AssemblyCfgErp erpObj = new AssemblyCfgErp(
|
|
|
erpAssCode, |
|
|
// GuidGenerator.Create(),
|
|
|
erpAssName, |
|
|
// erpAssCode,
|
|
|
0, |
|
|
// erpAssName,
|
|
|
vehicleModel |
|
|
// 0,
|
|
|
); |
|
|
// vehicleModel
|
|
|
foreach (var partObj in partLst) |
|
|
// );
|
|
|
{ |
|
|
// foreach (var partObj in partLst)
|
|
|
erpObj.AddChildObject( |
|
|
// {
|
|
|
GuidGenerator.Create(), |
|
|
// erpObj.AddChildObject(
|
|
|
partObj.PartCode, |
|
|
// GuidGenerator.Create(),
|
|
|
partObj.PartNum, |
|
|
// partObj.PartCode,
|
|
|
partObj.PartCode2 |
|
|
// partObj.PartNum,
|
|
|
); |
|
|
// partObj.PartCode2
|
|
|
} |
|
|
// );
|
|
|
List<string> repeatLst = _assemblyDomainService.ReturnRepeatErpAssembly(erpObj, erpDataLst, material3Lst); //返回重复总成
|
|
|
// }
|
|
|
foreach (var repeatStr in repeatLst) |
|
|
// List<string> repeatLst = _assemblyDomainService.ReturnRepeatErpAssembly(erpObj, erpDataLst, material3Lst); //返回重复总成
|
|
|
{ |
|
|
// foreach (var repeatStr in repeatLst)
|
|
|
repeatMsg += repeatStr; |
|
|
// {
|
|
|
} |
|
|
// repeatMsg += repeatStr;
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
// }
|
|
|
if (repeatMsg.Length > 0) |
|
|
// }
|
|
|
{ |
|
|
// if (repeatMsg.Length > 0)
|
|
|
ret.Status = false; |
|
|
// {
|
|
|
ret.Message = repeatMsg; |
|
|
// ret.Status = false;
|
|
|
return ret; |
|
|
// ret.Message = repeatMsg;
|
|
|
} |
|
|
// return ret;
|
|
|
|
|
|
// }
|
|
|
//遍历总成,插入数据库
|
|
|
|
|
|
int maxVer = _assemblyCfgErpRepository.Any() ? _assemblyCfgErpRepository.Max(itm => itm.ErpAssemblyVersion) : 0; |
|
|
// //遍历总成,插入数据库
|
|
|
foreach (var erpAssemblyCode in erpAssemblyCodeLst) |
|
|
// int maxVer = _assemblyCfgErpRepository.Any() ? _assemblyCfgErpRepository.Max(itm => itm.ErpAssemblyVersion) : 0;
|
|
|
{ |
|
|
// foreach (var erpAssemblyCode in erpAssemblyCodeLst)
|
|
|
var partLst = ass2partLst.Where(itm => itm.ErpAssemblyCode == erpAssemblyCode).ToList(); |
|
|
// {
|
|
|
if (partLst.Count() > 0) |
|
|
// var partLst = ass2partLst.Where(itm => itm.ErpAssemblyCode == erpAssemblyCode).ToList();
|
|
|
{ |
|
|
// if (partLst.Count() > 0)
|
|
|
string erpAssCode = partLst[0].ErpAssemblyCode; |
|
|
// {
|
|
|
string erpAssName = partLst[0].ErpAssemblyName; |
|
|
// string erpAssCode = partLst[0].ErpAssemblyCode;
|
|
|
string vehicleModel = partLst[0].VehicleModel; |
|
|
// string erpAssName = partLst[0].ErpAssemblyName;
|
|
|
AssemblyCfgErp erpObj = new AssemblyCfgErp( |
|
|
// string vehicleModel = partLst[0].VehicleModel;
|
|
|
GuidGenerator.Create(), |
|
|
// AssemblyCfgErp erpObj = new AssemblyCfgErp(
|
|
|
erpAssCode, |
|
|
// GuidGenerator.Create(),
|
|
|
erpAssName, |
|
|
// erpAssCode,
|
|
|
++maxVer, |
|
|
// erpAssName,
|
|
|
vehicleModel |
|
|
// ++maxVer,
|
|
|
); |
|
|
// vehicleModel
|
|
|
foreach (var partObj in partLst) |
|
|
// );
|
|
|
{ |
|
|
// foreach (var partObj in partLst)
|
|
|
erpObj.AddChildObject( |
|
|
// {
|
|
|
GuidGenerator.Create(), |
|
|
// erpObj.AddChildObject(
|
|
|
partObj.PartCode, |
|
|
// GuidGenerator.Create(),
|
|
|
partObj.PartNum, |
|
|
// partObj.PartCode,
|
|
|
partObj.PartCode2 |
|
|
// partObj.PartNum,
|
|
|
); |
|
|
// partObj.PartCode2
|
|
|
} |
|
|
// );
|
|
|
AssemblyCfgErp obj2 = await _assemblyCfgErpRepository.InsertAsync(erpObj); |
|
|
// }
|
|
|
await _assemblyDomainService.RemoveRepeatErpAssembly(obj2, erpDataLst); //删除重复总成
|
|
|
// AssemblyCfgErp obj2 = await _assemblyCfgErpRepository.InsertAsync(erpObj);
|
|
|
} |
|
|
// await _assemblyDomainService.RemoveRepeatErpAssembly(obj2, erpDataLst); //删除重复总成
|
|
|
} |
|
|
// }
|
|
|
|
|
|
// }
|
|
|
_globalSettingsDomainService.SetSetting(GlobalSettingsNameEnum.刷新报文解析缓存, true); |
|
|
|
|
|
ret.Status = true; |
|
|
// _globalSettingsDomainService.SetSetting(GlobalSettingsNameEnum.刷新报文解析缓存, true);
|
|
|
return ret; |
|
|
// ret.Status = true;
|
|
|
} |
|
|
// return ret;
|
|
|
catch (Exception ex) |
|
|
//}
|
|
|
{ |
|
|
//catch (Exception ex)
|
|
|
ret.Status = false; |
|
|
//{
|
|
|
ret.Message = _errorMessagePrefix + "ImportErpAssemblyAsync 执行出错:" + ex.Message; |
|
|
// ret.Status = false;
|
|
|
_logger.LogError(ret.Message); |
|
|
// ret.Message = _errorMessagePrefix + "ImportErpAssemblyAsync 执行出错:" + ex.Message;
|
|
|
return ret; |
|
|
// _logger.LogError(ret.Message);
|
|
|
} |
|
|
// return ret;
|
|
|
|
|
|
//}
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 总成组导入
|
|
|
/// 总成组导入【红旗版本】
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="files"></param>
|
|
|
/// <param name="files"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
@ -830,12 +831,12 @@ SELECT top 1 v.Id |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var partdists = srcLst.Select(r => r.MaterialNum).Distinct(); |
|
|
var partdists = srcLst.Select(r => r.MaterialNum).Distinct(); |
|
|
foreach (var material in partdists) |
|
|
foreach (var sapMaterial in partdists) |
|
|
{ |
|
|
{ |
|
|
var material3 = material3Lst.FirstOrDefault(r => r.MaterialNum == material); |
|
|
var material3 = material3Lst.FirstOrDefault(r => r.MaterialNum == sapMaterial); |
|
|
if (material3 == null) |
|
|
if (material3 == null) |
|
|
{ |
|
|
{ |
|
|
error += $"零件编号【{material}】系统中不存在,请检查后再导入\r\n"; |
|
|
error += $"零件编号【{sapMaterial}】系统中不存在,请检查后再导入\r\n"; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -856,27 +857,27 @@ SELECT top 1 v.Id |
|
|
string arrStr = string.Join(',', arr); |
|
|
string arrStr = string.Join(',', arr); |
|
|
|
|
|
|
|
|
var qry = from item in srcLst |
|
|
var qry = from item in srcLst |
|
|
group item by item.SpecExplain into g |
|
|
group item by new { item.SpecExplain, item.ColorExplain } into g |
|
|
select new |
|
|
select new |
|
|
{ |
|
|
{ |
|
|
SpecExplain = g.Key, |
|
|
SpecExplain = g.Key.SpecExplain, |
|
|
ColorExplain = g.ElementAt(0).ColorExplain, |
|
|
ColorExplain = g.Key.ColorExplain, |
|
|
Details = g.Select(itm => itm.MaterialNum).ToList() |
|
|
Details = g.Select(itm => itm.MaterialNum).ToList() |
|
|
}; |
|
|
}; |
|
|
foreach (var item in qry) |
|
|
foreach (var item in qry) |
|
|
{ |
|
|
{ |
|
|
if (item.Details.Count != 4) |
|
|
if (item.Details.Count != 4) |
|
|
{ |
|
|
{ |
|
|
strBuild.AppendLine($"规格说明{item.SpecExplain}包含的物料号不是4个"); |
|
|
strBuild.AppendLine($"规格说明{item.SpecExplain}、颜色说明{item.ColorExplain}包含的物料号不是4个"); |
|
|
} |
|
|
} |
|
|
//遍历物料号
|
|
|
//遍历物料号
|
|
|
List<string> strLst = new List<string>(); |
|
|
List<string> strLst = new List<string>(); |
|
|
foreach (string materialNum in item.Details) |
|
|
foreach (string sapMaterialNum in item.Details) |
|
|
{ |
|
|
{ |
|
|
var materialObj = material3Lst.FirstOrDefault(itm => itm.RelationKey == materialNum); |
|
|
var materialObj = material3Lst.FirstOrDefault(itm => itm.MaterialNum == sapMaterialNum); |
|
|
if (materialObj == null) |
|
|
if (materialObj == null) |
|
|
{ |
|
|
{ |
|
|
strBuild.AppendLine($"规格说明{item.SpecExplain}:物料号{materialNum}在物料表不存在!"); |
|
|
strBuild.AppendLine($"规格说明{item.SpecExplain}:物料号{sapMaterialNum}在物料表不存在!"); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
@ -886,7 +887,7 @@ SELECT top 1 v.Id |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
strBuild.AppendLine($"规格说明{item.SpecExplain}:物料号{materialNum}的MaterialType2不是【{arrStr}】其中之一!"); |
|
|
strBuild.AppendLine($"规格说明{item.SpecExplain}:物料号{sapMaterialNum}的MaterialType2不是【{arrStr}】其中之一!"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|