mahao 1 year ago
parent
commit
dfcbfe430b
  1. 86
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/MaiDanBBACSaSeCompareExportService.cs
  2. 86
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/MaiDanHBPOSaSeCompareExportService.cs
  3. 237
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/PubSaSeCompareExportService.cs
  4. 135
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs

86
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/MaiDanBBACSaSeCompareExportService.cs

@ -72,7 +72,8 @@ namespace SettleAccount.Job.Services.Report
var seStartDateTime = DateTime.Parse(strSeStartDateTime); var seStartDateTime = DateTime.Parse(strSeStartDateTime);
var seEndDateTime = DateTime.Parse(strSeEndDateTime); var seEndDateTime = DateTime.Parse(strSeEndDateTime);
var filename = exportName.FirstOrDefault(); var filename = exportName.FirstOrDefault();
var pubSaSeCompareDiffs = GetSaSeCompareData(version, seStartDateTime, seEndDateTime); //var pubSaSeCompareDiffs = GetSaSeCompareData(version, seStartDateTime, seEndDateTime);
var pubSaSeCompareDiffs = GetSaSeCompareDataJis<BBAC_SA_DETAIL, BBAC_SE_DETAIL>(EnumBusinessType.MaiDanJianBBAC, version, seStartDateTime, seEndDateTime);
HandlePubSaSeCompareDiffList(pubSaSeCompareDiffs); HandlePubSaSeCompareDiffList(pubSaSeCompareDiffs);
@ -93,6 +94,7 @@ namespace SettleAccount.Job.Services.Report
#region 结算数据处理 #region 结算数据处理
HandleSaDetails<BBAC_CAN_SA_DETAIL, BBAC_NOT_SA_DETAIL>(pubSaSeCompareDiffs, businessType, version); HandleSaDetails<BBAC_CAN_SA_DETAIL, BBAC_NOT_SA_DETAIL>(pubSaSeCompareDiffs, businessType, version);
HandleSaDetailsMain<BBAC_SA_DETAIL>(pubSaSeCompareDiffs, businessType, version);
#endregion #endregion
if (string.IsNullOrEmpty(lu) == false) if (string.IsNullOrEmpty(lu) == false)
@ -115,87 +117,5 @@ namespace SettleAccount.Job.Services.Report
Notify(); Notify();
return id.ToString(); return id.ToString();
} }
#region 私有方法
/// <summary>
/// 获取结算与发运比对数据
/// </summary>
public List<SaSeCompareDiff> GetSaSeCompareData(int version, DateTime seStartDateTime, DateTime seEndDateTime)
{
//结算
var saGroup = 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),
LU = groupItem.Max(t => t.LU),
SettleDate = groupItem.Max(t => t.SettleDate),
PartCode = groupItem.Max(t => t.PartCode),
};
//发运
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),
ToLoc = groupItem.Max(t => t.ToLoc),
ErpToLoc = groupItem.Max(t => t.ErpToLoc)
};
var saSeCompareLeft = from sa in saGroup
join se in seGroup
on new { sa.PN, sa.CustomerPartCodeNoSpace } equals new { se.PN, se.CustomerPartCodeNoSpace }
into temp
from se in temp.DefaultIfEmpty()
select new SaSeCompareDiff()
{
WmsBillNum = se.WmsBillNum,
ShippingDate = se.ShippingDate,
CustomerOfflineTime = sa.SettleDate,
PN = sa.PN,
SAQty = sa.Qty,
SEQty = se.Qty,
ToLocCode = se.ToLoc,
ToErpLocCode = se.ErpToLoc,
SeCustomerPartCode = se.CustomerPartCodeNoSpace,
SeFactoryPartCode = se.FactoryPartCode,
SaCustomerPartCode = sa.CustomerPartCodeNoSpace,
SaFactoryPartCode = sa.PartCode,
CustomerPartCode = sa.LU,
};
var saSeCompareRight = 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()
select new SaSeCompareDiff()
{
WmsBillNum = se.WmsBillNum,
ShippingDate = se.ShippingDate,
CustomerOfflineTime = sa.SettleDate,
PN = se.PN,
SAQty = sa.Qty,
SEQty = se.Qty,
ToLocCode = se.ToLoc,
ToErpLocCode = se.ErpToLoc,
SeCustomerPartCode = se.CustomerPartCodeNoSpace,
SeFactoryPartCode = se.FactoryPartCode,
SaCustomerPartCode = sa.CustomerPartCodeNoSpace,
SaFactoryPartCode = sa.PartCode,
CustomerPartCode = sa.LU ?? se.LU
};
var saSeCompareFullJoin = saSeCompareLeft.Union(saSeCompareRight).ToList();
return saSeCompareFullJoin;
}
#endregion
} }
} }

