From d5694bf2cd7bc781d0d7f7af94c96f0e62079649 Mon Sep 17 00:00:00 2001 From: mahao Date: Fri, 1 Sep 2023 15:15:09 +0800 Subject: [PATCH 1/2] up --- .../Entities/Prices/PriceListDtoBase.cs | 4 +- .../Entities/BQ/BBAC_SA_SERVICE.cs | 39 +++++++++++-------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/Prices/PriceListDtoBase.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/Prices/PriceListDtoBase.cs index b1ca1613..24819e29 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/Prices/PriceListDtoBase.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/Prices/PriceListDtoBase.cs @@ -148,13 +148,13 @@ public class PriceListImportDto /// 开始时间 /// [ImporterHeader(Name = "*Valid From")] - public string ValidFrom { get; set; } + public DateTime ValidFrom { get; set; } /// /// 结束时间 /// [ImporterHeader(Name = "*Valid To")] - public string ValidTo { get; set; } + public DateTime ValidTo { get; set; } /// /// 客户编码 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 c1b64e09..6a3cc12d 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 @@ -1,17 +1,9 @@ using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Linq; -using System.LinqAsync; -using System.Security.Policy; using System.Threading.Tasks; -using AutoMapper; -using DocumentFormat.OpenXml.Drawing.Charts; -using DocumentFormat.OpenXml.Wordprocessing; using EFCore.BulkExtensions; -using FlexLabs.EntityFrameworkCore.Upsert.Internal; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using SettleAccount.Domain.BQ; using Volo.Abp; @@ -162,7 +154,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase //结算分组号 var bbacSaGroupNums = importBBACSaDetails.Select(t => t.GroupNum).Distinct(); //已存在的结算分组号 - var havBBACSaGroupNums = (await _bbacSaDetailRepository.GetListAsync(t => bbacSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct(); + var havBBACSaGroupNums = (await _bbacSaDetailRepository.GetListAsync(t => bbacSaGroupNums.Contains(t.GroupNum)).ConfigureAwait(false)).Select(t => t.GroupNum).Distinct(); if (havBBACSaGroupNums.Any() == true) { foreach (var item in havBBACSaGroupNums) @@ -396,7 +388,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase var importPubSaLUs = bbacSaDetails.Select(t => t.LU).Distinct(); //销售价格 var priceListEntitys = _priceListRepository.Where(t => importPubSaLUs.Contains(t.LU)).ToList(); - var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)); + var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); bbacSaDetails.ForEach(bbacSaDetail => { //根据物料号、结算日期获取价格 @@ -420,6 +412,19 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase #region 添加入库 await _bbacSaRepository.InsertAsync(bbacSa).ConfigureAwait(false); + //存在买单将BBAC数据添加买单件BBAC主表数据 + if (bbacSaDetails.Any(t => t.BusinessType == EnumBusinessType.MaiDanJianBBAC)) + { + //买单件结算主表 + await _bbacSaRepository.InsertAsync(new BBAC_SA() + { + BillNum = bbacSaBillNum, + State = "0", + BusinessType = EnumBusinessType.MaiDanJianBBAC, + Site = Site, + Version = Version + }).ConfigureAwait(false); + } await _bbacSaDetailRepository.DbContext.BulkInsertAsync(bbacSaDetails).ConfigureAwait(false); if (bbacCanSaDetails.Count > 0) { @@ -443,7 +448,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase } if (materialRelationships.Count > 0) { - await _materialRelationshipRepository.InsertManyAsync(materialRelationships); + await _materialRelationshipRepository.InsertManyAsync(materialRelationships).ConfigureAwait(false); } #endregion } @@ -454,15 +459,15 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase private async Task<(List bbacSas, List bbacSaDetails, List bbacCanSas, List bbacCanSaDetails, List bbacNotSaDetails)> GetBBACSaDelItemsAsync(Guid id) { //结算主表 - List bbacSas = new List(); + var bbacSas = new List(); //结算明细 - List bbacSaDetails = new List(); + var bbacSaDetails = new List(); //可结算主表 - List bbacCanSas = new List(); + var bbacCanSas = new List(); //可结算明细 - List bbacCanSaDetails = new List(); + var bbacCanSaDetails = new List(); //不可结算 - List bbacNotSaDetails = new List(); + var bbacNotSaDetails = new List(); var bbacSaEntity = await _bbacSaRepository.FindAsync(id).ConfigureAwait(false); if (bbacSaEntity != null) { @@ -476,7 +481,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase throw new UserFriendlyException($"{bbacSaBillNum} 该单据可结算单状态无法删除!", "400"); } - bbacSas.Add(bbacSaEntity); + bbacSas = await _bbacSaRepository.GetListAsync(t => t.BillNum == bbacSaBillNum).ConfigureAwait(false); bbacSaDetails = await _bbacSaDetailRepository.GetListAsync(t => t.BillNum == bbacSaBillNum).ConfigureAwait(false); bbacCanSaDetails = await _bbacCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum).ConfigureAwait(false); bbacNotSaDetails = await _bbacNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum).ConfigureAwait(false); From f12a8e4eba32499792ffd3f31f980317b5455d4c Mon Sep 17 00:00:00 2001 From: mahao Date: Fri, 1 Sep 2023 15:20:51 +0800 Subject: [PATCH 2/2] up --- .../Entities/Prices/PriceListAppServiceBJ.cs | 231 +++++++++--------- 1 file changed, 114 insertions(+), 117 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs index dd6e30ad..5f02b23f 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs @@ -1,15 +1,13 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Shouldly; using System; using System.Collections.Generic; -using System.Diagnostics.Contracts; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Shouldly; using Volo.Abp.Application.Dtos; using Volo.Abp.Caching; -using Volo.Abp.Domain.Repositories; using Win.Abp.Snowflakes; using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.SettleAccount.CommonManagers; @@ -19,136 +17,135 @@ using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExportReports; using Win.Sfs.Shared.RepositoryBase; -namespace Win.Sfs.SettleAccount.Entities.Prices +namespace Win.Sfs.SettleAccount.Entities.Prices; + +/// +/// 备件价格 +/// +[AllowAnonymous] +[Route("api/settleaccount/[controller]/[action]")] +public class PriceListAppServiceBJ : SettleAccountApplicationBase { + private readonly INormalEfCoreRepository _repository; + + public PriceListAppServiceBJ( + INormalEfCoreRepository repository, + IDistributedCache cache, + IExcelImportAppService excelImportService, + ISnowflakeIdGenerator snowflakeIdGenerator, + ICommonManager commonManager + ) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) + { + _repository = repository; + } + + #region 导入、导出 /// - /// 备件价格 + /// 导入 /// - [AllowAnonymous] - [Route("api/settleaccount/[controller]/[action]")] - public class PriceListAppServiceBJ : SettleAccountApplicationBase + [HttpPost] + public async Task ImportAsync([FromForm] IFormFileCollection files, string version) { - private readonly INormalEfCoreRepository _repository; + var checkList = new List(); + ExportImporter _exportImporter = new ExportImporter(); + var result = await _exportImporter.UploadExcelImportByHeadDesc(files, _excelImportService).ConfigureAwait(false); + List _checkls = new List(); + _checkls.Add("1040"); + _checkls.Add("1046"); + _checkls.Add("104T"); + result = result.Where(p => _checkls.Contains(p.ClientCode)).ToList(); - public PriceListAppServiceBJ( - INormalEfCoreRepository repository, - IDistributedCache cache, - IExcelImportAppService excelImportService, - ISnowflakeIdGenerator snowflakeIdGenerator, - ICommonManager commonManager - ) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) - { - _repository = repository; - } + var entityList = ObjectMapper.Map, List>(result); + entityList = entityList.GroupBy(p => new { p.LU, p.ClientCode, p.BeginDate, p.EndDate }).Select(p => p.FirstOrDefault()).ToList(); + var contractNo = entityList.FirstOrDefault().ContractNo; - #region 导入、导出 - /// - /// 导入 - /// - [HttpPost] - public async Task ImportAsync([FromForm] IFormFileCollection files, string version) + #region 校验 + if (entityList.Any()) { - var checkList = new List(); - ExportImporter _exportImporter = new ExportImporter(); - var result = await _exportImporter.UploadExcelImportByHeadDesc(files, _excelImportService).ConfigureAwait(false); - List _checkls = new List(); - _checkls.Add("1040"); - _checkls.Add("1046"); - _checkls.Add("104T"); - result = result.Where(p => _checkls.Contains(p.ClientCode)).ToList(); - - var entityList = ObjectMapper.Map, List>(result); - entityList = entityList.GroupBy(p => new { p.LU, p.ClientCode, p.BeginDate, p.EndDate }).Select(p => p.FirstOrDefault()).ToList(); - var contractNo = entityList.FirstOrDefault().ContractNo; - - #region 校验 - if (entityList.Any()) - { - var query = from item1 in entityList - join item2 in entityList - on new { item1.LU } equals new { item2.LU } - where (item1.BeginDate > item2.BeginDate && item1.EndDate < item2.EndDate) || (item2.BeginDate > item1.BeginDate && item2.EndDate < item1.EndDate) || (item1.BeginDate == item2.BeginDate && item1.EndDate != item2.EndDate) || (item1.BeginDate != item2.BeginDate && item1.EndDate == item2.EndDate) - select item1.LU; - var repeat = query.Distinct().ToList(); - foreach (var item in query) - { - checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item},时间区间存在交集", string.Empty)); - } - } - if (checkList.Count > 0) - { - string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); - return new JsonResult(new { code = ApplicationConsts.ImportFailCode, message = "导入失败", fileName = fileName }); - } - #endregion - var lus = entityList.Select(p => p.LU); - - var prices = _repository.Where(t => lus.Contains(t.LU) && t.ContractNo != contractNo).ToList(); - if (prices.Any()) - { - var query = from item1 in entityList - join item2 in prices - on new { item1.LU } equals new { item2.LU } - where (item1.BeginDate >= item2.BeginDate && item1.EndDate <= item2.EndDate) || (item2.BeginDate >= item1.BeginDate && item2.EndDate <= item1.EndDate) - select item1.LU; - var repeat = query.Distinct().ToList(); - foreach (var item in repeat) - { - checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item},时间区间与系统内数据存在交集", string.Empty)); - } - } - if (checkList.Count > 0) - { - string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); - return new JsonResult(new { code = ApplicationConsts.ImportFailCode, message = "导入失败", fileName = fileName }); - } - - var priceListModelEntitys = _repository.Where(t => t.ContractNo == contractNo && lus.Contains(t.LU)).ToList(); - if (priceListModelEntitys.Any()) + var query = from item1 in entityList + join item2 in entityList + on new { item1.LU } equals new { item2.LU } + where (item1.BeginDate > item2.BeginDate && item1.EndDate < item2.EndDate) || (item2.BeginDate > item1.BeginDate && item2.EndDate < item1.EndDate) || (item1.BeginDate == item2.BeginDate && item1.EndDate != item2.EndDate) || (item1.BeginDate != item2.BeginDate && item1.EndDate == item2.EndDate) + select item1.LU; + var repeat = query.Distinct().ToList(); + foreach (var item in query) { - await _repository.DeleteManyAsync(priceListModelEntitys).ConfigureAwait(false); + checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item},时间区间存在交集", string.Empty)); } + } + if (checkList.Count > 0) + { + string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); + return new JsonResult(new { code = ApplicationConsts.ImportFailCode, message = "导入失败", fileName = fileName }); + } + #endregion + var lus = entityList.Select(p => p.LU); - foreach (var item in entityList) + var prices = _repository.Where(t => lus.Contains(t.LU) && t.ContractNo != contractNo).ToList(); + if (prices.Any()) + { + var query = from item1 in entityList + join item2 in prices + on new { item1.LU } equals new { item2.LU } + where (item1.BeginDate >= item2.BeginDate && item1.EndDate <= item2.EndDate) || (item2.BeginDate >= item1.BeginDate && item2.EndDate <= item1.EndDate) + select item1.LU; + var repeat = query.Distinct().ToList(); + foreach (var item in repeat) { - item.Update(GuidGenerator.Create()); + checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item},时间区间与系统内数据存在交集", string.Empty)); } - await _repository.InsertManyAsync(entityList).ConfigureAwait(false); - return new JsonResult(new { Code = 200, Message = "导入成功" }); } - - /// - /// 导出 - /// - [HttpPost] - public async Task ExportAsync(RequestDto input) + if (checkList.Count > 0) { - string fileName = $"备件价格_{Guid.NewGuid()}.xlsx"; - var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); - var dtos = ObjectMapper.Map, List>(entities); - - ExportImporter _exportImporter = new ExportImporter(); - var result = await _exportImporter.ExcelExporter(dtos); - result.ShouldNotBeNull(); + string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); + return new JsonResult(new { code = ApplicationConsts.ImportFailCode, message = "导入失败", fileName = fileName }); + } - await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }); - return fileName; + var priceListModelEntitys = _repository.Where(t => t.ContractNo == contractNo && lus.Contains(t.LU)).ToList(); + if (priceListModelEntitys.Any()) + { + await _repository.DeleteManyAsync(priceListModelEntitys).ConfigureAwait(false); } - #endregion - #region CURD - /// - /// 获取列表 - /// - [HttpPost] - public async Task> GetListAsync(RequestDto input) + foreach (var item in entityList) { - var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); - var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); - var dtos = ObjectMapper.Map, List>(entities); - return new PagedResultDto(totalCount, dtos); + item.Update(GuidGenerator.Create()); } - #endregion + await _repository.InsertManyAsync(entityList).ConfigureAwait(false); + return new JsonResult(new { Code = 200, Message = "导入成功" }); + } + + /// + /// 导出 + /// + [HttpPost] + public async Task ExportAsync(RequestDto input) + { + string fileName = $"备件价格_{Guid.NewGuid()}.xlsx"; + var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); + var dtos = ObjectMapper.Map, List>(entities); + + ExportImporter _exportImporter = new ExportImporter(); + var result = await _exportImporter.ExcelExporter(dtos); + result.ShouldNotBeNull(); + + await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }); + return fileName; + } + #endregion + + #region CURD + /// + /// 获取列表 + /// + [HttpPost] + public async Task> GetListAsync(RequestDto input) + { + var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); + var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); + var dtos = ObjectMapper.Map, List>(entities); + return new PagedResultDto(totalCount, dtos); } + #endregion }