mahao 1 year ago
parent
commit
4df7b76833
  1. 75
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs
  2. 136
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs

75
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs

@ -29,40 +29,44 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable
/// </summary>
public async Task Invoke()
{
try
{
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
await HandDelEdiDataAsync().ConfigureAwait(false);
await HandDelEdiDataAsync().ConfigureAwait(false);
var seDetailGroup = db.Set<BBAC_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var ediDetailGroup = db.Set<BBAC_SE_EDI>()
.Where(t => t.IsDeleted == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var seDetailGroup = db.Set<BBAC_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var ediDetailGroup = db.Set<BBAC_SE_EDI>()
.Where(t => t.IsDeleted == false && t.IsHaveSeData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var keyCodes = from se in seDetailGroup
from edi in ediDetailGroup
where se.PN == edi.PN && se.CustomerPartCodeNoSpace == edi.CustomerPartCodeNoSpace
select new { se.PN, se.CustomerPartCodeNoSpace };
var seDetailsQuery = from se in db.Set<BBAC_SE_DETAIL>()
from keyCode in keyCodes
where se.PN == keyCode.PN && se.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && se.IsHaveEdiData == false
select se;
var ediDetailsQuery = from edi in db.Set<BBAC_SE_EDI>()
from keyCode in keyCodes
where edi.PN == keyCode.PN && edi.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && edi.IsDeleted == false && edi.IsHaveSeData == false
select edi;
var keyCodes = (from se in seDetailGroup
from edi in ediDetailGroup
where se.PN == edi.PN && se.CustomerPartCodeNoSpace == edi.CustomerPartCodeNoSpace
select new { se.PN, se.CustomerPartCodeNoSpace }
).Take(1000).ToList();
if (keyCodes.Any())
{
var pns = keyCodes.Select(t => t.PN).Distinct().ToList();
var seDetails = seDetailsQuery.Take(5000).ToList();
var ediDetails = ediDetailsQuery.Take(5000).ToList();
var seDetails = db.Set<BBAC_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.Where(t => pns.Contains(t.PN))
.AsEnumerable<BBAC_SE_DETAIL>()
.GroupJoin(keyCodes, x => new { x.PN, x.CustomerPartCodeNoSpace }, y => y, (x, y) => x)
.ToList();
var ediDetails = db.Set<BBAC_SE_EDI>()
.Where(t => t.IsDeleted == false)
.Where(t => t.IsHaveSeData == false)
.Where(t => pns.Contains(t.PN))
.AsEnumerable<BBAC_SE_EDI>()
.GroupJoin(keyCodes, x => new { x.PN, x.CustomerPartCodeNoSpace }, y => y, (x, y) => x)
.ToList();
seDetails.ForEach(t => t.IsHaveEdiData = true);
ediDetails.ForEach(t => t.IsHaveSeData = true);
using var transaction = await db.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
@ -73,13 +77,8 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable
catch (Exception)
{
await transaction.RollbackAsync().ConfigureAwait(false);
throw;
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
@ -100,27 +99,27 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable
{
seed++;
//Edi 删除的数据(有发运数据)
var ediDelKeyCodes = db.Set<HBPO_SE_EDI>().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).GroupBy(t => t.PN).Select(t => t.Key).Take(1000).ToList();
var ediDelKeyCodes = db.Set<BBAC_SE_EDI>().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).GroupBy(t => t.PN).Select(t => t.Key).Take(1000).ToList();
if (ediDelKeyCodes.Any())
{
var seDetails = db.Set<HBPO_SE_DETAIL>()
var seDetails = db.Set<BBAC_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == true)
.Where(t => ediDelKeyCodes.Contains(t.PN))
.ToList();
if (seDetails.Any())
{
seDetails.ForEach(t => t.IsHaveEdiData = false);
await db.BulkUpdateAsync<HBPO_SE_DETAIL>(seDetails).ConfigureAwait(false);
await db.BulkUpdateAsync<BBAC_SE_DETAIL>(seDetails).ConfigureAwait(false);
}
var ediDetails = db.Set<HBPO_SE_EDI>()
var ediDetails = db.Set<BBAC_SE_EDI>()
.Where(t => t.IsHaveSeData == true)
.Where(t => ediDelKeyCodes.Contains(t.PN))
.ToList();
if (ediDetails.Any())
{
ediDetails.ForEach(t => t.IsHaveSeData = false);
await db.BulkUpdateAsync<HBPO_SE_EDI>(ediDetails).ConfigureAwait(false);
await db.BulkUpdateAsync<BBAC_SE_EDI>(ediDetails).ConfigureAwait(false);
}
}
else

136
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs

@ -8,6 +8,7 @@ using LinqToDB;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using SettleAccount.Domain.BQ;
using ShardingCore.Extensions;
using Volo.Abp.Application.Services;
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -25,111 +26,49 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable
_serviceProvider = serviceProvider;
}
/// <summary>
/// 执行
/// </summary>
public async Task InvokeOld()
{
try
{
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
await HandDelEdiDataAsync().ConfigureAwait(false);
var seDetailGroup = db.Set<HBPO_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var ediDetailGroup = db.Set<HBPO_SE_EDI>()
.Where(t => t.IsDeleted == false && t.IsHaveSeData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var keyCodes = (from se in seDetailGroup
from edi in ediDetailGroup
where se.PN == edi.PN && se.CustomerPartCodeNoSpace == edi.CustomerPartCodeNoSpace
select new { se.PN, se.CustomerPartCodeNoSpace }
).Take(5000).ToList();
if (keyCodes.Any())
{
var pnGroup = keyCodes.GroupBy(t => t.PN).Select(t => new { t.Key, CustomerPartCodeNoSpaces = t.Select(s => s.CustomerPartCodeNoSpace).Distinct() });
foreach (var item in pnGroup)
{
var pn = item.Key;
var lus = item.CustomerPartCodeNoSpaces;
}
}
var seDetailsQuery = from se in db.Set<HBPO_SE_DETAIL>()
from keyCode in keyCodes
where se.PN == keyCode.PN && se.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && se.IsHaveEdiData == false
select se;
var ediDetailsQuery = from edi in db.Set<HBPO_SE_EDI>()
from keyCode in keyCodes
where edi.PN == keyCode.PN && edi.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && edi.IsDeleted == false && edi.IsHaveSeData == false
select edi;
var seDetails = seDetailsQuery.Take(5000).ToList();
var ediDetails = ediDetailsQuery.Take(5000).ToList();
seDetails.ForEach(t => t.IsHaveEdiData = true);
ediDetails.ForEach(t => t.IsHaveSeData = true);
using var transaction = await db.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
await db.BulkUpdateAsync<HBPO_SE_DETAIL>(seDetails).ConfigureAwait(false);
await db.BulkUpdateAsync<HBPO_SE_EDI>(ediDetails).ConfigureAwait(false);
await transaction.CommitAsync().ConfigureAwait(false);
}
catch (Exception)
{
await transaction.RollbackAsync().ConfigureAwait(false);
throw;
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 执行
/// </summary>
public async Task Invoke()
{
try
{
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
await HandDelEdiDataAsync().ConfigureAwait(false);
var seDetailGroup = db.Set<HBPO_SE_DETAIL>().Where(t => t.IsHaveEdiData == false).GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }).Select(t => new { t.Key.PN, t.Key.CustomerPartCodeNoSpace });
var ediDetailGroup = db.Set<HBPO_SE_EDI>().Where(t => t.IsDeleted == false && t.IsHaveSeData == false).GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }).Select(t => new { t.Key.PN, t.Key.CustomerPartCodeNoSpace });
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
var keyCodes = from se in seDetailGroup
from edi in ediDetailGroup
where se.PN == edi.PN && se.CustomerPartCodeNoSpace == edi.CustomerPartCodeNoSpace
select new { se.PN, se.CustomerPartCodeNoSpace };
var seDetailsQuery = from se in db.Set<HBPO_SE_DETAIL>()
from keyCode in keyCodes
where se.PN == keyCode.PN && se.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && se.IsHaveEdiData == false
select se;
var ediDetailsQuery = from edi in db.Set<HBPO_SE_EDI>()
from keyCode in keyCodes
where edi.PN == keyCode.PN && edi.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && edi.IsDeleted == false && edi.IsHaveSeData == false
select edi;
await HandDelEdiDataAsync().ConfigureAwait(false);
var seDetailGroup = db.Set<HBPO_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var ediDetailGroup = db.Set<HBPO_SE_EDI>()
.Where(t => t.IsDeleted == false && t.IsHaveSeData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var keyCodes = (from se in seDetailGroup
from edi in ediDetailGroup
where se.PN == edi.PN && se.CustomerPartCodeNoSpace == edi.CustomerPartCodeNoSpace
select new { se.PN, se.CustomerPartCodeNoSpace }
).Take(1000).ToList();
if (keyCodes.Any())
{
var pns = keyCodes.Select(t => t.PN).Distinct().ToList();
var seDetails = seDetailsQuery.Take(5000).ToList();
var ediDetails = ediDetailsQuery.Take(5000).ToList();
var seDetails = db.Set<HBPO_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.Where(t => pns.Contains(t.PN))
.AsEnumerable<HBPO_SE_DETAIL>()
.GroupJoin(keyCodes, x => new { x.PN, x.CustomerPartCodeNoSpace }, y => y, (x, y) => x)
.ToList();
var ediDetails = db.Set<HBPO_SE_EDI>()
.Where(t => t.IsDeleted == false)
.Where(t => t.IsHaveSeData == false)
.Where(t => pns.Contains(t.PN))
.AsEnumerable<HBPO_SE_EDI>()
.GroupJoin(keyCodes, x => new { x.PN, x.CustomerPartCodeNoSpace }, y => y, (x, y) => x)
.ToList();
seDetails.ForEach(t => t.IsHaveEdiData = true);
ediDetails.ForEach(t => t.IsHaveSeData = true);
using var transaction = await db.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
@ -140,13 +79,8 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable
catch (Exception)
{
await transaction.RollbackAsync().ConfigureAwait(false);
throw;
}
}
catch (Exception)
{
throw;
}
}
/// <summary>

Loading…
Cancel
Save