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/CautionNoticeTaskSubscriber.cs

164 lines
6.2 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;
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
{
/// <summary>
/// 重要通知任务订阅
/// </summary>
public class CautionNoticeTaskSubscriber : IEventSubscriber
{
private IServiceProvider _services { get; }
private readonly ILogger<CautionNoticeTaskSubscriber> _logger;
//private readonly INamedServiceProvider<ITaskManageService> _namedTaskManageServiceProvider;
public CautionNoticeTaskSubscriber(IServiceProvider services, ILogger<CautionNoticeTaskSubscriber> logger)
{
_services = services;
_logger = logger;
// _namedTaskManageServiceProvider = namedTaskManageServiceProvider;
}
/// <summary>
/// 新增重要通知任务
/// </summary>
/// <param name="context">订阅上下文</param>
/// <returns></returns>
[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<SqlSugarRepository<BookingOrder>>();
//var bookingSlotRepo = scope.ServiceProvider.GetRequiredService<SqlSugarRepository<BookingSlotBase>>();
var service = scope.ServiceProvider.GetRequiredService<ITaskManageService>();
//var service = _namedTaskManageServiceProvider.GetService(nameof(TaskManageService));
DateTime nowDate = DateTime.Now;
/*
1、生成重要提醒任务
2、先从订舱订单提取操作OP和销售OP推送钉钉和邮件提醒。
3、如果没有订舱订单可以从舱位获取操作OP推送钉钉和邮件提醒。
*/
CautionNoticeTaskDto dto = GetInfo(paraObj);
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,
}
};
messageInfo.Main.TaskTenatId = dto.tenentId;
messageInfo.Main.TaskTenatName = dto.tenentName;
messageInfo.Main.VesselVoyno = $"{dto.vessel}/{dto.voyno}";
messageInfo.Main.TaskUserId = dto.userId.ToString();
messageInfo.Main.TaskUserName = dto.userName;
messageInfo.Main.CarrierId = dto.carrier;
messageInfo.Main.CustomerId = dto.customerId;
messageInfo.Main.CustomerName = dto.customerName;
messageInfo.Main.TaskTitle = $"重要提醒-{dto.cautionNoticeType.GetDescription()} {dto.vessel}/{dto.voyno} {dto.etd} BLNo:{dto.mblNo}";
messageInfo.Main.TaskDesp = $"重要提醒-{dto.cautionNoticeType.GetDescription()} {dto.vessel}/{dto.voyno} {dto.etd} BLNo:{dto.mblNo}";
messageInfo.Main.CautionNoticeInfo = new TaskManageOrderCautionNoticeInfo
{
BookingId = dto.bookingId,
BookingSlotId = dto.bookingSlotId,
CautionNoticeType = dto.cautionNoticeType,
Carrier = dto.carrier,
MBlNo = dto.mblNo,
OrigVal = dto.origVal,
NewVal = dto.newVal,
NotifyContent = dto.notifyContent,
SourceSystem = dto.sourceSystem,
SourceBusiType = dto.sourceBusiType,
SourceBusiTypeName = dto.sourceBusiTypeName,
CreateTime = DateTime.Now,
NoticeList = new List<TaskManageOrderCautionNoticeDetailInfo>()
};
if (dto.notifyList != null && dto.notifyList.Count > 0)
{
dto.notifyList.ForEach(p =>
{
foreach(var item in p.notifyMethod)
{
var notifyInfo = new TaskManageOrderCautionNoticeDetailInfo
{
CautionNoticeType = item,
Email = p.notifyEmail,
UserId = p.notifyUserId,
UserName = p.notifyUserName,
Mobile = p.notifyMobile,
};
messageInfo.Main.CautionNoticeInfo.NoticeList.Add(notifyInfo);
}
});
}
var rlt = await service.CreateTaskJob(messageInfo);
}
private CautionNoticeTaskDto GetInfo(object payload)
{
CautionNoticeTaskDto dto = null;
try
{
dto = JSON.Deserialize<CautionNoticeTaskDto>(JSON.Serialize(payload));
}
catch(Exception ex)
{
_logger.LogInformation($"解析订阅参数失败,原因:{ex.Message}");
throw Oops.Bah($"解析订阅参数失败,原因:{ex.Message}");
}
return dto;
}
}
}