|
|
@ -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>
|
|
|
|