86
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/MaiDanHBPOSaSeCompareExportService.cs

@ -72,7 +72,8 @@ namespace SettleAccount.Job.Services.Report
var seStartDateTime = DateTime.Parse(strSeStartDateTime); var seStartDateTime = DateTime.Parse(strSeStartDateTime);
var seEndDateTime = DateTime.Parse(strSeEndDateTime); var seEndDateTime = DateTime.Parse(strSeEndDateTime);
var filename = exportName.FirstOrDefault(); var filename = exportName.FirstOrDefault();
var pubSaSeCompareDiffs = GetSaSeCompareData(version, seStartDateTime, seEndDateTime); //var pubSaSeCompareDiffs = GetSaSeCompareData(version, seStartDateTime, seEndDateTime);
var pubSaSeCompareDiffs = GetSaSeCompareDataJis<HBPO_SA_DETAIL, HBPO_SE_DETAIL>(EnumBusinessType.MaiDanJianHBPO, version, seStartDateTime, seEndDateTime);
HandlePubSaSeCompareDiffList(pubSaSeCompareDiffs); HandlePubSaSeCompareDiffList(pubSaSeCompareDiffs);
@ -93,6 +94,7 @@ namespace SettleAccount.Job.Services.Report
#region 结算数据处理 #region 结算数据处理
HandleSaDetails<HBPO_CAN_SA_DETAIL, HBPO_NOT_SA_DETAIL>(pubSaSeCompareDiffs, businessType, version); HandleSaDetails<HBPO_CAN_SA_DETAIL, HBPO_NOT_SA_DETAIL>(pubSaSeCompareDiffs, businessType, version);
HandleSaDetailsMain<HBPO_SA_DETAIL>(pubSaSeCompareDiffs, businessType, version);
#endregion #endregion
if (string.IsNullOrEmpty(lu) == false) if (string.IsNullOrEmpty(lu) == false)
@ -115,87 +117,5 @@ namespace SettleAccount.Job.Services.Report
Notify(); Notify();
return id.ToString(); return id.ToString();
} }
#region 私有方法
/// <summary>
/// 获取结算与发运比对数据
/// </summary>
public List<SaSeCompareDiff> GetSaSeCompareData(int version, DateTime seStartDateTime, DateTime seEndDateTime)
{
//结算
var saGroup = from sa in _settleAccountDbContext.Set<HBPO_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),
LU = groupItem.Max(t => t.LU),
SettleDate = groupItem.Max(t => t.SettleDate),
PartCode = groupItem.Max(t => t.PartCode),
};
//发运
var seGroup = from se in _settleAccountDbContext.Set<HBPO_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),
ToLoc = groupItem.Max(t => t.ToLoc),
ErpToLoc = groupItem.Max(t => t.ErpToLoc)
};
var saSeCompareLeft = from sa in saGroup
join se in seGroup
on new { sa.PN, sa.CustomerPartCodeNoSpace } equals new { se.PN, se.CustomerPartCodeNoSpace }
into temp
from se in temp.DefaultIfEmpty()
select new SaSeCompareDiff()
{
WmsBillNum = se.WmsBillNum,
ShippingDate = se.ShippingDate,
CustomerOfflineTime = sa.SettleDate,
PN = sa.PN,
SAQty = sa.Qty,
SEQty = se.Qty,
ToLocCode = se.ToLoc,
ToErpLocCode = se.ErpToLoc,
SeCustomerPartCode = se.CustomerPartCodeNoSpace,
SeFactoryPartCode = se.FactoryPartCode,
SaCustomerPartCode = sa.CustomerPartCodeNoSpace,
SaFactoryPartCode = sa.PartCode,
CustomerPartCode = sa.LU
};
var saSeCompareRight = from se in seGroup
join sa in saGroup
on new { se.PN, se.LU } equals new { sa.PN, sa.LU }
into temp
from sa in temp.DefaultIfEmpty()
select new SaSeCompareDiff()
{
WmsBillNum = se.WmsBillNum,
ShippingDate = se.ShippingDate,
CustomerOfflineTime = sa.SettleDate,
PN = se.PN,
SAQty = sa.Qty,
SEQty = se.Qty,
ToLocCode = se.ToLoc,
ToErpLocCode = se.ErpToLoc,
SeCustomerPartCode = se.CustomerPartCodeNoSpace,
SeFactoryPartCode = se.FactoryPartCode,
SaCustomerPartCode = sa.CustomerPartCodeNoSpace,
SaFactoryPartCode = sa.PartCode,
CustomerPartCode = sa.LU ?? se.LU
};
var saSeCompareFullJoin = saSeCompareLeft.Union(saSeCompareRight).ToList();
return saSeCompareFullJoin;
}
#endregion
} }
} }

