|
|
@ -24,14 +24,10 @@ using Win.Sfs.Shared.RepositoryBase; |
|
|
|
namespace SettleAccount.Job.Services.Report |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Pub结算发运对比导出服务
|
|
|
|
/// 结算、发运对比导出服务
|
|
|
|
/// </summary>
|
|
|
|
public class PubSaSeCompareExportService : SaSeCompareExportBaseService, ITransientDependency, IExportJob |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// HubContext
|
|
|
|
/// </summary>
|
|
|
|
private readonly IHubContext<PageHub> _hubContext; |
|
|
|
/// <summary>
|
|
|
|
/// DbContext
|
|
|
|
/// </summary>
|
|
|
@ -40,22 +36,18 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
/// 替换件关系仓储
|
|
|
|
/// </summary>
|
|
|
|
private readonly INormalEfCoreRepository<TB_RePartsRelationship, Guid> _tbRePartsRelationshipRepository; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// PUB二次比对仓储
|
|
|
|
/// </summary>
|
|
|
|
private readonly INormalEfCoreRepository<PUB_SEC_DETAIL, Guid> _pubSeCDetailRepository; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Pub结算发运对比Dapper
|
|
|
|
/// </summary>
|
|
|
|
private readonly PubSaSeCompareDapperRepository _pubSaSeCompareDapperRepository; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 文件容器
|
|
|
|
/// </summary>
|
|
|
|
private readonly IBlobContainer<MyFileContainer> _fileContainer; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// AutoMapper
|
|
|
|
/// </summary>
|
|
|
@ -71,9 +63,8 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
INormalEfCoreRepository<PUB_SEC_DETAIL, Guid> pubSeCDetailRepository, |
|
|
|
PubSaSeCompareDapperRepository pubSaSeCompareDapperRepository, |
|
|
|
IBlobContainer<MyFileContainer> fileContainer, |
|
|
|
IObjectMapper objectMapper) : base(hubContext) |
|
|
|
IObjectMapper objectMapper) : base(hubContext, settleAccountDbContext) |
|
|
|
{ |
|
|
|
_hubContext = hubContext; |
|
|
|
_settleAccountDbContext = settleAccountDbContext; |
|
|
|
_tbRePartsRelationshipRepository = tbRePartsRelationshipRepository; |
|
|
|
_pubSeCDetailRepository = pubSeCDetailRepository; |
|
|
@ -114,59 +105,9 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
|
|
|
|
HandlePubSaSeCompareDiffList(pubSaSeCompareDiffs); |
|
|
|
|
|
|
|
//有结算有发运
|
|
|
|
var haveSaHaveSes = pubSaSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.HaveSaHaveSe); |
|
|
|
//有结算无发运
|
|
|
|
var haveSaNotHaveSes = pubSaSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.HaveSaNotHaveSe); |
|
|
|
//无结算有发运
|
|
|
|
var notHaveSaHaveSes = pubSaSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.NotHaveSaHaveSe); |
|
|
|
//二次匹配上的记录
|
|
|
|
var secondMatchHaveSaHaveSes = new List<PubSaSeCompareDiff>(); |
|
|
|
|
|
|
|
#region 二次对比
|
|
|
|
//二次对比(替换无结算有发运数据的厂内零件号)
|
|
|
|
var repFactoryPartCodes = notHaveSaHaveSes.Select(t => t.FactoryPartCode).Distinct().ToList(); |
|
|
|
|
|
|
|
var tbRePartsRelationships = _settleAccountDbContext.Set<TB_RePartsRelationship>().Where(t => repFactoryPartCodes.Contains(t.LU) && t.BusinessType == businessType).ToList(); |
|
|
|
//var tbRePartsRelationshipsOld = _tbRePartsRelationshipRepository.GetListAsync(t => repFactoryPartCodes.Contains(t.LU) && t.BusinessType == businessType).Result;
|
|
|
|
|
|
|
|
tbRePartsRelationships.ForEach(tbRePartsRelationship => |
|
|
|
{ |
|
|
|
notHaveSaHaveSes.FindAll(t => t.FactoryPartCode == tbRePartsRelationship.LU).ForEach(t => |
|
|
|
{ |
|
|
|
t.ReplaceFactoryPartCode = tbRePartsRelationship.RepLU; |
|
|
|
t.IsReplace = true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
//获取二次比对上的数据
|
|
|
|
secondMatchHaveSaHaveSes = (from notHaveSaHaveSe in notHaveSaHaveSes |
|
|
|
join haveSaNotHaveSe in haveSaNotHaveSes |
|
|
|
on new { notHaveSaHaveSe.PN, notHaveSaHaveSe.ReplaceFactoryPartCode } equals new { haveSaNotHaveSe.PN, haveSaNotHaveSe.ReplaceFactoryPartCode } |
|
|
|
where notHaveSaHaveSe.IsReplace == true |
|
|
|
select new PubSaSeCompareDiff() |
|
|
|
{ |
|
|
|
WmsBillNum = notHaveSaHaveSe.WmsBillNum, |
|
|
|
ShippingDate = notHaveSaHaveSe.ShippingDate, |
|
|
|
SeqNumber = notHaveSaHaveSe.SeqNumber, |
|
|
|
PJISSeqNumber = notHaveSaHaveSe.PJISSeqNumber, |
|
|
|
CustomerOfflineTime = haveSaNotHaveSe.CustomerOfflineTime, |
|
|
|
SAQty = haveSaNotHaveSe.SAQty, |
|
|
|
SEQty = notHaveSaHaveSe.SEQty, |
|
|
|
FixPrice = haveSaNotHaveSe.FixPrice, |
|
|
|
PN = haveSaNotHaveSe.PN, |
|
|
|
ToLocCode = notHaveSaHaveSe.ToLocCode, |
|
|
|
ToErpLocCode = notHaveSaHaveSe.ToErpLocCode, |
|
|
|
Category = EnumPubSaSeCompareCategory.HaveSaHaveSe, |
|
|
|
SeCustomerPartCode = notHaveSaHaveSe.SeCustomerPartCode, |
|
|
|
SeFactoryPartCode = notHaveSaHaveSe.SeFactoryPartCode, |
|
|
|
SaCustomerPartCode = haveSaNotHaveSe.SaCustomerPartCode, |
|
|
|
SaFactoryPartCode = haveSaNotHaveSe.SaFactoryPartCode, |
|
|
|
CustomerPartCode = notHaveSaHaveSe.CustomerPartCode, |
|
|
|
PartCodeDesc = notHaveSaHaveSe.PartCodeDesc, |
|
|
|
FactoryPartCode = notHaveSaHaveSe.FactoryPartCode, |
|
|
|
ReplaceFactoryPartCode = notHaveSaHaveSe.ReplaceFactoryPartCode |
|
|
|
}).ToList(); |
|
|
|
//二次匹配上的记录
|
|
|
|
var secondMatchHaveSaHaveSes = HandleSecondCompare(pubSaSeCompareDiffs, businessType); |
|
|
|
if (secondMatchHaveSaHaveSes.Any()) |
|
|
|
{ |
|
|
|
//二次匹配 匹配上的厂内零件号、PN
|
|
|
@ -273,10 +214,15 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
|
|
|
|
#region 私有方法
|
|
|
|
/// <summary>
|
|
|
|
/// 获取结算与发运比对数据
|
|
|
|
/// 获取比对数据
|
|
|
|
/// </summary>
|
|
|
|
public List<PubSaSeCompareDiff> GetSaSeCompareData(EnumBusinessType businessType, int version, DateTime seStartDateTime, DateTime seEndDateTime) |
|
|
|
{ |
|
|
|
//印度件LU对比
|
|
|
|
if (businessType == EnumBusinessType.YinDuJian) |
|
|
|
{ |
|
|
|
return GetSaSeCompareDataYinDu(version, seStartDateTime, seEndDateTime); |
|
|
|
} |
|
|
|
//结算
|
|
|
|
var saGroup = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>() |
|
|
|
where sa.BusinessType == businessType && sa.Version == version |
|
|
@ -305,7 +251,7 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
ToLocCode = groupItem.Max(t => t.ToLocCode), |
|
|
|
ToErpLocCode = groupItem.Max(t => t.ToErpLocCode) |
|
|
|
}; |
|
|
|
var saSeCompareLeft = (from sa in saGroup |
|
|
|
var saSeCompareLeft = from sa in saGroup |
|
|
|
join se in seGroup |
|
|
|
on new { sa.PN, sa.LU } equals new { se.PN, se.LU } |
|
|
|
into temp |
|
|
@ -315,7 +261,7 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
WmsBillNum = se.WmsBillNum, |
|
|
|
ShippingDate = se.ShippingDate, |
|
|
|
CustomerOfflineTime = sa.SettleDate, |
|
|
|
PN = sa.LU, |
|
|
|
PN = sa.PN, |
|
|
|
SAQty = sa.Qty, |
|
|
|
SEQty = se.Qty, |
|
|
|
FixPrice = sa.Price, |
|
|
@ -325,8 +271,8 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
SeFactoryPartCode = se.FactoryPartCode, |
|
|
|
SaCustomerPartCode = sa.LU, |
|
|
|
SaFactoryPartCode = sa.PartCode |
|
|
|
}); |
|
|
|
var saSeCompareRight = (from se in seGroup |
|
|
|
}; |
|
|
|
var saSeCompareRight = from se in seGroup |
|
|
|
join sa in saGroup |
|
|
|
on new { se.PN, se.LU } equals new { sa.PN, sa.LU } |
|
|
|
into temp |
|
|
@ -336,7 +282,7 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
WmsBillNum = se.WmsBillNum, |
|
|
|
ShippingDate = se.ShippingDate, |
|
|
|
CustomerOfflineTime = sa.SettleDate, |
|
|
|
PN = se.LU, |
|
|
|
PN = se.PN, |
|
|
|
SAQty = sa.Qty, |
|
|
|
SEQty = se.Qty, |
|
|
|
FixPrice = sa.Price, |
|
|
@ -346,28 +292,33 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
SeFactoryPartCode = se.FactoryPartCode, |
|
|
|
SaCustomerPartCode = sa.LU, |
|
|
|
SaFactoryPartCode = sa.PartCode |
|
|
|
}); |
|
|
|
//印度件LU对比
|
|
|
|
if (businessType == EnumBusinessType.YinDuJian && (1 + 1) == 3) |
|
|
|
}; |
|
|
|
|
|
|
|
var saSeCompareFullJoin = saSeCompareLeft.Union(saSeCompareRight).ToList(); |
|
|
|
return saSeCompareFullJoin; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取比对数据
|
|
|
|
/// </summary>
|
|
|
|
public List<PubSaSeCompareDiff> GetSaSeCompareDataYinDu(int version, DateTime seStartDateTime, DateTime seEndDateTime) |
|
|
|
{ |
|
|
|
saGroup = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>() |
|
|
|
where sa.BusinessType == businessType && sa.Version == version |
|
|
|
var saGroup = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>() |
|
|
|
where sa.BusinessType == EnumBusinessType.YinDuJian && sa.Version == version |
|
|
|
group sa by new { sa.LU } into groupItem |
|
|
|
select new |
|
|
|
{ |
|
|
|
PN = "", |
|
|
|
groupItem.Key.LU, |
|
|
|
Qty = groupItem.Sum(t => t.Qty), |
|
|
|
Price = groupItem.Max(t => t.Price), |
|
|
|
SettleDate = groupItem.Max(t => t.SettleDate), |
|
|
|
PartCode = groupItem.Max(t => t.PartCode), |
|
|
|
}; |
|
|
|
seGroup = from se in _settleAccountDbContext.Set<PUB_SE_DETAIL>() |
|
|
|
where se.BusinessType == businessType && se.BillTime >= seStartDateTime && se.BillTime <= seEndDateTime |
|
|
|
var seGroup = from se in _settleAccountDbContext.Set<PUB_SE_DETAIL>() |
|
|
|
where se.BusinessType == EnumBusinessType.YinDuJian && se.BillTime >= seStartDateTime && se.BillTime <= seEndDateTime |
|
|
|
group se by new { se.LU } into groupItem |
|
|
|
select new |
|
|
|
{ |
|
|
|
PN = "", |
|
|
|
groupItem.Key.LU, |
|
|
|
Qty = groupItem.Sum(t => t.Qty), |
|
|
|
WmsBillNum = groupItem.Max(t => t.WmsBillNum), |
|
|
@ -376,9 +327,48 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
ToLocCode = groupItem.Max(t => t.ToLocCode), |
|
|
|
ToErpLocCode = groupItem.Max(t => t.ToErpLocCode) |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
var saSeCompareFullJoin = saSeCompareLeft.Concat(saSeCompareRight).ToList(); |
|
|
|
var saSeCompareLeft = from sa in saGroup |
|
|
|
join se in seGroup |
|
|
|
on sa.LU equals se.LU |
|
|
|
into temp |
|
|
|
from se in temp.DefaultIfEmpty() |
|
|
|
select new PubSaSeCompareDiff() |
|
|
|
{ |
|
|
|
WmsBillNum = se.WmsBillNum, |
|
|
|
ShippingDate = se.ShippingDate, |
|
|
|
CustomerOfflineTime = sa.SettleDate, |
|
|
|
SAQty = sa.Qty, |
|
|
|
SEQty = se.Qty, |
|
|
|
FixPrice = sa.Price, |
|
|
|
ToLocCode = se.ToLocCode, |
|
|
|
ToErpLocCode = se.ToErpLocCode, |
|
|
|
SeCustomerPartCode = se.LU, |
|
|
|
SeFactoryPartCode = se.FactoryPartCode, |
|
|
|
SaCustomerPartCode = sa.LU, |
|
|
|
SaFactoryPartCode = sa.PartCode |
|
|
|
}; |
|
|
|
var saSeCompareRight = from se in seGroup |
|
|
|
join sa in saGroup |
|
|
|
on se.LU equals sa.LU |
|
|
|
into temp |
|
|
|
from sa in temp.DefaultIfEmpty() |
|
|
|
select new PubSaSeCompareDiff() |
|
|
|
{ |
|
|
|
WmsBillNum = se.WmsBillNum, |
|
|
|
ShippingDate = se.ShippingDate, |
|
|
|
CustomerOfflineTime = sa.SettleDate, |
|
|
|
SAQty = sa.Qty, |
|
|
|
SEQty = se.Qty, |
|
|
|
FixPrice = sa.Price, |
|
|
|
ToLocCode = se.ToLocCode, |
|
|
|
ToErpLocCode = se.ToErpLocCode, |
|
|
|
SeCustomerPartCode = se.LU, |
|
|
|
SeFactoryPartCode = se.FactoryPartCode, |
|
|
|
SaCustomerPartCode = sa.LU, |
|
|
|
SaFactoryPartCode = sa.PartCode |
|
|
|
}; |
|
|
|
var saSeCompareFullJoin = saSeCompareLeft.Union(saSeCompareRight).ToList(); |
|
|
|
return saSeCompareFullJoin; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|