From c1b02d7e8214eccf1685968c8787ff9b4230dbbe Mon Sep 17 00:00:00 2001 From: mahao Date: Tue, 12 Sep 2023 15:58:11 +0800 Subject: [PATCH] up --- .../Entities/Prices/PriceListAppService.cs | 57 +++++++++++------- .../Entities/Prices/PriceListAppServiceBJ.cs | 58 +++++++++++-------- .../ImportExcelCommon/ExportImporter.cs | 4 ++ 3 files changed, 74 insertions(+), 45 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs index 4403ccc7..447d7d27 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs @@ -80,25 +80,25 @@ public class PriceListAppService : SettleAccountApplicationBase result = result.FindAll(p => filter.Contains(p.Plant)).ToList(); result.FindAll(t => !string.IsNullOrEmpty(t.ES1) || !string.IsNullOrEmpty(t.ES2)).ForEach(t => t.PartNo = t.PartNo + new string(' ', 6) + t.ES1 + t.ES2); var newPrice = ObjectMapper.Map, List>(result); - newPrice = newPrice.GroupBy(p => new { p.LU, p.ClientCode, p.BeginTime, p.EndTime }).Select(p => p.FirstOrDefault()).ToList(); + newPrice = newPrice.GroupBy(p => new { p.Date, p.ClientCode, p.LU, p.BeginTime, p.EndTime }).Select(p => p.FirstOrDefault()).ToList(); #region 校验 if (newPrice.Any()) { var query = from item1 in newPrice join item2 in newPrice - on new { item1.LU, item1.ClientCode } equals new { item2.LU, item2.ClientCode } + on new { item1.Date, item1.ClientCode, item1.LU } equals new { item2.Date, item2.ClientCode, item2.LU } where (item1.BeginTime > item2.BeginTime && item1.EndTime < item2.EndTime) || (item2.BeginTime > item1.BeginTime && item2.EndTime < item1.EndTime) || (item1.BeginTime == item2.BeginTime && item1.EndTime != item2.EndTime) || (item1.BeginTime != item2.BeginTime && item1.EndTime == item2.EndTime) - select item1.LU; + select item1; 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)); + checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item.LU},合同签订时间:{item.Date},时间区间存在交集", string.Empty)); } foreach (var item in CheckPriceListContinuity(newPrice)) { - checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item.LU},时间区间【{item.BeginTime}至{item.EndTime}】不连续", string.Empty)); + checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item.LU},合同签订时间:{item.Date},时间区间【{item.BeginTime}至{item.EndTime}】不连续", string.Empty)); } } if (checkList.Count > 0) @@ -108,22 +108,30 @@ public class PriceListAppService : SettleAccountApplicationBase } #endregion + newPrice.ForEach(t => t.IsCancel = true); + newPrice.GroupBy(t => new { t.ClientCode, t.LU }) + .SelectMany(t => + { + var data = t.OrderByDescending(t => t.Date).First().Date; + return t.Where(t => t.Date == data); + }) + .ForEach(t => t.IsCancel = false); + var importLus = newPrice.Select(t => t.LU).Distinct().ToList(); var oldPrices = _settleAccountDbContext.Set() .Where(t => t.IsCancel == false) .Where(t => importLus.Contains(t.LU)) .ToList(); //系统中合同日期比导入文件中的合同日期晚 - var oldPriceNewDate = from oldprice in oldPrices - from newprice in newPrice - where oldprice.LU == newprice.LU && oldprice.Date > newprice.Date - select oldprice; + var oldPriceNewDate = from oldPriceItem in oldPrices + from newPriceItem in newPrice.FindAll(t => t.IsCancel == false) + where oldPriceItem.ClientCode == newPriceItem.ClientCode && oldPriceItem.LU == newPriceItem.LU && oldPriceItem.Date > newPriceItem.Date + select new { oldPriceItem, newPriceItem }; oldPrices.ForEach(t => t.IsCancel = true); if (oldPriceNewDate.Any()) { - oldPrices.FindAll(t => oldPriceNewDate.Contains(t)).ForEach(t => t.IsCancel = false); - var importCancelLus = oldPrices.Select(t => t.LU).Distinct(); - newPrice.FindAll(t => importCancelLus.Contains(t.LU)).ForEach(t => t.IsCancel = true); + oldPrices.FindAll(t => t.IsCancel == true && oldPriceNewDate.Select(t => t.oldPriceItem).Contains(t)).ForEach(t => t.IsCancel = false); + newPrice.FindAll(t => t.IsCancel == false && oldPriceNewDate.Select(t => t.newPriceItem).Contains(t)).ForEach(t => t.IsCancel = true); } foreach (var item in newPrice) { @@ -155,22 +163,27 @@ public class PriceListAppService : SettleAccountApplicationBase return priceList; // 只有一个或零个价格条目 } - var clientCodeGroup = priceList.GroupBy(t => t.ClientCode); - foreach (var item in clientCodeGroup) + var dateGroups = priceList.GroupBy(t => t.Date); + foreach (var dateGroup in dateGroups) { - if (item.ToList().Count <= 1) - { - continue; - } - var sortedList = item.OrderBy(t => t.LU).ThenBy(t => t.BeginTime).ToList(); - for (var i = 1; i < sortedList.Count; i++) + var clientCodeGroups = dateGroup.GroupBy(t => t.ClientCode); + foreach (var clientCodeGroup in clientCodeGroups) { - if (sortedList[i].LU == sortedList[i - 1].LU && sortedList[i].BeginTime != sortedList[i - 1].EndTime.AddDays(1)) + if (clientCodeGroup.ToList().Count <= 1) { - result.Add(sortedList[i]); + continue; + } + var sortedList = clientCodeGroup.OrderBy(t => t.LU).ThenBy(t => t.BeginTime).ToList(); + for (var i = 1; i < sortedList.Count; i++) + { + if (sortedList[i].LU == sortedList[i - 1].LU && sortedList[i].BeginTime != sortedList[i - 1].EndTime.AddDays(1)) + { + result.Add(sortedList[i]); + } } } } + return result; // 所有价格时间都连续 } 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 f78edce6..aed28b00 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 @@ -63,25 +63,25 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase result = result.Where(p => filter.Contains(p.Plant)).ToList(); result.FindAll(t => !string.IsNullOrEmpty(t.ES1) || !string.IsNullOrEmpty(t.ES2)).ForEach(t => t.PartNo = t.PartNo + new string(' ', 6) + t.ES1 + t.ES2); var newPrice = ObjectMapper.Map, List>(result); - newPrice = newPrice.GroupBy(p => new { p.LU, p.BeginDate, p.EndDate }).Select(p => p.FirstOrDefault()).ToList(); + newPrice = newPrice.GroupBy(p => new { p.Date, p.ClientCode, p.LU, p.BeginDate, p.EndDate }).Select(p => p.FirstOrDefault()).ToList(); #region 校验 if (newPrice.Any()) { var query = from item1 in newPrice join item2 in newPrice - on item1.LU equals item2.LU + on new { item1.Date, item1.ClientCode, item1.LU } equals new { item2.Date, item2.ClientCode, 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; + select item1; 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)); + checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item.LU},合同签订时间:{item.Date},时间区间存在交集", string.Empty)); } foreach (var item in CheckPriceListContinuity(newPrice)) { - checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item.LU},时间区间【{item.BeginDate}至{item.EndDate}】不连续", string.Empty)); + checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item.LU},合同签订时间:{item.Date},时间区间【{item.BeginDate}至{item.EndDate}】不连续", string.Empty)); } } if (checkList.Count > 0) @@ -91,22 +91,30 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase } #endregion + newPrice.ForEach(t => t.IsCancel = true); + newPrice.GroupBy(t => new { t.ClientCode, t.LU }) + .SelectMany(t => + { + var data = t.OrderByDescending(t => t.Date).First().Date; + return t.Where(t => t.Date == data); + }) + .ForEach(t => t.IsCancel = false); + var importLus = newPrice.Select(t => t.LU).Distinct().ToList(); var oldPrices = _settleAccountDbContext.Set() .Where(t => t.IsCancel == false) .Where(t => importLus.Contains(t.LU)) .ToList(); //系统中合同日期比导入文件中的合同日期晚 - var oldPriceNewDate = from oldprice in oldPrices - from newprice in newPrice - where oldprice.LU == newprice.LU && oldprice.Date > newprice.Date - select oldprice; + var oldPriceNewDate = from oldPriceItem in oldPrices + from newPriceItem in newPrice.FindAll(t => t.IsCancel == false) + where oldPriceItem.ClientCode == newPriceItem.ClientCode && oldPriceItem.LU == newPriceItem.LU && oldPriceItem.Date > newPriceItem.Date + select new { oldPriceItem, newPriceItem }; oldPrices.ForEach(t => t.IsCancel = true); if (oldPriceNewDate.Any()) { - oldPrices.FindAll(t => oldPriceNewDate.Contains(t)).ForEach(t => t.IsCancel = false); - var importCancelLus = oldPrices.Select(t => t.LU).Distinct(); - newPrice.FindAll(t => importCancelLus.Contains(t.LU)).ForEach(t => t.IsCancel = true); + oldPrices.FindAll(t => t.IsCancel == true && oldPriceNewDate.Select(t => t.oldPriceItem).Contains(t)).ForEach(t => t.IsCancel = false); + newPrice.FindAll(t => t.IsCancel == false && oldPriceNewDate.Select(t => t.newPriceItem).Contains(t)).ForEach(t => t.IsCancel = true); } foreach (var item in newPrice) { @@ -139,24 +147,28 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase return priceList; // 只有一个或零个价格条目 } - var clientCodeGroup = priceList.GroupBy(t => t.ClientCode); - foreach (var item in clientCodeGroup) + var dateGroups = priceList.GroupBy(t => t.Date); + foreach (var dateGroup in dateGroups) { - if (item.ToList().Count <= 1) - { - continue; - } - var sortedList = item.OrderBy(t => t.LU).ThenBy(t => t.BeginDate).ToList(); - for (var i = 1; i < sortedList.Count; i++) + var clientCodeGroups = dateGroup.GroupBy(t => t.ClientCode); + foreach (var clientCodeGroup in clientCodeGroups) { - if (sortedList[i].LU == sortedList[i - 1].LU && sortedList[i].BeginDate != sortedList[i - 1].EndDate.AddDays(1)) + if (clientCodeGroup.ToList().Count <= 1) + { + continue; + } + var sortedList = clientCodeGroup.OrderBy(t => t.LU).ThenBy(t => t.BeginDate).ToList(); + for (var i = 1; i < sortedList.Count; i++) { - result.Add(sortedList[i]); + if (sortedList[i].LU == sortedList[i - 1].LU && sortedList[i].BeginDate != sortedList[i - 1].EndDate.AddDays(1)) + { + result.Add(sortedList[i]); + } } } } - return result; + return result; // 所有价格时间都连续 } /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs index 7dd05aa9..2218e76d 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs @@ -52,6 +52,10 @@ namespace Win.Sfs.SettleAccount.ExcelImporter public virtual async Task> UploadExcelImport([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService) where T : class, new() { + if (files.Count > 1) + { + throw new UserFriendlyException("只能上传一个附件!", "400"); + } using var fs = ServiceProvider.CreateScope(); var fc = fs.ServiceProvider.GetRequiredService>(); Type type = typeof(T).GetType();