|
@ -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; // 所有价格时间都连续
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|