237
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/PubSaSeCompareExportService.cs

@ -6,6 +6,7 @@ using System.Linq;
using Magicodes.ExporterAndImporter.Excel; using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Extensions;
using SettleAccount.Bases;
using SettleAccount.Domain.BQ; using SettleAccount.Domain.BQ;
using SettleAccount.Job.SignalR; using SettleAccount.Job.SignalR;
using ShardingCore.Extensions; using ShardingCore.Extensions;
@ -34,18 +35,6 @@ namespace SettleAccount.Job.Services.Report
/// </summary> /// </summary>
private readonly SettleAccountDbContext _settleAccountDbContext; private readonly SettleAccountDbContext _settleAccountDbContext;
/// <summary> /// <summary>
/// 替换件关系仓储
/// </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> /// </summary>
private readonly IBlobContainer<MyFileContainer> _fileContainer; private readonly IBlobContainer<MyFileContainer> _fileContainer;
@ -60,16 +49,10 @@ namespace SettleAccount.Job.Services.Report
public PubSaSeCompareExportService( public PubSaSeCompareExportService(
IHubContext<PageHub> hubContext, IHubContext<PageHub> hubContext,
SettleAccountDbContext settleAccountDbContext, SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<TB_RePartsRelationship, Guid> tbRePartsRelationshipRepository,
INormalEfCoreRepository<PUB_SEC_DETAIL, Guid> pubSeCDetailRepository,
PubSaSeCompareDapperRepository pubSaSeCompareDapperRepository,
IBlobContainer<MyFileContainer> fileContainer, IBlobContainer<MyFileContainer> fileContainer,
IObjectMapper objectMapper) : base(hubContext, settleAccountDbContext) IObjectMapper objectMapper) : base(hubContext, settleAccountDbContext)
{ {
_settleAccountDbContext = settleAccountDbContext; _settleAccountDbContext = settleAccountDbContext;
_tbRePartsRelationshipRepository = tbRePartsRelationshipRepository;
_pubSeCDetailRepository = pubSeCDetailRepository;
_pubSaSeCompareDapperRepository = pubSaSeCompareDapperRepository;
_fileContainer = fileContainer; _fileContainer = fileContainer;
_objectMapper = objectMapper; _objectMapper = objectMapper;
} }
@ -102,7 +85,7 @@ namespace SettleAccount.Job.Services.Report
} }
var filename = exportName.FirstOrDefault(); var filename = exportName.FirstOrDefault();
//var pubSaSeCompareDiffs = _pubSaSeCompareDapperRepository.GetDetailDiffReportList(strBusinessType, version, seStartDateTime, seEndDateTime); //var pubSaSeCompareDiffs = _pubSaSeCompareDapperRepository.GetDetailDiffReportList(strBusinessType, version, seStartDateTime, seEndDateTime);
var pubSaSeCompareDiffs = GetSaSeCompareData(businessType, version, DateTime.Parse(seStartDateTime), DateTime.Parse(seEndDateTime)); var pubSaSeCompareDiffs = GetSaSeCompareData(businessType, version);
HandlePubSaSeCompareDiffList(pubSaSeCompareDiffs); HandlePubSaSeCompareDiffList(pubSaSeCompareDiffs);
@ -123,7 +106,6 @@ namespace SettleAccount.Job.Services.Report
#region 结算数据处理 #region 结算数据处理
HandleSaDetails<PUB_CAN_SA_DETAIL, PUB_NOT_SA_DETAIL>(pubSaSeCompareDiffs, businessType, version); HandleSaDetails<PUB_CAN_SA_DETAIL, PUB_NOT_SA_DETAIL>(pubSaSeCompareDiffs, businessType, version);
HandleSaDetailsMain<PUB_SA_DETAIL>(pubSaSeCompareDiffs, businessType, version); HandleSaDetailsMain<PUB_SA_DETAIL>(pubSaSeCompareDiffs, businessType, version);
#endregion #endregion
@ -183,99 +165,12 @@ namespace SettleAccount.Job.Services.Report
/// <summary> /// <summary>
/// 获取比对数据 /// 获取比对数据
/// </summary> /// </summary>
[Obsolete] private List<SaSeCompareDiff> GetSaSeCompareData(EnumBusinessType businessType, int version)
private List<SaSeCompareDiff> GetSaSeCompareDataOld(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
group sa by new { sa.PN, sa.CustomerPartCodeNoSpace } into groupItem
select new
{
groupItem.Key.PN,
groupItem.Key.CustomerPartCodeNoSpace,
Qty = groupItem.Sum(t => t.Qty),
LU = groupItem.Max(t => t.LU),
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.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.ToLocCode),
ToErpLocCode = groupItem.Max(t => t.ToErpLocCode)
};
var saSeCompareLeft = from sa in saGroup
join se in seGroup
on new { sa.PN, sa.CustomerPartCodeNoSpace } equals new { se.PN, se.CustomerPartCodeNoSpace }
into temp
from se in temp.DefaultIfEmpty()
select new SaSeCompareDiff()
{
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
};
var saSeCompareRight = 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()
select new SaSeCompareDiff()
{
WmsBillNum = se.WmsBillNum,
ShippingDate = se.ShippingDate,
CustomerOfflineTime = sa.SettleDate,
PN = se.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 ?? se.LU
};
var saSeCompareFullJoin = saSeCompareLeft.Union(saSeCompareRight).ToList();
return saSeCompareFullJoin;
}
/// <summary>
/// 获取比对数据
/// </summary>
private List<SaSeCompareDiff> GetSaSeCompareData(EnumBusinessType businessType, int version, DateTime seStartDateTime, DateTime seEndDateTime)
{ {
//印度件LU对比 //印度件LU对比
if (businessType == EnumBusinessType.YinDuJian) if (businessType == EnumBusinessType.YinDuJian)
{ {
return GetSaSeCompareDataYinDu(version, seStartDateTime, seEndDateTime); return GetSaSeCompareDataYinDu(version);
} }
//结算 //结算
var saGroup = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>() var saGroup = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>()
@ -289,7 +184,7 @@ namespace SettleAccount.Job.Services.Report
Version = groupItem.Max(t => t.Version), Version = groupItem.Max(t => t.Version),
LU = groupItem.Max(t => t.LU), LU = groupItem.Max(t => t.LU),
SettleDate = groupItem.Max(t => t.SettleDate), SettleDate = groupItem.Max(t => t.SettleDate),
PartCode = groupItem.Max(t => t.PartCode), PartCode = groupItem.Max(t => t.PartCode)
}; };
var saGroupByVersion = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>() var saGroupByVersion = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>()
where sa.BusinessType == businessType && sa.Version == version where sa.BusinessType == businessType && sa.Version == version
@ -302,7 +197,7 @@ namespace SettleAccount.Job.Services.Report
Version = groupItem.Max(t => t.Version), Version = groupItem.Max(t => t.Version),
LU = groupItem.Max(t => t.LU), LU = groupItem.Max(t => t.LU),
SettleDate = groupItem.Max(t => t.SettleDate), SettleDate = groupItem.Max(t => t.SettleDate),
PartCode = groupItem.Max(t => t.PartCode), PartCode = groupItem.Max(t => t.PartCode)
}; };
//发运 //发运
var seGroup = from se in _settleAccountDbContext.Set<PUB_SE_DETAIL>() var seGroup = from se in _settleAccountDbContext.Set<PUB_SE_DETAIL>()
@ -384,21 +279,35 @@ namespace SettleAccount.Job.Services.Report
/// <summary> /// <summary>
/// 获取比对数据 /// 获取比对数据
/// </summary> /// </summary>
private List<SaSeCompareDiff> GetSaSeCompareDataYinDu(int version, DateTime seStartDateTime, DateTime seEndDateTime) private List<SaSeCompareDiff> GetSaSeCompareDataYinDu(int version)
{ {
//结算
var saGroup = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>() var saGroup = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>()
where sa.BusinessType == EnumBusinessType.YinDuJian && sa.Version == version where sa.BusinessType == EnumBusinessType.YinDuJian
group sa by new { sa.CustomerPartCodeNoSpace } into groupItem group sa by new { sa.CustomerPartCodeNoSpace } into groupItem
select new select new
{ {
groupItem.Key.CustomerPartCodeNoSpace, groupItem.Key.CustomerPartCodeNoSpace,
Qty = groupItem.Sum(t => t.Qty), Qty = groupItem.Sum(t => t.Qty),
Version = groupItem.Max(t => t.Version),
LU = groupItem.Max(t => t.LU), LU = groupItem.Max(t => t.LU),
SettleDate = groupItem.Max(t => t.SettleDate), SettleDate = groupItem.Max(t => t.SettleDate),
PartCode = groupItem.Max(t => t.PartCode), PartCode = groupItem.Max(t => t.PartCode)
}; };
var saGroupByVersion = from sa in _settleAccountDbContext.Set<PUB_SA_DETAIL>()
where sa.BusinessType == EnumBusinessType.YinDuJian && sa.Version == version
group sa by new { sa.CustomerPartCodeNoSpace } into groupItem
select new
{
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)
};
//发运
var seGroup = from se in _settleAccountDbContext.Set<PUB_SE_DETAIL>() 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.CustomerPartCodeNoSpace } into groupItem group se by new { se.CustomerPartCodeNoSpace } into groupItem
select new select new
{ {
@ -412,48 +321,62 @@ namespace SettleAccount.Job.Services.Report
ToErpLocCode = groupItem.Max(t => t.ToErpLocCode) ToErpLocCode = groupItem.Max(t => t.ToErpLocCode)
}; };
var saSeCompareLeft = from sa in saGroup //有结算无发运
join se in seGroup var haveSaNotHaveSeList = (from sa in saGroup
on sa.CustomerPartCodeNoSpace equals se.CustomerPartCodeNoSpace join se in seGroup
into temp on sa.CustomerPartCodeNoSpace equals se.CustomerPartCodeNoSpace
from se in temp.DefaultIfEmpty() into temp
select new SaSeCompareDiff() from se in temp.DefaultIfEmpty()
{ where se.CustomerPartCodeNoSpace == null
WmsBillNum = se.WmsBillNum, select new SaSeCompareDiff()
ShippingDate = se.ShippingDate, {
CustomerOfflineTime = sa.SettleDate, Version = sa.Version,
SAQty = sa.Qty, CustomerOfflineTime = sa.SettleDate,
SEQty = se.Qty, SAQty = sa.Qty,
ToLocCode = se.ToLocCode, SaCustomerPartCode = sa.CustomerPartCodeNoSpace,
ToErpLocCode = se.ToErpLocCode, SaFactoryPartCode = sa.PartCode,
SeCustomerPartCode = se.CustomerPartCodeNoSpace, CustomerPartCode = sa.LU
SeFactoryPartCode = se.FactoryPartCode, }).ToList();
SaCustomerPartCode = sa.CustomerPartCodeNoSpace, //无结算有发运
SaFactoryPartCode = sa.PartCode, var notHaveSaHaveSeList = (from se in seGroup
CustomerPartCode = sa.LU join sa in saGroup
}; on se.CustomerPartCodeNoSpace equals sa.CustomerPartCodeNoSpace
var saSeCompareRight = from se in seGroup into temp
join sa in saGroup from sa in temp.DefaultIfEmpty()
on se.CustomerPartCodeNoSpace equals sa.CustomerPartCodeNoSpace where sa.CustomerPartCodeNoSpace == null
into temp select new SaSeCompareDiff()
from sa in temp.DefaultIfEmpty() {
select new SaSeCompareDiff() WmsBillNum = se.WmsBillNum,
{ ShippingDate = se.ShippingDate,
WmsBillNum = se.WmsBillNum, SEQty = se.Qty,
ShippingDate = se.ShippingDate, ToLocCode = se.ToLocCode,
CustomerOfflineTime = sa.SettleDate, ToErpLocCode = se.ToErpLocCode,
SAQty = sa.Qty, SeCustomerPartCode = se.CustomerPartCodeNoSpace,
SEQty = se.Qty, SeFactoryPartCode = se.FactoryPartCode,
ToLocCode = se.ToLocCode, CustomerPartCode = se.LU
ToErpLocCode = se.ToErpLocCode, }).ToList();
SeCustomerPartCode = se.CustomerPartCodeNoSpace,
SeFactoryPartCode = se.FactoryPartCode, //有结算有发运
SaCustomerPartCode = sa.CustomerPartCodeNoSpace, var haveSaHaveSeList = (from sa in saGroupByVersion
SaFactoryPartCode = sa.PartCode, from se in seGroup
CustomerPartCode = sa.LU ?? se.LU where sa.CustomerPartCodeNoSpace == se.CustomerPartCodeNoSpace
}; select new SaSeCompareDiff()
var saSeCompareFullJoin = saSeCompareLeft.Union(saSeCompareRight).ToList(); {
return saSeCompareFullJoin; Version = sa.Version,
WmsBillNum = se.WmsBillNum,
ShippingDate = se.ShippingDate,
CustomerOfflineTime = sa.SettleDate,
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
}).ToList();
return haveSaHaveSeList.Union(haveSaNotHaveSeList).Union(notHaveSaHaveSeList).ToList();
} }
#endregion #endregion
} }

