订单删除时判断是否需要运踪退订,并且改为异步

master
zhangxiaofeng 4 months ago
parent ed19e5e983
commit 9c1a0be992

@ -173,5 +173,27 @@ namespace Myshipping.Application.Event
throw Oops.Bah(html.Message); 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<SqlSugarRepository<BookingOrder>>();
long userId = paraObj.UserId;
long tenentId = paraObj.TenentId;
string userName = paraObj.UserName;
string djyUserId = paraObj.DjyUserId;
var data = paraObj.Data as List<BillTraceUnsubscribeList>;
var bookingOrderService = scope.ServiceProvider.GetRequiredService<IBookingYunZong>();
await bookingOrderService.UnsubscribeBillTrace(data, tenentId, userId, userName, djyUserId);
}
} }
} }

@ -2071,10 +2071,11 @@ namespace Myshipping.Application
else if (string.IsNullOrEmpty(entity.MBLNO) && !string.IsNullOrEmpty(mlist.MBLNO) && mlist.IsBookingYZ != "0") else if (string.IsNullOrEmpty(entity.MBLNO) && !string.IsNullOrEmpty(mlist.MBLNO) && mlist.IsBookingYZ != "0")
{ {
// 在已经订阅运踪的情况下,如果操作员删除提单号,则取消订阅运踪 // 在已经订阅运踪的情况下,如果操作员删除提单号,则取消订阅运踪
await UnsubscribeBillTrace(new List<BillTraceUnsubscribeList>(1) var unsubcribeDto = new List<BillTraceUnsubscribeList>(1)
{ {
new BillTraceUnsubscribeList(mlist.Id.ToString(), mlist.MBLNO) 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)) if (!string.IsNullOrEmpty(reqId))
{ {
@ -2403,8 +2404,6 @@ namespace Myshipping.Application
{ {
throw Oops.Bah("未获取到相关url,请联系管理员!"); throw Oops.Bah("未获取到相关url,请联系管理员!");
} }
// 要取消订阅运踪的列表
List<BillTraceUnsubscribeList> waitUnsubscribeBilltrace = new(arr.Count());
var tenantParamList = await _cache.GetAllTenantParam(); var tenantParamList = await _cache.GetAllTenantParam();
var isAskDs = tenantParamList.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == TenantParamCode.ASK_DS_BEFORE_DELETE_BOOKING_ORDER); 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 + "删除成功!"); _logger.LogInformation(mblno + "删除成功!");
// 取消订阅运踪 // 取消订阅运踪
waitUnsubscribeBilltrace.Add(new BillTraceUnsubscribeList(Id.ToString(), mblno)); if (!string.IsNullOrEmpty(order.IsBookingYZ) && order.IsBookingYZ != "0")
{
var unsubcribeDto = new List<BillTraceUnsubscribeList>(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") 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 }); await _bookingEDIExt.UpdateAsync(x => x.BookingId == Id && x.IsDeleted == false, x => new BookingEDIExt { IsDeleted = true });
_logger.LogInformation(mblno + "删除成功!"); _logger.LogInformation(mblno + "删除成功!");
// 取消订阅运踪 if (!string.IsNullOrEmpty(order.IsBookingYZ) && order.IsBookingYZ != "0")
waitUnsubscribeBilltrace.Add(new BillTraceUnsubscribeList(Id.ToString(), mblno)); {
var unsubcribeDto = new List<BillTraceUnsubscribeList>(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") if (isCancelAllocationSlot == "YES")
{ {
@ -2528,12 +2540,6 @@ namespace Myshipping.Application
} }
} }
// 取消订阅运踪
if (waitUnsubscribeBilltrace.Count > 0)
{
await UnsubscribeBillTrace(waitUnsubscribeBilltrace);
}
#region 消息队列推送删除信息 #region 消息队列推送删除信息
//var itemcode = _cache.GetAllTenantParam().Result.Where(x => x.ParaCode == "BOOKING_DATA_PUSH" && x.TenantId == UserManager.TENANT_ID).Select(x => x.ItemCode).FirstOrDefault(); //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)) //if (!string.IsNullOrEmpty(itemcode))
@ -3587,74 +3593,7 @@ namespace Myshipping.Application
} }
/// <summary>
/// 退订运踪
/// </summary>
public async Task UnsubscribeBillTrace(List<BillTraceUnsubscribeList> 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<BillTraceUnsubscribeList>(),
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<RespCommon>();
_logger.LogInformation("调用退订运踪接口返回" + html.ToJsonString());
if (html.Success != true)
{
_logger.LogError("调用退订运踪接口返回:" + html.ToJsonString());
throw Oops.Bah(html.Message);
}
}
#endregion #endregion
#region 放舱(入货通知) #region 放舱(入货通知)

@ -18,6 +18,7 @@ using Myshipping.Application.Service.BookingYunZong.Dto;
using Myshipping.Core.Entity; using Myshipping.Core.Entity;
using Mapster; using Mapster;
using Furion.JsonSerialization; using Furion.JsonSerialization;
using Myshipping.Application.Service.BookingOrder.Dto;
namespace Myshipping.Application namespace Myshipping.Application
{ {
@ -32,6 +33,8 @@ namespace Myshipping.Application
private readonly IDjyWebsiteAccountConfigService _account; private readonly IDjyWebsiteAccountConfigService _account;
private readonly SqlSugarRepository<BookingOrder> _rep; private readonly SqlSugarRepository<BookingOrder> _rep;
private readonly SqlSugarRepository<BookingStatusLog> _repStatuslog; private readonly SqlSugarRepository<BookingStatusLog> _repStatuslog;
private readonly SqlSugarRepository<BookingLog> _repBookinglog;
private readonly SqlSugarRepository<BookingLogDetail> _repBookinglogdetail;
private readonly SqlSugarRepository<BookingStatusLogDetail> _statuslogdetail; private readonly SqlSugarRepository<BookingStatusLogDetail> _statuslogdetail;
private readonly SqlSugarRepository<BookingStatus> _repBookingStatus; private readonly SqlSugarRepository<BookingStatus> _repBookingStatus;
private readonly IBookingOrderService _bookingorderservice; private readonly IBookingOrderService _bookingorderservice;
@ -869,6 +872,75 @@ namespace Myshipping.Application
}
}
/// <summary>
/// 退订运踪
/// </summary>
public async Task UnsubscribeBillTrace(List<BillTraceUnsubscribeList> 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<BillTraceUnsubscribeList>(),
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<RespCommon>();
_logger.LogInformation("调用退订运踪接口返回" + html.ToJsonString());
if (html.Success != true)
{
_logger.LogError("调用退订运踪接口返回:" + html.ToJsonString());
throw Oops.Bah(html.Message);
} }
} }
} }

@ -1,4 +1,5 @@
using System; using Myshipping.Application.Service.BookingOrder.Dto;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -9,5 +10,6 @@ namespace Myshipping.Application
public interface IBookingYunZong public interface IBookingYunZong
{ {
Task RefreshYunZong(long[] Ids); Task RefreshYunZong(long[] Ids);
Task UnsubscribeBillTrace(List<BillTraceUnsubscribeList> billtraces, long tenentId, long userId, string userName, string djyUserId);
} }
} }

Loading…
Cancel
Save