diff --git a/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeInfo.cs b/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeInfo.cs index c6dca8a0..15d86934 100644 --- a/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeInfo.cs +++ b/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeInfo.cs @@ -55,7 +55,7 @@ namespace Myshipping.Application /// 通知差异类型 WeekAt-计费周差异;PriceCalcDate-计费日期差异;ChangeTransfer-直达转为中转;ChangeVesselVoyno-船名航次变化;VGMCutDateAdvanced-VGM截止时间提前;SICutDateAdvanced-SI截止时间提前 /// public string CAUTION_NOTICE_TYPE { get; set; } - + /// /// 是否计费周差异 1-是 0-否 /// @@ -105,5 +105,56 @@ namespace Myshipping.Application /// 修改值 /// public string NEW_VAL { get; set; } + + /// + /// VGM截止时间原始值 + /// + + public string VGM_CUT_OLD_VAL { get; set; } + + /// + /// VGM截止时间修改值 + /// + public string VGM_CUT_NEW_VAL { get; set; } + + /// + /// SI截止时间原始值 + /// + public string SI_CUT_OLD_VAL { get; set; } + + /// + /// SI截止时间修改值 + /// + public string SI_CUT_NEW_VAL { get; set; } + + /// + /// 直达变中转原值 + /// + public string DIRECT_TO_TRANS_OLD_VAL { get; set; } + + /// + /// 直达变中转修改值 + /// + public string DIRECT_TO_TRANS_NEW_VAL { get; set; } + + /// + /// 船名原始值 + /// + public string VESSEL_OLD_VAL { get; set; } + + /// + /// 船名修改值 + /// + public string VESSEL_NEW_VAL { get; set; } + + /// + /// 航次原始值 + /// + public string VOYNO_OLD_VAL { get; set; } + + /// + /// 航次修改值 + /// + public string VOYNO_NEW_VAL { get; set; } } } diff --git a/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeWholeShipDetailInfo.cs b/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeWholeShipDetailInfo.cs index 4c54b710..6b957526 100644 --- a/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeWholeShipDetailInfo.cs +++ b/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeWholeShipDetailInfo.cs @@ -1,12 +1,20 @@ -using System; +using Myshipping.Application.Entity; +using SqlSugar; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Myshipping.Application { - public class TaskCautionNoticeWholeShipDetailInfo + /// + /// 重要任务提醒整船通知单号明细 + /// + [SugarTable("task_caution_notice_whole_ship_detail")] + [Description("重要任务提醒整船通知单号明细")] + public class TaskCautionNoticeWholeShipDetailInfo : TaskManageDbEntity { /// /// 任务主键 @@ -72,5 +80,10 @@ namespace Myshipping.Application /// 重试次数 /// public int RETRY_NUM { get; set; } + + /// + /// 批次号 + /// + public string BATCH_NO { get; set; } } } diff --git a/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeWholeShipInfo.cs b/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeWholeShipInfo.cs index 689f9513..1865d792 100644 --- a/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeWholeShipInfo.cs +++ b/Myshipping.Application/Entity/TaskManagePlat/TaskCautionNoticeWholeShipInfo.cs @@ -1,5 +1,8 @@ -using System; +using Myshipping.Application.Entity; +using SqlSugar; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,7 +12,9 @@ namespace Myshipping.Application /// /// 重要任务提醒整船通知 /// - public class TaskCautionNoticeWholeShipInfo + [SugarTable("task_caution_notice_whole_ship")] + [Description("重要任务提醒整船通知")] + public class TaskCautionNoticeWholeShipInfo : TaskManageDbEntity { /// /// 任务主键 @@ -101,5 +106,10 @@ namespace Myshipping.Application /// public string OLD_VAL_MD5 { get; set; } + /// + /// 统计日期 + /// + public Nullable STAT_DAY { get; set; } + } } diff --git a/Myshipping.Application/Service/BookingLabel/BookingLabelService.cs b/Myshipping.Application/Service/BookingLabel/BookingLabelService.cs index 3f35b6cd..bb635ba1 100644 --- a/Myshipping.Application/Service/BookingLabel/BookingLabelService.cs +++ b/Myshipping.Application/Service/BookingLabel/BookingLabelService.cs @@ -149,7 +149,7 @@ namespace Myshipping.Application [NonAction] private async Task> Cache() { - var list = await _rep.AsQueryable().ToListAsync(); + var list = await _rep.AsQueryable().Filter(null,true).Where(a=>a.TenantId == UserManager.TENANT_ID).ToListAsync(); var cacheList = list.Adapt>(); await _cache.SetTimeoutAsync(CommonConst.CACHE_KEY_BOOKING_LABEL + ":" + UserManager.TENANT_ID, cacheList, TimeSpan.FromDays(3)); diff --git a/Myshipping.Application/Service/BookingLabel/Dto/BookingLabelRegexDto.cs b/Myshipping.Application/Service/BookingLabel/Dto/BookingLabelRegexDto.cs index 31fde9cb..07440659 100644 --- a/Myshipping.Application/Service/BookingLabel/Dto/BookingLabelRegexDto.cs +++ b/Myshipping.Application/Service/BookingLabel/Dto/BookingLabelRegexDto.cs @@ -29,6 +29,8 @@ namespace Myshipping.Application equal, like, startwith, - notexists + notexists, + notequal, + notstartwith } } diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index bd654d79..28fe55a0 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -19,6 +19,7 @@ using Myshipping.Application.Helper; using Myshipping.Application.Service.BookingLabel.Dto; using Myshipping.Application.Service.BookingOrder.Dto; using Myshipping.Application.Service.BookingSlot.Dto; +using Myshipping.Application.Service.TaskManagePlat.Interface; using Myshipping.Core; using Myshipping.Core.Const; using Myshipping.Core.Entity; @@ -75,6 +76,7 @@ namespace Myshipping.Application private readonly INamedServiceProvider _namedBookingOrderServiceProvider; private readonly INamedServiceProvider _namedTaskManageServiceProvider; private readonly INamedServiceProvider _namedBookingLabelServiceProvider; + private readonly INamedServiceProvider _namedTaskCautionNoticeServiceProvider; private readonly IDjyCustomerService _djyCustomerService; private readonly IBookingValueAddedService _bookingValueAddedService; @@ -120,6 +122,7 @@ namespace Myshipping.Application SqlSugarRepository repLabelAllocation, IBookingLabelService bookingLabelService, INamedServiceProvider namedTaskManageServiceProvider, + INamedServiceProvider namedTaskCautionNoticeServiceProvider, SqlSugarRepository sysUserRepository, IDjyTenantParamService djyTenantParamService, SqlSugarRepository repPrintTemplate, @@ -155,6 +158,7 @@ namespace Myshipping.Application _djyTenantParamService = djyTenantParamService; _sysDataUserMenuService = sysDataUserMenuService; _namedBookingLabelServiceProvider = namedBookingLabelServiceProvider; + _namedTaskCautionNoticeServiceProvider = namedTaskCautionNoticeServiceProvider; } #region 舱位 @@ -361,6 +365,22 @@ namespace Myshipping.Application TenantId = model.TenantId })); + var inputDto = new BookingSlotBaseApiDto { + DataObj = new BookingSlotBaseApiSaveDto { + PORTDISCHARGEID = model.PORTDISCHARGEID, + PORTDISCHARGE = model.PORTDISCHARGE, + PORTLOADID = model.PORTLOADID, + PORTLOAD = model.PORTLOAD, + PLACEDELIVERY = model.PLACEDELIVERY, + PLACEDELIVERYID = model.PLACEDELIVERYID, + PLACERECEIPT = model.PLACERECEIPT, + PLACERECEIPTID = model.PLACERECEIPTID, + } + }; + + //这里自动匹配标签 + await GenerateSlotLabel(inputDto, model.Id); + return await Detail(model.Id); } @@ -3592,17 +3612,20 @@ namespace Myshipping.Application var bookingInfo = _repBookingOrder.AsQueryable().Filter(null, true).First(x => x.Id == ca.Alloc.BOOKING_ID && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID); - CreateTask(CautionNoticeTaskEnum.WeekAt, bcSrcDto, userList, bookingInfo, slotInfo, srcWeek, targetWeek, $"提单号:{bcSrcDto.MBLNo} \r\n计费周变更了 \r\n原:{srcWeek} \r\n新:{targetWeek}"); + CreateTask(CautionNoticeTaskEnum.WeekAt, bcSrcDto, userList, bookingInfo, slotInfo, srcWeek, targetWeek, $"提单号:{bcSrcDto.MBLNo} \r\n计费周变更了 \r\n原:{srcWeek} \r\n新:{targetWeek}",true); }); } else if (slotInfo != null) { - CreateTask(CautionNoticeTaskEnum.WeekAt, bcSrcDto, userList, null, slotInfo, srcWeek, targetWeek, $"提单号:{bcSrcDto.MBLNo} \r\n计费周变更了 \r\n原:{srcWeek} \r\n新:{targetWeek}"); + CreateTask(CautionNoticeTaskEnum.WeekAt, bcSrcDto, userList, null, slotInfo, srcWeek, targetWeek, $"提单号:{bcSrcDto.MBLNo} \r\n计费周变更了 \r\n原:{srcWeek} \r\n新:{targetWeek}", true); } } else { - new EmailNoticeHelper().SendEmailNotice($"MBLNO={bcSrcDto.MBLNo} slotId={slotId} 没有提取到计费周", $"MBLNO={bcSrcDto.MBLNo} slotId={slotId} 没有提取到计费周", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList()); + if (string.IsNullOrWhiteSpace(targetWeek)) + { + new EmailNoticeHelper().SendEmailNotice($"MBLNO={bcSrcDto.MBLNo} slotId={slotId} 没有提取到计费周", $"MBLNO={bcSrcDto.MBLNo} slotId={slotId} 没有提取到计费周", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList()); + } } string srcPriceDate = bcSrcDto.PriceCalculationDate.HasValue ? bcSrcDto.PriceCalculationDate.Value.ToString("yyyy-MM-dd") : ""; @@ -3618,38 +3641,39 @@ namespace Myshipping.Application var bookingInfo = _repBookingOrder.AsQueryable().Filter(null, true).First(x => x.Id == ca.Alloc.BOOKING_ID && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID); - CreateTask(CautionNoticeTaskEnum.PriceCalcDate, bcSrcDto, userList, bookingInfo, slotInfo, srcPriceDate, targetPriceDate, $"提单号:{bcSrcDto.MBLNo} \r\n计费日期变更了 \r\n原:{srcPriceDate} \r\n新:{targetPriceDate}"); + CreateTask(CautionNoticeTaskEnum.PriceCalcDate, bcSrcDto, userList, bookingInfo, slotInfo, srcPriceDate, targetPriceDate, $"提单号:{bcSrcDto.MBLNo} \r\n计费日期变更了 \r\n原:{srcPriceDate} \r\n新:{targetPriceDate}", true); }); } else if (slotInfo != null) { - CreateTask(CautionNoticeTaskEnum.PriceCalcDate, bcSrcDto, userList, null, slotInfo, srcPriceDate, targetPriceDate, $"提单号:{bcSrcDto.MBLNo} \r\n计费日期变更了 \r\n原:{srcPriceDate} \r\n新:{targetPriceDate}"); + CreateTask(CautionNoticeTaskEnum.PriceCalcDate, bcSrcDto, userList, null, slotInfo, srcPriceDate, targetPriceDate, $"提单号:{bcSrcDto.MBLNo} \r\n计费日期变更了 \r\n原:{srcPriceDate} \r\n新:{targetPriceDate}", true); } } else { - new EmailNoticeHelper().SendEmailNotice($"MBLNO={bcSrcDto.MBLNo} slotId={slotId} 没有提取到计费日期", $"MBLNO={bcSrcDto.MBLNo} slotId={slotId} 没有提取到计费日期", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList()); + if (string.IsNullOrWhiteSpace(targetPriceDate)) + { + new EmailNoticeHelper().SendEmailNotice($"MBLNO={bcSrcDto.MBLNo} slotId={slotId} 没有提取到计费日期", $"MBLNO={bcSrcDto.MBLNo} slotId={slotId} 没有提取到计费日期", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList()); + } } + bool isNeedWholeShip = false; + + CautionNoticeTaskWholeShipDto cautionNoticeTaskWholeShipDto = new CautionNoticeTaskWholeShipDto { + Carrier = slotInfo.CARRIERID + }; + string srcVesselVoyno = $"{bcSrcDto.Vessel}/{bcSrcDto.VoyNo}"; string targetVesselVoyno = $"{bcTargetDto.Vessel}/{bcTargetDto.VoyNo}"; if (!srcVesselVoyno.Equals(targetVesselVoyno, 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); + cautionNoticeTaskWholeShipDto.VesselOldVal = bcSrcDto.Vessel; + cautionNoticeTaskWholeShipDto.VesselNewVal = bcTargetDto.Vessel; + cautionNoticeTaskWholeShipDto.VoynoOldVal = bcSrcDto.VoyNo; + cautionNoticeTaskWholeShipDto.VoynoNewVal = bcTargetDto.VoyNo; - CreateTask(CautionNoticeTaskEnum.ChangeVesselVoyno, bcSrcDto, userList, bookingInfo, slotInfo, srcVesselVoyno, targetVesselVoyno, $"提单号:{bcSrcDto.MBLNo} \r\n船名航次变更了 \r\n原:{srcVesselVoyno} \r\n新:{targetVesselVoyno}"); - }); - } - else if (slotInfo != null) - { - CreateTask(CautionNoticeTaskEnum.ChangeVesselVoyno, bcSrcDto, userList, null, slotInfo, srcVesselVoyno, targetVesselVoyno, $"提单号:{bcSrcDto.MBLNo} \r\n船名航次变更了 \r\n原:{srcVesselVoyno} \r\n新:{targetVesselVoyno}"); - } + isNeedWholeShip = true; } @@ -3661,20 +3685,10 @@ namespace Myshipping.Application && srcCarrierType.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 - && x.TenantId == UserManager.TENANT_ID); + cautionNoticeTaskWholeShipDto.DirectToTransOldVal = "直达"; + cautionNoticeTaskWholeShipDto.DirectToTransNewVal = "中转"; - CreateTask(CautionNoticeTaskEnum.ChangeTransfer, bcSrcDto, userList, bookingInfo, slotInfo, "直达", "中转", $"提单号:{bcSrcDto.MBLNo} \r\n直达变成中转了"); - }); - } - else if (slotInfo != null) - { - CreateTask(CautionNoticeTaskEnum.ChangeTransfer, bcSrcDto, userList, null, slotInfo, "直达", "中转", $"提单号:{bcSrcDto.MBLNo} \r\n直达变成中转了"); - } + isNeedWholeShip = true; } string srcVGMCut = bcSrcDto.VGMSubmissionCutDate; @@ -3687,20 +3701,10 @@ namespace Myshipping.Application 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); + cautionNoticeTaskWholeShipDto.VGMCutOldVal = srcVGMCutDate.ToString("yyyy-MM-dd HH:mm"); + cautionNoticeTaskWholeShipDto.VGMCutNewVal = targeVGMCutDate.ToString("yyyy-MM-dd HH:mm"); - CreateTask(CautionNoticeTaskEnum.VGMCutDateAdvanced, bcSrcDto, userList, bookingInfo, slotInfo, srcVGMCut, targeVGMCut, $"提单号:{bcSrcDto.MBLNo} \r\nVGM截单时间提前了 \r\n原:{srcVGMCut} \r\n新:{targeVGMCut}"); - }); - } - else if (slotInfo != null) - { - CreateTask(CautionNoticeTaskEnum.VGMCutDateAdvanced, bcSrcDto, userList, null, slotInfo, srcVGMCut, targeVGMCut, $"提单号:{bcSrcDto.MBLNo} \r\nVGM截单时间提前了 \r\n原:{srcVGMCut} \r\n新:{targeVGMCut}"); - } + isNeedWholeShip = true; } } @@ -3715,22 +3719,24 @@ namespace Myshipping.Application //如果新给的SI截止时间,需要推送通知 if (srcSICutDate > targeSICutDate) { - 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); + cautionNoticeTaskWholeShipDto.SICutOldVal = srcSICutDate.ToString("yyyy-MM-dd HH:mm"); + cautionNoticeTaskWholeShipDto.SICutNewVal = targeSICutDate.ToString("yyyy-MM-dd HH:mm"); - CreateTask(CautionNoticeTaskEnum.SICutDateAdvanced, bcSrcDto, userList, bookingInfo, slotInfo, srcSICut, targeSICut, $"提单号:{bcSrcDto.MBLNo} \r\n样单截止时间提前了 \r\n原:{srcSICut} \r\n新:{targeSICut}"); - }); - } - else if (slotInfo != null) - { - CreateTask(CautionNoticeTaskEnum.SICutDateAdvanced, bcSrcDto, userList, null, slotInfo, srcSICut, targeSICut, $"提单号:{bcSrcDto.MBLNo} \r\n样单截止时间提前了 \r\n原:{srcSICut} \r\n新:{targeSICut}"); - } + isNeedWholeShip = true; } } + + //这里如果需要做整船提醒,需要单独走重要通知通道 + if (isNeedWholeShip) + { + //触发推送消息 + var name = _namedTaskCautionNoticeServiceProvider + .GetService(nameof(TaskCautionNoticeService)); + + var wholeShipRlt = await name.GenerateWholeShipCaucation(cautionNoticeTaskWholeShipDto, slotInfo); + + _logger.LogInformation($"触发整船提醒完成,结果={JSON.Serialize(wholeShipRlt)}"); + } } } catch (Exception ex) @@ -3838,6 +3844,7 @@ namespace Myshipping.Application SourceBusiType = dto.sourceBusiType, SourceBusiTypeName = dto.sourceBusiTypeName, CreateTime = DateTime.Now, + IsAutoSendNotice = dto.isAutoSendNotice, NoticeList = new List() }; @@ -3878,7 +3885,7 @@ namespace Myshipping.Application /// 变更值 /// 提示信息 private void CreateTask(CautionNoticeTaskEnum cautionNoticeType, TaskBCInfoDto bcSrcDto, List userList, BookingOrder bookingInfo, - BookingSlotBase bookingSlotInfo, string srcVal, string targetVal, string notifyContent) + BookingSlotBase bookingSlotInfo, string srcVal, string targetVal, string notifyContent,bool isAutoSendNotice) { List userIdList = new List(); @@ -3932,6 +3939,7 @@ namespace Myshipping.Application vessel = bcSrcDto.Vessel, voyno = bcSrcDto.VoyNo, tenentName = UserManager.TENANT_NAME, + isAutoSendNotice = isAutoSendNotice, notifyContent = notifyContent, notifyList = new List() @@ -4293,7 +4301,7 @@ namespace Myshipping.Application { if(operEnum == LabelRegexOperEnum.equal) { - if (dto.DataObj.PORTLOADID.Equals(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && dto.DataObj.PORTLOADID.Equals(regList[j].val)) { ruleList.Add(labelList[i]); @@ -4303,7 +4311,7 @@ namespace Myshipping.Application } else if (operEnum == LabelRegexOperEnum.startwith) { - if (dto.DataObj.PORTLOADID.StartsWith(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && dto.DataObj.PORTLOADID.StartsWith(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; @@ -4312,7 +4320,7 @@ namespace Myshipping.Application } else if (operEnum == LabelRegexOperEnum.like) { - if (dto.DataObj.PORTLOADID.Contains(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && dto.DataObj.PORTLOADID.Contains(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; @@ -4321,7 +4329,25 @@ namespace Myshipping.Application } else if (operEnum == LabelRegexOperEnum.notexists) { - if (!dto.DataObj.PORTLOADID.Equals(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && !dto.DataObj.PORTLOADID.Contains(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notequal) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && !dto.DataObj.PORTLOADID.Equals(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notstartwith) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && !dto.DataObj.PORTLOADID.StartsWith(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; @@ -4333,7 +4359,7 @@ namespace Myshipping.Application { if (operEnum == LabelRegexOperEnum.equal) { - if (dto.DataObj.PLACERECEIPT.Equals(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && dto.DataObj.PLACERECEIPT.Equals(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; @@ -4342,7 +4368,7 @@ namespace Myshipping.Application } else if (operEnum == LabelRegexOperEnum.startwith) { - if (dto.DataObj.PLACERECEIPT.StartsWith(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && dto.DataObj.PLACERECEIPT.StartsWith(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; @@ -4351,7 +4377,7 @@ namespace Myshipping.Application } else if (operEnum == LabelRegexOperEnum.like) { - if (dto.DataObj.PLACERECEIPT.Contains(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && dto.DataObj.PLACERECEIPT.Contains(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; @@ -4360,7 +4386,25 @@ namespace Myshipping.Application } else if (operEnum == LabelRegexOperEnum.notexists) { - if (!dto.DataObj.PLACERECEIPT.Equals(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && !dto.DataObj.PLACERECEIPT.Contains(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notequal) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && !dto.DataObj.PLACERECEIPT.Equals(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notstartwith) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && !dto.DataObj.PLACERECEIPT.StartsWith(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; @@ -4372,7 +4416,64 @@ namespace Myshipping.Application { if (operEnum == LabelRegexOperEnum.equal) { - if (dto.DataObj.PORTLOAD.Equals(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && dto.DataObj.PORTLOAD.Equals(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.startwith) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && dto.DataObj.PORTLOAD.StartsWith(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.like) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && dto.DataObj.PORTLOAD.Contains(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notequal) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && !dto.DataObj.PORTLOAD.Equals(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notexists) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && !dto.DataObj.PORTLOAD.Contains(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notstartwith) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && !dto.DataObj.PORTLOAD.StartsWith(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + } + else if (regList[j].name.Equals("PORTDISCHARGEID", StringComparison.OrdinalIgnoreCase)) + { + if (operEnum == LabelRegexOperEnum.equal) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && dto.DataObj.PORTDISCHARGEID.Equals(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; @@ -4381,7 +4482,7 @@ namespace Myshipping.Application } else if (operEnum == LabelRegexOperEnum.startwith) { - if (dto.DataObj.PORTLOAD.StartsWith(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && dto.DataObj.PORTDISCHARGEID.StartsWith(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; @@ -4390,7 +4491,16 @@ namespace Myshipping.Application } else if (operEnum == LabelRegexOperEnum.like) { - if (dto.DataObj.PORTLOAD.Contains(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && dto.DataObj.PORTDISCHARGEID.Contains(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notequal) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && !dto.DataObj.PORTDISCHARGEID.Equals(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; @@ -4399,7 +4509,130 @@ namespace Myshipping.Application } else if (operEnum == LabelRegexOperEnum.notexists) { - if (!dto.DataObj.PORTLOAD.Equals(regList[j].val)) + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && !dto.DataObj.PORTDISCHARGEID.Contains(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notstartwith) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && !dto.DataObj.PORTDISCHARGEID.StartsWith(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + } + else if (regList[j].name.Equals("PORTDISCHARGE", StringComparison.OrdinalIgnoreCase)) + { + if (operEnum == LabelRegexOperEnum.equal) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && dto.DataObj.PORTDISCHARGE.Equals(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.startwith) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && dto.DataObj.PORTDISCHARGE.StartsWith(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.like) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && dto.DataObj.PORTDISCHARGE.Contains(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notequal) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && !dto.DataObj.PORTDISCHARGE.Equals(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notexists) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && !dto.DataObj.PORTDISCHARGE.Contains(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notstartwith) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && !dto.DataObj.PORTDISCHARGE.StartsWith(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + } + else if (regList[j].name.Equals("PLACEDELIVERY", StringComparison.OrdinalIgnoreCase)) + { + if (operEnum == LabelRegexOperEnum.equal) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && dto.DataObj.PLACEDELIVERY.Equals(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.startwith) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && dto.DataObj.PLACEDELIVERY.StartsWith(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.like) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && dto.DataObj.PLACEDELIVERY.Contains(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notequal) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && !dto.DataObj.PLACEDELIVERY.Equals(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notexists) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && !dto.DataObj.PLACEDELIVERY.Contains(regList[j].val)) + { + ruleList.Add(labelList[i]); + isSucc = true; + break; + } + } + else if (operEnum == LabelRegexOperEnum.notstartwith) + { + if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && !dto.DataObj.PLACEDELIVERY.StartsWith(regList[j].val)) { ruleList.Add(labelList[i]); isSucc = true; diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskDto.cs index dbb362ae..dc8e1e73 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskDto.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskDto.cs @@ -122,6 +122,11 @@ namespace Myshipping.Application /// 通知人列表 /// public List notifyList { get; set; } + + /// + /// 是否自动转发通知 + /// + public bool isAutoSendNotice { get; set; } } /// diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskWholeShipDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskWholeShipDto.cs new file mode 100644 index 00000000..f39bf322 --- /dev/null +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/CautionNoticeTaskWholeShipDto.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + /// + /// 重要通知整船提醒 + /// + public class CautionNoticeTaskWholeShipDto + { + /// + /// 船公司 + /// + public string Carrier { get; set; } + + /// + /// VGM截止时间原始值 + /// + public string VGMCutOldVal { get; set; } + + /// + /// VGM截止时间修改值 + /// + public string VGMCutNewVal { get; set; } + + /// + /// SI截止时间原始值 + /// + public string SICutOldVal { get; set; } + + /// + /// SI截止时间修改值 + /// + public string SICutNewVal { get; set; } + + /// + /// 直达变中转原值 + /// + public string DirectToTransOldVal { get; set; } + + /// + /// 直达变中转修改值 + /// + public string DirectToTransNewVal { get; set; } + + /// + /// 直达变中转原值 + /// + public string VesselOldVal { get; set; } + + /// + /// 直达变中转修改值 + /// + public string VesselNewVal { get; set; } + + /// + /// 直达变中转原值 + /// + public string VoynoOldVal { get; set; } + + /// + /// 直达变中转修改值 + /// + public string VoynoNewVal { get; set; } + + /// + /// 统计日期 + /// + public string StatDay { get; set; } + + /// + /// 原始值MD5 + /// + public string OldMD5 { get; set; } + + /// + /// 主单号 + /// + public string MBLNo { get; set; } + + /// + /// 舱位ID + /// + public long SlotId { get; set; } + } +} diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/TaskManageOrderCautionNoticeInfo.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/TaskManageOrderCautionNoticeInfo.cs index 6d37471f..31af5f19 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/TaskManageOrderCautionNoticeInfo.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/CautionNoitce/TaskManageOrderCautionNoticeInfo.cs @@ -76,6 +76,62 @@ namespace Myshipping.Application /// public string NotifyContent { get; set; } + /// + /// VGM截止时间原始值 + /// + + public string VGMCutOldVal { get; set; } + + /// + /// VGM截止时间修改值 + /// + public string VGMCutNewVal { get; set; } + + /// + /// SI截止时间原始值 + /// + public string SICutOldVal { get; set; } + + /// + /// SI截止时间修改值 + /// + public string SICutNewVal { get; set; } + + /// + /// 直达变中转原值 + /// + public string DirectToTransOldVal { get; set; } + + /// + /// 直达变中转修改值 + /// + public string DirectToTransNewVal { get; set; } + + /// + /// 船名原始值 + /// + public string VesselOldVal { get; set; } + + /// + /// 船名修改值 + /// + public string VesselNewVal { get; set; } + + /// + /// 航次原始值 + /// + public string VoynoOldVal { get; set; } + + /// + /// 航次修改值 + /// + public string VoynoNewVal { get; set; } + + /// + /// 是否自动转发通知 + /// + public bool IsAutoSendNotice { get; set; } + /// /// 消息列表 /// diff --git a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskCautionNoticeService.cs b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskCautionNoticeService.cs index fc3ef9d9..53a5b879 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskCautionNoticeService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskCautionNoticeService.cs @@ -26,5 +26,14 @@ namespace Myshipping.Application.Service.TaskManagePlat.Interface /// 租户ID /// 返回回执 Task TriggerSendNotice(string taskPKId, long tenantId); + + + /// + /// 生成重要提醒整船通知 + /// + /// 请求详情 + /// 舱位详情 + /// 返回回执 + Task GenerateWholeShipCaucation(CautionNoticeTaskWholeShipDto model, BookingSlotBase slotBaseInfo); } } diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskCautionNoticeService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskCautionNoticeService.cs index d2bfc867..aa99bff9 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskCautionNoticeService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskCautionNoticeService.cs @@ -23,6 +23,7 @@ using NPOI.SS.Formula.Functions; using System.Reflection.Metadata; using Furion; using Myshipping.Application.Helper; +using Furion.DistributedIDGenerator; namespace Myshipping.Application { @@ -38,13 +39,27 @@ namespace Myshipping.Application private readonly SqlSugarRepository _taskCautionNoticeInfoRepository; private readonly SqlSugarRepository _taskCautionNoticeDetailInfoRepository; private readonly SqlSugarRepository _djyUserMailAccount; - + private readonly SqlSugarRepository _taskCautionNoticeWholeShipInfoRepository; + private readonly SqlSugarRepository _taskCautionNoticeWholeShipDetailInfoRepository; + private readonly SqlSugarRepository _repBase; + private readonly SqlSugarRepository _repCtn; + private readonly SqlSugarRepository _repAllocation; + private readonly SqlSugarRepository _repAllocationCtn; + private readonly SqlSugarRepository _repBookingOrder; + private readonly SqlSugarRepository _sysUserRepository; public TaskCautionNoticeService(ISysCacheService cache, ILogger logger, SqlSugarRepository taskBaseRepository, SqlSugarRepository taskCautionNoticeInfoRepository, SqlSugarRepository taskCautionNoticeDetailInfoRepository, - SqlSugarRepository djyUserMailAccount) + SqlSugarRepository taskCautionNoticeWholeShipInfoRepository, + SqlSugarRepository taskCautionNoticeWholeShipDetailInfoRepository, + SqlSugarRepository djyUserMailAccount, + SqlSugarRepository repBase, + SqlSugarRepository repCtn, SqlSugarRepository repAllocation, + SqlSugarRepository repAllocationCtn, + SqlSugarRepository repBookingOrder, + SqlSugarRepository sysUserRepository) { _cache = cache; _logger = logger; @@ -53,7 +68,14 @@ namespace Myshipping.Application _taskCautionNoticeInfoRepository = taskCautionNoticeInfoRepository; _taskCautionNoticeDetailInfoRepository = taskCautionNoticeDetailInfoRepository; _djyUserMailAccount = djyUserMailAccount; - + _taskCautionNoticeWholeShipInfoRepository = taskCautionNoticeWholeShipInfoRepository; + _taskCautionNoticeWholeShipDetailInfoRepository = taskCautionNoticeWholeShipDetailInfoRepository; + _repBase = repBase; + _repCtn = repCtn; + _repAllocation = repAllocation; + _repAllocationCtn = repAllocationCtn; + _repBookingOrder = repBookingOrder; + _sysUserRepository = sysUserRepository; } #region 获取重要提醒任务详情 @@ -270,5 +292,552 @@ namespace Myshipping.Application return result; } #endregion + + #region 生成重要提醒整船通知 + /// + /// 生成重要提醒整船通知 + /// + /// 请求详情 + /// 返回回执 + public async Task GenerateWholeShipCaucation(CautionNoticeTaskWholeShipDto model, BookingSlotBase slotBaseInfo) + { + TaskManageOrderResultDto rlt = new TaskManageOrderResultDto(); + + try + { + /* + 1、优先匹配是否已经有了整船的通知(船名、航次、SI截止时间、VGM截止时间、直达变中转、统计日期必须是当日的,注新值和旧值提交的都一致) + 2、如果能匹配到,并且明细里有此单号,不做处理;没有单号记录需要写入单号,并且重新发起当票的邮件和钉钉通知 + 3、如果没有匹配到,重新获取整船的单号,生成明细记录。发起邮件和钉钉通知 + */ + DateTime nowDate = DateTime.Now; + string batchNo = IDGen.NextID().ToString(); + + int statDay = int.Parse(nowDate.ToString("yyyyMMdd")); + + var shipInfo = await _taskCautionNoticeWholeShipInfoRepository.AsQueryable().Filter(null, true).FirstAsync(a => + a.VESSEL_OLD_VAL == model.VesselOldVal && a.VESSEL_NEW_VAL == model.VesselNewVal + && a.VOYNO_OLD_VAL == model.VoynoOldVal && a.VOYNO_NEW_VAL == model.VoynoNewVal + && a.SI_CUT_OLD_VAL == model.SICutOldVal && a.SI_CUT_NEW_VAL == model.SICutNewVal + && a.VGM_CUT_OLD_VAL == model.VGMCutOldVal && a.VGM_CUT_NEW_VAL == model.VGMCutNewVal + && a.DIRECT_TO_TRANS_OLD_VAL == model.DirectToTransOldVal && a.DIRECT_TO_TRANS_NEW_VAL == model.DirectToTransNewVal && a.STAT_DAY != null && a.STAT_DAY.Value == statDay); + + var detailRecordList = new List(); + + if (shipInfo == null) + { + TaskCautionNoticeWholeShipInfo shipEntity = new TaskCautionNoticeWholeShipInfo + { + PK_ID = IDGen.NextID().ToString(), + CARRIER = model.Carrier, + IsDeleted = false, + VESSEL_OLD_VAL = model.VesselOldVal, + VESSEL_NEW_VAL = model.VesselNewVal, + VOYNO_OLD_VAL = model.VoynoOldVal, + VOYNO_NEW_VAL = model.VoynoNewVal, + VGM_CUT_OLD_VAL = model.VGMCutOldVal, + VGM_CUT_NEW_VAL = model.VGMCutNewVal, + SI_CUT_OLD_VAL = model.SICutOldVal, + SI_CUT_NEW_VAL = model.SICutNewVal, + DIRECT_TO_TRANS_OLD_VAL = model.DirectToTransOldVal, + DIRECT_TO_TRANS_NEW_VAL = model.DirectToTransNewVal, + IS_CUT_DATE_ADVANCED = !string.IsNullOrWhiteSpace(model.SICutNewVal), + IS_VESSEL_CHANGE = !string.IsNullOrWhiteSpace(model.VesselNewVal), + IS_TRANSFER = !string.IsNullOrWhiteSpace(model.DirectToTransNewVal), + CreatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + STAT_DAY = statDay, + }; + + await _taskCautionNoticeWholeShipInfoRepository.InsertAsync(shipEntity); + + //检索所有订舱记录 + var bookingSlotAllocList = _repBase.AsQueryable().Filter(null, true) + .LeftJoin((slot, alloc) => slot.Id == alloc.BOOKING_SLOT_ID) + .Where((slot, alloc) => slot.VESSEL == model.VesselOldVal && slot.VOYNO == model.VoynoOldVal + && slot.CARRIERID == model.Carrier + && slot.IsDeleted == false && slot.TenantId == UserManager.TENANT_ID && (alloc == null || alloc.IsDeleted == false)) + .Select((slot, alloc) => new { Slot = slot, Alloc = alloc }).ToList(); + + + List bookingOrderList = new List(); + + //先批量取一遍关联的订舱记录 + if (bookingSlotAllocList.Any(t => t.Alloc != null)) + { + var bookingNoList = bookingSlotAllocList.Where(a => a.Alloc != null) + .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(); + } + + //生成完记录 + bookingSlotAllocList.ForEach(t => + { + //舱位分配表不为空表示有对应的订舱记录 + if (t.Alloc != null) + { + var bookingOrder = bookingOrderList.FirstOrDefault(b => b.Id == t.Alloc.BOOKING_ID); + List userIds = new List(); + List userList = new List(); + + if (!string.IsNullOrWhiteSpace(bookingOrder.OPID)) + userIds.Add(long.Parse(bookingOrder.OPID)); + + if (!string.IsNullOrWhiteSpace(bookingOrder.CUSTSERVICEID)) + userIds.Add(long.Parse(bookingOrder.CUSTSERVICEID)); + + userIds.Add(bookingOrder.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(); + + userList.ForEach(user => + { + //表示即有舱位也有订舱记录 + var detailInfo = new TaskCautionNoticeWholeShipDetailInfo + { + PK_ID = IDGen.NextID().ToString(), + P_ID = shipEntity.PK_ID, + BOOKING_ID = t.Alloc.BOOKING_ID, + BOOKING_SLOT_ID = t.Slot.Id, + BATCH_NO = batchNo, + IsDeleted = false, + MBL_NO = bookingOrder.MBLNO, + STATUS = "TEMP", + STATUS_NAME = "暂存", + NOTIFY_METHOD = CautionNoticeMethodEnum.Email.ToString(), + NOTIFY_USER_ID = user.Id.ToString(), + NOTIFY_USER_NAME = user.Name, + NOTIFY_MOBILE = user.Phone?.Trim(), + NOTIFY_EMAIL = user.Email?.Trim(), + CreatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + }; + + detailRecordList.Add(detailInfo); + + _taskCautionNoticeWholeShipDetailInfoRepository.InsertAsync(detailInfo); + + //表示即有舱位也有订舱记录 + var detail2Info = new TaskCautionNoticeWholeShipDetailInfo + { + PK_ID = IDGen.NextID().ToString(), + P_ID = shipEntity.PK_ID, + BOOKING_ID = t.Alloc.BOOKING_ID, + BOOKING_SLOT_ID = t.Slot.Id, + BATCH_NO = batchNo, + IsDeleted = false, + MBL_NO = bookingOrder.MBLNO, + STATUS = "TEMP", + STATUS_NAME = "暂存", + NOTIFY_METHOD = CautionNoticeMethodEnum.DingDing.ToString(), + NOTIFY_USER_ID = user.Id.ToString(), + NOTIFY_USER_NAME = user.Name, + NOTIFY_MOBILE = user.Phone?.Trim(), + NOTIFY_EMAIL = user.Email?.Trim(), + CreatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + }; + + detailRecordList.Add(detail2Info); + + _taskCautionNoticeWholeShipDetailInfoRepository.InsertAsync(detail2Info); + + }); + } + else + { + //表示只有舱位 + //表示即有舱位也有订舱记录 + var createUserId = t.Slot.CreatedUserId.Value; + + var user = _sysUserRepository.AsQueryable().Filter(null, true) + .First(x => x.Id == createUserId && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID); + + var detailInfo = new TaskCautionNoticeWholeShipDetailInfo + { + PK_ID = IDGen.NextID().ToString(), + P_ID = shipEntity.PK_ID, + BOOKING_SLOT_ID = t.Slot.Id, + BATCH_NO = batchNo, + IsDeleted = false, + MBL_NO = t.Slot.SLOT_BOOKING_NO, + STATUS = "TEMP", + STATUS_NAME = "暂存", + NOTIFY_METHOD = CautionNoticeMethodEnum.Email.ToString(), + NOTIFY_USER_ID = user.Id.ToString(), + NOTIFY_USER_NAME = user.Name, + NOTIFY_MOBILE = user.Phone?.Trim(), + NOTIFY_EMAIL = user.Email?.Trim(), + CreatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + }; + + detailRecordList.Add(detailInfo); + + _taskCautionNoticeWholeShipDetailInfoRepository.InsertAsync(detailInfo); + + //表示即有舱位也有订舱记录 + var detail2Info = new TaskCautionNoticeWholeShipDetailInfo + { + PK_ID = IDGen.NextID().ToString(), + P_ID = shipEntity.PK_ID, + BOOKING_SLOT_ID = t.Slot.Id, + BATCH_NO = batchNo, + IsDeleted = false, + MBL_NO = t.Slot.SLOT_BOOKING_NO, + STATUS = "TEMP", + STATUS_NAME = "暂存", + NOTIFY_METHOD = CautionNoticeMethodEnum.DingDing.ToString(), + NOTIFY_USER_ID = user.Id.ToString(), + NOTIFY_USER_NAME = user.Name, + NOTIFY_MOBILE = user.Phone?.Trim(), + NOTIFY_EMAIL = user.Email?.Trim(), + CreatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + }; + + detailRecordList.Add(detail2Info); + + _taskCautionNoticeWholeShipDetailInfoRepository.InsertAsync(detail2Info); + } + }); + } + else + { + var detailList = _taskCautionNoticeWholeShipDetailInfoRepository.AsQueryable().Filter(null, true) + .Where(a => a.P_ID == shipInfo.PK_ID).ToList(); + + var bookingSlotAllocList = _repBase.AsQueryable().Filter(null, true) + .LeftJoin((slot, alloc) => slot.Id == alloc.BOOKING_SLOT_ID) + .Where((slot, alloc) => slot.SLOT_BOOKING_NO == model.MBLNo + && slot.CARRIERID == model.Carrier + && slot.IsDeleted == false && slot.TenantId == UserManager.TENANT_ID && (alloc == null || alloc.IsDeleted == false)) + .Select((slot, alloc) => new { Slot = slot, Alloc = alloc }).ToList(); + + if (bookingSlotAllocList.Any(t => t.Alloc != null)) + { + var bookingNoList = bookingSlotAllocList.Where(a => a.Alloc != null) + .Select(a => a.Alloc.BOOKING_ID).ToList(); + + var lostList = bookingNoList.GroupJoin(detailList.Where(p => p.BOOKING_ID > 0).ToList(), l => l, + r => r.BOOKING_ID, (l, r) => + { + var currList = r.ToList(); + + if (currList.Count == 0) + return new { Succ = false, obj = l }; + + return new { Succ = true, obj = l }; + }).Where(p => p.Succ == false).ToList(); + + if (lostList.Count > 0) + { + var bookingOrderList = _repBookingOrder.AsQueryable().Filter(null, true) + .Where(x => bookingNoList.Contains(x.Id) && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToList(); + + _logger.LogInformation($"提单号:{model.MBLNo} 检索通知消息没有发送过,需要补发通知"); + + foreach (var md in lostList) + { + var bookingOrder = bookingOrderList.FirstOrDefault(p => p.Id == md.obj); + + List userIds = new List(); + List userList = new List(); + + if (!string.IsNullOrWhiteSpace(bookingOrder.OPID)) + userIds.Add(long.Parse(bookingOrder.OPID)); + + if (!string.IsNullOrWhiteSpace(bookingOrder.CUSTSERVICEID)) + userIds.Add(long.Parse(bookingOrder.CUSTSERVICEID)); + + userIds.Add(bookingOrder.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(); + + var slotInfo = bookingSlotAllocList + .FirstOrDefault(x => x.Alloc != null && x.Alloc.BOOKING_ID == bookingOrder.Id).Slot; + + userList.ForEach(user => + { + //表示即有舱位也有订舱记录 + var detailInfo = new TaskCautionNoticeWholeShipDetailInfo + { + PK_ID = IDGen.NextID().ToString(), + P_ID = shipInfo.PK_ID, + BOOKING_ID = bookingOrder.Id, + BOOKING_SLOT_ID = slotInfo.Id, + BATCH_NO = batchNo, + IsDeleted = false, + MBL_NO = bookingOrder.MBLNO, + STATUS = "TEMP", + STATUS_NAME = "暂存", + NOTIFY_METHOD = CautionNoticeMethodEnum.Email.ToString(), + NOTIFY_USER_ID = user.Id.ToString(), + NOTIFY_USER_NAME = user.Name, + NOTIFY_MOBILE = user.Phone?.Trim(), + NOTIFY_EMAIL = user.Email?.Trim(), + CreatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + }; + + detailRecordList.Add(detailInfo); + + _taskCautionNoticeWholeShipDetailInfoRepository.InsertAsync(detailInfo); + + //表示即有舱位也有订舱记录 + var detail2Info = new TaskCautionNoticeWholeShipDetailInfo + { + PK_ID = IDGen.NextID().ToString(), + P_ID = shipInfo.PK_ID, + BOOKING_ID = bookingOrder.Id, + BOOKING_SLOT_ID = slotInfo.Id, + BATCH_NO = batchNo, + IsDeleted = false, + MBL_NO = bookingOrder.MBLNO, + STATUS = "TEMP", + STATUS_NAME = "暂存", + NOTIFY_METHOD = CautionNoticeMethodEnum.DingDing.ToString(), + NOTIFY_USER_ID = user.Id.ToString(), + NOTIFY_USER_NAME = user.Name, + NOTIFY_MOBILE = user.Phone?.Trim(), + NOTIFY_EMAIL = user.Email?.Trim(), + CreatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + }; + + detailRecordList.Add(detail2Info); + + _taskCautionNoticeWholeShipDetailInfoRepository.InsertAsync(detail2Info); + + }); + } + + } + } + else + { + bookingSlotAllocList.ForEach(t => + { + var slotInfo = detailList.FirstOrDefault(p => p.BOOKING_SLOT_ID == t.Slot.Id); + + + if (slotInfo == null) + { + //表示只有舱位 + //表示即有舱位也有订舱记录 + var createUserId = t.Slot.CreatedUserId.Value; + + var user = _sysUserRepository.AsQueryable().Filter(null, true) + .First(x => x.Id == createUserId && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID); + + var detailInfo = new TaskCautionNoticeWholeShipDetailInfo + { + PK_ID = IDGen.NextID().ToString(), + P_ID = shipInfo.PK_ID, + BOOKING_SLOT_ID = t.Slot.Id, + BATCH_NO = batchNo, + IsDeleted = false, + MBL_NO = t.Slot.SLOT_BOOKING_NO, + STATUS = "TEMP", + STATUS_NAME = "暂存", + NOTIFY_METHOD = CautionNoticeMethodEnum.Email.ToString(), + NOTIFY_USER_ID = user.Id.ToString(), + NOTIFY_USER_NAME = user.Name, + NOTIFY_MOBILE = user.Phone?.Trim(), + NOTIFY_EMAIL = user.Email?.Trim(), + CreatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + }; + + detailRecordList.Add(detailInfo); + + _taskCautionNoticeWholeShipDetailInfoRepository.InsertAsync(detailInfo); + + //表示即有舱位也有订舱记录 + var detail2Info = new TaskCautionNoticeWholeShipDetailInfo + { + PK_ID = IDGen.NextID().ToString(), + P_ID = shipInfo.PK_ID, + BOOKING_SLOT_ID = t.Slot.Id, + BATCH_NO = batchNo, + IsDeleted = false, + MBL_NO = t.Slot.SLOT_BOOKING_NO, + STATUS = "TEMP", + STATUS_NAME = "暂存", + NOTIFY_METHOD = CautionNoticeMethodEnum.DingDing.ToString(), + NOTIFY_USER_ID = user.Id.ToString(), + NOTIFY_USER_NAME = user.Name, + NOTIFY_MOBILE = user.Phone?.Trim(), + NOTIFY_EMAIL = user.Email?.Trim(), + CreatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + }; + + detailRecordList.Add(detail2Info); + + _taskCautionNoticeWholeShipDetailInfoRepository.InsertAsync(detail2Info); + } + }); + } + } + + if(detailRecordList.Count > 0) + { + //推送邮件 + await PushDingdingNotice(detailRecordList, shipInfo, slotBaseInfo); + + //推送钉钉 + await PushEmailNotice(detailRecordList); + } + } + catch (Exception ex) + { + new EmailNoticeHelper().SendEmailNotice($"slotid={model.SlotId} 推送重要提醒整船通知异常", $"slotid={model.SlotId} 推送重要提醒整船通知异常 原因:{ex.Message}", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList()); + } + + return rlt; + } + #endregion + + private async Task PushDingdingNotice(List detailList, TaskCautionNoticeWholeShipInfo shipInfo, BookingSlotBase slotInfo) + { + try + { + var tenantId = detailList.FirstOrDefault().TenantId; + + StringBuilder contentBuilder = new StringBuilder(); + + contentBuilder.AppendLine("起运港:"+ slotInfo.PLACERECEIPT); + contentBuilder.AppendLine("目的港:" + slotInfo.PLACEDELIVERY); + contentBuilder.AppendLine("船名/航次:" + $"{slotInfo.VESSEL}/{slotInfo.VOYNO}"); + contentBuilder.AppendLine("ETD:" + (slotInfo.ETD.HasValue ? slotInfo.ETD.Value.ToString("yyyy-MM-dd") : "")); + contentBuilder.AppendLine("================="); + + //截止时间提前 + if (shipInfo.IS_CUT_DATE_ADVANCED) + { + if (shipInfo.VGM_CUT_OLD_VAL.Equals(shipInfo.VGM_CUT_NEW_VAL, StringComparison.OrdinalIgnoreCase)) + { + contentBuilder.AppendLine("VGM截止时间提前"); + contentBuilder.AppendLine("原:"+ shipInfo.VGM_CUT_OLD_VAL); + contentBuilder.AppendLine("新:" + shipInfo.VGM_CUT_OLD_VAL); + } + + if (shipInfo.SI_CUT_OLD_VAL.Equals(shipInfo.SI_CUT_NEW_VAL, StringComparison.OrdinalIgnoreCase)) + { + contentBuilder.AppendLine("SI截止时间提前"); + contentBuilder.AppendLine("原:" + shipInfo.VGM_CUT_OLD_VAL); + contentBuilder.AppendLine("新:" + shipInfo.VGM_CUT_OLD_VAL); + } + } + + //船名航次变更 + if (shipInfo.IS_VESSEL_CHANGE) + { + if (shipInfo.VESSEL_OLD_VAL.Equals(shipInfo.VESSEL_NEW_VAL, StringComparison.OrdinalIgnoreCase) || shipInfo.VOYNO_OLD_VAL.Equals(shipInfo.VOYNO_NEW_VAL, StringComparison.OrdinalIgnoreCase)) + { + contentBuilder.AppendLine("船名航次变更"); + contentBuilder.AppendLine("原:" + $"{shipInfo.VESSEL_OLD_VAL}/{shipInfo.VOYNO_OLD_VAL}"); + contentBuilder.AppendLine("新:" + $"{shipInfo.VESSEL_NEW_VAL}/{shipInfo.VOYNO_NEW_VAL}"); + } + } + + //直达变中转 + if (shipInfo.IS_TRANSFER) + { + contentBuilder.AppendLine("直达变中转"); + contentBuilder.AppendLine("原:" + shipInfo.DIRECT_TO_TRANS_OLD_VAL); + contentBuilder.AppendLine("新:" + shipInfo.DIRECT_TO_TRANS_NEW_VAL); + } + + contentBuilder.AppendLine("提单号 |对应操作 "); + + detailList.GroupBy(a => a.MBL_NO).Select(p => + { + return new { Key = p.Key, userList = p.ToList() }; + + }).ToList().ForEach(p => + { + if (!p.userList.FirstOrDefault().BOOKING_ID.HasValue) + { + contentBuilder.AppendLine($"{p.Key.PadRight(20, ' ')}|未分配操作"); + } + else + { + contentBuilder.AppendLine($"{p.Key.PadRight(20, ' ')}|{(string.Join(",", p.userList.Select(x => x.NOTIFY_USER_NAME).ToArray()).PadRight(40, ' '))}"); + } + }); + + + var mobileArg = detailList.Select(p => p.NOTIFY_MOBILE).Distinct().ToArray(); + + //_logger.LogInformation($"准备钉钉通知给 uid={a.NOTIFY_USER_NAME} name={a.NOTIFY_USER_NAME},内容:\r\n{noticeInfo.NOTIFY_CONTENT}"); + + + DingTalkGroupHelper.SendDingTalkGroupMessage($"{tenantId}_Notify", "重要通知提醒", $"{contentBuilder.ToString()}", false, mobileArg, null); + + //_logger.LogInformation($"钉钉通知完毕给 uid={a.NOTIFY_USER_NAME} name={a.NOTIFY_USER_NAME},内容:\r\n{noticeInfo.NOTIFY_CONTENT}"); + + //a.STATUS = "SUCC"; + //a.STATUS_NAME = "成功"; + + //_taskCautionNoticeDetailInfoRepository.AsUpdateable(a).UpdateColumns(p => new + //{ + // p.STATUS, + // p.STATUS_NAME + //}).ExecuteCommand(); + } + catch(Exception ex) + { + + } + } + + public async Task PushEmailNotice(List detailList) + { + try + { + + } + catch (Exception ex) + { + + } + } } }