mahao 1 year ago
parent
commit
c1b02d7e82
  1. 45
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs
  2. 46
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs
  3. 4
      code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs

45
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs

@ -80,25 +80,25 @@ public class PriceListAppService : SettleAccountApplicationBase<PriceList>
result = result.FindAll(p => filter.Contains(p.Plant)).ToList(); 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); 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<PriceListImportDto>, List<PriceList>>(result); var newPrice = ObjectMapper.Map<List<PriceListImportDto>, List<PriceList>>(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 校验 #region 校验
if (newPrice.Any()) if (newPrice.Any())
{ {
var query = from item1 in newPrice var query = from item1 in newPrice
join item2 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) 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(); var repeat = query.Distinct().ToList();
foreach (var item in repeat) 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)) 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) if (checkList.Count > 0)
@ -108,22 +108,30 @@ public class PriceListAppService : SettleAccountApplicationBase<PriceList>
} }
#endregion #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 importLus = newPrice.Select(t => t.LU).Distinct().ToList();
var oldPrices = _settleAccountDbContext.Set<PriceList>() var oldPrices = _settleAccountDbContext.Set<PriceList>()
.Where(t => t.IsCancel == false) .Where(t => t.IsCancel == false)
.Where(t => importLus.Contains(t.LU)) .Where(t => importLus.Contains(t.LU))
.ToList(); .ToList();
//系统中合同日期比导入文件中的合同日期晚 //系统中合同日期比导入文件中的合同日期晚
var oldPriceNewDate = from oldprice in oldPrices var oldPriceNewDate = from oldPriceItem in oldPrices
from newprice in newPrice from newPriceItem in newPrice.FindAll(t => t.IsCancel == false)
where oldprice.LU == newprice.LU && oldprice.Date > newprice.Date where oldPriceItem.ClientCode == newPriceItem.ClientCode && oldPriceItem.LU == newPriceItem.LU && oldPriceItem.Date > newPriceItem.Date
select oldprice; select new { oldPriceItem, newPriceItem };
oldPrices.ForEach(t => t.IsCancel = true); oldPrices.ForEach(t => t.IsCancel = true);
if (oldPriceNewDate.Any()) if (oldPriceNewDate.Any())
{ {
oldPrices.FindAll(t => oldPriceNewDate.Contains(t)).ForEach(t => t.IsCancel = false); oldPrices.FindAll(t => t.IsCancel == true && oldPriceNewDate.Select(t => t.oldPriceItem).Contains(t)).ForEach(t => t.IsCancel = false);
var importCancelLus = oldPrices.Select(t => t.LU).Distinct(); newPrice.FindAll(t => t.IsCancel == false && oldPriceNewDate.Select(t => t.newPriceItem).Contains(t)).ForEach(t => t.IsCancel = true);
newPrice.FindAll(t => importCancelLus.Contains(t.LU)).ForEach(t => t.IsCancel = true);
} }
foreach (var item in newPrice) foreach (var item in newPrice)
{ {
@ -155,14 +163,17 @@ public class PriceListAppService : SettleAccountApplicationBase<PriceList>
return priceList; // 只有一个或零个价格条目 return priceList; // 只有一个或零个价格条目
} }
var clientCodeGroup = priceList.GroupBy(t => t.ClientCode); var dateGroups = priceList.GroupBy(t => t.Date);
foreach (var item in clientCodeGroup) foreach (var dateGroup in dateGroups)
{
var clientCodeGroups = dateGroup.GroupBy(t => t.ClientCode);
foreach (var clientCodeGroup in clientCodeGroups)
{ {
if (item.ToList().Count <= 1) if (clientCodeGroup.ToList().Count <= 1)
{ {
continue; continue;
} }
var sortedList = item.OrderBy(t => t.LU).ThenBy(t => t.BeginTime).ToList(); var sortedList = clientCodeGroup.OrderBy(t => t.LU).ThenBy(t => t.BeginTime).ToList();
for (var i = 1; i < sortedList.Count; i++) 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)) if (sortedList[i].LU == sortedList[i - 1].LU && sortedList[i].BeginTime != sortedList[i - 1].EndTime.AddDays(1))
@ -171,6 +182,8 @@ public class PriceListAppService : SettleAccountApplicationBase<PriceList>
} }
} }
} }
}
return result; // 所有价格时间都连续 return result; // 所有价格时间都连续
} }

46
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs

