From 44971d150782f7e4116939b2b0143ee4dbd9cc1d Mon Sep 17 00:00:00 2001 From: tongfei <244188119@qq.com> Date: Tue, 26 Dec 2023 10:39:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml | 19 ++++++++-- src/WMS.Web.Domain/Entitys/InStock.cs | 27 +++++++++++--- .../IService/IInStockService.cs | 2 +- .../Infrastructure/IInStockRepositories.cs | 8 ++++ src/WMS.Web.Domain/Services/InStockService.cs | 24 +++++++----- .../InStockRepositories.cs | 37 +++++++++++++++++++ 6 files changed, 99 insertions(+), 18 deletions(-) diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 8449f63c..f04efdd9 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -592,6 +592,11 @@ + + + 重传 + + wms入库单明细 @@ -2129,6 +2134,14 @@ + + + 批量修改 + + + + + 根据单据头id获取数据 @@ -2570,7 +2583,7 @@ 入库单服务接口 - + 同步金蝶 @@ -3867,7 +3880,7 @@ 入库单服务 - + 同步-金蝶 @@ -3951,7 +3964,7 @@ - + 采购:同步金蝶 diff --git a/src/WMS.Web.Domain/Entitys/InStock.cs b/src/WMS.Web.Domain/Entitys/InStock.cs index 59070e14..9b1bce1e 100644 --- a/src/WMS.Web.Domain/Entitys/InStock.cs +++ b/src/WMS.Web.Domain/Entitys/InStock.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; +using WMS.Web.Core; using WMS.Web.Domain.Values; namespace WMS.Web.Domain.Entitys @@ -12,12 +13,12 @@ namespace WMS.Web.Domain.Entitys /// [Serializable] [Table("t_wms_instock")] - public class InStock + public class InStock : EntityBase { /// /// ID /// - public int Id { get; set; } + public override int Id { get; set; } /// /// 单据编号 @@ -95,10 +96,8 @@ namespace WMS.Web.Domain.Entitys this.CreateTime = DateTime.Now; if (this.Type == InstockType.Purchase) { - //只有采购订单入库才需要同步金蝶:单据头为同步中默认 this.SuccessSync = SyncStatus.SyncIng; - //erp明细为失败默认,在处理同步时能找到该明细 - this.ErpDetails.ForEach(f => f.SuccessSync = SyncStatus.Fail); + this.ErpDetails.ForEach(f => f.SuccessSync = SyncStatus.SyncIng); } else//非采购订单,这里就没有记录erpdetails的数据了 this.SuccessSync = SyncStatus.Success; @@ -180,5 +179,23 @@ namespace WMS.Web.Domain.Entitys this.OperateId = operateId; this.SyncTime = DateTime.Now; } + + /// + /// 重传 + /// + public void RepeatSync() + { + //只有完全失败的情况下才能重传 + if (this.SuccessSync != SyncStatus.Fail) return; + this.SuccessSync = SyncStatus.SyncIng; + var erpDetails = this.ErpDetails + .Where(w => w.SuccessSync == SyncStatus.Fail) + .ToList(); + foreach (var e in erpDetails) + { + e.SuccessSync = SyncStatus.SyncIng; + } + this.Remark = ""; + } } } diff --git a/src/WMS.Web.Domain/IService/IInStockService.cs b/src/WMS.Web.Domain/IService/IInStockService.cs index d70229f8..911d6ed0 100644 --- a/src/WMS.Web.Domain/IService/IInStockService.cs +++ b/src/WMS.Web.Domain/IService/IInStockService.cs @@ -24,7 +24,7 @@ namespace WMS.Web.Domain.IService /// /// /// - Task Sync(OperateRequest dto, LoginInDto loginInfo); + Task Sync(OperateRequest dto, LoginInDto loginInfo, bool isRepeatSync = true); /// /// 收货 diff --git a/src/WMS.Web.Domain/Infrastructure/IInStockRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IInStockRepositories.cs index 84600b33..9eff1513 100644 --- a/src/WMS.Web.Domain/Infrastructure/IInStockRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IInStockRepositories.cs @@ -59,6 +59,14 @@ namespace WMS.Web.Domain.Infrastructure /// Task Update(InStock entity, bool isTransaction = true); + /// + /// 批量修改 + /// + /// + /// + /// + Task UpdateRange(List entitys, bool isTransaction = true); + /// /// 根据单据头id获取数据 /// diff --git a/src/WMS.Web.Domain/Services/InStockService.cs b/src/WMS.Web.Domain/Services/InStockService.cs index 1c22b384..936dc02a 100644 --- a/src/WMS.Web.Domain/Services/InStockService.cs +++ b/src/WMS.Web.Domain/Services/InStockService.cs @@ -77,16 +77,21 @@ namespace WMS.Web.Domain.Services /// /// /// - public Task Sync(OperateRequest dto, LoginInDto loginInfo) + public Task Sync(OperateRequest dto, LoginInDto loginInfo, bool isRepeatSync = true) { - Task.Run(async () => + var list = _inStockRepositories.GetList(dto.Ids).GetAwaiter().GetResult(); + var isSuccess = true; + if (isRepeatSync) { - var scope = _serviceScopeFactory.CreateScope(); - var sc_inStockRepositories = scope.ServiceProvider.GetRequiredService(); - var list = await sc_inStockRepositories.GetList(dto.Ids); + list = list.Where(w => w.SuccessSync == SyncStatus.Fail).ToList(); + list.ForEach(f => f.RepeatSync()); + isSuccess = _inStockRepositories.UpdateRange(list, true).GetAwaiter().GetResult(); + } + Task.Run(async () => + { foreach (var entity in list) { - var res = await this.PurchaseInStock(entity, loginInfo, scope); + var res = await this.PurchaseInStock(entity, loginInfo); if (!res.IsSuccess) _logger.LogError($"入库单同步失败:{res.Message}"); } @@ -144,7 +149,7 @@ namespace WMS.Web.Domain.Services { OperateRequest oRequest = new OperateRequest(); oRequest.Ids.Add(entity.Id); - await Sync(oRequest, loginInfo); + await Sync(oRequest, loginInfo,false); } return Result.ReSuccess(); } @@ -732,13 +737,14 @@ namespace WMS.Web.Domain.Services /// /// /// - private async Task PurchaseInStock(InStock entity, LoginInDto loginInfo, IServiceScope scope) + private async Task PurchaseInStock(InStock entity, LoginInDto loginInfo) { + var scope = _serviceScopeFactory.CreateScope(); var sc_InStockRepositories = scope.ServiceProvider.GetRequiredService(); if (entity.Type != InstockType.Purchase) return Result.ReSuccess(); if (entity.SuccessSync == SyncStatus.Success) return Result.ReSuccess(); - var erpDetails = entity.ErpDetails.Where(w => w.SuccessSync == SyncStatus.Fail).ToList(); + var erpDetails = entity.ErpDetails.Where(w => w.SuccessSync == SyncStatus.SyncIng).ToList(); foreach (var s in erpDetails) { var erp_details = entity.ErpDetails diff --git a/src/WMS.Web.Repositories/InStockRepositories.cs b/src/WMS.Web.Repositories/InStockRepositories.cs index aa5ca3e7..47dbe403 100644 --- a/src/WMS.Web.Repositories/InStockRepositories.cs +++ b/src/WMS.Web.Repositories/InStockRepositories.cs @@ -196,6 +196,43 @@ namespace WMS.Web.Repositories } } + /// + /// 批量修改 + /// + /// + /// + /// + public async Task UpdateRange(List entitys, bool isTransaction = true) + { + IDbContextTransaction _transaction = null; + if (isTransaction) + _transaction = _context.Database.BeginTransaction(); + try + { + List list = entitys.Select(s => s.Id).ToList(); + + var res = await _context.Instock + .Include(s => s.Details) + .Include(s => s.ErpDetails) + .Where(f => list.Contains(f.Id)).ToListAsync(); + + _mapper.ToMapList(entitys, res); + _mapper.ToMapList(entitys.SelectMany(s => s.Details).ToList(), res.SelectMany(s => s.Details).ToList()); + _mapper.ToMapList(entitys.SelectMany(s => s.ErpDetails).ToList(), res.SelectMany(s => s.ErpDetails).ToList()); + await _context.SaveChangesAsync(); + if (_transaction != null) + _transaction.Commit(); + } + catch (Exception ex) + { + if (_transaction != null) + _transaction.Rollback(); + return false; + } + return true; + + } + /// /// 根据单据头id获取数据 ///