From 951f29565427dcbe0a72ff8ef1e91e8968d7bc4b Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 14 Jan 2022 09:02:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/Materials/MaterialAppService.cs | 4 +- .../Entities/Prices/PriceList.cs | 6 ++- .../Entities/Prices/PriceListManager.cs | 39 +++++++++++++------ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Materials/MaterialAppService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Materials/MaterialAppService.cs index 019902cf..9f6825b7 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Materials/MaterialAppService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Materials/MaterialAppService.cs @@ -174,7 +174,7 @@ namespace Win.Sfs.SettleAccount.Entities.Materials var _first = result.FirstOrDefault(p => p.MaterialCode == itm); if (_first != null) { - var _price = new PriceList(GuidGenerator.Create(), DateTime.MinValue, DateTime.MaxValue, _first.MaterialPrice, _first.MaterialCode, 0, GuidGenerator.Create(), version); + var _price = new PriceList(GuidGenerator.Create(), DateTime.MinValue, DateTime.MaxValue, _first.MaterialPrice, _first.MaterialCode, 0, GuidGenerator.Create(), version,string.Empty); _priceList.Add(_price); } } @@ -183,7 +183,7 @@ namespace Win.Sfs.SettleAccount.Entities.Materials var _first = result.FirstOrDefault(p => p.ChildMaterialCode == itm); if (_first != null) { - var _price = new PriceList(GuidGenerator.Create(), DateTime.MinValue, DateTime.MaxValue, _first.ChildMaterialPrice, _first.ChildMaterialCode, 0, GuidGenerator.Create(), version); + var _price = new PriceList(GuidGenerator.Create(), DateTime.MinValue, DateTime.MaxValue, _first.ChildMaterialPrice, _first.ChildMaterialCode, 0, GuidGenerator.Create(), version,string.Empty); _priceList.Add(_price); } } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/Prices/PriceList.cs b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/Prices/PriceList.cs index 720e4bac..b60d25c2 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/Prices/PriceList.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/Prices/PriceList.cs @@ -20,7 +20,7 @@ namespace Win.Sfs.SettleAccount.Entities.Prices { public PriceList() { } - public PriceList(Guid Id,DateTime beginDate, DateTime endDate, decimal price, string materialCode, int type,Guid parentId,string version):base(Id) + public PriceList(Guid Id,DateTime beginDate, DateTime endDate, decimal price, string materialCode, int type,Guid parentId,string version, string customerCode) :base(Id) { BeginDate = beginDate; EndDate = endDate; @@ -29,15 +29,17 @@ namespace Win.Sfs.SettleAccount.Entities.Prices Type = type; ParentId = parentId; Version = version; + CustomerCode = customerCode; } - public void Set(DateTime beginDate, DateTime endDate, decimal price, string materialCode, int type) + public void Set(DateTime beginDate, DateTime endDate, decimal price, string materialCode, int type,string customerCode) { BeginDate = beginDate; EndDate = endDate; Price = price; MaterialCode = materialCode; Type = type; + CustomerCode = customerCode; } public void Update(Guid id,string version) { diff --git a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/Prices/PriceListManager.cs b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/Prices/PriceListManager.cs index b91ebbc6..50f968ee 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/Prices/PriceListManager.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/Prices/PriceListManager.cs @@ -78,25 +78,40 @@ namespace Win.Sfs.SettleAccount.Entities.Prices var pricelist = GetPriceList(version); - + //var LeftJoin = from emp in ListOfEmployees // join dept in ListOfDepartment // on emp.DeptID equals dept.ID into JoinedEmpDept // from dept in JoinedEmpDept.DefaultIfEmpty() - - var add= from itm1 in entities join itm2 in pricelist - on new { itm1.Type, itm1.CustomerCode, itm1.MaterialCode } equals new { itm2.Type, itm2.CustomerCode, itm2.MaterialCode } - into temp from itm3 in temp.DefaultIfEmpty() where itm3 == null select itm1; - var update = from itm1 in entities join itm2 in pricelist - on new { itm1.Type, itm1.CustomerCode, itm1.MaterialCode } equals new { itm2.Type, itm2.CustomerCode, itm2.MaterialCode } + on new { itm1.Type, itm1.MaterialCode } equals new { itm2.Type, itm2.MaterialCode } where itm1.Price != itm2.Price - select new PriceList(itm2.Id, itm2.BeginDate, itm2.EndDate, itm1.Price, itm2.MaterialCode,itm2.Type, itm2.ParentId, itm2.Version); + select new PriceList(itm2.Id, itm2.BeginDate, itm2.EndDate, itm1.Price, itm2.MaterialCode, itm2.Type, itm2.ParentId, itm2.Version, itm1.CustomerCode); + + if (update.Count() > 0) + { + + await _repository.GetDbContext().BulkUpdateAsync(update.ToList()); + } + else + { + var add = from itm1 in entities + join itm2 in pricelist + on new { itm1.Type, itm1.MaterialCode } + equals new { itm2.Type, itm2.MaterialCode } + into temp + from itm3 in temp.DefaultIfEmpty() + where itm3 == null + select itm1; + await _repository.GetDbContext().BulkInsertAsync(add.ToList()); + + } + - await _repository.GetDbContext().BulkUpdateAsync(update.ToList()); - await _repository.GetDbContext().BulkInsertAsync(add.ToList()); + + var _first = _versionRepository.FirstOrDefault(p => p.Version == version); @@ -113,7 +128,7 @@ namespace Win.Sfs.SettleAccount.Entities.Prices public virtual async Task CreateAsync(PriceList input) { var entity = new PriceList( - GuidGenerator.Create(), input.BeginDate, input.EndDate, input.Price, input.MaterialCode, input.Type,input.ParentId,input.Version + GuidGenerator.Create(), input.BeginDate, input.EndDate, input.Price, input.MaterialCode, input.Type,input.ParentId,input.Version,input.CustomerCode ); return await _repository.InsertAsync(entity); @@ -125,7 +140,7 @@ namespace Win.Sfs.SettleAccount.Entities.Prices { var entity = await _repository.GetAsync(id); entity.Set( - input.BeginDate, input.EndDate, input.Price, input.MaterialCode, input.Type + input.BeginDate, input.EndDate, input.Price, input.MaterialCode, input.Type,input.CustomerCode ); return await _repository.UpdateAsync(entity);