|
|
@ -1,18 +1,11 @@ |
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq.Dynamic.Core; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using EFCore.BulkExtensions; |
|
|
|
using Magicodes.ExporterAndImporter.Core; |
|
|
|
using Magicodes.ExporterAndImporter.Excel; |
|
|
|
using Microsoft.AspNetCore.SignalR; |
|
|
|
using Microsoft.OpenApi.Extensions; |
|
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
|
|
|
using SettleAccount.Bases; |
|
|
|
using SettleAccount.Domain.BQ; |
|
|
|
using SettleAccount.Job.SignalR; |
|
|
|
using Shouldly; |
|
|
@ -80,7 +73,8 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
var seStartDateTime = DateTime.Parse(strSeStartDateTime); |
|
|
|
var seEndDateTime = DateTime.Parse(strSeEndDateTime); |
|
|
|
var filename = exportName.FirstOrDefault(); |
|
|
|
var pubSaSeCompareDiffs = GetSaSeCompareDataJis<BBAC_SA_DETAIL, BBAC_SE_DETAIL>(EnumBusinessType.MaiDanJianBBAC, version, seStartDateTime, seEndDateTime); |
|
|
|
//var pubSaSeCompareDiffs = GetSaSeCompareDataJis<BBAC_SA_DETAIL, BBAC_SE_DETAIL>(EnumBusinessType.MaiDanJianBBAC, version, seStartDateTime, seEndDateTime);
|
|
|
|
var pubSaSeCompareDiffs = GetSaSeCompareDataJis(version, seStartDateTime, seEndDateTime); |
|
|
|
|
|
|
|
HandlePubSaSeCompareDiffList(pubSaSeCompareDiffs); |
|
|
|
|
|
|
@ -130,6 +124,141 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
return id.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取结算、发运比对数据
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// 获取全量有结算无发运的数据
|
|
|
|
/// 获取全量无结算有发运的数据
|
|
|
|
/// 获取当期有结算有发运的数据
|
|
|
|
/// </remarks>
|
|
|
|
public List<SaSeCompareDiff> GetSaSeCompareDataJis(int version, DateTime seStartDateTime, DateTime seEndDateTime) |
|
|
|
{ |
|
|
|
//结算
|
|
|
|
var saGroup = from sa in _settleAccountDbContext.Set<BBAC_SA_DETAIL>() |
|
|
|
where sa.BusinessType == businessType |
|
|
|
group sa by new { sa.PN, sa.CustomerPartCodeNoSpace } into groupItem |
|
|
|
select new |
|
|
|
{ |
|
|
|
groupItem.Key.PN, |
|
|
|
groupItem.Key.CustomerPartCodeNoSpace, |
|
|
|
Qty = groupItem.Sum(t => t.Qty), |
|
|
|
Version = groupItem.Max(t => t.Version), |
|
|
|
LU = groupItem.Max(t => t.LU), |
|
|
|
SettleDate = groupItem.Max(t => t.SettleDate), |
|
|
|
PartCode = groupItem.Max(t => t.PartCode), |
|
|
|
CodeType = groupItem.Max(t => t.ProductionCodeType) |
|
|
|
}; |
|
|
|
var saGroupByMappingType = from sa in _settleAccountDbContext.Set<BBAC_SA_DETAIL>() |
|
|
|
where sa.BusinessType == businessType && sa.MappingType == EnumMappingType.None |
|
|
|
group sa by new { sa.PN, sa.CustomerPartCodeNoSpace } into groupItem |
|
|
|
select new |
|
|
|
{ |
|
|
|
groupItem.Key.PN, |
|
|
|
groupItem.Key.CustomerPartCodeNoSpace, |
|
|
|
Qty = groupItem.Sum(t => t.Qty), |
|
|
|
Version = groupItem.Max(t => t.Version), |
|
|
|
LU = groupItem.Max(t => t.LU), |
|
|
|
SettleDate = groupItem.Max(t => t.SettleDate), |
|
|
|
PartCode = groupItem.Max(t => t.PartCode), |
|
|
|
CodeType = groupItem.Max(t => t.ProductionCodeType) |
|
|
|
}; |
|
|
|
var saGroupByVersion = from sa in _settleAccountDbContext.Set<BBAC_SA_DETAIL>() |
|
|
|
where sa.BusinessType == businessType && sa.Version == version |
|
|
|
group sa by new { sa.PN, sa.CustomerPartCodeNoSpace } into groupItem |
|
|
|
select new |
|
|
|
{ |
|
|
|
groupItem.Key.PN, |
|
|
|
groupItem.Key.CustomerPartCodeNoSpace, |
|
|
|
Qty = groupItem.Sum(t => t.Qty), |
|
|
|
Version = groupItem.Max(t => t.Version), |
|
|
|
LU = groupItem.Max(t => t.LU), |
|
|
|
SettleDate = groupItem.Max(t => t.SettleDate), |
|
|
|
PartCode = groupItem.Max(t => t.PartCode), |
|
|
|
CodeType = groupItem.Max(t => t.ProductionCodeType) |
|
|
|
}; |
|
|
|
//发运
|
|
|
|
var seGroup = from se in _settleAccountDbContext.Set<BBAC_SE_DETAIL>() |
|
|
|
where se.BusinessType == businessType && se.BillTime >= seStartDateTime && se.BillTime <= seEndDateTime |
|
|
|
group se by new { se.PN, se.CustomerPartCodeNoSpace } into groupItem |
|
|
|
select new |
|
|
|
{ |
|
|
|
groupItem.Key.PN, |
|
|
|
groupItem.Key.CustomerPartCodeNoSpace, |
|
|
|
Qty = groupItem.Sum(t => t.Qty), |
|
|
|
LU = groupItem.Max(t => t.LU), |
|
|
|
WmsBillNum = groupItem.Max(t => t.WmsBillNum), |
|
|
|
ShippingDate = groupItem.Max(t => t.ShippingDate), |
|
|
|
FactoryPartCode = groupItem.Max(t => t.FactoryPartCode), |
|
|
|
ToLocCode = groupItem.Max(t => t.ToLoc), |
|
|
|
ToErpLocCode = groupItem.Max(t => t.ErpToLoc), |
|
|
|
CodeType = groupItem.Max(t => t.CodeType) |
|
|
|
}; |
|
|
|
|
|
|
|
//有结算无发运
|
|
|
|
var haveSaNotHaveSeList = (from sa in saGroupByMappingType |
|
|
|
join se in seGroup |
|
|
|
on new { sa.PN, sa.CustomerPartCodeNoSpace } equals new { se.PN, se.CustomerPartCodeNoSpace } |
|
|
|
into temp |
|
|
|
from se in temp.DefaultIfEmpty() |
|
|
|
where se.PN == null |
|
|
|
select new SaSeCompareDiff() |
|
|
|
{ |
|
|
|
Version = sa.Version, |
|
|
|
CustomerOfflineTime = sa.SettleDate, |
|
|
|
PN = sa.PN, |
|
|
|
SAQty = sa.Qty, |
|
|
|
SaCustomerPartCode = sa.CustomerPartCodeNoSpace, |
|
|
|
SaFactoryPartCode = sa.PartCode, |
|
|
|
CustomerPartCode = sa.LU, |
|
|
|
CodeType = sa.CodeType |
|
|
|
}).ToList(); |
|
|
|
//无结算有发运
|
|
|
|
var notHaveSaHaveSeList = (from se in seGroup |
|
|
|
join sa in saGroup |
|
|
|
on new { se.PN, se.CustomerPartCodeNoSpace } equals new { sa.PN, sa.CustomerPartCodeNoSpace } |
|
|
|
into temp |
|
|
|
from sa in temp.DefaultIfEmpty() |
|
|
|
where sa.PN == null |
|
|
|
select new SaSeCompareDiff() |
|
|
|
{ |
|
|
|
WmsBillNum = se.WmsBillNum, |
|
|
|
ShippingDate = se.ShippingDate, |
|
|
|
PN = se.PN, |
|
|
|
SEQty = se.Qty, |
|
|
|
ToLocCode = se.ToLocCode, |
|
|
|
ToErpLocCode = se.ToErpLocCode, |
|
|
|
SeCustomerPartCode = se.CustomerPartCodeNoSpace, |
|
|
|
SeFactoryPartCode = se.FactoryPartCode, |
|
|
|
CustomerPartCode = se.LU, |
|
|
|
CodeType = se.CodeType |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
//有结算有发运
|
|
|
|
var haveSaHaveSeList = (from sa in saGroupByVersion |
|
|
|
from se in seGroup |
|
|
|
where sa.PN == se.PN && sa.CustomerPartCodeNoSpace == se.CustomerPartCodeNoSpace |
|
|
|
select new SaSeCompareDiff() |
|
|
|
{ |
|
|
|
Version = sa.Version, |
|
|
|
WmsBillNum = se.WmsBillNum, |
|
|
|
ShippingDate = se.ShippingDate, |
|
|
|
CustomerOfflineTime = sa.SettleDate, |
|
|
|
PN = sa.PN, |
|
|
|
SAQty = sa.Qty, |
|
|
|
SEQty = se.Qty, |
|
|
|
ToLocCode = se.ToLocCode, |
|
|
|
ToErpLocCode = se.ToErpLocCode, |
|
|
|
SeCustomerPartCode = se.CustomerPartCodeNoSpace, |
|
|
|
SeFactoryPartCode = se.FactoryPartCode, |
|
|
|
SaCustomerPartCode = sa.CustomerPartCodeNoSpace, |
|
|
|
SaFactoryPartCode = sa.PartCode, |
|
|
|
CustomerPartCode = sa.LU, |
|
|
|
CodeType = sa.CodeType |
|
|
|
}).ToList(); |
|
|
|
return haveSaHaveSeList.Union(haveSaNotHaveSeList).Union(notHaveSaHaveSeList).ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 三次比对
|
|
|
|
/// </summary>
|
|
|
@ -149,16 +278,18 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
//无结算有发运
|
|
|
|
var notHaveSaHaveSes = saSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.NotHaveSaHaveSe); |
|
|
|
|
|
|
|
var haveSaNotHaveSeHashCodes = haveSaNotHaveSes.OrderBy(t => t.CustomerPartCode).GroupBy(t => t.PN).Select(t => new |
|
|
|
var haveSaNotHaveSeHashCodes = haveSaNotHaveSes.OrderBy(t => t.CustomerPartCode).GroupBy(t => new { t.CodeType, t.PN }).Select(t => new |
|
|
|
{ |
|
|
|
PN = t.Key, |
|
|
|
t.Key.CodeType, |
|
|
|
t.Key.PN, |
|
|
|
PartCodeHashCode = t.Select(t => t.CustomerPartCode).Aggregate((current, index) => $"{current};{index}").GetHashCode(), |
|
|
|
QtyHashCode = t.Select(t => t.SAQty.ToString()).Aggregate((current, index) => $"{current};{index}") |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
var notHaveSaHaveSeHashCodes = notHaveSaHaveSes.OrderBy(t => t.CustomerPartCode).GroupBy(t => t.PN).Select(t => new |
|
|
|
var notHaveSaHaveSeHashCodes = notHaveSaHaveSes.OrderBy(t => t.CustomerPartCode).GroupBy(t => new { t.CodeType, t.PN }).Select(t => new |
|
|
|
{ |
|
|
|
PN = t.Key, |
|
|
|
t.Key.CodeType, |
|
|
|
t.Key.PN, |
|
|
|
PartCodeHashCode = t.Select(t => t.CustomerPartCode).Aggregate((current, index) => $"{current};{index}").GetHashCode(), |
|
|
|
QtyHashCode = t.Select(t => t.SEQty.ToString()).Aggregate((current, index) => $"{current};{index}") |
|
|
|
}).ToList(); |
|
|
@ -168,7 +299,7 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
|
|
|
|
haveSaNotHaveSeHashCodes.ForEach(haveSaNotHaveSeHashCode => |
|
|
|
{ |
|
|
|
var matchPN = notHaveSaHaveSeHashCodes.FirstOrDefault(t => t.PartCodeHashCode == haveSaNotHaveSeHashCode.PartCodeHashCode && t.QtyHashCode == haveSaNotHaveSeHashCode.QtyHashCode && matchPNs.ContainsKey(t.PN) == false); |
|
|
|
var matchPN = notHaveSaHaveSeHashCodes.FirstOrDefault(t => t.CodeType == haveSaNotHaveSeHashCode.CodeType && t.PartCodeHashCode == haveSaNotHaveSeHashCode.PartCodeHashCode && t.QtyHashCode == haveSaNotHaveSeHashCode.QtyHashCode && matchPNs.ContainsKey(t.PN) == false); |
|
|
|
|
|
|
|
if (matchPN != null) |
|
|
|
{ |
|
|
@ -204,7 +335,8 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
PartCodeDesc = haveSaNotHaveSe.PartCodeDesc, |
|
|
|
FactoryPartCode = haveSaNotHaveSe.FactoryPartCode, |
|
|
|
ReplaceFactoryPartCode = haveSaNotHaveSe.ReplaceFactoryPartCode, |
|
|
|
IsUpdateMappingType = false |
|
|
|
IsUpdateMappingType = false, |
|
|
|
CodeType = haveSaNotHaveSe.CodeType |
|
|
|
}).ToList(); |
|
|
|
threeMatchHaveSaHaveSes.AddRange(threeMatchHaveSaHaveSesItem); |
|
|
|
} |
|
|
|