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

165 lines
6.5 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);
}
}
//收到LARA提单号
[EventSubscribe("BookingAuto:LaraBlno")]
public async Task BookingAutoLaraBlno(EventHandlerExecutingContext context)
{
_logger.LogInformation($"收到订舱自动化LARA提单号消息{context.Source.Payload}");
var msgBC = context.Source.Payload as BookingAutoMessageLaraBlno;
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.CsrCode && x.TenantId == msgBC.TenantId);
if (booking != null)
{
booking.MBLNO = msgBC.MBLNO; //回写提单号
await repoBooking.AsUpdateable(booking).UpdateColumns(x => new { x.MBLNO }).ExecuteCommandAsync();
}
}
//收到INTTRA BC
[EventSubscribe("BookingAuto:InttraBc")]
public async Task BookingAutoInttraBc(EventHandlerExecutingContext context)
{
_logger.LogInformation($"收到订舱自动化InttraBc消息{context.Source.Payload}");
var msgBC = context.Source.Payload as BookingAutoMessageInttraBC;
var scope = _services.CreateScope();
var repoBooking = scope.ServiceProvider.GetRequiredService<SqlSugarRepository<BookingOrder>>();
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();
}
}
//收到CMA VGM Missing
[EventSubscribe("BookingAuto:CmaVgmMissing")]
public async Task BookingAutoCmaVgmMissing(EventHandlerExecutingContext context)
{
_logger.LogInformation($"收到订舱自动化CMA VGM Missing消息{context.Source.Payload}");
var msgVgmMissing = context.Source.Payload as BookingAutoMessageCmaVgmMissing;
var scope = _services.CreateScope();
var repoBooking = scope.ServiceProvider.GetRequiredService<SqlSugarRepository<BookingOrder>>();
var repoCtn = scope.ServiceProvider.GetRequiredService<SqlSugarRepository<BookingCtn>>();
var mblnoList = msgVgmMissing.DetailData.Select(x => x.MBLNO).Distinct().ToList();
foreach (var mblno in mblnoList)
{
var booking = await repoBooking.AsQueryable().Filter(null, true).FirstAsync(x => x.MBLNO == mblno && x.TenantId == msgVgmMissing.TenantId);
if (booking != null)
{
var ctns = await repoCtn.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.BILLID == booking.Id).ToListAsync();
foreach (var ctnMiss in msgVgmMissing.DetailData.Where(x => x.MBLNO == mblno))
{
var ctn = ctns.FirstOrDefault(x => x.CNTRNO == ctnMiss.CtnNO);
if (ctn != null)
{
ctn.CTNSTATUS = "Missing";
await repoCtn.AsUpdateable(ctn).UpdateColumns(x => new { x.CTNSTATUS }).ExecuteCommandAsync();
}
}
}
}
}
}
}