diff --git a/Myshipping.Application/Event/CautionNoticeTaskSubscriber.cs b/Myshipping.Application/Event/CautionNoticeTaskSubscriber.cs index 58eda83e..6ccc1f6d 100644 --- a/Myshipping.Application/Event/CautionNoticeTaskSubscriber.cs +++ b/Myshipping.Application/Event/CautionNoticeTaskSubscriber.cs @@ -69,79 +69,83 @@ namespace Myshipping.Application.Event //生成任务 if (dto.cautionNoticeType == CautionNoticeTaskEnum.WeekAt) { - TaskManageOrderMessageInfo messageInfo = new TaskManageOrderMessageInfo + + } + + TaskManageOrderMessageInfo messageInfo = new TaskManageOrderMessageInfo + { + Head = new TaskManageOrderMessageHeadInfo { - 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) + 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 { - slotInfo = bookingSlotRepo.AsQueryable().Filter(null, true).First(x => x.Id == dto.bookingSlotId); + TaskType = TaskBaseTypeEnum.CAUTION_NOTICE, } + }; - if (dto.bookingId > 0) - { - bookingOrder = bookingRepo.AsQueryable().Filter(null, true).First(x => x.Id == dto.bookingId); - } + BookingSlotBase slotInfo = null; + BookingOrder bookingOrder = null; - messageInfo.Main.TaskTenatId = slotInfo.TenantId; - messageInfo.Main.TaskTenatName = slotInfo.TenantName; + string mblNo = string.Empty; + string vesselVoyno = string.Empty; + string etd = string.Empty; - 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 (dto.bookingSlotId > 0) + { + slotInfo = bookingSlotRepo.AsQueryable().Filter(null, true).First(x => x.Id == dto.bookingSlotId); + } - if (bookingOrder != null) - { - messageInfo.Main.CustomerId = bookingOrder.CUSTOMERID; - messageInfo.Main.CustomerName = bookingOrder.CUSTOMERNAME; - } + if (dto.bookingId > 0) + { + bookingOrder = bookingRepo.AsQueryable().Filter(null, true).First(x => x.Id == dto.bookingId); + } - messageInfo.Main.TaskTitle = $"重要提醒-计费周发生变更 {vesselVoyno} {etd} BLNo:{mblNo}"; - messageInfo.Main.TaskDesp = $"重要提醒-计费周发生变更 {vesselVoyno} {etd} BLNo:{mblNo}"; + messageInfo.Main.TaskTenatId = slotInfo.TenantId; + messageInfo.Main.TaskTenatName = slotInfo.TenantName; - messageInfo.Main.CautionNoticeInfo = new TaskManageOrderCautionNoticeInfo + 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 ?? ""}"; - var rlt = await service.CreateTaskJob(messageInfo); + 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 + { + BookingId = dto.bookingId, + BookingSlotId = dto.bookingSlotId, + CautionNoticeType = dto.cautionNoticeType, + }; + + var rlt = await service.CreateTaskJob(messageInfo); } private CautionNoticeTaskDto GetInfo(object payload) diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index 2513133e..8cf83d56 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -19,6 +19,7 @@ using Myshipping.Application.Service.BookingLabel.Dto; using Myshipping.Application.Service.BookingOrder.Dto; using Myshipping.Application.Service.BookingSlot.Dto; using Myshipping.Core; +using Myshipping.Core.Entity; using Myshipping.Core.Service; using NPOI.XSSF.UserModel; using SqlSugar; @@ -30,6 +31,7 @@ using System.IO; using System.Linq; using System.Net.Http; using System.Net.Http.Headers; +using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -57,6 +59,7 @@ namespace Myshipping.Application private readonly SqlSugarRepository _repBookingLogDetail; private readonly SqlSugarRepository _bookingfile; private readonly SqlSugarRepository _repPrintTemplate; + private readonly SqlSugarRepository _sysUserRepository; private readonly ILogger _logger; private readonly ISysCacheService _cache; @@ -101,6 +104,7 @@ namespace Myshipping.Application SqlSugarRepository repBookingOrder, SqlSugarRepository repLabelAllocation, IBookingLabelService bookingLabelService, + SqlSugarRepository sysUserRepository, SqlSugarRepository repPrintTemplate) { _repBase = repBase; @@ -126,6 +130,8 @@ namespace Myshipping.Application _repLabelAllocation = repLabelAllocation; _bookingLabelService = bookingLabelService; _repPrintTemplate = repPrintTemplate; + + _sysUserRepository = sysUserRepository; } #region 舱位 @@ -3060,8 +3066,51 @@ namespace Myshipping.Application { if (bcSrcDto.CarrierId.Equals("MSK", StringComparison.OrdinalIgnoreCase)) { - var bookingList = _repAllocation.AsQueryable().Filter(null, true) - .Where(x => x.BOOKING_SLOT_ID == slotId && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToList(); + 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(); + + 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) + { + 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); + } + + userIds = userIds.Distinct().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 ?? ""; @@ -3069,40 +3118,74 @@ namespace Myshipping.Application //如果计费周不一致需要推送推送任务台生成重要提醒 if (!srcWeek.Equals(targetWeek, StringComparison.OrdinalIgnoreCase)) { - if (bookingList.Count > 0) + if (bookingSlotAllocList.Count > 0) { - bookingList.ForEach(async ca => + bookingSlotAllocList.ForEach(async ca => { - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", - new CautionNoticeTaskDto + 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.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 (bookingInfo != null) + { + if (!string.IsNullOrWhiteSpace(bookingInfo.OPID)) { - cautionNoticeType = CautionNoticeTaskEnum.WeekAt, - bookingId = ca.BOOKING_ID, - bookingSlotId = ca.BOOKING_SLOT_ID, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - })); + 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 { - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", - new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.WeekAt, - bookingSlotId = slotId, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - })); + 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); + } + + await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); } } @@ -3111,40 +3194,72 @@ namespace Myshipping.Application if (!srcPriceCalcDate.Equals(targePriceCalcDate, StringComparison.OrdinalIgnoreCase)) { - if (bookingList.Count > 0) + if (bookingSlotAllocList.Count > 0) { - bookingList.ForEach(async ca => + bookingSlotAllocList.ForEach(async ca => { - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", - new CautionNoticeTaskDto + 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)) { - cautionNoticeType = CautionNoticeTaskEnum.PriceCalcDate, - bookingId = ca.BOOKING_ID, - bookingSlotId = ca.BOOKING_SLOT_ID, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - })); + 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 { - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", - new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.PriceCalcDate, - bookingSlotId = slotId, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - })); + 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); + } + + await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); } } @@ -3157,40 +3272,70 @@ namespace Myshipping.Application //船名航次出现变化需要做重要提醒 if (!srcVessel.Equals(targetVessel, StringComparison.OrdinalIgnoreCase) || !srcVoyno.Equals(targetVoyno, StringComparison.OrdinalIgnoreCase)) { - if (bookingList.Count > 0) + if (bookingSlotAllocList.Count > 0) { - bookingList.ForEach(async ca => + bookingSlotAllocList.ForEach(async ca => { - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", - new CautionNoticeTaskDto + 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) + { + if (!string.IsNullOrWhiteSpace(bookingInfo.OPID)) { - cautionNoticeType = CautionNoticeTaskEnum.ChangeVesselVoyno, - bookingId = ca.BOOKING_ID, - bookingSlotId = ca.BOOKING_SLOT_ID, - createTime = DateTime.Now, - origVal = $"{srcVessel}/{srcVoyno}", - newVal = $"{targetVessel}/{targetVoyno}", - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - })); + 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 { - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", - new CautionNoticeTaskDto - { - cautionNoticeType = CautionNoticeTaskEnum.ChangeVesselVoyno, - bookingSlotId = slotId, - createTime = DateTime.Now, - origVal = srcWeek, - newVal = targetWeek, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - })); + 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)); } } @@ -3202,45 +3347,204 @@ namespace Myshipping.Application && srcVessel.Equals("DIRECT_SHIP", StringComparison.OrdinalIgnoreCase) && targetCarrierType.Equals("TRANSFER_SHIP", StringComparison.OrdinalIgnoreCase)) { - if (bookingList.Count > 0) + if (bookingSlotAllocList.Count > 0) { - bookingList.ForEach(async ca => + bookingSlotAllocList.ForEach(async ca => { - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", - new CautionNoticeTaskDto + 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)) { - cautionNoticeType = CautionNoticeTaskEnum.ChangeTransfer, - bookingId = ca.BOOKING_ID, - bookingSlotId = ca.BOOKING_SLOT_ID, - createTime = DateTime.Now, - origVal = srcCarrierType, - newVal = targetCarrierType, - tenentId = UserManager.TENANT_ID, - userId = UserManager.UserId, - userName = UserManager.Name, - })); + 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 { - await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", - new CautionNoticeTaskDto + 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() + }; + + if (slotInfo != null) + { + CreateContact(notice.notifyList, userList, slotInfo.CreatedUserId.Value, bcSrcDto.MBLNo, notice.cautionNoticeType); + } + + await _publisher.PublishAsync(new ChannelEventSource("CautionNoticeTask:Add", notice)); + } + } + + + string srcVGMCut = bcSrcDto.VGMSubmissionCutDate; + string targeVGMCut = bcTargetDto.VGMSubmissionCutDate; + + 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 (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.ChangeTransfer, - bookingSlotId = slotId, + cautionNoticeType = CautionNoticeTaskEnum.CutDateAdvanced, + bookingId = ca.Alloc.BOOKING_ID, + bookingSlotId = ca.Slot.Id, createTime = DateTime.Now, - origVal = srcCarrierType, - newVal = targetCarrierType, + 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)); + + }); + } + 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)); + } } } } } #endregion + + #region 生成联系人 + /// + /// 生成联系人 + /// + /// 联系人列表 + /// 已检索用户详情列表 + /// 联系用户ID + /// 提单号 + /// 重要通知类型 + private void CreateContact(List notifyList, List userList,long contactId,string mblNo, CautionNoticeTaskEnum cautionNoticeType) + { + if (!notifyList.Any(p => p.notifyUserId == contactId)) + { + var userInfo = userList.FirstOrDefault(x => x.Id == contactId); + + if (userInfo != null) + { + var contact = new CautionNoticeTaskNoitfyDto + { + notifyUserId = userInfo.Id, + notifyUserName = userInfo.Name, + notifyMethod = new CautionNoticeMethodEnum[] { CautionNoticeMethodEnum.Email, CautionNoticeMethodEnum.DingDing }, + notifyMobile = userInfo.Phone?.Trim(), + notifyEmail = userInfo.Email?.Trim(), + }; + + if (string.IsNullOrWhiteSpace(userInfo.Phone)) + { + _logger.LogInformation($"MBLNO={mblNo} 比对舱位{cautionNoticeType.ToString()} 有变化,通知人{userInfo.Name}没有手机号"); + + new EmailNoticeHelper().SendEmailNotice($"MBLNO={mblNo} 比对舱位{cautionNoticeType.ToString()} 有变化,通知人{userInfo.Name}没有手机号", $"MBLNO={mblNo} 比对舱位{cautionNoticeType.ToString()} 有变化,通知人{userInfo.Name}没有手机号", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList()); + } + + if (string.IsNullOrWhiteSpace(userInfo.Email)) + { + _logger.LogInformation($"MBLNO={mblNo} 比对舱位{cautionNoticeType.ToString()} 有变化,通知人{userInfo.Name}没有邮箱"); + + new EmailNoticeHelper().SendEmailNotice($"MBLNO={mblNo} 比对舱位{cautionNoticeType.ToString()} 有变化,通知人{userInfo.Name}没有邮箱", $"MBLNO={mblNo} 比对舱位{cautionNoticeType.ToString()} 有变化,通知人{userInfo.Name}没有邮箱", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList()); + } + + notifyList.Add(contact); + } + } + } + #endregion } diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskDto.cs index 8ffd2895..093b13fe 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskDto.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskDto.cs @@ -58,6 +58,50 @@ namespace Myshipping.Application /// public string userName { get; set; } + /// + /// 提单号 + /// + public string mblNo { get; set; } + + /// + /// 通知内容 + /// + public string notifyContent { get; set; } + + /// + /// 通知人列表 + /// + public List notifyList { get; set; } + } + + /// + /// 通知人详情 + /// + public class CautionNoticeTaskNoitfyDto + { + /// + /// 通知人ID + /// + public long notifyUserId { get; set; } + + /// + /// 通知人名称 + /// + public string notifyUserName { get; set; } + + /// + /// 通知方式 + /// + public CautionNoticeMethodEnum[] notifyMethod { get; set; } + + /// + /// 通知人手机 + /// + public string notifyMobile { get; set; } + /// + /// 通知人邮箱 + /// + public string notifyEmail { get; set; } } } diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml index aa060360..171fe776 100644 --- a/Myshipping.Core/Myshipping.Core.xml +++ b/Myshipping.Core/Myshipping.Core.xml @@ -7296,6 +7296,22 @@ + + + 获取跨站点登录授权key + + + 默认用户名/密码:admin/admin + + + + + 授权key换取token + + + 默认用户名/密码:admin/admin + + 登录输入参数 @@ -7319,6 +7335,16 @@ 123456 + + + 用户Id + + + + + 根据授权key 换取token + + 用户登录输出参数 diff --git a/Myshipping.Core/Service/Auth/AuthService.cs b/Myshipping.Core/Service/Auth/AuthService.cs index e8cea526..365d4d9c 100644 --- a/Myshipping.Core/Service/Auth/AuthService.cs +++ b/Myshipping.Core/Service/Auth/AuthService.cs @@ -467,4 +467,46 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient // 生成Token令牌 return await GetLoginToken(user, tenant); } + + + + /// + /// 获取跨站点登录授权key + /// + /// + /// 默认用户名/密码:admin/admin + /// + [HttpPost("/GetAuthorizationKey")] + [AllowAnonymous] + public async Task GetAuthorizationKey([Required] GetAuthorizationKeyInput input) + { + //将key写入到redis 并指定五秒过期 + string key = Guid.NewGuid().ToString(); + await _cache.SetTimeoutAsync( key, input.UserId, TimeSpan.FromSeconds(5)); + //将key返回 + return key; + } + + /// + /// 授权key换取token + /// + /// + /// 默认用户名/密码:admin/admin + /// + [HttpPost("/GetTokenByAuthorizationKey")] + [AllowAnonymous] + public async Task GetTokenByAuthorizationKey([Required] GetTokenByAuthorizationKeyInput input) + { + //判断key有效性 + if (!_cache.Exists(input.Key)) + { + throw Oops.Bah("授权码无效"); + } + //获取用户信息 + var user = _sysUserRep.AsQueryable().Filter(null, true).First(u => u.DjyUserId == _cache.Get(input.Key)); + //获取对应租户 + var tenant = _sysTenantRep.Single(user.TenantId); + //颁发token + return await GetLoginToken(user, tenant); + } } diff --git a/Myshipping.Core/Service/Auth/Dto/LoginInput.cs b/Myshipping.Core/Service/Auth/Dto/LoginInput.cs index eac481da..fdb06232 100644 --- a/Myshipping.Core/Service/Auth/Dto/LoginInput.cs +++ b/Myshipping.Core/Service/Auth/Dto/LoginInput.cs @@ -28,3 +28,19 @@ public class LoginInput [Required(ErrorMessage = "密码不能为空")] public string Password { get; set; } } + +public class GetAuthorizationKeyInput +{ + /// + /// 用户Id + /// + public string UserId { get; set; } +} + +/// +/// 根据授权key 换取token +/// +public class GetTokenByAuthorizationKeyInput +{ + public string Key { get; set; } +} \ No newline at end of file