diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs index ac312e3c..16dca66d 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs @@ -128,8 +128,8 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase Site = bbacSaImportRequestDto.Site; Version = bbacSaImportRequestDto.Version; #region 导入数据转换、数据校验 - ExportImporter _exportImporter = new ExportImporter(); - var importDtos = await _exportImporter.UploadExcelImport(bbacSaImportRequestDto.Files, _excelImportService).ConfigureAwait(false); + var exportImporter = new ExportImporter(); + var importDtos = await exportImporter.UploadExcelImport(bbacSaImportRequestDto.Files, _excelImportService).ConfigureAwait(false); importDtos.ForEach(importDto => { @@ -146,6 +146,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase { 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 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 return new JsonResult(new { Code = 200, Message = "导入成功" }); } + + /// + /// 数据校验 + /// + private async Task> CheckAsync(List saDetails, EnumBusinessType businessType) + { + #region 数据校验 + //数据校验 + var checkList = new List(); + + //验证客户对应厂内零件号是否存在 + //导入的零件号集合 + 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 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 //销售价格 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.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 .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 diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs index f2120af9..a5b5b01f 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs @@ -371,7 +371,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase var priceListEntitys = _priceListRepository.Where(t => t.IsCancel == false) .Where(t => t.ClientCode == "104T") .Where(t => importPubSaLUs.Contains(t.LU)).ToList(); - var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); + var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => t.BusinessType == BusinessType && importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); hbpoSaDetails.ForEach(hbpoSaDetail => { //根据物料号、结算日期获取价格 @@ -485,7 +485,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase //验证客户对应厂内零件号是否存在 //导入的零件号集合 var importSaLUs = hbpoSaDetails.Select(t => t.LU).Distinct(); - var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); + var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => t.BusinessType == BusinessType && importSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); //不存在的客户零件号(差集) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs index 3e9b6355..99c8a179 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs @@ -36,6 +36,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ; [Route("api/settleaccount/[controller]/[action]")] public class PUB_SA_SERVICE : SettleAccountApplicationBase { + /// + /// DbContext + /// + public SettleAccountDbContext _settleAccountDbContext; /// /// PUB结算仓储 /// @@ -76,7 +80,8 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase /// /// 构造 /// - public PUB_SA_SERVICE(INormalEfCoreRepository repository, + public PUB_SA_SERVICE(SettleAccountDbContext settleAccountDbContext, + INormalEfCoreRepository repository, INormalEfCoreRepository pubSaDetailRepository, INormalEfCoreRepository pubCanSaRepository, INormalEfCoreRepository pubCanSaDetailRepository, @@ -91,6 +96,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase ICommonManager commonManager ) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) { + _settleAccountDbContext = settleAccountDbContext; _repository = repository; _pubSaDetailRepository = pubSaDetailRepository; _pubCanSaRepository = pubCanSaRepository; @@ -105,7 +111,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase /// /// 期间 /// - private int _version; + private int version; /// /// 业务类别 /// @@ -123,7 +129,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase public async Task ImportAsync([FromForm] PUB_SAImportRequestDto pubSaImportRequestDto) { IActionResult result = new JsonResult(new { Code = 400 }); - _version = pubSaImportRequestDto.Version; + version = pubSaImportRequestDto.Version; businessType = pubSaImportRequestDto.BusinessType; site = pubSaImportRequestDto.Site; switch (pubSaImportRequestDto.BusinessType) @@ -376,7 +382,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase //验证客户对应厂内零件号是否存在 //导入的零件号集合 var importPubSaLUs = pubSaDetails.Select(t => t.LU).Distinct(); - var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); + var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => t.BusinessType == businessType && importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); //不存在的客户零件号(差集) @@ -429,9 +435,6 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase /// private async Task InsertSaDataAsync(List pubSaDetails, EnumBusinessType businessType) { - //客户零件关系 - var materialRelationships = new List(); - #region 处理结算数据 for (var i = 0; i < pubSaDetails.Count; i++) { @@ -439,7 +442,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase pubSaDetail.SetId(GuidGenerator.Create()); pubSaDetail.CustomerPartCodeNoSpace = pubSaDetail.LU.Replace(" ", ""); pubSaDetail.KeyCode = pubSaDetail.PN + pubSaDetail.LU; - pubSaDetail.Version = _version; + pubSaDetail.Version = version; pubSaDetail.BusinessType = businessType; pubSaDetail.IndexNum = i; } @@ -494,9 +497,8 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase //导入的零件号集合 var importPubSaLUs = pubSaDetails.Select(t => t.LU).Distinct(); - var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); + var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => t.BusinessType == businessType && importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); - var seAllMaterialRelationships = materialRelationshipEntitys.Union(materialRelationships); pubSaDetails.ForEach(pubSaDetail => { pubSaDetail.PartCode = materialRelationshipEntitys.FirstOrDefault(t => t.SettleMaterialCode == pubSaDetail.LU)?.ErpMaterialCode; @@ -505,10 +507,6 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase #region 添加入库 await SeDataEntryAsync(pubSaDetails).ConfigureAwait(false); - if (materialRelationships.Count > 0) - { - await _materialRelationshipRepository.InsertManyAsync(materialRelationships).ConfigureAwait(false); - } #endregion return new JsonResult(new { Code = 200, Message = "导入成功" }); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/MaterialRelationships/MaterialRelationshipAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/MaterialRelationships/MaterialRelationshipAppService.cs index ade23b7d..2041292f 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/MaterialRelationships/MaterialRelationshipAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/MaterialRelationships/MaterialRelationshipAppService.cs @@ -63,13 +63,13 @@ public class MaterialRelationshipAppService : SettleAccountApplicationBase 0) { var query = from arc in _ls - group arc by new { arc.ErpMaterialCode } + group arc by new { arc.SettleMaterialCode } into g where g.Count() > 1 select g; foreach (var itm in query) { - checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("厂内物料号{0}有重复", itm.Key.ErpMaterialCode), string.Empty)); + checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("客户物料号{0}有重复", itm.Key.SettleMaterialCode), string.Empty)); } } if (checkList.Count > 0)