From 7ffc29083a810fadc2f20463acc9b928cf2d268f Mon Sep 17 00:00:00 2001 From: mahao Date: Wed, 6 Sep 2023 15:34:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E8=BF=90=E3=80=81EDI=E5=AF=B9?= =?UTF-8?q?=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BQ/Syncs/JisBBACSeEdiCompareAppService.cs | 53 ++++++++++++------- .../BQ/Syncs/JisHBPOSeEdiCompareAppService.cs | 53 ++++++++++++------- .../JisBBACSaSeEdiCompareExportService.cs | 9 ++-- .../JisBBACSeEdiCompareExportService.cs | 12 ++--- .../JisHBPOSaSeEdiCompareExportService.cs | 9 ++-- .../JisHBPOSeEdiCompareExportService.cs | 12 ++--- .../Report/SaSeCompareExportBaseService.cs | 11 ++-- 7 files changed, 95 insertions(+), 64 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 c75341b6..9c43c708 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 @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Coravel.Invocable; @@ -37,20 +36,20 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable 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, LU = t.Key.CustomerPartCodeNoSpace }); - var ediDetailGroup = db.Set().Where(t => t.IsDeleted == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU }); + 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).GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }).Select(t => new { t.Key.PN, t.Key.CustomerPartCodeNoSpace }); var keyCodes = from se in seDetailGroup from edi in ediDetailGroup - where se.PN == edi.PN && se.LU == edi.LU - select new { se.PN, se.LU }; + 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.LU && se.IsHaveEdiData == false + 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.LU == keyCode.LU && edi.IsDeleted == false && edi.IsHaveSeData == false + where edi.PN == keyCode.PN && edi.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && edi.IsDeleted == false && edi.IsHaveSeData == false select edi; var seDetails = seDetailsQuery.Take(5000).ToList(); @@ -90,24 +89,38 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable */ using var serviceScope = _serviceProvider.CreateScope(); var db = serviceScope.ServiceProvider.GetRequiredService(); - //Edi 删除的数据(有发运数据) - var ediDelKeyCodes = db.Set().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct().ToList(); - - if (ediDelKeyCodes.Any()) + var seed = 0; + while (seed < 10) { - var seDetails = db.Set().Join(ediDelKeyCodes, a => new { a.PN, LU = a.CustomerPartCodeNoSpace }, b => new { b.PN, b.LU }, (a, b) => a); - var ediDetails = db.Set().Join(ediDelKeyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a); - if (seDetails.Any()) + 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(); + if (ediDelKeyCodes.Any()) { - seDetails.ForEach(t => t.IsHaveEdiData = false); - db.Set().UpdateRange(seDetails); + 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); + } + + 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); + } } - if (ediDetails.Any()) + else { - ediDetails.ForEach(t => t.IsHaveSeData = false); - db.Set().UpdateRange(ediDetails); + break; } - await db.SaveChangesAsync().ConfigureAwait(false); } } } 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 290008fe..e7d203d5 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 @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Threading.Tasks; @@ -38,20 +37,20 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable 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, LU = t.Key.CustomerPartCodeNoSpace }); - var ediDetailGroup = db.Set().Where(t => t.IsDeleted == false && t.IsHaveSeData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU }); + 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 }); var keyCodes = from se in seDetailGroup from edi in ediDetailGroup - where se.PN == edi.PN && se.LU == edi.LU - select new { se.PN, se.LU }; + 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.LU && se.IsHaveEdiData == false + 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.LU == keyCode.LU && edi.IsDeleted == false && edi.IsHaveSeData == false + where edi.PN == keyCode.PN && edi.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && edi.IsDeleted == false && edi.IsHaveSeData == false select edi; var seDetails = seDetailsQuery.Take(5000).ToList(); @@ -85,24 +84,38 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable { using var serviceScope = _serviceProvider.CreateScope(); var db = serviceScope.ServiceProvider.GetRequiredService(); - //Edi 删除的数据(有发运数据) - var ediDelKeyCodes = db.Set().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct().ToList(); - - if (ediDelKeyCodes.Any()) + var seed = 0; + while (seed < 10) { - var seDetails = db.Set().Join(ediDelKeyCodes, a => new { a.PN, LU = a.CustomerPartCodeNoSpace }, b => new { b.PN, b.LU }, (a, b) => a); - var ediDetails = db.Set().Join(ediDelKeyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a); - if (seDetails.Any()) + 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(); + if (ediDelKeyCodes.Any()) { - seDetails.ForEach(t => t.IsHaveEdiData = false); - db.Set().UpdateRange(seDetails); + 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); + } + + 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); + } } - if (ediDetails.Any()) + else { - ediDetails.ForEach(t => t.IsHaveSeData = false); - db.Set().UpdateRange(ediDetails); + break; } - await db.SaveChangesAsync().ConfigureAwait(false); } } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSaSeEdiCompareExportService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSaSeEdiCompareExportService.cs index b255c3c0..f4402be1 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSaSeEdiCompareExportService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSaSeEdiCompareExportService.cs @@ -149,16 +149,17 @@ namespace SettleAccount.Job.Services.Report //Edi var ediGroup = from edi in _settleAccountDbContext.Set() where edi.IsDeleted == false && edi.IsHaveSeData == true - group edi by new { edi.PN, edi.LU } into groupItem + group edi by new { edi.PN, edi.CustomerPartCodeNoSpace } into groupItem select new { groupItem.Key.PN, - groupItem.Key.LU, - Qty = groupItem.Sum(t => t.Qty) + groupItem.Key.CustomerPartCodeNoSpace, + Qty = groupItem.Sum(t => t.Qty), + LU = groupItem.Max(t => t.LU) }; var seEdiGroup = from se in seGroup join edi in ediGroup - on new { se.PN, se.CustomerPartCodeNoSpace } equals new { edi.PN, CustomerPartCodeNoSpace = edi.LU } + on new { se.PN, se.CustomerPartCodeNoSpace } equals new { edi.PN, edi.CustomerPartCodeNoSpace } into ediTemp from edi in ediTemp.DefaultIfEmpty() select new diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSeEdiCompareExportService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSeEdiCompareExportService.cs index 0aab90ac..0a6d9dac 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSeEdiCompareExportService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSeEdiCompareExportService.cs @@ -77,7 +77,7 @@ namespace SettleAccount.Job.Services.Report //有EDI无发运 var haveEdiNotHaveSeList = _settleAccountDbContext.Set().Where(t => t.IsHaveSeData == false) - .GroupBy(t => new { t.LU, t.PN }) + .GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }) .Select(t => new JisBBACEidSeCompareExport() { Category = "JIS", @@ -86,7 +86,7 @@ namespace SettleAccount.Job.Services.Report SequenceNumber = t.Max(t => t.Extend3), ParType = t.Max(t => t.Extend2), PN = t.Key.PN, - MaterialNumber = t.Key.LU, + MaterialNumber = t.Max(t => t.LU), EdiQty = t.Sum(t => t.Qty), AssemblyDate = default, MatchNumber = default, @@ -95,7 +95,7 @@ namespace SettleAccount.Job.Services.Report }).ToList(); //无EDI有发运 var notHaveEdiHaveSeList = _settleAccountDbContext.Set().Where(t => t.IsHaveEdiData == false) - .GroupBy(t => new { t.CustomerPartCodeNoSpace, t.PN }) + .GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }) .Select(t => new JisBBACEidSeCompareExport() { Category = "JIS", @@ -115,11 +115,11 @@ namespace SettleAccount.Job.Services.Report //有EDI有发运 var ediGroup = from edi in _settleAccountDbContext.Set() where edi.IsDeleted == false && edi.IsHaveSeData == true - group edi by new { edi.PN, edi.LU } into groupItem + group edi by new { edi.PN, edi.CustomerPartCodeNoSpace } into groupItem select new { groupItem.Key.PN, - groupItem.Key.LU, + groupItem.Key.CustomerPartCodeNoSpace, Qty = groupItem.Sum(t => t.Qty), Extend2 = groupItem.Max(t => t.Extend2), Extend3 = groupItem.Max(t => t.Extend3), @@ -146,7 +146,7 @@ namespace SettleAccount.Job.Services.Report }; var haveEdiHaveSeList = (from edi in ediGroup join se in seGroup - on new { edi.PN, edi.LU } equals new { se.PN, LU = se.CustomerPartCodeNoSpace } + on new { edi.PN, edi.CustomerPartCodeNoSpace } equals new { se.PN, se.CustomerPartCodeNoSpace } select new JisBBACEidSeCompareExport() { Category = "JIS", diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSaSeEdiCompareExportService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSaSeEdiCompareExportService.cs index 8a7fe7ab..3ca8f1fd 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSaSeEdiCompareExportService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSaSeEdiCompareExportService.cs @@ -164,16 +164,17 @@ namespace SettleAccount.Job.Services.Report //Edi var ediGroup = from edi in _settleAccountDbContext.Set() where edi.IsDeleted == false && edi.IsHaveSeData == true - group edi by new { edi.PN, edi.LU } into groupItem + group edi by new { edi.PN, edi.CustomerPartCodeNoSpace } into groupItem select new { groupItem.Key.PN, - groupItem.Key.LU, - Qty = groupItem.Sum(t => t.Qty) + groupItem.Key.CustomerPartCodeNoSpace, + Qty = groupItem.Sum(t => t.Qty), + LU = groupItem.Max(t => t.LU) }; var seEdiGroup = from se in seGroup join edi in ediGroup - on new { se.PN, se.CustomerPartCodeNoSpace } equals new { edi.PN, CustomerPartCodeNoSpace = edi.LU } + on new { se.PN, se.CustomerPartCodeNoSpace } equals new { edi.PN, edi.CustomerPartCodeNoSpace } into ediTemp from edi in ediTemp.DefaultIfEmpty() select new diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSeEdiCompareExportService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSeEdiCompareExportService.cs index d095c8bb..58fef3a4 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSeEdiCompareExportService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSeEdiCompareExportService.cs @@ -74,7 +74,7 @@ namespace SettleAccount.Job.Services.Report //有EDI无发运 var haveEdiNotHaveSeList = _settleAccountDbContext.Set().Where(t => t.IsHaveSeData == false) - .GroupBy(t => new { t.LU, t.PN }) + .GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }) .Select(t => new JisHBPOEidSeCompareExport() { Category = "JIS", @@ -83,7 +83,7 @@ namespace SettleAccount.Job.Services.Report SequenceNumber = t.Max(t => t.SeqNumber), ParType = "01", PN = t.Key.PN, - MaterialNumber = t.Key.LU, + MaterialNumber = t.Max(t => t.LU), EdiQty = t.Sum(t => t.Qty), AssemblyDate = default, MatchNumber = default, @@ -92,7 +92,7 @@ namespace SettleAccount.Job.Services.Report }).ToList(); //无EDI有发运 var notHaveEdiHaveSeList = _settleAccountDbContext.Set().Where(t => t.IsHaveEdiData == false) - .GroupBy(t => new { t.CustomerPartCodeNoSpace, t.PN }) + .GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }) .Select(t => new JisHBPOEidSeCompareExport() { Category = "JIS", @@ -114,11 +114,11 @@ namespace SettleAccount.Job.Services.Report //有EDI有发运 var ediGroup = from edi in _settleAccountDbContext.Set() where edi.IsDeleted == false && edi.IsHaveSeData == true - group edi by new { edi.PN, edi.LU } into groupItem + group edi by new { edi.PN, edi.CustomerPartCodeNoSpace } into groupItem select new { groupItem.Key.PN, - groupItem.Key.LU, + groupItem.Key.CustomerPartCodeNoSpace, Qty = groupItem.Sum(t => t.Qty), SeqNumber = groupItem.Max(t => t.SeqNumber) }; @@ -143,7 +143,7 @@ namespace SettleAccount.Job.Services.Report }; var haveEdiHaveSeList = (from edi in ediGroup join se in seGroup - on new { edi.PN, edi.LU } equals new { se.PN, LU = se.CustomerPartCodeNoSpace } + on new { edi.PN, edi.CustomerPartCodeNoSpace } equals new { se.PN, se.CustomerPartCodeNoSpace } select new JisHBPOEidSeCompareExport() { Category = "JIS", diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs index ad469c7a..84dc1bf8 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs @@ -4,10 +4,10 @@ using EFCore.BulkExtensions; using Magicodes.ExporterAndImporter.Core.Extension; using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.SignalR; +using Microsoft.EntityFrameworkCore; using SettleAccount.Bases; using SettleAccount.Domain.BQ; using SettleAccount.Job.SignalR; -using Volo.Abp; using Win.Sfs.SettleAccount; using Win.Sfs.SettleAccount.Consts; using Win.Sfs.SettleAccount.Enums; @@ -184,9 +184,10 @@ namespace SettleAccount.Job.Services.Report if (haveSaHaveSes.Any()) { //结算详情 - var saDetails = (from sa in _settleAccountDbContext.Set() - where sa.BusinessType == businessType && sa.Version == version - select sa).ToList(); + var saDetails = _settleAccountDbContext.Set() + .Where(t => t.BusinessType == businessType) + .Where(t => t.Version == version) + .ToList(); if (saDetails.Any()) { var saDetailsUpdate = saDetails.Join(haveSaHaveSes, o => new { o.PN, o.LU }, i => new { i.PN, LU = i.CustomerPartCode }, (o, i) => @@ -202,6 +203,8 @@ namespace SettleAccount.Job.Services.Report return o; }).ToList(); _settleAccountDbContext.BulkUpdate(saDetailsUpdate); + _settleAccountDbContext.Set().FromSqlInterpolated($"SELECT * FROM dbo.Blogs"); + _settleAccountDbContext.Database.ExecuteSqlInterpolated($"SELECT * FROM dbo.Blogs"); } } }