From 4df7b76833d41fe65272728a0d8236063cdbf573 Mon Sep 17 00:00:00 2001 From: mahao Date: Thu, 7 Sep 2023 14:34:21 +0800 Subject: [PATCH] UP --- .../BQ/Syncs/JisBBACSeEdiCompareAppService.cs | 75 +++++----- .../BQ/Syncs/JisHBPOSeEdiCompareAppService.cs | 136 +++++------------- 2 files changed, 72 insertions(+), 139 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs index d18e986a..1fdb81d2 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs @@ -29,40 +29,44 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable /// public async Task Invoke() { - try - { - using var serviceScope = _serviceProvider.CreateScope(); - var db = serviceScope.ServiceProvider.GetRequiredService(); + using var serviceScope = _serviceProvider.CreateScope(); + var db = serviceScope.ServiceProvider.GetRequiredService(); - await HandDelEdiDataAsync().ConfigureAwait(false); + await HandDelEdiDataAsync().ConfigureAwait(false); - var seDetailGroup = db.Set() - .Where(t => t.IsHaveEdiData == false) - .GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }) - .Select(t => t.Key); - var ediDetailGroup = db.Set() - .Where(t => t.IsDeleted == false) - .GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }) - .Select(t => t.Key); + var seDetailGroup = db.Set() + .Where(t => t.IsHaveEdiData == false) + .GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }) + .Select(t => t.Key); + var ediDetailGroup = db.Set() + .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() - 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() - 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() + .Where(t => t.IsHaveEdiData == false) + .Where(t => pns.Contains(t.PN)) + .AsEnumerable() + .GroupJoin(keyCodes, x => new { x.PN, x.CustomerPartCodeNoSpace }, y => y, (x, y) => x) + .ToList(); + var ediDetails = db.Set() + .Where(t => t.IsDeleted == false) + .Where(t => t.IsHaveSeData == false) + .Where(t => pns.Contains(t.PN)) + .AsEnumerable() + .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; - } } /// @@ -100,27 +99,27 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable { seed++; //Edi 删除的数据(有发运数据) - var ediDelKeyCodes = db.Set().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).GroupBy(t => t.PN).Select(t => t.Key).Take(1000).ToList(); + var ediDelKeyCodes = db.Set().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() + var seDetails = db.Set() .Where(t => t.IsHaveEdiData == true) .Where(t => ediDelKeyCodes.Contains(t.PN)) .ToList(); if (seDetails.Any()) { seDetails.ForEach(t => t.IsHaveEdiData = false); - await db.BulkUpdateAsync(seDetails).ConfigureAwait(false); + await db.BulkUpdateAsync(seDetails).ConfigureAwait(false); } - var ediDetails = db.Set() + var ediDetails = db.Set() .Where(t => t.IsHaveSeData == true) .Where(t => ediDelKeyCodes.Contains(t.PN)) .ToList(); if (ediDetails.Any()) { ediDetails.ForEach(t => t.IsHaveSeData = false); - await db.BulkUpdateAsync(ediDetails).ConfigureAwait(false); + await db.BulkUpdateAsync(ediDetails).ConfigureAwait(false); } } else diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs index 88ec8c01..62af0ff4 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs +++ b/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; } - /// - /// 执行 - /// - public async Task InvokeOld() - { - try - { - using var serviceScope = _serviceProvider.CreateScope(); - var db = serviceScope.ServiceProvider.GetRequiredService(); - - await HandDelEdiDataAsync().ConfigureAwait(false); - - var seDetailGroup = db.Set() - .Where(t => t.IsHaveEdiData == false) - .GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }) - .Select(t => t.Key); - var ediDetailGroup = db.Set() - .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() - 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() - 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(seDetails).ConfigureAwait(false); - await db.BulkUpdateAsync(ediDetails).ConfigureAwait(false); - await transaction.CommitAsync().ConfigureAwait(false); - } - catch (Exception) - { - await transaction.RollbackAsync().ConfigureAwait(false); - throw; - } - } - catch (Exception) - { - throw; - } - } - /// /// 执行 /// public async Task Invoke() { - try - { - using var serviceScope = _serviceProvider.CreateScope(); - var db = serviceScope.ServiceProvider.GetRequiredService(); - - await HandDelEdiDataAsync().ConfigureAwait(false); - - var seDetailGroup = db.Set().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().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(); - 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() - 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() - 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() + .Where(t => t.IsHaveEdiData == false) + .GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }) + .Select(t => t.Key); + var ediDetailGroup = db.Set() + .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() + .Where(t => t.IsHaveEdiData == false) + .Where(t => pns.Contains(t.PN)) + .AsEnumerable() + .GroupJoin(keyCodes, x => new { x.PN, x.CustomerPartCodeNoSpace }, y => y, (x, y) => x) + .ToList(); + var ediDetails = db.Set() + .Where(t => t.IsDeleted == false) + .Where(t => t.IsHaveSeData == false) + .Where(t => pns.Contains(t.PN)) + .AsEnumerable() + .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; - } } ///