|
|
|
|
using Furion.EventBus;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
|
using Myshipping.Application.MQ;
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
|
using Myshipping.Core.Entity;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application.Event
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 订舱自动化事件处理
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BookingAutoSubscriber : IEventSubscriber
|
|
|
|
|
{
|
|
|
|
|
private IServiceProvider _services { get; }
|
|
|
|
|
private readonly ILogger<BookingAutoSubscriber> _logger;
|
|
|
|
|
|
|
|
|
|
public BookingAutoSubscriber(IServiceProvider services, ILogger<BookingAutoSubscriber> logger)
|
|
|
|
|
{
|
|
|
|
|
_services = services;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//收到BC
|
|
|
|
|
[EventSubscribe("BookingAuto:BC")]
|
|
|
|
|
public async Task BookingAutoBC(EventHandlerExecutingContext context)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"收到订舱自动化BC消息:{context.Source.Payload}");
|
|
|
|
|
|
|
|
|
|
var msgBC = context.Source.Payload as BookingAutoMessageBC;
|
|
|
|
|
|
|
|
|
|
var scope = _services.CreateScope();
|
|
|
|
|
|
|
|
|
|
var repoBooking = scope.ServiceProvider.GetRequiredService<SqlSugarRepository<BookingOrder>>();
|
|
|
|
|
var repoStatuslog = scope.ServiceProvider.GetRequiredService<SqlSugarRepository<BookingStatusLog>>();
|
|
|
|
|
var bookingfile = scope.ServiceProvider.GetRequiredService<SqlSugarRepository<BookingFile>>();
|
|
|
|
|
var booking = await repoBooking.AsQueryable().Filter(null, true).FirstAsync(x => x.CUSTNO == msgBC.BookingNO && x.TenantId == msgBC.TenantId);
|
|
|
|
|
if (booking != null)
|
|
|
|
|
{
|
|
|
|
|
booking.MBLNO = msgBC.MBLNO; //回写提单号
|
|
|
|
|
await repoBooking.AsUpdateable(booking).UpdateColumns(x => new { x.MBLNO }).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
//货运动态
|
|
|
|
|
var bsl = new BookingStatusLog();
|
|
|
|
|
bsl.BookingId = booking.Id;
|
|
|
|
|
bsl.Status = $"收到BC";
|
|
|
|
|
bsl.OpTime = DateTime.Now;
|
|
|
|
|
bsl.Category = "ship";
|
|
|
|
|
bsl.MBLNO = booking.MBLNO;
|
|
|
|
|
await repoStatuslog.InsertAsync(bsl);
|
|
|
|
|
|
|
|
|
|
//挂载附件
|
|
|
|
|
var newFile = new BookingFile
|
|
|
|
|
{
|
|
|
|
|
FileName = Path.GetFileName(msgBC.AttachUrl),
|
|
|
|
|
FilePath = msgBC.AttachUrl,
|
|
|
|
|
TypeCode = "BC",
|
|
|
|
|
TypeName = ".pdf",
|
|
|
|
|
BookingId = booking.Id,
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
await bookingfile.InsertAsync(newFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|