From 5a5ca9f39e544456eaeef5b36b29c9f201d54d61 Mon Sep 17 00:00:00 2001 From: mahao Date: Tue, 15 Aug 2023 15:27:56 +0800 Subject: [PATCH] =?UTF-8?q?Jis=E5=8F=91=E8=BF=90=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BQ/Syncs/BBACSeSyncAppService.cs | 18 ++-- .../Entities/BQ/Syncs/HBPOSeSyncAppService.cs | 13 ++- .../BQ/Syncs/JisBBACSeEdiCompareAppService.cs | 72 ++++++++++---- .../BQ/Syncs/JisHBPOSeEdiCompareAppService.cs | 97 ++++++++++--------- .../Managers/MaterialRelationshipManager.cs | 3 +- .../Entities/BQ/Syncs/TM_BJBMPT_JIS_RECORD.cs | 10 +- .../Entities/BQ/Syncs/TM_BJBMPT_JIT_RECORD.cs | 11 +-- 7 files changed, 135 insertions(+), 89 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/BBACSeSyncAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/BBACSeSyncAppService.cs index d9df6905..ae136f48 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/BBACSeSyncAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/BBACSeSyncAppService.cs @@ -39,14 +39,14 @@ public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService private readonly INormalEfCoreRepository _bbacSeDetailRepository; /// - /// 客户零件关系仓储 + /// 客户零件关系领域 /// - private readonly INormalEfCoreRepository _materialRelationshipRepository; + private readonly MaterialRelationshipManager _materialRelationshipManager; /// - /// 客户零件关系领域 + /// 客户零件关系集合 /// - private readonly MaterialRelationshipManager _materialRelationshipManager; + private List _addMaterialRelationships; /// /// 构造 @@ -61,6 +61,7 @@ public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService _syncPositionFlagRepository = syncPositionFlagRepository; _bbacSeDetailRepository = bbacSeDetailRepository; _materialRelationshipManager = materialRelationshipManager; + _addMaterialRelationships = new List(); } [ApiExplorerSettings(IgnoreApi = true)] @@ -74,6 +75,11 @@ public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService { await SyncJitRecordAsync(); await SyncJisRecordAsync(); + if (_addMaterialRelationships.Any()) + { + _addMaterialRelationships = _addMaterialRelationships.GroupBy(t => new { t.ErpMaterialCode }).Select(t => t.First()).ToList(); + await _materialRelationshipManager.AddNewMaterialRelationships(_addMaterialRelationships).ConfigureAwait(false); + } } /// @@ -101,7 +107,7 @@ public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService { //客户零件号和厂内零件号 var materialRelationships = bbacSeDetails.GroupBy(t => new { t.LU, t.PartCode }).Select(t => new MaterialRelationship(GuidGenerator.Create(), t.Key.LU, "", t.Key.PartCode, "")); - await _materialRelationshipManager.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false); + _addMaterialRelationships.AddRange(materialRelationships); bbacSeDetails.ForEach(bbacSeDetail => { @@ -151,7 +157,7 @@ public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService { //客户零件号和厂内零件号 var materialRelationships = bbacSeDetails.GroupBy(t => new { t.LU, t.PartCode }).Select(t => new MaterialRelationship(GuidGenerator.Create(), t.Key.LU, "", t.Key.PartCode, "")); - await _materialRelationshipManager.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false); + _addMaterialRelationships.AddRange(materialRelationships); bbacSeDetails.ForEach(bbacSeDetail => bbacSeDetail.KeyCode = bbacSeDetail.PN + bbacSeDetail.LU); await _bbacSeDetailRepository.InsertManyAsync(bbacSeDetails); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/HBPOSeSyncAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/HBPOSeSyncAppService.cs index 0b4bf49d..480740a9 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/HBPOSeSyncAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/HBPOSeSyncAppService.cs @@ -49,6 +49,11 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable, IJobService /// private readonly MaterialRelationshipManager _materialRelationshipManager; + /// + /// 客户零件关系集合 + /// + private List _addMaterialRelationships; + /// /// 构造 /// @@ -64,6 +69,7 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable, IJobService _hbpoSeDetailRepository = hbpoSeDetailRepository; _pubSeDetailRepository = pubSeDetailRepository; _materialRelationshipManager = materialRelationshipManager; + _addMaterialRelationships = new List(); } [ApiExplorerSettings(IgnoreApi = true)] @@ -80,6 +86,11 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable, IJobService { await SyncJitRecordAsync().ConfigureAwait(false); await SyncJisRecordAsync().ConfigureAwait(false); + if (_addMaterialRelationships.Any()) + { + _addMaterialRelationships = _addMaterialRelationships.GroupBy(t => new { t.ErpMaterialCode }).Select(t => t.First()).ToList(); + await _materialRelationshipManager.AddNewMaterialRelationships(_addMaterialRelationships).ConfigureAwait(false); + } } /// @@ -200,7 +211,7 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable, IJobService var maiDanHBPOSeLuRePartCodes = maiDanHBPOSeDetails.Select(t => new { t.LU, t.PartCode }); var luRePartCodes = hbpoSeLuRePartCodes.Union(maiDanHBPOSeLuRePartCodes); var materialRelationships = luRePartCodes.GroupBy(t => new { t.LU, t.PartCode }).Select(t => new MaterialRelationship(GuidGenerator.Create(), t.Key.LU, "", t.Key.PartCode, "")); - await _materialRelationshipManager.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false); + _addMaterialRelationships.AddRange(materialRelationships); hbpoSeDetails.ForEach(hbpoSeDetail => hbpoSeDetail.KeyCode = hbpoSeDetail.PN + hbpoSeDetail.LU); maiDanHBPOSeDetails.ForEach(maiDanHBPOSeDetail => 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 17a8ada2..fbd80e37 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 @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Coravel.Invocable; +using LinqToDB; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using SettleAccount.Domain.BQ; using Volo.Abp.Application.Services; @@ -16,6 +18,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; [ApiExplorerSettings(IgnoreApi = true)] public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable { + private readonly object _lockObj = new object(); private readonly IServiceProvider _serviceProvider; public JisBBACSeEdiCompareAppService(IServiceProvider serviceProvider) @@ -28,21 +31,39 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable /// public async Task Invoke() { - using var serviceScope = _serviceProvider.CreateScope(); - var db = serviceScope.ServiceProvider.GetRequiredService(); - - await HandDelEdiDataAsync().ConfigureAwait(false); + try + { + using var serviceScope = _serviceProvider.CreateScope(); + var db = serviceScope.ServiceProvider.GetRequiredService(); - var seDetailGroup = db.Set().Where(t => t.IsHaveEdiData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU }); - 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 keyCodes = seDetailGroup.Join(ediDetailGroup, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (se, edi) => new { se.PN, se.LU }); - var seDetails = db.Set().Where(t => keyCodes.Contains(new { t.PN, t.LU })); - var ediDetails = db.Set().Where(t => keyCodes.Contains(new { t.PN, t.LU })); - seDetails.ForEach(t => t.IsHaveEdiData = true); - ediDetails.ForEach(t => t.IsHaveSeData = true); - db.Set().UpdateRange(seDetails); - db.Set().UpdateRange(ediDetails); - await db.SaveChangesAsync().ConfigureAwait(false); + await HandDelEdiDataAsync().ConfigureAwait(false); + lock (_lockObj) + { + var seDetailGroup = db.Set().Where(t => t.IsHaveEdiData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU }); + 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 keyCodes = seDetailGroup.Join(ediDetailGroup, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (se, edi) => new { se.PN, se.LU }); + if (keyCodes.Any()) + { + var seDetails = db.Set().Join(keyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a); + var ediDetails = db.Set().Join(keyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a); + if (seDetails.Any()) + { + seDetails.ForEach(t => t.IsHaveEdiData = true); + db.Set().UpdateRange(seDetails); + } + if (ediDetails.Any()) + { + ediDetails.ForEach(t => t.IsHaveSeData = true); + db.Set().UpdateRange(ediDetails); + } + db.SaveChanges(); + } + } + } + catch (Exception) + { + throw; + } } /// @@ -61,12 +82,21 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable //Edi 删除的数据(有发运数据) var ediDelKeyCodes = db.Set().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct(); - var seDetails = db.Set().Where(t => ediDelKeyCodes.Contains(new { t.PN, t.LU })); - var ediDetails = db.Set().Where(t => ediDelKeyCodes.Contains(new { t.PN, t.LU })); - seDetails.ForEach(t => t.IsHaveEdiData = false); - ediDetails.ForEach(t => t.IsHaveSeData = false); - db.Set().UpdateRange(seDetails); - db.Set().UpdateRange(ediDetails); - await db.SaveChangesAsync().ConfigureAwait(false); + if (ediDelKeyCodes.Any()) + { + var seDetails = db.Set().Join(ediDelKeyCodes, a => new { a.PN, a.LU }, 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()) + { + seDetails.ForEach(t => t.IsHaveEdiData = false); + db.Set().UpdateRange(seDetails); + } + if (ediDetails.Any()) + { + ediDetails.ForEach(t => t.IsHaveSeData = false); + db.Set().UpdateRange(ediDetails); + } + 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 42ff332f..3fce2653 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 @@ -20,6 +20,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; [ApiExplorerSettings(IgnoreApi = true)] public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable { + private readonly object _lockObj = new object(); private readonly IServiceProvider _serviceProvider; /// @@ -46,48 +47,39 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable /// public async Task Invoke() { - Debug.WriteLine($"执行了:{this.GetType()}"); - using var serviceScope = _serviceProvider.CreateScope(); - var db = serviceScope.ServiceProvider.GetRequiredService(); - - await HandDelEdiDataAsync().ConfigureAwait(false); - - var seDetailGroup = from se in db.Set() - where se.IsHaveEdiData == false - group se by new { se.PN, se.LU } - into a - select new { a.Key.PN, a.Key.LU }; - - var ediDetailGroup = from edi in db.Set() - where edi.IsDeleted == false && edi.IsHaveSeData == false - group edi by new { edi.PN, edi.LU } - into a - select new { a.Key.PN, a.Key.LU }; - - var keyCodes = from se in seDetailGroup - join edi in ediDetailGroup on new - { - se.PN, - se.LU - } equals new - { - edi.PN, - edi.LU - } - select new { se.PN, se.LU }; - - //var seDetailGroup2 = db.Set().Where(t => t.IsHaveEdiData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU }); - //var ediDetailGroup2 = db.Set().Where(t => t.IsHaveSeData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU }); - //var keyCodes2 = seDetailGroup2.Join(ediDetailGroup2, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (se, edi) => new { se.PN, se.LU }); - var seDetails = db.Set().Where(t => keyCodes.Contains(new { t.PN, t.LU })); - var ediDetails = db.Set().Where(t => keyCodes.Contains(new { t.PN, t.LU })); - seDetails.ForEach(t => t.IsHaveEdiData = true); - ediDetails.ForEach(t => t.IsHaveSeData = true); - db.Set().UpdateRange(seDetails); - db.Set().UpdateRange(ediDetails); - await db.SaveChangesAsync().ConfigureAwait(false); + try + { + using var serviceScope = _serviceProvider.CreateScope(); + var db = serviceScope.ServiceProvider.GetRequiredService(); - Debug.WriteLine($"处理数量:{keyCodes.Count()}"); + await HandDelEdiDataAsync().ConfigureAwait(false); + lock (_lockObj) + { + var seDetailGroup = db.Set().Where(t => t.IsHaveEdiData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU }); + 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 keyCodes = seDetailGroup.Join(ediDetailGroup, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (se, edi) => new { se.PN, se.LU }); + if (keyCodes.Any()) + { + var seDetails = db.Set().Join(keyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a); + var ediDetails = db.Set().Join(keyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a); + if (seDetails.Any()) + { + seDetails.ForEach(t => t.IsHaveEdiData = true); + db.Set().UpdateRange(seDetails); + } + if (ediDetails.Any()) + { + ediDetails.ForEach(t => t.IsHaveSeData = true); + db.Set().UpdateRange(ediDetails); + } + db.SaveChanges(); + } + } + } + catch (Exception) + { + throw; + } } /// @@ -100,12 +92,21 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable //Edi 删除的数据(有发运数据) var ediDelKeyCodes = db.Set().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct(); - var seDetails = db.Set().Where(t => ediDelKeyCodes.Contains(new { t.PN, t.LU })); - var ediDetails = db.Set().Where(t => ediDelKeyCodes.Contains(new { t.PN, t.LU })); - seDetails.ForEach(t => t.IsHaveEdiData = false); - ediDetails.ForEach(t => t.IsHaveSeData = false); - db.Set().UpdateRange(seDetails); - db.Set().UpdateRange(ediDetails); - await db.SaveChangesAsync().ConfigureAwait(false); + if (ediDelKeyCodes.Any()) + { + var seDetails = db.Set().Join(ediDelKeyCodes, a => new { a.PN, a.LU }, 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()) + { + seDetails.ForEach(t => t.IsHaveEdiData = false); + db.Set().UpdateRange(seDetails); + } + if (ediDetails.Any()) + { + ediDetails.ForEach(t => t.IsHaveSeData = false); + db.Set().UpdateRange(ediDetails); + } + await db.SaveChangesAsync().ConfigureAwait(false); + } } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/MaterialRelationshipManager.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/MaterialRelationshipManager.cs index 0400a179..75072812 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/MaterialRelationshipManager.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/MaterialRelationshipManager.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Services; using Win.Sfs.SettleAccount.MaterialRelationships; using Win.Sfs.Shared.RepositoryBase; @@ -29,7 +30,7 @@ public class MaterialRelationshipManager : DomainService { //客户零件号和厂内零件号 var luRePartCodes = materialRelationships.Select(t => new { t.ErpMaterialCode, t.SettleMaterialCode }).Distinct().ToList(); - var haveLuRePartCodes = materialRelationships.Join(_materialRelationshipRepository, + var haveLuRePartCodes = materialRelationships.Join(_materialRelationshipRepository.AsNoTracking(), a => new { a.ErpMaterialCode, a.SettleMaterialCode }, b => new { b.ErpMaterialCode, b.SettleMaterialCode }, (a, b) => a).ToList(); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIS_RECORD.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIS_RECORD.cs index 08fd2553..452748c8 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIS_RECORD.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIS_RECORD.cs @@ -35,8 +35,8 @@ public class TM_BJBMPT_JIS_RECORD [DisplayName("JIS生产码类型")] public string CodeType { get; set; } - [DisplayName("状态")] - public EnumBillState State { get; set; } + //[DisplayName("状态")] + //public EnumBillState State { get; set; } [DisplayName("订单零件号")] public string RealPartCode { get; set; } @@ -51,7 +51,7 @@ public class TM_BJBMPT_JIS_RECORD public string CustPartCode { get; set; } [DisplayName("数量")] - public decimal Qty { get; set; } + public decimal? Qty { get; set; } [DisplayName("发货单号")] public string BillNum { get; set; } @@ -60,7 +60,7 @@ public class TM_BJBMPT_JIS_RECORD public string MESConfigCode { get; set; } [DisplayName("订单时间")] - public DateTime AssembleData { get; set; } + public DateTime? AssembleData { get; set; } [DisplayName("来源库位")] public string FromLoc { get; set; } @@ -120,5 +120,5 @@ public class TM_BJBMPT_JIS_RECORD public string Position { get; set; } [DisplayName("创建时间")] - public DateTime CreateTime { get; set; } + public DateTime? CreateTime { get; set; } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIT_RECORD.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIT_RECORD.cs index fd21f5f9..67c6d5db 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIT_RECORD.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIT_RECORD.cs @@ -39,7 +39,7 @@ public class TM_BJBMPT_JIT_RECORD public string Seq { get; set; } [DisplayName("订单时间")] - public DateTime AssembleData { get; set; } + public DateTime? AssembleData { get; set; } [DisplayName("发货条码")] public string DeliverCode { get; set; } @@ -89,9 +89,6 @@ public class TM_BJBMPT_JIT_RECORD [DisplayName("原生产码")] public string OrigiCode { get; set; } - [DisplayName("描述")] - public string PartDesc { get; set; } - [DisplayName("备注")] public string Remark { get; set; } @@ -125,11 +122,11 @@ public class TM_BJBMPT_JIT_RECORD [DisplayName("虚拟小总成")] public string MatchNumber { get; set; } - [DisplayName("状态")] - public EnumBillState State { get; set; } + //[DisplayName("状态")] + //public EnumBillState State { get; set; } [DisplayName("创建时间")] - public DateTime CreateTime { get; set; } + public DateTime? CreateTime { get; set; } } public enum EnumProTpe