From 8b873cdde1a5ffa191c329986155c1e5b2656f32 Mon Sep 17 00:00:00 2001 From: mahao Date: Mon, 17 Jul 2023 16:55:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E9=9B=B6=E4=BB=B6=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SettleAccountHttpApiHostModule.cs | 2 +- .../Entities/BQ/Dtos/PUB_SA_DTO.cs | 7 ++ ...SettleAccount.Application.Contracts.csproj | 1 + .../Entities/BQ/PUB_SA_SERVICE.cs | 105 ++++++++++++++---- .../MaterialRelationshipAppService.cs | 5 +- 5 files changed, 93 insertions(+), 27 deletions(-) diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/SettleAccountHttpApiHostModule.cs b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/SettleAccountHttpApiHostModule.cs index 4d667a6f..0f2868cc 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/SettleAccountHttpApiHostModule.cs +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/SettleAccountHttpApiHostModule.cs @@ -336,7 +336,7 @@ namespace Win.Sfs.SettleAccount xmlapppath = Path.Combine(AppContext.BaseDirectory, "SettleAccount.Application.Contracts.xml"); if (File.Exists(xmlapppath)) { - options.IncludeXmlComments(xmlapppath); + options.IncludeXmlComments(xmlapppath, true); } options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs index c5e80aca..e6ef907e 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs @@ -52,7 +52,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos /// /// 结算日期 /// + [Display(Name = "结算日期")] [ImporterHeader(Name = "Pstng Date")] + [Required(ErrorMessage = "{0}不能为空")] public DateTime SettleDate { set; get; } /// @@ -66,7 +68,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos /// /// 生产号 /// + [Display(Name = "生产号")] [ImporterHeader(Name = "External Delivery ID")] + [Required(ErrorMessage = "{0}不能为空")] public string PN { get; set; } ///// @@ -80,13 +84,16 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos ///// /// 数量 /// + [Display(Name = "数量")] [ImporterHeader(Name = "Quantity")] public decimal Qty { get; set; } /// /// 结算分组号 /// + [Display(Name = "结算分组号")] [ImporterHeader(Name = "Delivery")] + [Required(ErrorMessage = "{0}不能为空")] public string GroupNum { get; set; } /////// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/SettleAccount.Application.Contracts.csproj b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/SettleAccount.Application.Contracts.csproj index 9c561c2e..94b2bc17 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/SettleAccount.Application.Contracts.csproj +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/SettleAccount.Application.Contracts.csproj @@ -7,6 +7,7 @@ Win.Sfs.SettleAccount 1.0.25 true + True 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 2d562ede..738f6112 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 @@ -22,6 +22,8 @@ using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.Entities.Prices; using Win.Sfs.SettleAccount.ExcelImporter; +using Win.Sfs.SettleAccount.ExportReports; +using Win.Sfs.SettleAccount.MaterialRelationships; using Win.Sfs.Shared.RepositoryBase; namespace Win.Sfs.SettleAccount.Entities.BQ @@ -63,6 +65,16 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// private readonly INormalEfCoreRepository _priceListRepository; + /// + /// 客户零件关系仓储 + /// + private readonly INormalEfCoreRepository _materialRelationshipRepository; + + /// + /// 替换件关系仓储 + /// + private readonly INormalEfCoreRepository _tbRePartsRelationshipRepository; + /// /// 构造 /// @@ -97,8 +109,37 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public async Task ZGJImportAsync([FromForm] IFormFileCollection files) { + //数据校验 + var checkList = new List(); //类型(直供件) - EnumBusinessType businessType = EnumBusinessType.ZhiGongJian; + var businessType = EnumBusinessType.ZhiGongJian; + //结算单号 + var pubSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); + //结算主表 + var pubSa = new PUB_SA() + { + BillNum = pubSaBillNum, + State = "1" + }; + //结算明细 + var pubSaDetails = new List(); + //可算单号 + var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); + //可算主表 + var pubCanSa = new PUB_CAN_SA() + { + BillNum = pubCanSaBillNum, + SettleBillNum = pubSaBillNum, + State = SettleBillState.未结状态, + BusinessType = businessType + }; + //可结算明细 + var pubCanSaDetails = new List(); + //不可结算明细 + var pubNotSaDetails = new List(); + + + #region 导入数据转换、数据校验 ExportImporter _exportImporter = new ExportImporter(); var result = await _exportImporter.UploadExcelImport(files, _excelImportService); var importPubSaDetails = ObjectMapper.Map, List>(result); @@ -106,15 +147,27 @@ namespace Win.Sfs.SettleAccount.Entities.BQ //结算分组号 var pubSaGroupNums = importPubSaDetails.Select(t => t.GroupNum).Distinct(); - //销售价格 - var priceListEntitys = await _priceListRepository.GetAllAsync(); + //已存在的结算分组号 + var havPubSaGroupNums = (await _pubSaDetailRepository.GetListAsync(t => pubSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct(); + if (havPubSaGroupNums.Any() == true) + { + foreach (var item in havPubSaGroupNums) + { + checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"结算分组号{item}已存在", string.Empty)); + } + //throw new UserFriendlyException($"导入失败,结算分组号({string.Join(",", havPubSaGroupNums)})已存在", "400"); + } - var pubSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); - var pubSa = new PUB_SA() + if (checkList.Count > 0) { - BillNum = pubSaBillNum, - State = "1" - }; + return await ExportErrorReportAsync(checkList); + } + #endregion + + + #region 处理结算数据 + //销售价格 + var priceListEntitys = await _priceListRepository.GetAllAsync(); importPubSaDetails.ForEach(importPubSaDetail => { @@ -136,28 +189,30 @@ namespace Win.Sfs.SettleAccount.Entities.BQ importPubSaDetail.Price = priceListEntity?.Price ?? 0; }); - //可结算 - var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); - var pubCanSa = new PUB_CAN_SA() - { - BillNum = pubCanSaBillNum, - SettleBillNum = pubSaBillNum, - State = SettleBillState.未结状态, - BusinessType = businessType - }; + ////导入的零件号集合 + //var importPubSaLUs = importPubSaDetails.Select(t => t.LU).Distinct(); + //_materialRelationshipRepository.GetListAsync(t => t.) + + #endregion + + + #region 入库数据赋值 + //结算明细 + pubSaDetails = importPubSaDetails; //不可结算 结算分组号码(根据价格区分结算、不可结算) var pubNotSaGroupNums = importPubSaDetails.FindAll(t => t.Price == default(decimal)).Select(t => t.GroupNum).Distinct(); var pubSaDetailsCanSes = importPubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == false); var pubSaDetailsNotCanSes = importPubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == true); - //可结算 - var pubCanSaDetails = ObjectMapper.Map, List>(pubSaDetailsCanSes); - //不可结算 - var pubNotSaDetails = ObjectMapper.Map, List>(pubSaDetailsNotCanSes); + //可结算明细 + pubCanSaDetails = ObjectMapper.Map, List>(pubSaDetailsCanSes); + //不可结算明细 + pubNotSaDetails = ObjectMapper.Map, List>(pubSaDetailsNotCanSes); + #endregion - //添加入库 + #region 添加入库 await _repository.InsertAsync(pubSa); await _pubSaDetailRepository.InsertManyAsync(importPubSaDetails); if (pubCanSaDetails.Count > 0) @@ -181,7 +236,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ }); await _pubNotSaDetailRepository.InsertManyAsync(pubNotSaDetails); - } + } + #endregion + return ApplicationConsts.SuccessStr; } @@ -245,7 +302,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ //验证可结算主表状态 if (pubCanSaDelEntitys.Any(t => t.State != SettleBillState.未结状态)) { - throw new UserFriendlyException($"该单据可结算单状态无法删除!"); + throw new UserFriendlyException($"该单据可结算单状态无法删除!", "400"); } pubSaDetailDelEntitys = await _pubSaDetailRepository.GetListAsync(t => t.BillNum == pubSaBillNum); 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 c5872bba..d639f03e 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 @@ -12,6 +12,7 @@ using Win.Abp.Snowflakes; using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.SettleAccount.CommonManagers; using Win.Sfs.SettleAccount.Constant; +using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExportReports; using Win.Sfs.SettleAccount.MaterialRelationships; @@ -96,7 +97,7 @@ namespace Win.Sfs.SettleAccount.Entities.MaterialRelationships /// 导出 /// [HttpPost] - public async Task ExportAsync(RequestDtoBase input) + public async Task ExportAsync(RequestDto input) { string fileName = $"客户零件关系_{Guid.NewGuid()}.xlsx"; var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); @@ -116,7 +117,7 @@ namespace Win.Sfs.SettleAccount.Entities.MaterialRelationships /// 获取列表 /// [HttpPost] - public async Task> GetListAsync(RequestDtoBase input) + public async Task> GetListAsync(RequestDto input) { var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true); var totalCount = await _repository.GetCountByFilterAsync(input.Filters);