From a97c46b1a2edff0322559a2a5c1c949246e1e251 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Fri, 24 May 2024 15:39:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=88=B1=E4=BD=8D=E5=B7=AE?= =?UTF-8?q?=E5=BC=82=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/BookingSlot/BookingSlotService.cs | 640 ++++++------------ .../BookingSlot/IBookingSlotService.cs | 14 - 2 files changed, 222 insertions(+), 432 deletions(-) diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index 31ee45d5..651429e5 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -66,6 +66,8 @@ namespace Myshipping.Application private readonly IEventPublisher _publisher; private readonly INamedServiceProvider _namedBookingOrderServiceProvider; + private readonly INamedServiceProvider _namedTaskManageServiceProvider; + private readonly IDjyCustomerService _djyCustomerService; private readonly IBookingValueAddedService _bookingValueAddedService; private readonly IBookingLabelService _bookingLabelService; @@ -104,6 +106,7 @@ namespace Myshipping.Application SqlSugarRepository repBookingOrder, SqlSugarRepository repLabelAllocation, IBookingLabelService bookingLabelService, + INamedServiceProvider namedTaskManageServiceProvider, SqlSugarRepository sysUserRepository, SqlSugarRepository repPrintTemplate) { @@ -132,6 +135,7 @@ namespace Myshipping.Application _repPrintTemplate = repPrintTemplate; _sysUserRepository = sysUserRepository; + _namedTaskManageServiceProvider = namedTaskManageServiceProvider; } #region 舱位 @@ -753,7 +757,7 @@ namespace Myshipping.Application TaskBCInfoDto bcTargetDto = dto.DataObj.Adapt(); //执行差异重要提醒 - //await MeasureDiffCautionTask(bcSrcDto, bcTargetDto, model.Id); + await MeasureDiffCautionTask(bcSrcDto, bcTargetDto, model.Id); //提取箱信息 var ctnList = _repCtn.AsQueryable().Filter(null, true) @@ -3051,39 +3055,6 @@ namespace Myshipping.Application } #endregion - ///// - ///// 校验是否可以生成订舱订单 - ///// - ///// 舱位主键 - ///// - //[HttpGet("/BookingSlot/ValidateCreateBookingOrder")] - //public async Task ValidateCreateBookingOrder(long id) - //{ - // TaskManageOrderResultDto result = new TaskManageOrderResultDto(); - // var slotInfo = await _repBase.AsQueryable().FirstAsync(a => a.Id == id); - // if (slotInfo == null) - // { - // throw Oops.Oh($"获取舱位失败,舱位不存在或已作废"); - // } - // //if(so) - // return result; - //} - - /// - /// 批量发送邮件提醒(发送客户) - /// - /// 舱位批量发送邮件请求 - /// - [HttpPost("/BookingSlot/SendEmail")] - public async Task SendEmail(BookingSlotSendEmailDto model) - { - TaskManageOrderResultDto result = new TaskManageOrderResultDto(); - - result.succ = true; - - return result; - } - #region 估算差异重要提醒 /// /// 估算差异重要提醒 @@ -3095,439 +3066,107 @@ namespace Myshipping.Application [NonAction] public async Task MeasureDiffCautionTask(TaskBCInfoDto bcSrcDto, TaskBCInfoDto bcTargetDto, long slotId) { - if (bcSrcDto.CarrierId.Equals("MSK", StringComparison.OrdinalIgnoreCase)) + try { - var bookingSlotAllocList = _repBase.AsQueryable().Filter(null, true) + if (bcSrcDto.CarrierId.Equals("MSK", StringComparison.OrdinalIgnoreCase)) + { + var bookingSlotAllocList = _repBase.AsQueryable().Filter(null, true) .LeftJoin((slot, alloc) => slot.Id == alloc.BOOKING_SLOT_ID) .Where((slot, alloc) => slot.Id == slotId && slot.IsDeleted == false && slot.TenantId == UserManager.TENANT_ID && alloc.IsDeleted == false) .Select((slot, alloc) => new { Slot = slot, Alloc = alloc }).ToList(); - List bookingOrderList = new List(); - List userList = new List(); - List userIds = new List(); + List bookingOrderList = new List(); + List userList = new List(); + List userIds = new List(); - if (bookingSlotAllocList.Any(t => t.Alloc != null)) - { - var bookingNoList = bookingSlotAllocList.Select(a => a.Alloc.BOOKING_ID).ToList(); - - bookingOrderList = _repBookingOrder.AsQueryable().Filter(null, true) - .Where(x => bookingNoList.Contains(x.Id) && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToList(); - - if (bookingOrderList.Count > 0) + if (bookingSlotAllocList.Any(t => t.Alloc != null)) { - bookingOrderList.ForEach(bk => - { - if (!string.IsNullOrWhiteSpace(bk.OPID)) - userIds.Add(long.Parse(bk.OPID)); - - if (!string.IsNullOrWhiteSpace(bk.SALEID)) - userIds.Add(long.Parse(bk.SALEID)); - - if (!string.IsNullOrWhiteSpace(bk.CUSTSERVICEID)) - userIds.Add(long.Parse(bk.CUSTSERVICEID)); - - userIds.Add(bk.CreatedUserId.Value); - }); - } - } - - var slotInfo = bookingSlotAllocList.FirstOrDefault().Slot; - - if (slotInfo != null) - { - userIds.Add(slotInfo.CreatedUserId.Value); - } + var bookingNoList = bookingSlotAllocList.Select(a => a.Alloc.BOOKING_ID).ToList(); - userIds = userIds.Distinct().ToList(); + bookingOrderList = _repBookingOrder.AsQueryable().Filter(null, true) + .Where(x => bookingNoList.Contains(x.Id) && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToList(); - userList = _sysUserRepository.AsQueryable().Filter(null, true) - .Where(x => userIds.Contains(x.Id) && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToList(); - - string srcWeek = bcSrcDto.WeekAt ?? ""; - string targetWeek = bcTargetDto.WeekAt ?? ""; - - //如果计费周不一致需要推送推送任务台生成重要提醒 - if (!srcWeek.Equals(targetWeek, StringComparison.OrdinalIgnoreCase)) - { - if (bookingSlotAllocList.Count > 0) - { - bookingSlotAllocList.ForEach(async ca => + if (bookingOrderList.Count > 0) { - var bookingInfo = _repBookingOrder.AsQueryable().Filter(null, true).First(x => x.Id == ca.Alloc.BOOKING_ID && x.IsDeleted == false - && x.TenantId == UserManager.TENANT_ID); - - var notice = new CautionNoticeTaskDto + bookingOrderList.ForEach(bk => { - cautionNoticeType = CautionNoticeTaskEnum.WeekAt, - bookingId = ca.Alloc.BOOKING_ID, - bookingSlotId = ca.Slot.Id, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - mblNo = bcSrcDto.MBLNo, - notifyContent = $"mblno:{bcSrcDto.MBLNo} 计费周变更了 原:{srcWeek} 新:{targetWeek}", - notifyList = new List() - }; + if (!string.IsNullOrWhiteSpace(bk.OPID)) + userIds.Add(long.Parse(bk.OPID)); - if (bookingInfo != null) - { - if (!string.IsNullOrWhiteSpace(bookingInfo.OPID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.OPID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } + if (!string.IsNullOrWhiteSpace(bk.SALEID)) + userIds.Add(long.Parse(bk.SALEID)); - if (!string.IsNullOrWhiteSpace(bookingInfo.SALEID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.SALEID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } + if (!string.IsNullOrWhiteSpace(bk.CUSTSERVICEID)) + userIds.Add(long.Parse(bk.CUSTSERVICEID)); - if (!string.IsNullOrWhiteSpace(bookingInfo.CUSTSERVICEID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.CUSTSERVICEID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - } - - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); - - }); - } - else - { - var notice = new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.WeekAt, - bookingSlotId = slotInfo.Id, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - mblNo = bcSrcDto.MBLNo, - notifyContent = $"mblno:{bcSrcDto.MBLNo} 计费周变更了 原:{srcWeek} 新:{targetWeek}", - notifyList = new List() - }; - - if (slotInfo != null) - { - CreateContact(notice.notifyList, userList, slotInfo.CreatedUserId.Value, bcSrcDto.MBLNo, notice.cautionNoticeType); + userIds.Add(bk.CreatedUserId.Value); + }); } - - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); } - } - string srcPriceCalcDate = bcSrcDto.PriceCalculationDate.HasValue ? bcSrcDto.PriceCalculationDate.Value.ToString("yyyy-MM-dd") : ""; - string targePriceCalcDate = bcTargetDto.PriceCalculationDate.HasValue ? bcTargetDto.PriceCalculationDate.Value.ToString("yyyy-MM-dd") : ""; + var slotInfo = bookingSlotAllocList.FirstOrDefault().Slot; - if (!srcPriceCalcDate.Equals(targePriceCalcDate, StringComparison.OrdinalIgnoreCase)) - { - if (bookingSlotAllocList.Count > 0) + if (slotInfo != null) { - bookingSlotAllocList.ForEach(async ca => - { - var bookingInfo = _repBookingOrder.AsQueryable().Filter(null, true).First(x => x.Id == ca.Alloc.BOOKING_ID && x.IsDeleted == false - && x.TenantId == UserManager.TENANT_ID); - - var notice = new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.PriceCalcDate, - bookingId = ca.Alloc.BOOKING_ID, - bookingSlotId = ca.Slot.Id, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - mblNo = bcSrcDto.MBLNo, - notifyContent = $"mblno:{bcSrcDto.MBLNo} 计费日期变更了 原:{srcPriceCalcDate} 新:{targePriceCalcDate}", - notifyList = new List() - }; - - if (bookingInfo != null) - { - if (!string.IsNullOrWhiteSpace(bookingInfo.OPID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.OPID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - - if (!string.IsNullOrWhiteSpace(bookingInfo.SALEID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.SALEID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - - if (!string.IsNullOrWhiteSpace(bookingInfo.CUSTSERVICEID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.CUSTSERVICEID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - } - - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); - - }); + userIds.Add(slotInfo.CreatedUserId.Value); } - else - { - var notice = new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.PriceCalcDate, - bookingSlotId = slotInfo.Id, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - notifyList = new List() - }; - if (slotInfo != null) - { - CreateContact(notice.notifyList, userList, slotInfo.CreatedUserId.Value, bcSrcDto.MBLNo, notice.cautionNoticeType); - } + userIds = userIds.Distinct().ToList(); - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); - } - } - - string srcVessel = bcSrcDto.Vessel ?? ""; - string targetVessel = bcTargetDto.Vessel ?? ""; + userList = _sysUserRepository.AsQueryable().Filter(null, true) + .Where(x => userIds.Contains(x.Id) && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToList(); - string srcVoyno = bcSrcDto.VoyNo ?? ""; - string targetVoyno = bcTargetDto.VoyNo ?? ""; + string srcWeek = bcSrcDto.WeekAt ?? ""; + string targetWeek = bcTargetDto.WeekAt ?? ""; - //船名航次出现变化需要做重要提醒 - if (!srcVessel.Equals(targetVessel, StringComparison.OrdinalIgnoreCase) || !srcVoyno.Equals(targetVoyno, StringComparison.OrdinalIgnoreCase)) - { - if (bookingSlotAllocList.Count > 0) + if (!srcWeek.Equals(targetWeek, StringComparison.OrdinalIgnoreCase)) { - bookingSlotAllocList.ForEach(async ca => + if (bookingSlotAllocList.Count > 0) { - var bookingInfo = _repBookingOrder.AsQueryable().Filter(null, true).First(x => x.Id == ca.Alloc.BOOKING_ID && x.IsDeleted == false - && x.TenantId == UserManager.TENANT_ID); - - var notice = new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.ChangeVesselVoyno, - bookingId = ca.Alloc.BOOKING_ID, - bookingSlotId = ca.Slot.Id, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - notifyList = new List() - }; - - if (bookingInfo != null) + bookingSlotAllocList.ForEach(async ca => { - if (!string.IsNullOrWhiteSpace(bookingInfo.OPID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.OPID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - - if (!string.IsNullOrWhiteSpace(bookingInfo.SALEID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.SALEID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - - if (!string.IsNullOrWhiteSpace(bookingInfo.CUSTSERVICEID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.CUSTSERVICEID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - } - - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); - - }); - } - else - { - var notice = new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.ChangeVesselVoyno, - bookingSlotId = slotInfo.Id, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - notifyList = new List() - }; - - if (slotInfo != null) - { - CreateContact(notice.notifyList, userList, slotInfo.CreatedUserId.Value, bcSrcDto.MBLNo, notice.cautionNoticeType); - } - - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); - } - } - - string srcCarrierType = bcSrcDto.CarriageType ?? ""; - string targetCarrierType = bcTargetDto.CarriageType ?? ""; - - //如果原来是直航现在变成了中转需要做重要提醒 - if (!srcVessel.Equals(targetVessel, StringComparison.OrdinalIgnoreCase) - && srcVessel.Equals("DIRECT_SHIP", StringComparison.OrdinalIgnoreCase) - && targetCarrierType.Equals("TRANSFER_SHIP", StringComparison.OrdinalIgnoreCase)) - { - if (bookingSlotAllocList.Count > 0) - { - bookingSlotAllocList.ForEach(async ca => - { - var bookingInfo = _repBookingOrder.AsQueryable().Filter(null, true).First(x => x.Id == ca.Alloc.BOOKING_ID && x.IsDeleted == false + var bookingInfo = _repBookingOrder.AsQueryable().Filter(null, true).First(x => x.Id == ca.Alloc.BOOKING_ID && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID); - var notice = new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.ChangeTransfer, - bookingId = ca.Alloc.BOOKING_ID, - bookingSlotId = ca.Slot.Id, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - notifyContent = $"mblno:{bcSrcDto.MBLNo} 直达变中转了", - notifyList = new List() - }; - - if (bookingInfo != null) - { - if (!string.IsNullOrWhiteSpace(bookingInfo.OPID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.OPID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - - if (!string.IsNullOrWhiteSpace(bookingInfo.SALEID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.SALEID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - - if (!string.IsNullOrWhiteSpace(bookingInfo.CUSTSERVICEID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.CUSTSERVICEID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - } - - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); - - }); - } - else - { - var notice = new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.ChangeTransfer, - bookingSlotId = slotInfo.Id, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - notifyContent = $"mblno:{bcSrcDto.MBLNo} 直达变中转了", - notifyList = new List() - }; + CreateTask(CautionNoticeTaskEnum.WeekAt, bcSrcDto, userList, bookingInfo, slotInfo, srcWeek, targetWeek, $"提单号:{bcSrcDto.MBLNo} 计费周变更了 原:{srcWeek} 新:{targetWeek}"); + }); + } - if (slotInfo != null) + if (slotInfo != null && !userIds.Any(p => p == slotInfo.CreatedUserId.Value)) { - CreateContact(notice.notifyList, userList, slotInfo.CreatedUserId.Value, bcSrcDto.MBLNo, notice.cautionNoticeType); + CreateTask(CautionNoticeTaskEnum.WeekAt, bcSrcDto, userList, null, slotInfo, srcWeek, targetWeek, $"提单号:{bcSrcDto.MBLNo} 计费周变更了 原:{srcWeek} 新:{targetWeek}"); } - - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); } - } - - string srcVGMCut = bcSrcDto.VGMSubmissionCutDate; - string targeVGMCut = bcTargetDto.VGMSubmissionCutDate; + string srcPriceDate = bcSrcDto.PriceCalculationDate.HasValue? bcSrcDto.PriceCalculationDate.Value.ToString("yyyy-MM-dd"): ""; + string targetPriceDate = bcTargetDto.PriceCalculationDate.HasValue ? bcSrcDto.PriceCalculationDate.Value.ToString("yyyy-MM-dd") : ""; - if (!string.IsNullOrWhiteSpace(srcVGMCut) && !string.IsNullOrWhiteSpace(targeVGMCut) && !srcVGMCut.Equals(targeVGMCut)) - { - DateTime srcVGMCutDate = DateTime.Parse(srcVGMCut); - DateTime targeVGMCutDate = DateTime.Parse(targeVGMCut); - - //如果新给的VGM截止时间,需要推送通知 - if (srcVGMCutDate > targeVGMCutDate) + if (!srcPriceDate.Equals(targetPriceDate, StringComparison.OrdinalIgnoreCase)) { if (bookingSlotAllocList.Count > 0) { bookingSlotAllocList.ForEach(async ca => { var bookingInfo = _repBookingOrder.AsQueryable().Filter(null, true).First(x => x.Id == ca.Alloc.BOOKING_ID && x.IsDeleted == false - && x.TenantId == UserManager.TENANT_ID); - - var notice = new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.CutDateAdvanced, - bookingId = ca.Alloc.BOOKING_ID, - bookingSlotId = ca.Slot.Id, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - notifyContent = $"VGM截止时间提前了,原:{srcVGMCut} 新:{targeVGMCut}", - notifyList = new List() - }; - - if (bookingInfo != null) - { - if (!string.IsNullOrWhiteSpace(bookingInfo.OPID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.OPID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - - if (!string.IsNullOrWhiteSpace(bookingInfo.SALEID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.SALEID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - - if (!string.IsNullOrWhiteSpace(bookingInfo.CUSTSERVICEID)) - { - CreateContact(notice.notifyList, userList, long.Parse(bookingInfo.CUSTSERVICEID), bcSrcDto.MBLNo, notice.cautionNoticeType); - } - } - - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); + && x.TenantId == UserManager.TENANT_ID); + CreateTask(CautionNoticeTaskEnum.PriceCalcDate, bcSrcDto, userList, bookingInfo, slotInfo, srcPriceDate, targetPriceDate, $"提单号:{bcSrcDto.MBLNo} 计费日期变更了 原:{srcPriceDate} 新:{targetPriceDate}"); }); } - else - { - var notice = new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.ChangeVesselVoyno, - bookingSlotId = slotInfo.Id, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - notifyList = new List() - }; - - if (slotInfo != null) - { - CreateContact(notice.notifyList, userList, slotInfo.CreatedUserId.Value, bcSrcDto.MBLNo, notice.cautionNoticeType); - } - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); + if (slotInfo != null && !userIds.Any(p => p == slotInfo.CreatedUserId.Value)) + { + CreateTask(CautionNoticeTaskEnum.PriceCalcDate, bcSrcDto, userList, null, slotInfo, srcPriceDate, targetPriceDate, $"提单号:{bcSrcDto.MBLNo} 计费日期变更了 原:{srcPriceDate} 新:{targetPriceDate}"); } } } } + catch (Exception ex) + { + _logger.LogInformation($"提单号:{bcSrcDto.MBLNo} slotId={slotId} 估算差异重要提醒发生异常"); + + new EmailNoticeHelper().SendEmailNotice($"MBLNO={bcSrcDto.MBLNo} slotId={slotId} 估算差异重要提醒发生异常", $"MBLNO={bcSrcDto.MBLNo} slotId={slotId} 估算差异重要提醒发生异常", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList()); + } } #endregion @@ -3576,6 +3215,171 @@ namespace Myshipping.Application } } #endregion + + private async Task SendTask(CautionNoticeTaskDto dto) + { + TaskManageOrderMessageInfo messageInfo = new TaskManageOrderMessageInfo + { + Head = new TaskManageOrderMessageHeadInfo + { + GID = IDGen.NextID().ToString(), + MessageType = "CAUTION_TASK", + SenderId = "CautionNoticeTask", + SenderName = "重要提醒任务生成", + ReceiverId = "TaskManage", + ReceiverName = "任务台", + RequestDate = DateTime.Now.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() + }; + + 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 service = _namedTaskManageServiceProvider.GetService(nameof(TaskManageService)); + var rlt = await service.CreateTaskJob(messageInfo); + } + + #region 生成重要提醒任务 + /// + /// 生成重要提醒任务 + /// + /// 重要提醒任务类型 + /// 原数据详情 + /// 提取的用户详情列表 + /// 订舱详情 + /// 舱位详情 + /// 原值 + /// 变更值 + /// 提示信息 + private void CreateTask(CautionNoticeTaskEnum cautionNoticeType, TaskBCInfoDto bcSrcDto, List userList, BookingOrder bookingInfo, + BookingSlotBase bookingSlotInfo, string srcVal, string targetVal, string notifyContent) + { + List userIdList = new List(); + + if (bookingInfo != null) + { + if (!string.IsNullOrWhiteSpace(bookingInfo.OPID)) + { + userIdList.Add(long.Parse(bookingInfo.OPID)); + } + + if (!string.IsNullOrWhiteSpace(bookingInfo.SALEID)) + { + userIdList.Add(long.Parse(bookingInfo.SALEID)); + } + + if (!string.IsNullOrWhiteSpace(bookingInfo.CUSTSERVICEID)) + { + userIdList.Add(long.Parse(bookingInfo.CUSTSERVICEID)); + } + + userIdList.Add(bookingInfo.CreatedUserId.Value); + } + + if (bookingSlotInfo != null) + { + userIdList.Add(bookingSlotInfo.CreatedUserId.Value); + } + + userIdList = userIdList.Distinct().ToList(); + + userIdList.ForEach(x => + { + var userInfo = userList.FirstOrDefault(p => p.Id == x); + + var notice = new CautionNoticeTaskDto + { + cautionNoticeType = cautionNoticeType, + createTime = DateTime.Now, + origVal = srcVal, + newVal = targetVal, + tenentId = userInfo.TenantId.Value, + userId = userInfo.Id, + userName = userInfo.Name, + mblNo = bcSrcDto.MBLNo, + carrier = bcSrcDto.CarrierId, + sourceSystem = "DjyBooking", + sourceBusiType = "BookingSlot", + sourceBusiTypeName = "舱位管理", + vessel = bcSrcDto.Vessel, + voyno = bcSrcDto.VoyNo, + etd = bcSrcDto.ETD, + tenentName = UserManager.TENANT_NAME, + + notifyContent = notifyContent, + notifyList = new List() + }; + + if (bookingInfo != null) + { + notice.bookingId = bookingInfo.Id; + notice.customerId = bookingInfo.CUSTOMERID; + notice.customerName = bookingInfo.CUSTOMERNAME; + } + + if (bookingSlotInfo != null) + { + notice.bookingSlotId = bookingSlotInfo.Id; + } + + CreateContact(notice.notifyList, userList, x, bcSrcDto.MBLNo, notice.cautionNoticeType); + + SendTask(notice).GetAwaiter().GetResult(); + }); + } + #endregion } diff --git a/Myshipping.Application/Service/BookingSlot/IBookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/IBookingSlotService.cs index fcb48617..134853ef 100644 --- a/Myshipping.Application/Service/BookingSlot/IBookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/IBookingSlotService.cs @@ -119,20 +119,6 @@ namespace Myshipping.Application Task SearchBookingSlotWithOrderByNo(string slotBookingNo, long tenantId); - ///// - ///// 校验是否可以生成订舱订单 - ///// - ///// 舱位主键 - ///// 返回回执 - //Task ValidateCreateBookingOrder(long id); - - /// - /// 批量发送邮件提醒(发送客户) - /// - /// 舱位批量发送邮件请求 - /// 返回回执 - Task SendEmail(BookingSlotSendEmailDto model); - /// /// 请求BC比对 ///