From 91753f9dd8d09a3f7295f196bd05ff418ba89b5c Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Fri, 12 Apr 2024 16:46:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87=E7=A7=9F=E6=88=B7=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=8E=A7=E5=88=B6=E5=88=A0=E9=99=A4=E6=97=B6=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=85=88=E8=AF=A2=E9=97=AE=E4=B8=9C=E8=83=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookingOrder/BookingOrderService.cs | 117 ++++++++++-------- Myshipping.Core/Const/TenantParamCode.cs | 5 + Myshipping.Core/Myshipping.Core.xml | 5 + 3 files changed, 74 insertions(+), 53 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 0c5d644b..d13a3cd8 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -2291,6 +2291,9 @@ namespace Myshipping.Application // 要取消订阅运踪的列表 List waitUnsubscribeBilltrace = new(arr.Count()); + var tenantParamList = await _cache.GetAllTenantParam(); + var isAskDs = tenantParamList.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == TenantParamCode.ASK_DS_BEFORE_DELETE_BOOKING_ORDER); + foreach (var ar in arr) { long Id = Convert.ToInt64(ar); @@ -2304,27 +2307,64 @@ namespace Myshipping.Application // 将待删除的订舱单id存放到Cache中。目的:使用SendBookingOrder()推送订舱单数据前通过Cache判断是否正在走删除逻辑,来决定是否推送(如果是正在处理删除逻辑的数据,则不推送) string deletingCacheKey = $"DeletingBookingOrderId_{ar}"; - await _cache.SetTimeoutAsync(deletingCacheKey, null, TimeSpan.FromMinutes(1)); - _logger.LogInformation("设置待删除的订舱单id到Cache中,key:" + deletingCacheKey); - BookingOrderDelete bookingOrderDelete = new BookingOrderDelete(); - List deletelist = new List(); - deletelist.Add(new BookingOrderDeleteDetail + try { - Id = Id, - MBLNO = mblno - }); - bookingOrderDelete.Delete = deletelist; + await _cache.SetTimeoutAsync(deletingCacheKey, null, TimeSpan.FromMinutes(1)); + _logger.LogInformation("设置待删除的订舱单id到Cache中,key:" + deletingCacheKey); - var stn = await url.SetBody(bookingOrderDelete).PostAsStringAsync(); - var jobj = stn.ToJObject(); - _logger.LogInformation(mblno + "删除单据:" + jobj); - if (jobj.GetIntValue("Code") == 200) - { - JObject data = jobj.GetValue("Data") as JObject; - JArray NoDeleted = data.GetValue("NoDeleted") as JArray; var deleteTime = DateTime.Now; - if (NoDeleted == null || NoDeleted.Count() == 0) + if (isAskDs?.ItemCode == "YES") + { + BookingOrderDelete bookingOrderDelete = new BookingOrderDelete(); + List deletelist = new List + { + new BookingOrderDeleteDetail + { + Id = Id, + MBLNO = mblno + } + }; + bookingOrderDelete.Delete = deletelist; + + var stn = await url.SetBody(bookingOrderDelete).PostAsStringAsync(); + var jobj = stn.ToJObject(); + _logger.LogInformation(mblno + "删除单据:" + jobj); + if (jobj.GetIntValue("Code") == 200) + { + JObject data = jobj.GetValue("Data") as JObject; + JArray NoDeleted = data.GetValue("NoDeleted") as JArray; + if (NoDeleted == null || NoDeleted.Count() == 0 || (NoDeleted[0] is JObject re2 && re2.GetIntValue("Code") == 201)) + { + var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).Select(x => x.Id).ToListAsync(); + await _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = true }); + await _ctndetailrep.UpdateAsync(x => ctnlist.Contains((long)x.CTNID), x => new BookingCtnDetail { IsDeleted = true }); + await _rep.UpdateAsync(x => x.Id == Id, x => new BookingOrder { IsDeleted = true, DeleteTime = deleteTime }); + await _bookingEDIExt.UpdateAsync(x => x.BookingId == Id && x.IsDeleted == false, x => new BookingEDIExt { IsDeleted = true }); + _logger.LogInformation(mblno + "删除成功!"); + + // 取消订阅运踪 + waitUnsubscribeBilltrace.Add(new BillTraceUnsubscribeList(Id.ToString(), mblno)); + + // 记录日志 + var newOrder = order.Adapt(); + newOrder.IsDeleted = true; + newOrder.DeleteTime = deleteTime; + await SaveLog(newOrder, order, "删除"); + } + else + { + var re = NoDeleted[0] as JObject; + string result = re.GetStringValue("Result"); + throw Oops.Bah(result); + } + } + else + { + throw Oops.Bah(mblno + "删除单据失败"); + } + } + else { var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).Select(x => x.Id).ToListAsync(); await _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = true }); @@ -2342,48 +2382,19 @@ namespace Myshipping.Application newOrder.DeleteTime = deleteTime; await SaveLog(newOrder, order, "删除"); } - else - { - var re = NoDeleted[0] as JObject; - if (re.GetIntValue("Code") == 201) - { - var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).Select(x => x.Id).ToListAsync(); - await _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = true }); - await _ctndetailrep.UpdateAsync(x => ctnlist.Contains((long)x.CTNID), x => new BookingCtnDetail { IsDeleted = true }); - await _rep.UpdateAsync(x => x.Id == Id, x => new BookingOrder { IsDeleted = true, DeleteTime = deleteTime }); - await _bookingEDIExt.UpdateAsync(x => x.BookingId == Id && x.IsDeleted == false, x => new BookingEDIExt { IsDeleted = true }); - _logger.LogInformation(mblno + "删除成功!"); - - // 取消订阅运踪 - waitUnsubscribeBilltrace.Add(new BillTraceUnsubscribeList(Id.ToString(), mblno)); - - // 记录日志 - var newOrder = order.Adapt(); - newOrder.IsDeleted = true; - newOrder.DeleteTime = deleteTime; - await SaveLog(newOrder, order, "删除"); - } - else - { - await _cache.DelAsync(deletingCacheKey); - _logger.LogInformation("从Cache中移除待删除的订舱单id,key:" + deletingCacheKey); - - string result = re.GetStringValue("Result"); - throw Oops.Bah(result); - } - - } } - else + catch (Exception) { await _cache.DelAsync(deletingCacheKey); _logger.LogInformation("从Cache中移除待删除的订舱单id,key:" + deletingCacheKey); - throw Oops.Bah(mblno + "删除单据失败"); + throw; + } + finally + { + await _cache.DelAsync(deletingCacheKey); + _logger.LogInformation("从Cache中移除待删除的订舱单id,key:" + deletingCacheKey); } - - await _cache.DelAsync(deletingCacheKey); - _logger.LogInformation("从Cache中移除待删除的订舱单id,key:" + deletingCacheKey); } // 取消订阅运踪 diff --git a/Myshipping.Core/Const/TenantParamCode.cs b/Myshipping.Core/Const/TenantParamCode.cs index a0549bca..ff8bb48b 100644 --- a/Myshipping.Core/Const/TenantParamCode.cs +++ b/Myshipping.Core/Const/TenantParamCode.cs @@ -24,5 +24,10 @@ /// 通过运踪更新船舶动态开关 /// public const string ENABLE_STATUS_TO_SAILING_DATE = "EnableStatusToSailingDate"; + + /// + /// 删除订舱前是否先询问东胜 + /// + public const string ASK_DS_BEFORE_DELETE_BOOKING_ORDER = "AskDsBeforeDeleteBookingOrder"; } } diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml index 820e1fbb..89bc38d5 100644 --- a/Myshipping.Core/Myshipping.Core.xml +++ b/Myshipping.Core/Myshipping.Core.xml @@ -872,6 +872,11 @@ 通过运踪更新船舶动态开关 + + + 删除订舱前是否先询问东胜 + + 代码