diff --git a/Myshipping.Application/Event/BillTraceSubscriber.cs b/Myshipping.Application/Event/BillTraceSubscriber.cs index d5efc343..cae27b7c 100644 --- a/Myshipping.Application/Event/BillTraceSubscriber.cs +++ b/Myshipping.Application/Event/BillTraceSubscriber.cs @@ -173,5 +173,27 @@ namespace Myshipping.Application.Event throw Oops.Bah(html.Message); } } + + + [EventSubscribe("BillTrace:Unsubscribe")] + public async Task BillTraceUnsubscribe(EventHandlerExecutingContext context) + { + _logger.LogInformation($"收到运踪退订请求:{context.Source.Payload}"); + + var paraObj = context.Source.Payload as dynamic; + + using var scope = _services.CreateScope(); + var repoOrder = scope.ServiceProvider.GetRequiredService>(); + + long userId = paraObj.UserId; + long tenentId = paraObj.TenentId; + string userName = paraObj.UserName; + string djyUserId = paraObj.DjyUserId; + + var data = paraObj.Data as List; + + var bookingOrderService = scope.ServiceProvider.GetRequiredService(); + await bookingOrderService.UnsubscribeBillTrace(data, tenentId, userId, userName, djyUserId); + } } } diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index c7416dda..4a545270 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -2071,10 +2071,11 @@ namespace Myshipping.Application else if (string.IsNullOrEmpty(entity.MBLNO) && !string.IsNullOrEmpty(mlist.MBLNO) && mlist.IsBookingYZ != "0") { // 在已经订阅运踪的情况下,如果操作员删除提单号,则取消订阅运踪 - await UnsubscribeBillTrace(new List(1) + var unsubcribeDto = new List(1) { new BillTraceUnsubscribeList(mlist.Id.ToString(), mlist.MBLNO) - }); + }; + await _publisher.PublishAsync(new ChannelEventSource("BillTrace:Unsubscribe", new { Data = unsubcribeDto, TenentId = UserManager.TENANT_ID, UserId = UserManager.UserId, UserName = UserManager.Name, DjyUserId = UserManager.DjyUserId })); if (!string.IsNullOrEmpty(reqId)) { @@ -2403,8 +2404,6 @@ namespace Myshipping.Application { throw Oops.Bah("未获取到相关url,请联系管理员!"); } - // 要取消订阅运踪的列表 - 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); @@ -2463,7 +2462,14 @@ namespace Myshipping.Application _logger.LogInformation(mblno + "删除成功!"); // 取消订阅运踪 - waitUnsubscribeBilltrace.Add(new BillTraceUnsubscribeList(Id.ToString(), mblno)); + if (!string.IsNullOrEmpty(order.IsBookingYZ) && order.IsBookingYZ != "0") + { + var unsubcribeDto = new List(1) + { + new BillTraceUnsubscribeList(Id.ToString(), order.MBLNO) + }; + await _publisher.PublishAsync(new ChannelEventSource("BillTrace:Unsubscribe", new { Data = unsubcribeDto, TenentId = UserManager.TENANT_ID, UserId = UserManager.UserId, UserName = UserManager.Name, DjyUserId = UserManager.DjyUserId })); + } if (isCancelAllocationSlot == "YES") { @@ -2498,8 +2504,14 @@ namespace Myshipping.Application 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)); + if (!string.IsNullOrEmpty(order.IsBookingYZ) && order.IsBookingYZ != "0") + { + var unsubcribeDto = new List(1) + { + new BillTraceUnsubscribeList(Id.ToString(), order.MBLNO) + }; + await _publisher.PublishAsync(new ChannelEventSource("BillTrace:Unsubscribe", new { Data = unsubcribeDto, TenentId = UserManager.TENANT_ID, UserId = UserManager.UserId, UserName = UserManager.Name, DjyUserId = UserManager.DjyUserId })); + } if (isCancelAllocationSlot == "YES") { @@ -2528,12 +2540,6 @@ namespace Myshipping.Application } } - // 取消订阅运踪 - if (waitUnsubscribeBilltrace.Count > 0) - { - await UnsubscribeBillTrace(waitUnsubscribeBilltrace); - } - #region 消息队列推送删除信息 //var itemcode = _cache.GetAllTenantParam().Result.Where(x => x.ParaCode == "BOOKING_DATA_PUSH" && x.TenantId == UserManager.TENANT_ID).Select(x => x.ItemCode).FirstOrDefault(); //if (!string.IsNullOrEmpty(itemcode)) @@ -3587,74 +3593,7 @@ namespace Myshipping.Application } - /// - /// 退订运踪 - /// - public async Task UnsubscribeBillTrace(List billtraces) - { - if (billtraces == null) - { - throw Oops.Bah("未传入正确参数!"); - } - - var key = _webAccountConfig.GetAccountConfig("seae_billtraceurl", UserManager.UserId).Result; - if (key == null) - { - throw Oops.Bah("调用运踪接口相关账号未维护!"); - } - var url = _cache.GetAllDictData().Result?.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "request_unsubscribe_seae_billtrace_url")?.Value; - if (string.IsNullOrEmpty(url)) - { - throw Oops.Bah("未配置退订运踪接口地址!"); - } - - BillTraceUnsubscribeDto reqDto = new BillTraceUnsubscribeDto() - { - Children = new List(), - Key = key.Account, - PWD = key.Password, - Gid = UserManager.DjyUserId - }; - foreach (BillTraceUnsubscribeList item in billtraces) - { - _logger.LogInformation("调用退订运踪接口,提单号:" + item.MBLNO); - if (string.IsNullOrEmpty(item.BusinessId)) - { - throw Oops.Bah("订舱记录主键不能为空!"); - } - reqDto.Children.Add(new BillTraceUnsubscribeList(item.BusinessId, item.MBLNO)); - - ////添加booking日志 - var bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog - { - Type = "Trace", - BookingId = Convert.ToInt64(item.BusinessId), - TenantId = Convert.ToInt64(UserManager.TENANT_ID), - CreatedTime = DateTime.Now, - CreatedUserId = UserManager.UserId, - CreatedUserName = UserManager.Name - }); - - await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail - { - PId = bid, - Field = "", - OldValue = "", - NewValue = "退订运踪", - }); - await _rep.UpdateAsync(x => x.Id == Convert.ToInt64(item.BusinessId), x => new BookingOrder { IsBookingYZ = "0" }); - } - var json = reqDto.ToJsonString(); - _logger.LogInformation("调用退订运踪接口发送json:" + json); - var html = await url.SetHttpMethod(HttpMethod.Post).SetQueries(new { msg = json }).SetRetryPolicy(3, 5000).SendAsAsync(); - _logger.LogInformation("调用退订运踪接口返回" + html.ToJsonString()); - if (html.Success != true) - { - _logger.LogError("调用退订运踪接口返回:" + html.ToJsonString()); - throw Oops.Bah(html.Message); - } - } #endregion #region 放舱(入货通知) diff --git a/Myshipping.Application/Service/BookingYunZong/BookingYunZong.cs b/Myshipping.Application/Service/BookingYunZong/BookingYunZong.cs index ccc72af1..89c67ca6 100644 --- a/Myshipping.Application/Service/BookingYunZong/BookingYunZong.cs +++ b/Myshipping.Application/Service/BookingYunZong/BookingYunZong.cs @@ -18,6 +18,7 @@ using Myshipping.Application.Service.BookingYunZong.Dto; using Myshipping.Core.Entity; using Mapster; using Furion.JsonSerialization; +using Myshipping.Application.Service.BookingOrder.Dto; namespace Myshipping.Application { @@ -32,6 +33,8 @@ namespace Myshipping.Application private readonly IDjyWebsiteAccountConfigService _account; private readonly SqlSugarRepository _rep; private readonly SqlSugarRepository _repStatuslog; + private readonly SqlSugarRepository _repBookinglog; + private readonly SqlSugarRepository _repBookinglogdetail; private readonly SqlSugarRepository _statuslogdetail; private readonly SqlSugarRepository _repBookingStatus; private readonly IBookingOrderService _bookingorderservice; @@ -869,6 +872,75 @@ namespace Myshipping.Application + } + } + + /// + /// 退订运踪 + /// + public async Task UnsubscribeBillTrace(List billtraces, long tenentId, long userId, string userName, string djyUserId) + { + if (billtraces == null) + { + throw Oops.Bah("未传入正确参数!"); + } + + var key = await _account.GetAccountConfig("seae_billtraceurl", userId); + if (key == null) + { + throw Oops.Bah("调用运踪接口相关账号未维护!"); + } + + var url = _cache.GetAllDictData().Result?.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "request_unsubscribe_seae_billtrace_url")?.Value; + if (string.IsNullOrEmpty(url)) + { + throw Oops.Bah("未配置退订运踪接口地址!"); + } + + BillTraceUnsubscribeDto reqDto = new BillTraceUnsubscribeDto() + { + Children = new List(), + Key = key.Account, + PWD = key.Password, + Gid = djyUserId + }; + foreach (BillTraceUnsubscribeList item in billtraces) + { + _logger.LogInformation("调用退订运踪接口,提单号:" + item.MBLNO); + if (string.IsNullOrEmpty(item.BusinessId)) + { + throw Oops.Bah("订舱记录主键不能为空!"); + } + reqDto.Children.Add(new BillTraceUnsubscribeList(item.BusinessId, item.MBLNO)); + + ////添加booking日志 + var bid = await _repBookinglog.InsertReturnSnowflakeIdAsync(new BookingLog + { + Type = "Trace", + BookingId = Convert.ToInt64(item.BusinessId), + TenantId = Convert.ToInt64(tenentId), + CreatedTime = DateTime.Now, + CreatedUserId = userId, + CreatedUserName = userName + }); + + await _repBookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail + { + PId = bid, + Field = "", + OldValue = "", + NewValue = "退订运踪", + }); + await _rep.UpdateAsync(x => x.Id == Convert.ToInt64(item.BusinessId), x => new BookingOrder { IsBookingYZ = "0" }); + } + var json = reqDto.ToJsonString(); + _logger.LogInformation("调用退订运踪接口发送json:" + json); + var html = await url.SetHttpMethod(HttpMethod.Post).SetQueries(new { msg = json }).SetRetryPolicy(3, 5000).SendAsAsync(); + _logger.LogInformation("调用退订运踪接口返回" + html.ToJsonString()); + if (html.Success != true) + { + _logger.LogError("调用退订运踪接口返回:" + html.ToJsonString()); + throw Oops.Bah(html.Message); } } } diff --git a/Myshipping.Application/Service/BookingYunZong/IBookingYunZong.cs b/Myshipping.Application/Service/BookingYunZong/IBookingYunZong.cs index 407c91f7..a88e814e 100644 --- a/Myshipping.Application/Service/BookingYunZong/IBookingYunZong.cs +++ b/Myshipping.Application/Service/BookingYunZong/IBookingYunZong.cs @@ -1,4 +1,5 @@ -using System; +using Myshipping.Application.Service.BookingOrder.Dto; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,5 +10,6 @@ namespace Myshipping.Application public interface IBookingYunZong { Task RefreshYunZong(long[] Ids); + Task UnsubscribeBillTrace(List billtraces, long tenentId, long userId, string userName, string djyUserId); } }