From a8112c62cf3435f8999b982e372f16e7124b985f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BE=E8=8D=A3=E5=9B=BD?= Date: Thu, 20 Jan 2022 13:37:39 +0800 Subject: [PATCH] [fix]Event Sample(Part) --- .../Parts/ITaPartRepository.cs | 5 ++-- .../Repositories/TaPartRepository.cs | 26 ++++++++++++++++++- .../PartEventHandler.cs | 21 +++------------ .../PurchaseOrderEventHandler.cs | 2 +- .../ReceiptEventHandler.cs | 2 +- .../SupplierEventHandler.cs | 2 +- .../UnplannedReceiptEventHandler.cs | 2 +- 7 files changed, 36 insertions(+), 24 deletions(-) diff --git a/WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Parts/ITaPartRepository.cs b/WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Parts/ITaPartRepository.cs index 39ddb62..6a1256b 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Parts/ITaPartRepository.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Parts/ITaPartRepository.cs @@ -1,10 +1,11 @@ -using Volo.Abp.DependencyInjection; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories; namespace Win_in.Sfs.Scp.v1.Domain { public interface ITaPartRepository : IRepository,ITransientDependency { - + Task UpsertAsync(TA_PART taPart); } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.v1.EntityFrameworkCore/Repositories/TaPartRepository.cs b/WebApiService/src/Win_in.Sfs.Scp.v1.EntityFrameworkCore/Repositories/TaPartRepository.cs index 5f402ce..96ef239 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.v1.EntityFrameworkCore/Repositories/TaPartRepository.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.v1.EntityFrameworkCore/Repositories/TaPartRepository.cs @@ -1,4 +1,5 @@ -using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Win_in.Sfs.Scp.v1.Domain; @@ -10,5 +11,28 @@ namespace Win_in.Sfs.Scp.v1.EntityFrameworkCore public TaPartRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { } + + public async Task UpsertAsync( TA_PART taPart) + { + TA_PART ret; + var current = await GetAsync(p =>p.Site==taPart.Site + && p.PartCode == taPart.PartCode); + if (current == null) + { + ret =await InsertAsync(taPart); + } + else + { + + //使用直接赋值 + current.PartDesc1 = taPart.PartDesc1; + current.PartDesc2 = taPart.PartDesc2; + //... + + ret =await UpdateAsync(current); + } + + return ret; + } } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.v1.Event/PartEventHandler.cs b/WebApiService/src/Win_in.Sfs.Scp.v1.Event/PartEventHandler.cs index a1d1cb0..e7413f6 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.v1.Event/PartEventHandler.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.v1.Event/PartEventHandler.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities.Events; using Volo.Abp.EventBus; @@ -27,24 +28,10 @@ namespace Win_in.Sfs.Scp.WebApi var part = eventData.Entity; Console.WriteLine("Local Event:" + part.Code); - //根据传入数据新增或修改TA_PART - + //使用AutoMapper执行类型转换 var taPart = _objectMapper.Map(part); - var current = await _taPartRepository.GetAsync(p => p.PartCode == taPart.PartCode); - if (current == null) - { - await _taPartRepository.InsertAsync(taPart); - } - else - { - current = _objectMapper.Map(part); - - // current.PartDesc1 = part.Desc1; - // current.PartDesc2 = part.Desc2; - //... - - await _taPartRepository.UpdateAsync(current); - } + //根据传入数据新增或修改TA_PART + var ret = await _taPartRepository.UpsertAsync(taPart); } diff --git a/WebApiService/src/Win_in.Sfs.Scp.v1.Event/PurchaseOrderEventHandler.cs b/WebApiService/src/Win_in.Sfs.Scp.v1.Event/PurchaseOrderEventHandler.cs index c2ea19b..a922230 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.v1.Event/PurchaseOrderEventHandler.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.v1.Event/PurchaseOrderEventHandler.cs @@ -15,7 +15,7 @@ namespace Win_in.Sfs.Scp.WebApi return Task.CompletedTask; - //TODO 新增或修改TB_PO + //TODO 新增或修改TB_PO,TB_PO_DETAIL } } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.v1.Event/ReceiptEventHandler.cs b/WebApiService/src/Win_in.Sfs.Scp.v1.Event/ReceiptEventHandler.cs index 2958a42..385edd3 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.v1.Event/ReceiptEventHandler.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.v1.Event/ReceiptEventHandler.cs @@ -16,7 +16,7 @@ namespace Win_in.Sfs.Scp.WebApi return Task.CompletedTask; - //TODO 新增 TB_RECEIPT 或 TB_REJECT + //TODO 根据单据类型,新增 TB_RECEIPT 或 TB_REJECT } } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.v1.Event/SupplierEventHandler.cs b/WebApiService/src/Win_in.Sfs.Scp.v1.Event/SupplierEventHandler.cs index 7fb677c..8c07c7e 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.v1.Event/SupplierEventHandler.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.v1.Event/SupplierEventHandler.cs @@ -15,7 +15,7 @@ namespace Win_in.Sfs.Scp.WebApi return Task.CompletedTask; - //TODO 根据传入数据新增或修改TA_VENDER + //TODO 新增或修改TA_VENDER } } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.v1.Event/UnplannedReceiptEventHandler.cs b/WebApiService/src/Win_in.Sfs.Scp.v1.Event/UnplannedReceiptEventHandler.cs index 915f87b..e76fdb4 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.v1.Event/UnplannedReceiptEventHandler.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.v1.Event/UnplannedReceiptEventHandler.cs @@ -16,7 +16,7 @@ namespace Win_in.Sfs.Scp.WebApi return Task.CompletedTask; - //TODO 新增无订单的TB_RECEIPT + //TODO 新增或修改无订单的TB_RECEIPT } } } \ No newline at end of file