using Furion; using Furion.DependencyInjection; using Furion.DistributedIDGenerator; using Furion.EventBus; using Furion.FriendlyException; using Furion.JsonSerialization; using MathNet.Numerics.LinearAlgebra.Factorization; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Myshipping.Application.Entity; using Myshipping.Core; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Myshipping.Application.Event { /// /// 重要通知任务订阅 /// public class CautionNoticeTaskSubscriber : IEventSubscriber { private IServiceProvider _services { get; } private readonly ILogger _logger; private readonly INamedServiceProvider _namedTaskManageServiceProvider; public CautionNoticeTaskSubscriber(IServiceProvider services, ILogger logger, INamedServiceProvider namedTaskManageServiceProvider) { _services = services; _logger = logger; _namedTaskManageServiceProvider = namedTaskManageServiceProvider; } /// /// 新增重要通知任务 /// /// 订阅上下文 /// [EventSubscribe("CautionNoticeTask:Add")] public async Task CautionNoticeTaskAdd(EventHandlerExecutingContext context) { _logger.LogInformation($"收到更新订阅请求:{context.Source.Payload}"); var paraObj = context.Source.Payload; using var scope = _services.CreateScope(); var bookingRepo = scope.ServiceProvider.GetRequiredService>(); var bookingSlotRepo = scope.ServiceProvider.GetRequiredService>(); var service = _namedTaskManageServiceProvider.GetService(nameof(TaskManageService)); DateTime nowDate = DateTime.Now; /* 1、生成重要提醒任务 2、先从订舱订单提取操作OP和销售OP,推送钉钉和邮件提醒。 3、如果没有订舱订单,可以从舱位获取操作OP,推送钉钉和邮件提醒。 */ CautionNoticeTaskDto dto = GetInfo(paraObj); //生成任务 if (dto.cautionNoticeType == CautionNoticeTaskEnum.WeekAt) { TaskManageOrderMessageInfo messageInfo = new TaskManageOrderMessageInfo { Head = new TaskManageOrderMessageHeadInfo { GID = IDGen.NextID().ToString(), MessageType = "CAUTION_TASK", SenderId = "CautionNoticeTask", SenderName = "重要提醒任务生成", ReceiverId = "TaskManage", ReceiverName = "任务台", RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff"), Version = "1.0", RequestAction = "Add" }, Main = new TaskManageOrderMessageMainInfo { TaskType = TaskBaseTypeEnum.CAUTION_NOTICE, } }; BookingSlotBase slotInfo = null; BookingOrder bookingOrder = null; string mblNo = string.Empty; string vesselVoyno = string.Empty; string etd = string.Empty; if (dto.bookingSlotId > 0) { slotInfo = bookingSlotRepo.AsQueryable().Filter(null, true).First(x => x.Id == dto.bookingSlotId); } if (dto.bookingId > 0) { bookingOrder = bookingRepo.AsQueryable().Filter(null, true).First(x => x.Id == dto.bookingId); } messageInfo.Main.TaskTenatId = slotInfo.TenantId; messageInfo.Main.TaskTenatName = slotInfo.TenantName; if (slotInfo != null) { if (slotInfo.CARRIERID.Equals("MSK", StringComparison.OrdinalIgnoreCase)) { mblNo = slotInfo.SLOT_BOOKING_NO; messageInfo.Main.MBlNo = slotInfo.SLOT_BOOKING_NO; messageInfo.Main.ETD = slotInfo.ETD; vesselVoyno = $"{(slotInfo.VESSEL ?? "")}/{slotInfo.VOYNO ?? ""}"; messageInfo.Main.VesselVoyno = vesselVoyno; messageInfo.Main.TaskUserId = dto.userId.ToString(); messageInfo.Main.TaskUserName = dto.userName; messageInfo.Main.CarrierId = slotInfo.CARRIERID; } } if (bookingOrder != null) { messageInfo.Main.CustomerId = bookingOrder.CUSTOMERID; messageInfo.Main.CustomerName = bookingOrder.CUSTOMERNAME; } messageInfo.Main.TaskTitle = $"重要提醒-计费周发生变更 {vesselVoyno} {etd} BLNo:{mblNo}"; messageInfo.Main.TaskDesp = $"重要提醒-计费周发生变更 {vesselVoyno} {etd} BLNo:{mblNo}"; messageInfo.Main.CautionNoticeInfo = new TaskManageOrderCautionNoticeInfo { }; var rlt = await service.CreateTaskJob(messageInfo); } } private CautionNoticeTaskDto GetInfo(object payload) { CautionNoticeTaskDto dto = null; try { dto = JSON.Deserialize(JSON.Serialize(payload)); } catch(Exception ex) { _logger.LogInformation($"解析订阅参数失败,原因:{ex.Message}"); throw Oops.Bah($"解析订阅参数失败,原因:{ex.Message}"); } return dto; } } }