From 6d8ab3b9a0c263ca098e04da6590b590f4a2bda8 Mon Sep 17 00:00:00 2001 From: mahao Date: Sat, 15 Jul 2023 13:09:43 +0800 Subject: [PATCH] =?UTF-8?q?PUB=E7=BB=93=E7=AE=97=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BQ/PUB_SA_SERVICE.cs | 89 ++++++++++++------- ...ttleAccountApplicationAutoMapperProfile.cs | 5 ++ 2 files changed, 60 insertions(+), 34 deletions(-) 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 2527a759..2d562ede 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 @@ -2,12 +2,14 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using NPOI.Util; +using NUglify.Helpers; using SettleAccount.Bases; using SettleAccount.Domain.BQ; using Shouldly; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Dynamic.Core; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Dtos; @@ -67,6 +69,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public PUB_SA_SERVICE(INormalEfCoreRepository repository, INormalEfCoreRepository pubSaDetailRepository, INormalEfCoreRepository priceListRepository, + INormalEfCoreRepository pubCanSaRepository, + INormalEfCoreRepository pubCanSaDetailRepository, + INormalEfCoreRepository pubNotSaDetailRepository, IDistributedCache cache, IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, @@ -75,6 +80,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { _repository = repository; _pubSaDetailRepository = pubSaDetailRepository; + _pubCanSaRepository = pubCanSaRepository; + _pubCanSaDetailRepository = pubCanSaDetailRepository; + _pubNotSaDetailRepository = pubNotSaDetailRepository; _priceListRepository = priceListRepository; } @@ -89,9 +97,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public async Task ZGJImportAsync([FromForm] IFormFileCollection files) { + //类型(直供件) + EnumBusinessType businessType = EnumBusinessType.ZhiGongJian; ExportImporter _exportImporter = new ExportImporter(); var result = await _exportImporter.UploadExcelImport(files, _excelImportService); - var _ls = ObjectMapper.Map, List>(result); + var importPubSaDetails = ObjectMapper.Map, List>(result); + + //结算分组号 + var pubSaGroupNums = importPubSaDetails.Select(t => t.GroupNum).Distinct(); //销售价格 var priceListEntitys = await _priceListRepository.GetAllAsync(); @@ -103,63 +116,70 @@ namespace Win.Sfs.SettleAccount.Entities.BQ State = "1" }; - _ls.ForEach(s => + importPubSaDetails.ForEach(importPubSaDetail => { - if (s.LU != null) + List luList = importPubSaDetail.LU.Split(" ").ToList(); + if (luList.Count > 1) { - List luList = s.LU.Split(" ").ToList(); - s.LU = luList[0].Replace(" ", ""); - if (luList.Count > 1) - { - luList.RemoveAt(0); - luList.Reverse(); - var luAssemble = luList.Select(t => t.Replace(" ", "")); - s.LU += luAssemble.Aggregate(" ", (current, index) => current + index); - } + importPubSaDetail.LU = luList[0].Replace(" ", ""); + luList.RemoveAt(0); + var luAssemble = luList.Select(t => t.Replace(" ", "")); + importPubSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index); } - s.LU = s.LU; - s.BillNum = pubSaBillNum; - s.Site = "XX工厂"; - s.KeyCode = s.LU + s.PN; + importPubSaDetail.BillNum = pubSaBillNum; + importPubSaDetail.Site = "XX工厂"; + importPubSaDetail.KeyCode = importPubSaDetail.PN + importPubSaDetail.LU; //根据物料号、结算日期获取价格 - var priceListEntity = priceListEntitys.Find(t => t.LU == s.LU && s.SettleDate > t.BeginTime && s.SettleDate < t.EndTime); - s.Price = priceListEntity?.Price ?? 0; + var priceListEntity = priceListEntitys.Find(t => t.LU == importPubSaDetail.LU && importPubSaDetail.SettleDate > t.BeginTime && importPubSaDetail.SettleDate < t.EndTime); + importPubSaDetail.Price = priceListEntity?.Price ?? 0; }); //可结算 - var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); + var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); var pubCanSa = new PUB_CAN_SA() { BillNum = pubCanSaBillNum, SettleBillNum = pubSaBillNum, State = SettleBillState.未结状态, - BusinessType = EnumBusinessType.ZhiGongJian + BusinessType = businessType }; //不可结算 结算分组号码(根据价格区分结算、不可结算) - var pubNotSaGroupNum = _ls.FindAll(t => t.Price != 0).Select(t => t.GroupNum).Distinct(); - var pubSaDetailsCanSe = _ls.FindAll(t => pubNotSaGroupNum.Contains(t.GroupNum) == false); - var pubSaDetailsNotCanSe = _ls.FindAll(t => pubNotSaGroupNum.Contains(t.GroupNum) == true); + 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>(pubSaDetailsCanSe); + var pubCanSaDetails = ObjectMapper.Map, List>(pubSaDetailsCanSes); //不可结算 - var pubNotSaDetails = ObjectMapper.Map, List>(pubSaDetailsNotCanSe); + var pubNotSaDetails = ObjectMapper.Map, List>(pubSaDetailsNotCanSes); //添加入库 await _repository.InsertAsync(pubSa); - await _pubSaDetailRepository.InsertManyAsync(_ls); + await _pubSaDetailRepository.InsertManyAsync(importPubSaDetails); if (pubCanSaDetails.Count > 0) { pubCanSa.InvGroupNum = pubCanSaDetails.Count.ToString(); + pubCanSaDetails.ForEach(pubCanSaDetail => + { + pubCanSaDetail.BillNum = pubCanSaDetail.InvGroupNum = pubCanSaBillNum; + pubCanSaDetail.BusinessType = businessType; + }); + await _pubCanSaRepository.InsertAsync(pubCanSa); await _pubCanSaDetailRepository.InsertManyAsync(pubCanSaDetails); } if (pubNotSaDetails.Count > 0) { + pubNotSaDetails.ForEach(pubNotSaDetail => + { + pubNotSaDetail.InvGroupNum = pubCanSaBillNum; + pubNotSaDetail.BusinessType = businessType; + }); + await _pubNotSaDetailRepository.InsertManyAsync(pubNotSaDetails); } return ApplicationConsts.SuccessStr; @@ -206,30 +226,31 @@ namespace Win.Sfs.SettleAccount.Entities.BQ //结算主表 PUB_SA pubSaDelEntity; //结算明细 - IEnumerable pubSaDetailDelEntitys = default; + List pubSaDetailDelEntitys; //可结算主表 - IEnumerable pubCanSaDelEntitys = default; + List pubCanSaDelEntitys; //可结算明细 - IEnumerable pubCanSaDetailDelEntitys = default; + List pubCanSaDetailDelEntitys; //不可结算 - IEnumerable pubNotSaDetailDelEntitys = default; + List pubNotSaDetailDelEntitys; pubSaDelEntity = await _repository.FindAsync(id); - if (pubSaDelEntity != null) return; + if (pubSaDelEntity == null) return; //结算单据 string pubSaBillNum = pubSaDelEntity.BillNum; - pubCanSaDelEntitys = _pubCanSaRepository.Where(t => t.SettleBillNum == pubSaBillNum); + pubCanSaDelEntitys = await _pubCanSaRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); //验证可结算主表状态 if (pubCanSaDelEntitys.Any(t => t.State != SettleBillState.未结状态)) { throw new UserFriendlyException($"该单据可结算单状态无法删除!"); } - pubCanSaDetailDelEntitys = _pubCanSaDetailRepository.Where(t => t.SettleBillNum == pubSaBillNum); - pubNotSaDetailDelEntitys = _pubNotSaDetailRepository.Where(t => t.SettleBillNum == pubSaBillNum); + pubSaDetailDelEntitys = await _pubSaDetailRepository.GetListAsync(t => t.BillNum == pubSaBillNum); + pubCanSaDetailDelEntitys = await _pubCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); + pubNotSaDetailDelEntitys = await _pubNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); //删除 await _repository.DeleteAsync(pubSaDelEntity); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs index d80ca761..cc892c5a 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs @@ -820,6 +820,11 @@ namespace Win.Sfs.SettleAccount { CreateMap(); + CreateMap() + .ForMember(x => x.SettleBillNum, y => y.MapFrom(d => d.BillNum)); + CreateMap() + .ForMember(x => x.SettleBillNum, y => y.MapFrom(d => d.BillNum)); + CreateMap(); }