You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/Event/BookingAutoSubscriber.cs

81 lines
2.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Furion.DependencyInjection;
using Furion.EventBus;
using Furion.RemoteRequest.Extensions;
using Mapster;
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;
private readonly INamedServiceProvider<IBookingSlotService> _namedBookingSlotServiceProvider;
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);
}
}
}
}