From 78aac30a0aef0e9570bb771f317e92cbc671aed7 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Thu, 30 May 2024 18:37:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=88=B1=E4=BD=8D=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helper/PlaceToPortHelper.cs | 78 +++++++++++++ .../Service/BookingSlot/BookingSlotService.cs | 110 +++++++++--------- Myshipping.Core/Const/CommonConst.cs | 11 ++ Myshipping.Core/Myshipping.Core.xml | 20 ++++ 4 files changed, 162 insertions(+), 57 deletions(-) create mode 100644 Myshipping.Application/Helper/PlaceToPortHelper.cs diff --git a/Myshipping.Application/Helper/PlaceToPortHelper.cs b/Myshipping.Application/Helper/PlaceToPortHelper.cs new file mode 100644 index 00000000..0a291702 --- /dev/null +++ b/Myshipping.Application/Helper/PlaceToPortHelper.cs @@ -0,0 +1,78 @@ +using Myshipping.Core; +using Myshipping.Core.Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application.Helper +{ + public static class PlaceToPortHelper + { + public static async Task PlaceReceiptToPortload(string portEnName, List cachePortLoad, Func>> cacheMapPortLoadFunc) + { + if (string.IsNullOrEmpty(portEnName)) + { + return null; + } + + // 匹配方式1:精准匹配 + var portInfo = cachePortLoad.FirstOrDefault(x => x.EnName.Equals(portEnName, StringComparison.OrdinalIgnoreCase)); + if (portInfo != null) return portInfo; + + // 匹配方式2:起始模糊匹配 + portInfo = cachePortLoad.FirstOrDefault(x => x.EnName.StartsWith(portEnName, StringComparison.OrdinalIgnoreCase)); + if (portInfo != null) return portInfo; + + // 匹配方式3:完整模糊匹配 + portInfo = cachePortLoad.FirstOrDefault(x => x.EnName.Contains(portEnName, StringComparison.OrdinalIgnoreCase)); + if (portInfo != null) return portInfo; + + // 匹配方式4:精准映射匹配 + var mapCachePortLoad = await cacheMapPortLoadFunc(); + var map = mapCachePortLoad.FirstOrDefault(x => x.Module == CommonConst.RECEIPT_TO_PORTLOAD + && x.MapName.Equals(portEnName, StringComparison.OrdinalIgnoreCase)); + + if (map != null) + { + portInfo = cachePortLoad.FirstOrDefault(x => x.Code == map.Code); + + if (portInfo != null) return portInfo; + } + return null; + } + public static async Task PlaceDeliveryToPort(string portEnName, List cachePort, Func>> cacheMapPortFunc) + { + if (string.IsNullOrEmpty(portEnName)) + { + return null; + } + + // 匹配方式1:精准匹配 + var portInfo = cachePort.FirstOrDefault(x => x.EnName.Equals(portEnName, StringComparison.OrdinalIgnoreCase)); + if (portInfo != null) return portInfo; + + // 匹配方式2:起始模糊匹配 + portInfo = cachePort.FirstOrDefault(x => x.EnName.StartsWith(portEnName, StringComparison.OrdinalIgnoreCase)); + if (portInfo != null) return portInfo; + + // 匹配方式3:完整模糊匹配 + portInfo = cachePort.FirstOrDefault(x => x.EnName.Contains(portEnName, StringComparison.OrdinalIgnoreCase)); + if (portInfo != null) return portInfo; + + // 匹配方式4:精准映射匹配 + var mapCachePort = await cacheMapPortFunc(); + var map = mapCachePort.FirstOrDefault(x => x.Module == CommonConst.DELIVERY_TO_PORT + && x.MapName.Equals(portEnName, StringComparison.OrdinalIgnoreCase)); + + if (map != null) + { + portInfo = cachePort.FirstOrDefault(x => x.Code == map.Code); + + if (portInfo != null) return portInfo; + } + return null; + } + } +} diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index a27820d7..8fe092a6 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -623,13 +623,9 @@ namespace Myshipping.Application var portEnName = dto.DataObj.PLACERECEIPT.Split(',')[0]?.Trim(); if (!string.IsNullOrWhiteSpace(portEnName)) { - var cachePort = await _cache.GetAllCodePort(); + var cachePortLoad = await _cache.GetAllCodePortLoad(); + var portInfo = await PlaceToPortHelper.PlaceReceiptToPortload(portEnName, cachePortLoad, () => _cache.GetAllMappingPortLoad()); - var portInfo = cachePort.FirstOrDefault(x => x.EnName.StartsWith(portEnName, StringComparison.OrdinalIgnoreCase)); - if (portInfo == null) - { - portInfo = cachePort.FirstOrDefault(x => x.EnName.Contains(portEnName, StringComparison.OrdinalIgnoreCase)); - } if (portInfo == null) { _logger.LogInformation("通过收货地城市名称未匹配到港口信息,订舱编号:{SLOT_BOOKING_NO}", dto.DataObj.SLOT_BOOKING_NO); @@ -656,11 +652,8 @@ namespace Myshipping.Application if (!string.IsNullOrWhiteSpace(portEnName)) { var cachePort = await _cache.GetAllCodePort(); - var portInfo = cachePort.FirstOrDefault(x => x.EnName.StartsWith(portEnName + ',', StringComparison.OrdinalIgnoreCase)); - if (portInfo == null) - { - portInfo = cachePort.FirstOrDefault(x => x.EnName.Contains(portEnName, StringComparison.OrdinalIgnoreCase)); - } + + var portInfo = await PlaceToPortHelper.PlaceDeliveryToPort(portEnName, cachePort, () => _cache.GetAllMappingPort()); if (portInfo == null) { @@ -1140,6 +1133,7 @@ namespace Myshipping.Application var list = await _repBase.AsQueryable().Filter(null, true) .Where(x => x.TenantId == telentId && x.IsDeleted == false + && x.IS_CANCELLATION == false && !string.IsNullOrEmpty(x.PLACERECEIPT) && !string.IsNullOrEmpty(x.PLACEDELIVERY) && (string.IsNullOrEmpty(x.PORTLOADID) || string.IsNullOrEmpty(x.PORTDISCHARGEID))) @@ -1163,9 +1157,10 @@ namespace Myshipping.Application { // 解析收货地,得到装货港名称及五字码 var portEnName = item.PLACERECEIPT.Split(',')[0]?.Trim(); - if (!string.IsNullOrWhiteSpace(portEnName)) + if (!string.IsNullOrWhiteSpace(portEnName) + && (string.IsNullOrEmpty(item.PORTLOADID) || string.IsNullOrEmpty(item.PORTLOAD))) { - var portInfo = cachePortLoad.FirstOrDefault(x => x.EnName.Equals(portEnName, StringComparison.OrdinalIgnoreCase)); + var portInfo = await PlaceToPortHelper.PlaceReceiptToPortload(portEnName, cachePortLoad, () => _cache.GetAllMappingPortLoad()); if (portInfo != null) { if (string.IsNullOrEmpty(item.PORTLOADID)) @@ -1189,12 +1184,13 @@ namespace Myshipping.Application var portEnName2 = item.PLACEDELIVERY.Split(',')[0]?.Trim(); if (!string.IsNullOrWhiteSpace(portEnName2)) { - var portInfo = cachePort.FirstOrDefault(x => x.EnName.StartsWith(portEnName2, StringComparison.OrdinalIgnoreCase)); - if (portInfo == null) - { - portInfo = cachePort.FirstOrDefault(x => x.EnName.Contains(portEnName2, StringComparison.OrdinalIgnoreCase)); - } - if (portInfo != null) + var portInfo = await PlaceToPortHelper.PlaceDeliveryToPort(portEnName2, cachePort, () => _cache.GetAllMappingPort()); + + if (portInfo != null + && (string.IsNullOrEmpty(item.PORTDISCHARGEID) + || string.IsNullOrEmpty(item.PORTDISCHARGE) + || string.IsNullOrEmpty(item.PORTDISCHARGE_COUNTRY_CODE) + || string.IsNullOrEmpty(item.PORTDISCHARGE_COUNTRY))) { if (string.IsNullOrEmpty(item.PORTDISCHARGEID)) { @@ -1237,38 +1233,38 @@ namespace Myshipping.Application x.PORTDISCHARGE_COUNTRY, }).ExecuteCommandAsync(); - var group = updateList.Where(x => !string.IsNullOrEmpty(x.VESSEL) - && !string.IsNullOrEmpty(x.VOYNO) - && !string.IsNullOrEmpty(x.CONTRACT_NO) - && !string.IsNullOrEmpty(x.BOOKING_SLOT_TYPE) - && !string.IsNullOrEmpty(x.CARRIERID) - && !string.IsNullOrEmpty(x.PORTLOADID) - && !string.IsNullOrEmpty(x.PORTDISCHARGEID)) - .GroupBy(x => new - { - x.VESSEL, - x.VOYNO, - x.CARRIERID, - x.BOOKING_SLOT_TYPE, - x.PORTDISCHARGEID, - x.PORTLOADID, - x.CONTRACT_NO - }).ToList(); - - foreach (var item in group) - { - await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", new BookingSlotStockUpdateModel - { - BOOKING_SLOT_TYPE = item.Key.BOOKING_SLOT_TYPE, - CARRIERID = item.Key.CARRIERID, - CONTRACT_NO = item.Key.CONTRACT_NO, - VESSEL = item.Key.VESSEL, - VOYNO = item.Key.VOYNO, - PORTLOADID = item.Key.PORTLOADID, - PORTDISCHARGEID = item.Key.PORTDISCHARGEID, - TenantId = UserManager.TENANT_ID - })); - } + //var group = updateList.Where(x => !string.IsNullOrEmpty(x.VESSEL) + // && !string.IsNullOrEmpty(x.VOYNO) + // && !string.IsNullOrEmpty(x.CONTRACT_NO) + // && !string.IsNullOrEmpty(x.BOOKING_SLOT_TYPE) + // && !string.IsNullOrEmpty(x.CARRIERID) + // && !string.IsNullOrEmpty(x.PORTLOADID) + // && !string.IsNullOrEmpty(x.PORTDISCHARGEID)) + // .GroupBy(x => new + // { + // x.VESSEL, + // x.VOYNO, + // x.CARRIERID, + // x.BOOKING_SLOT_TYPE, + // x.PORTDISCHARGEID, + // x.PORTLOADID, + // x.CONTRACT_NO + // }).ToList(); + + //foreach (var item in group) + //{ + // await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", new BookingSlotStockUpdateModel + // { + // BOOKING_SLOT_TYPE = item.Key.BOOKING_SLOT_TYPE, + // CARRIERID = item.Key.CARRIERID, + // CONTRACT_NO = item.Key.CONTRACT_NO, + // VESSEL = item.Key.VESSEL, + // VOYNO = item.Key.VOYNO, + // PORTLOADID = item.Key.PORTLOADID, + // PORTDISCHARGEID = item.Key.PORTDISCHARGEID, + // TenantId = UserManager.TENANT_ID + // })); + //} } } #endregion @@ -3106,7 +3102,7 @@ namespace Myshipping.Application BookingSlotBase slotInfo = null; - if(bookingSlotAllocList.Count > 0) + if (bookingSlotAllocList.Count > 0) { slotInfo = bookingSlotAllocList.FirstOrDefault().Slot; } @@ -3114,7 +3110,7 @@ namespace Myshipping.Application { slotInfo = _repBase.AsQueryable().Filter(null, true).First(t => t.Id == slotId); } - + if (slotInfo != null) { @@ -3147,7 +3143,7 @@ namespace Myshipping.Application } } - string srcPriceDate = bcSrcDto.PriceCalculationDate.HasValue? bcSrcDto.PriceCalculationDate.Value.ToString("yyyy-MM-dd"): ""; + string srcPriceDate = bcSrcDto.PriceCalculationDate.HasValue ? bcSrcDto.PriceCalculationDate.Value.ToString("yyyy-MM-dd") : ""; string targetPriceDate = bcTargetDto.PriceCalculationDate.HasValue ? bcTargetDto.PriceCalculationDate.Value.ToString("yyyy-MM-dd") : ""; //如果原始的没有解析计费日期,就不做提醒了 @@ -3359,7 +3355,7 @@ namespace Myshipping.Application messageInfo.Main.MBlNo = dto.mblNo; messageInfo.Main.ETD = dto.etd; - messageInfo.Main.TaskTitle = $"重要提醒-{dto.cautionNoticeType.GetDescription()} BLNo:{dto.mblNo} {dto.vessel}/{dto.voyno} {(dto.etd.HasValue? dto.etd.Value.ToString("yyyy-MM-dd"):"")} "; + messageInfo.Main.TaskTitle = $"重要提醒-{dto.cautionNoticeType.GetDescription()} BLNo:{dto.mblNo} {dto.vessel}/{dto.voyno} {(dto.etd.HasValue ? dto.etd.Value.ToString("yyyy-MM-dd") : "")} "; messageInfo.Main.TaskDesp = $"重要提醒-{dto.cautionNoticeType.GetDescription()} BLNo:{dto.mblNo} {dto.vessel}/{dto.voyno} {(dto.etd.HasValue ? dto.etd.Value.ToString("yyyy-MM-dd") : "")}"; messageInfo.Main.CautionNoticeInfo = new TaskManageOrderCautionNoticeInfo @@ -3473,11 +3469,11 @@ namespace Myshipping.Application notifyList = new List() }; - if(!string.IsNullOrWhiteSpace(bcSrcDto.ETD)) + if (!string.IsNullOrWhiteSpace(bcSrcDto.ETD)) { DateTime etd = DateTime.MinValue; - if(DateTime.TryParse(bcSrcDto.ETD,out etd)) + if (DateTime.TryParse(bcSrcDto.ETD, out etd)) { notice.etd = etd; } diff --git a/Myshipping.Core/Const/CommonConst.cs b/Myshipping.Core/Const/CommonConst.cs index c97f7a8a..9a874018 100644 --- a/Myshipping.Core/Const/CommonConst.cs +++ b/Myshipping.Core/Const/CommonConst.cs @@ -260,6 +260,17 @@ public class CommonConst public const string CACHE_KEY_BOOKING_LABEL = "BookingLabelList"; #endregion + #region 映射模块 + /// + /// 收货地名称解析装货港港口 + /// + public const string RECEIPT_TO_PORTLOAD = "ReceiptToPortLoad"; + + /// + /// 交货地名称解析卸货港港口 + /// + public const string DELIVERY_TO_PORT = "DeliveryToPort"; + #endregion #region 系统运行方式 /// diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml index 842327b7..beb29ecb 100644 --- a/Myshipping.Core/Myshipping.Core.xml +++ b/Myshipping.Core/Myshipping.Core.xml @@ -822,6 +822,16 @@ 标签缓存键 + + + 收货地名称解析装货港港口 + + + + + 交货地名称解析卸货港港口 + + 和川(会执行一些和川特有的逻辑) @@ -7340,6 +7350,16 @@ 用户Id + + + 权限范围 + + + + + 权限类型(1用户,2公司) + + 根据授权key 换取token