|
|
@ -32,7 +32,10 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
/// HubContext
|
|
|
|
/// </summary>
|
|
|
|
private readonly IHubContext<PageHub> _hubContext; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// DbContext
|
|
|
|
/// </summary>
|
|
|
|
private readonly SettleAccountDbContext _settleAccountDbContext; |
|
|
|
/// <summary>
|
|
|
|
/// 替换件关系仓储
|
|
|
|
/// </summary>
|
|
|
@ -63,6 +66,7 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
/// </summary>
|
|
|
|
public PubSaSeCompareExportService( |
|
|
|
IHubContext<PageHub> hubContext, |
|
|
|
SettleAccountDbContext settleAccountDbContext, |
|
|
|
INormalEfCoreRepository<TB_RePartsRelationship, Guid> tbRePartsRelationshipRepository, |
|
|
|
INormalEfCoreRepository<PUB_SEC_DETAIL, Guid> pubSeCDetailRepository, |
|
|
|
PubSaSeCompareDapperRepository pubSaSeCompareDapperRepository, |
|
|
@ -70,6 +74,7 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
IObjectMapper objectMapper) |
|
|
|
{ |
|
|
|
_hubContext = hubContext; |
|
|
|
_settleAccountDbContext = settleAccountDbContext; |
|
|
|
_tbRePartsRelationshipRepository = tbRePartsRelationshipRepository; |
|
|
|
_pubSeCDetailRepository = pubSeCDetailRepository; |
|
|
|
_pubSaSeCompareDapperRepository = pubSaSeCompareDapperRepository; |
|
|
@ -104,7 +109,8 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
businessTypeDisplayName = attributeOfType.Name; |
|
|
|
} |
|
|
|
var filename = exportName.FirstOrDefault(); |
|
|
|
var pubSaSeCompareDiffs = _pubSaSeCompareDapperRepository.GetDetailDiffReportList(strBusinessType, version, seStartDateTime, seEndDateTime); |
|
|
|
//var pubSaSeCompareDiffs = _pubSaSeCompareDapperRepository.GetDetailDiffReportList(strBusinessType, version, seStartDateTime, seEndDateTime);
|
|
|
|
var pubSaSeCompareDiffs = GetSaSeCompareData(businessType, int.Parse(version), DateTime.Parse(seStartDateTime), DateTime.Parse(seEndDateTime)); |
|
|
|
|
|
|
|
pubSaSeCompareDiffs.ForEach(p => |
|
|
|
{ |
|
|
@ -155,30 +161,77 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
var secondMatchHaveSaHaveSes = new List<PubSaSeCompareDiff>(); |
|
|
|
|
|
|
|
#region 二次对比
|
|
|
|
////二次对比(替换零件号)
|
|
|
|
//var repLUs = notHaveSaHaveSes.Select(t => t.SeLU).Distinct().ToList();
|
|
|
|
//var tbRePartsRelationships = _tbRePartsRelationshipRepository.GetListAsync(t => repLUs.Contains(t.RepLU) && t.BusinessType == businessType).Result;
|
|
|
|
//二次对比(替换无结算有发运数据的厂内零件号)
|
|
|
|
var repFactoryPartCodes = notHaveSaHaveSes.Select(t => t.FactoryPartCode).Distinct().ToList(); |
|
|
|
|
|
|
|
//tbRePartsRelationships.ForEach(tbRePartsRelationship =>
|
|
|
|
//{
|
|
|
|
// notHaveSaHaveSes.FindAll(t => t.SeLU == tbRePartsRelationship.RepLU).ForEach(t =>
|
|
|
|
// {
|
|
|
|
// t.ReplaceLU = tbRePartsRelationship.LU;
|
|
|
|
// });
|
|
|
|
//});
|
|
|
|
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; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
//var haveSaNotHaveSeLUPNs = haveSaNotHaveSes.Select(t => new { t.ReplaceLU, t.PN });
|
|
|
|
//var notHaveSaHaveSeLUPNs = notHaveSaHaveSes.Select(t => new { t.ReplaceLU, t.PN });
|
|
|
|
////二次匹配 匹配上的零件号
|
|
|
|
//var secondMatchLUPNs = haveSaNotHaveSeLUPNs.Intersect(notHaveSaHaveSeLUPNs);
|
|
|
|
//if (secondMatchLUPNs.Any() == 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(); |
|
|
|
if (secondMatchHaveSaHaveSes.Any()) |
|
|
|
{ |
|
|
|
//二次匹配 匹配上的厂内零件号、PN
|
|
|
|
var secondMatchFPartCodePNs = secondMatchHaveSaHaveSes.Select(t => new { t.ReplaceFactoryPartCode, t.PN }); |
|
|
|
pubSaSeCompareDiffs.RemoveAll<PubSaSeCompareDiff>(t => secondMatchFPartCodePNs.Contains(new { t.ReplaceFactoryPartCode, t.PN })); |
|
|
|
pubSaSeCompareDiffs.AddRange(secondMatchHaveSaHaveSes); |
|
|
|
//二次对比比对上的数据入库
|
|
|
|
var pubSeCDetailEntitys = _objectMapper.Map<List<PubSaSeCompareDiff>, List<PUB_SEC_DETAIL>>(secondMatchHaveSaHaveSes); |
|
|
|
_settleAccountDbContext.Set<PUB_SEC_DETAIL>().AddRange(pubSeCDetailEntitys); |
|
|
|
//_pubSeCDetailRepository.InsertManyAsync(pubSeCDetailEntitys);
|
|
|
|
} |
|
|
|
|
|
|
|
//var haveSaNotHaveSeFPartCodePNs = haveSaNotHaveSes.Select(t => new { t.ReplaceFactoryPartCode, t.PN });
|
|
|
|
//var notHaveSaHaveSeFPartCodePNs = notHaveSaHaveSes.Select(t => new { t.ReplaceFactoryPartCode, t.PN });
|
|
|
|
////二次匹配 匹配上的厂内零件号、PN
|
|
|
|
//var secondMatchFPartCodePNs = haveSaNotHaveSeFPartCodePNs.Intersect(notHaveSaHaveSeFPartCodePNs);
|
|
|
|
//if (secondMatchFPartCodePNs.Any() == true)
|
|
|
|
//{
|
|
|
|
// pubSaSeCompareDiffs.RemoveAll<PubSaSeCompareDiff>(t => secondMatchLUPNs.Contains(new { t.ReplaceLU, t.PN }));
|
|
|
|
// pubSaSeCompareDiffs.RemoveAll<PubSaSeCompareDiff>(t => secondMatchFPartCodePNs.Contains(new { t.ReplaceFactoryPartCode, t.PN }));
|
|
|
|
|
|
|
|
// foreach (var secondMatchLUPN in secondMatchLUPNs)
|
|
|
|
// foreach (var secondMatchFPartCodePN in secondMatchFPartCodePNs)
|
|
|
|
// {
|
|
|
|
// var haveSaNotHaveSe = haveSaNotHaveSes.FirstOrDefault(t => t.ReplaceLU == secondMatchLUPN.ReplaceLU && t.PN == secondMatchLUPN.PN);
|
|
|
|
// var notHaveSaHaveSe = notHaveSaHaveSes.FirstOrDefault(t => t.ReplaceLU == secondMatchLUPN.ReplaceLU && t.PN == secondMatchLUPN.PN);
|
|
|
|
// var haveSaNotHaveSe = haveSaNotHaveSes.FirstOrDefault(t => t.ReplaceFactoryPartCode == secondMatchFPartCodePN.ReplaceFactoryPartCode && t.PN == secondMatchFPartCodePN.PN);
|
|
|
|
// var notHaveSaHaveSe = notHaveSaHaveSes.FirstOrDefault(t => t.ReplaceFactoryPartCode == secondMatchFPartCodePN.ReplaceFactoryPartCode && t.PN == secondMatchFPartCodePN.PN);
|
|
|
|
// if (haveSaNotHaveSe != null && notHaveSaHaveSe != null)
|
|
|
|
// {
|
|
|
|
|
|
|
|
// }
|
|
|
|
// secondMatchHaveSaHaveSes.Add(new PubSaSeCompareDiff()
|
|
|
|
// {
|
|
|
|
// WmsBillNum = notHaveSaHaveSe.WmsBillNum,
|
|
|
@ -202,15 +255,6 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
// });
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
////二次对比比对上的数据入库
|
|
|
|
//if (secondMatchHaveSaHaveSes.Count > 0)
|
|
|
|
//{
|
|
|
|
// pubSaSeCompareDiffs.AddRange(secondMatchHaveSaHaveSes);
|
|
|
|
|
|
|
|
// var pubSeCDetailEntitys = _objectMapper.Map<List<PubSaSeCompareDiff>, List<PUB_SEC_DETAIL>>(secondMatchHaveSaHaveSes);
|
|
|
|
// _pubSeCDetailRepository.InsertManyAsync(pubSeCDetailEntitys);
|
|
|
|
//}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(lu) == false) |
|
|
@ -221,6 +265,7 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
{ |
|
|
|
pubSaSeCompareDiffs = pubSaSeCompareDiffs.FindAll(p => p.PN == pn); |
|
|
|
} |
|
|
|
pubSaSeCompareDiffs = pubSaSeCompareDiffs.OrderBy(t => t.Category).ToList(); |
|
|
|
var excelExporter = new ExcelExporter(); |
|
|
|
|
|
|
|
#region 根据业务分类转换不同导出Dto
|
|
|
@ -272,6 +317,94 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
} |
|
|
|
|
|
|
|
#region 私有方法
|
|
|
|
/// <summary>
|
|
|
|
/// 获取结算与发运比对数据
|
|
|
|
/// </summary>
|
|
|
|
public List<PubSaSeCompareDiff> GetSaSeCompareData(EnumBusinessType businessType, int version, DateTime seStartDateTime, DateTime seEndDateTime) |
|
|
|
{ |
|
|
|
//结算
|
|
|
|
var saGroup = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>() |
|
|
|
where sa.BusinessType == businessType && sa.Version == version |
|
|
|
group sa by new { sa.PN, sa.LU } into groupItem |
|
|
|
select new |
|
|
|
{ |
|
|
|
groupItem.Key.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), |
|
|
|
}; |
|
|
|
//发运
|
|
|
|
var seGroup = from se in _settleAccountDbContext.Set<PUB_SE_DETAIL>() |
|
|
|
where se.BusinessType == businessType && se.BillTime >= seStartDateTime && se.BillTime <= seEndDateTime |
|
|
|
group se by new { se.PN, se.LU } into groupItem |
|
|
|
select new |
|
|
|
{ |
|
|
|
groupItem.Key.PN, |
|
|
|
groupItem.Key.LU, |
|
|
|
Qty = groupItem.Sum(t => t.Qty), |
|
|
|
WmsBillNum = groupItem.Max(t => t.WmsBillNum), |
|
|
|
ShippingDate = groupItem.Max(t => t.ShippingDate), |
|
|
|
FactoryPartCode = groupItem.Max(t => t.FactoryPartCode), |
|
|
|
ToLocCode = groupItem.Max(t => t.ToLocCode), |
|
|
|
ToErpLocCode = groupItem.Max(t => t.ToErpLocCode) |
|
|
|
}; |
|
|
|
//印度件LU对比
|
|
|
|
if (businessType == EnumBusinessType.YinDuJian) |
|
|
|
{ |
|
|
|
saGroup = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>() |
|
|
|
where sa.BusinessType == businessType && 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 |
|
|
|
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), |
|
|
|
ShippingDate = groupItem.Max(t => t.ShippingDate), |
|
|
|
FactoryPartCode = groupItem.Max(t => t.FactoryPartCode), |
|
|
|
ToLocCode = groupItem.Max(t => t.ToLocCode), |
|
|
|
ToErpLocCode = groupItem.Max(t => t.ToErpLocCode) |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
var saSeCompareList = (from sa in saGroup |
|
|
|
join se in seGroup |
|
|
|
on new { sa.PN, sa.LU } equals new { se.PN, se.LU } |
|
|
|
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 |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
return saSeCompareList; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 创建导出文件结构
|
|
|
|
/// </summary>
|
|
|
|
public ExcelExporter BindExcelExporter<T>(List<T> pubSaSeCompareDetailExports, string businessTypeDisplayName) where T : PubSaSeCompareDetailExport, IPubSaSeCompareDetailExport, new() |
|
|
|
{ |
|
|
|
//结算核对汇总
|
|
|
@ -328,8 +461,7 @@ namespace SettleAccount.Job.Services.Report |
|
|
|
|
|
|
|
.Append(haveSaNotHaveSeExports, $"{businessTypeDisplayName}有结算无发货明细输出") |
|
|
|
.SeparateBySheet() |
|
|
|
.Append(haveSaNotHaveSeSumExports, $"{businessTypeDisplayName}有结算无发货汇总输出") |
|
|
|
.SeparateBySheet(); |
|
|
|
.Append(haveSaNotHaveSeSumExports, $"{businessTypeDisplayName}有结算无发货汇总输出"); |
|
|
|
} |
|
|
|
|
|
|
|
private void Notify() |
|
|
|