@ -63,25 +63,25 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase<PriceListBJ>
result = result.Where(p => filter.Contains(p.Plant)).ToList(); 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); 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<PriceListBJImportDto>, List<PriceListBJ>>(result); var newPrice = ObjectMapper.Map<List<PriceListBJImportDto>, List<PriceListBJ>>(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 校验 #region 校验
if (newPrice.Any()) if (newPrice.Any())
{ {
var query = from item1 in newPrice var query = from item1 in newPrice
join item2 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) 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(); var repeat = query.Distinct().ToList();
foreach (var item in repeat) 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)) 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) if (checkList.Count > 0)
@ -91,22 +91,30 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase<PriceListBJ>
} }
#endregion #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 importLus = newPrice.Select(t => t.LU).Distinct().ToList();
var oldPrices = _settleAccountDbContext.Set<PriceListBJ>() var oldPrices = _settleAccountDbContext.Set<PriceListBJ>()
.Where(t => t.IsCancel == false) .Where(t => t.IsCancel == false)
.Where(t => importLus.Contains(t.LU)) .Where(t => importLus.Contains(t.LU))
.ToList(); .ToList();
//系统中合同日期比导入文件中的合同日期晚 //系统中合同日期比导入文件中的合同日期晚
var oldPriceNewDate = from oldprice in oldPrices var oldPriceNewDate = from oldPriceItem in oldPrices
from newprice in newPrice from newPriceItem in newPrice.FindAll(t => t.IsCancel == false)
where oldprice.LU == newprice.LU && oldprice.Date > newprice.Date where oldPriceItem.ClientCode == newPriceItem.ClientCode && oldPriceItem.LU == newPriceItem.LU && oldPriceItem.Date > newPriceItem.Date
select oldprice; select new { oldPriceItem, newPriceItem };
oldPrices.ForEach(t => t.IsCancel = true); oldPrices.ForEach(t => t.IsCancel = true);
if (oldPriceNewDate.Any()) if (oldPriceNewDate.Any())
{ {
oldPrices.FindAll(t => oldPriceNewDate.Contains(t)).ForEach(t => t.IsCancel = false); oldPrices.FindAll(t => t.IsCancel == true && oldPriceNewDate.Select(t => t.oldPriceItem).Contains(t)).ForEach(t => t.IsCancel = false);
var importCancelLus = oldPrices.Select(t => t.LU).Distinct(); newPrice.FindAll(t => t.IsCancel == false && oldPriceNewDate.Select(t => t.newPriceItem).Contains(t)).ForEach(t => t.IsCancel = true);
newPrice.FindAll(t => importCancelLus.Contains(t.LU)).ForEach(t => t.IsCancel = true);
} }
foreach (var item in newPrice) foreach (var item in newPrice)
{ {
@ -139,14 +147,17 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase<PriceListBJ>
return priceList; // 只有一个或零个价格条目 return priceList; // 只有一个或零个价格条目
} }
var clientCodeGroup = priceList.GroupBy(t => t.ClientCode); var dateGroups = priceList.GroupBy(t => t.Date);
foreach (var item in clientCodeGroup) foreach (var dateGroup in dateGroups)
{ {
if (item.ToList().Count <= 1) var clientCodeGroups = dateGroup.GroupBy(t => t.ClientCode);
foreach (var clientCodeGroup in clientCodeGroups)
{
if (clientCodeGroup.ToList().Count <= 1)
{ {
continue; continue;
} }
var sortedList = item.OrderBy(t => t.LU).ThenBy(t => t.BeginDate).ToList(); var sortedList = clientCodeGroup.OrderBy(t => t.LU).ThenBy(t => t.BeginDate).ToList();
for (var i = 1; i < sortedList.Count; i++) for (var i = 1; i < sortedList.Count; i++)
{ {
if (sortedList[i].LU == sortedList[i - 1].LU && sortedList[i].BeginDate != sortedList[i - 1].EndDate.AddDays(1)) if (sortedList[i].LU == sortedList[i - 1].LU && sortedList[i].BeginDate != sortedList[i - 1].EndDate.AddDays(1))
@ -155,8 +166,9 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase<PriceListBJ>
} }
} }
} }
}
return result; return result; // 所有价格时间都连续
} }
/// <summary> /// <summary>

4
code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs

@ -52,6 +52,10 @@ namespace Win.Sfs.SettleAccount.ExcelImporter
public virtual async Task<List<T>> UploadExcelImport<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService) public virtual async Task<List<T>> UploadExcelImport<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService)
where T : class, new() where T : class, new()
{ {
if (files.Count > 1)
{
throw new UserFriendlyException("只能上传一个附件!", "400");
}
using var fs = ServiceProvider.CreateScope(); using var fs = ServiceProvider.CreateScope();
var fc = fs.ServiceProvider.GetRequiredService<IBlobContainer<MyFileContainer>>(); var fc = fs.ServiceProvider.GetRequiredService<IBlobContainer<MyFileContainer>>();
Type type = typeof(T).GetType(); Type type = typeof(T).GetType();

Loading…
Cancel
Save