|
|
@ -128,8 +128,8 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA> |
|
|
|
Site = bbacSaImportRequestDto.Site; |
|
|
|
Version = bbacSaImportRequestDto.Version; |
|
|
|
#region 导入数据转换、数据校验
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
var importDtos = await _exportImporter.UploadExcelImport<BBAC_SA_DETAIL_IMPORT_DTO>(bbacSaImportRequestDto.Files, _excelImportService).ConfigureAwait(false); |
|
|
|
var exportImporter = new ExportImporter(); |
|
|
|
var importDtos = await exportImporter.UploadExcelImport<BBAC_SA_DETAIL_IMPORT_DTO>(bbacSaImportRequestDto.Files, _excelImportService).ConfigureAwait(false); |
|
|
|
|
|
|
|
importDtos.ForEach(importDto => |
|
|
|
{ |
|
|
@ -146,6 +146,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA> |
|
|
|
{ |
|
|
|
importBBACSaDetail.Version = Version; |
|
|
|
importBBACSaDetail.Site = Site; |
|
|
|
importBBACSaDetail.BusinessType = importBBACSaDetail.PN.Contains("R0") ? EnumBusinessType.MaiDanJianBBAC : EnumBusinessType.JisBBAC; |
|
|
|
}); |
|
|
|
|
|
|
|
//数据校验
|
|
|
@ -165,23 +166,23 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA> |
|
|
|
if (!checkList.Any()) |
|
|
|
{ |
|
|
|
//验证客户对应厂内零件号是否存在
|
|
|
|
//导入的零件号集合
|
|
|
|
var importPubSaLUs = importBBACSaDetails.Select(t => t.LU).Distinct(); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); |
|
|
|
|
|
|
|
//不存在的客户零件号(差集)
|
|
|
|
var noExistSettleMaterialCodes = importPubSaLUs.Except(materialRelationshipEntitySettleMaterialCodes); |
|
|
|
noExistSettleMaterialCodes.ForEach(t => |
|
|
|
|
|
|
|
var jisSaDetails = importBBACSaDetails.FindAll(t => t.BusinessType == EnumBusinessType.JisBBAC); |
|
|
|
var maiDanSaDetails = importBBACSaDetails.FindAll(t => t.BusinessType == EnumBusinessType.MaiDanJianHBPO); |
|
|
|
if (jisSaDetails.Any()) |
|
|
|
{ |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"客户零件号【{t}】对应厂内零件号系统中不存在", string.Empty)); |
|
|
|
}); |
|
|
|
checkList.AddRange(await CheckAsync(jisSaDetails, EnumBusinessType.JisBBAC).ConfigureAwait(false)); |
|
|
|
} |
|
|
|
if (maiDanSaDetails.Any()) |
|
|
|
{ |
|
|
|
checkList.AddRange(await CheckAsync(maiDanSaDetails, EnumBusinessType.MaiDanJianBBAC).ConfigureAwait(false)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message= "错误提示文件已下载,请打开文件查看", fileName = fileName }); |
|
|
|
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = fileName }); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
@ -192,6 +193,32 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA> |
|
|
|
|
|
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 数据校验
|
|
|
|
/// </summary>
|
|
|
|
private async Task<List<ErrorExportDto>> CheckAsync(List<BBAC_SA_DETAIL> saDetails, EnumBusinessType businessType) |
|
|
|
{ |
|
|
|
#region 数据校验
|
|
|
|
//数据校验
|
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
|
|
|
|
//验证客户对应厂内零件号是否存在
|
|
|
|
//导入的零件号集合
|
|
|
|
var saLus = saDetails.Select(t => t.LU).Distinct(); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => t.BusinessType == businessType && saLus.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
var settleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); |
|
|
|
|
|
|
|
//不存在的客户零件号(差集)
|
|
|
|
var noExistSettleMaterialCodes = saLus.Except(settleMaterialCodes); |
|
|
|
noExistSettleMaterialCodes.ForEach(t => |
|
|
|
{ |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"客户零件号【{t}】对应厂内零件号系统中不存在", string.Empty)); |
|
|
|
}); |
|
|
|
|
|
|
|
return checkList; |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region CURD
|
|
|
@ -400,7 +427,6 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA> |
|
|
|
bbacSaDetail.BillNum = bbacSaBillNum; |
|
|
|
bbacSaDetail.KeyCode = bbacSaDetail.PN + bbacSaDetail.LU; |
|
|
|
bbacSaDetail.CustomerPartCodeNoSpace = bbacSaDetail.LU.Replace(" ", ""); |
|
|
|
bbacSaDetail.BusinessType = bbacSaDetail.PN.Contains("R0") ? EnumBusinessType.MaiDanJianBBAC : _businessType; |
|
|
|
}); |
|
|
|
|
|
|
|
//导入的零件号集合
|
|
|
@ -408,7 +434,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA> |
|
|
|
//销售价格
|
|
|
|
|
|
|
|
var priceListEntitys = GetPriceListEntitys(importPubSaLUs); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => new List<EnumBusinessType> { EnumBusinessType.JisBBAC, EnumBusinessType.MaiDanJianBBAC }.Contains(t.BusinessType) && importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
bbacSaDetails.ForEach(bbacSaDetail => |
|
|
|
{ |
|
|
|
//根据物料号、结算日期获取价格
|
|
|
@ -420,7 +446,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA> |
|
|
|
.FirstOrDefault(); |
|
|
|
bbacSaDetail.Price = priceListEntity?.Price ?? 0; |
|
|
|
|
|
|
|
bbacSaDetail.PartCode = materialRelationshipEntitys.FirstOrDefault(t => t.SettleMaterialCode == bbacSaDetail.LU)?.ErpMaterialCode; |
|
|
|
bbacSaDetail.PartCode = materialRelationshipEntitys.FirstOrDefault(t => t.BusinessType == bbacSaDetail.BusinessType && t.SettleMaterialCode == bbacSaDetail.LU)?.ErpMaterialCode; |
|
|
|
}); |
|
|
|
#endregion
|
|
|
|
|
|
|
|