135
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using EFCore.BulkExtensions; using EFCore.BulkExtensions;
using Magicodes.ExporterAndImporter.Core.Extension; using Magicodes.ExporterAndImporter.Core.Extension;
using Magicodes.ExporterAndImporter.Excel; using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using SettleAccount.Bases; using SettleAccount.Bases;
using SettleAccount.Domain.BQ; using SettleAccount.Domain.BQ;
using SettleAccount.Job.SignalR; using SettleAccount.Job.SignalR;
@ -35,9 +35,120 @@ namespace SettleAccount.Job.Services.Report
_settleAccountDbContext = settleAccountDbContext; _settleAccountDbContext = settleAccountDbContext;
} }
public virtual void HandlePubSaSeCompareDiffList(List<SaSeCompareDiff> pubSaSeCompareDiffs) /// <summary>
/// 获取结算、发运比对数据
/// </summary>
public List<SaSeCompareDiff> GetSaSeCompareDataJis<TSaDetail, TSeDetail>(EnumBusinessType businessType, int version, DateTime seStartDateTime, DateTime seEndDateTime)
where TSaDetail : SA_BASE
where TSeDetail : JisSeBase
{
//结算
var saGroup = from sa in _settleAccountDbContext.Set<TSaDetail>()
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)
};
var saGroupByVersion = from sa in _settleAccountDbContext.Set<TSaDetail>()
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)
};
//发运
var seGroup = from se in _settleAccountDbContext.Set<TSeDetail>()
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)
};
//有结算无发运
var haveSaNotHaveSeList = (from sa in saGroup
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
}).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
}).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
}).ToList();
return haveSaHaveSeList.Union(haveSaNotHaveSeList).Union(notHaveSaHaveSeList).ToList();
}
public virtual void HandlePubSaSeCompareDiffList(List<SaSeCompareDiff> saSeCompareDiffs)
{ {
pubSaSeCompareDiffs.ForEach(p => saSeCompareDiffs.ForEach(p =>
{ {
p.Category = (string.IsNullOrEmpty(p.SaCustomerPartCode), string.IsNullOrEmpty(p.SeCustomerPartCode)) switch p.Category = (string.IsNullOrEmpty(p.SaCustomerPartCode), string.IsNullOrEmpty(p.SeCustomerPartCode)) switch
{ {
@ -77,16 +188,16 @@ namespace SettleAccount.Job.Services.Report
/// <summary> /// <summary>
/// 二次比对 /// 二次比对
/// </summary> /// </summary>
public virtual List<SaSeCompareDiff> HandleSecondCompare(List<SaSeCompareDiff> pubSaSeCompareDiffs, EnumBusinessType businessType) public virtual List<SaSeCompareDiff> HandleSecondCompare(List<SaSeCompareDiff> saSeCompareDiffs, EnumBusinessType businessType)
{ {
//二次匹配上的记录 //二次匹配上的记录
var secondMatchHaveSaHaveSes = new List<SaSeCompareDiff>(); var secondMatchHaveSaHaveSes = new List<SaSeCompareDiff>();
//有结算无发运 和 无结算有发运 //有结算无发运 和 无结算有发运
var haveSaNotHaveSeUnionNotHaveSaHaveSes = pubSaSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.HaveSaNotHaveSe || t.Category == EnumPubSaSeCompareCategory.NotHaveSaHaveSe); var haveSaNotHaveSeUnionNotHaveSaHaveSes = saSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.HaveSaNotHaveSe || t.Category == EnumPubSaSeCompareCategory.NotHaveSaHaveSe);
//有结算无发运 //有结算无发运
var haveSaNotHaveSes = pubSaSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.HaveSaNotHaveSe); var haveSaNotHaveSes = saSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.HaveSaNotHaveSe);
//无结算有发运 //无结算有发运
var notHaveSaHaveSes = pubSaSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.NotHaveSaHaveSe); var notHaveSaHaveSes = saSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.NotHaveSaHaveSe);
//二次对比(替换发运数据的厂内零件号) //二次对比(替换发运数据的厂内零件号)
var repFactoryPartCodes = haveSaNotHaveSeUnionNotHaveSaHaveSes.Select(t => t.FactoryPartCode).Distinct().ToList(); var repFactoryPartCodes = haveSaNotHaveSeUnionNotHaveSaHaveSes.Select(t => t.FactoryPartCode).Distinct().ToList();
@ -133,12 +244,12 @@ namespace SettleAccount.Job.Services.Report
/// 结算数据处理 /// 结算数据处理
/// 写入库位、替换零件号 /// 写入库位、替换零件号
/// </summary> /// </summary>
public virtual void HandleSaDetails<TCanSa, TNotSa>(List<SaSeCompareDiff> pubSaSeCompareDiffs, EnumBusinessType businessType, int version) public virtual void HandleSaDetails<TCanSa, TNotSa>(List<SaSeCompareDiff> saSeCompareDiffs, EnumBusinessType businessType, int version)
where TCanSa : SA_CAN_BASE where TCanSa : SA_CAN_BASE
where TNotSa : SA_NOT_BASE where TNotSa : SA_NOT_BASE
{ {
//写入库位、替换零件号 //写入库位、替换零件号
var haveSaHaveSes = pubSaSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.HaveSaHaveSe); var haveSaHaveSes = saSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.HaveSaHaveSe);
if (haveSaHaveSes.Any()) if (haveSaHaveSes.Any())
{ {
//可结算单 //可结算单
@ -174,12 +285,12 @@ namespace SettleAccount.Job.Services.Report
} }
/// <summary> /// <summary>
/// 处理发运数据 /// 处理结算数据
/// 结算、发运对比上的数据修改结算数据状态 /// 结算、发运对比上的数据修改结算数据状态
/// </summary> /// </summary>
public virtual void HandleSaDetailsMain<T>(List<SaSeCompareDiff> pubSaSeCompareDiffs, EnumBusinessType businessType, int version) where T : SA_BASE public virtual void HandleSaDetailsMain<T>(List<SaSeCompareDiff> saSeCompareDiffs, EnumBusinessType businessType, int version) where T : SA_BASE
{ {
var haveSaHaveSes = pubSaSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.HaveSaHaveSe); var haveSaHaveSes = saSeCompareDiffs.FindAll(t => t.Category == EnumPubSaSeCompareCategory.HaveSaHaveSe);
if (haveSaHaveSes.Any()) if (haveSaHaveSes.Any())
{ {
//结算详情 //结算详情

Loading…
Cancel
Save