From 71aa96eb0bcd1221eaf2761eed245c8c0ef6db61 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Thu, 6 Jun 2024 18:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9INTTRA=E8=AE=A2=E8=88=B1?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=81=E6=B0=B4=E5=8F=B7=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helper/BusinessIDGenHelper.cs | 75 +++++++++++++++++++ .../BookingOrder/BookingOrderService.cs | 22 +++++- .../TaskPOLContainerNotPickUpService.cs | 1 + 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 Myshipping.Application/Helper/BusinessIDGenHelper.cs diff --git a/Myshipping.Application/Helper/BusinessIDGenHelper.cs b/Myshipping.Application/Helper/BusinessIDGenHelper.cs new file mode 100644 index 00000000..d2fa17da --- /dev/null +++ b/Myshipping.Application/Helper/BusinessIDGenHelper.cs @@ -0,0 +1,75 @@ +using Furion; +using Furion.FriendlyException; +using Myshipping.Core; +using Myshipping.Core.Entity; +using Myshipping.Core.Service; +using Org.BouncyCastle.Asn1.Tsp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application.Helper +{ + public static class BusinessIDGenHelper + { + /// + /// 生成流水号 + /// + /// 租户ID + /// + public static string GenNext(long tenantId) + { + if (tenantId <= 0) + throw Oops.Oh($"租户ID不能为空"); + + var _djyTenantParamService = App.GetService(); + + var paramInfo = _djyTenantParamService + .GetParaCodeWithValue(new[] { "BOOKING_MSG_REFERNO_STARTCODE" }).GetAwaiter().GetResult().FirstOrDefault(); + + string startCode = string.Empty; + + if (paramInfo != null) + { + startCode = paramInfo.ParaValue?.Trim(); + } + + if (string.IsNullOrWhiteSpace(startCode)) + throw Oops.Oh($"当前租户未配置“订舱申请号生成开头代码”租户参数"); + + string flowno = string.Empty; + + var cacheService = App.GetService(); + + //生成KEY 代码类型-BOOKING_TENANTID_ + string cacheKey = $"BOOKING_{tenantId}"; + string cacheCalcKey = $"BOOKING_{tenantId}_CALC"; + + DateTime nowDate = DateTime.Now; + DateTime expireDateTime = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, 23, 59, 59); + + var expireTimeSpan = expireDateTime.Subtract(DateTime.Now).Duration(); + + var autoIncrementKey = RedisHelper.IncrBy(cacheCalcKey); + + if (cacheService.Exists(cacheKey)) + { + flowno = $"{startCode}{nowDate.ToString("yyyyMMdd")}{autoIncrementKey.ToString().PadLeft(4, '0')}"; + } + else + { + if (autoIncrementKey > 0) + RedisHelper.IncrBy(cacheCalcKey, -autoIncrementKey); + + //重新计数 + autoIncrementKey = RedisHelper.IncrBy(cacheCalcKey); + + cacheService.SetTimeoutAsync(cacheKey, autoIncrementKey, expireTimeSpan).GetAwaiter().GetResult(); + } + + return flowno; + } + } +} diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index c910e199..5203950a 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -1718,6 +1718,7 @@ namespace Myshipping.Application } entity.VERSION = Guid.NewGuid().ToString(); + entity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString(); entity.BSDATE = DateTime.Today; entity.BSNO = null; @@ -7537,7 +7538,26 @@ namespace Myshipping.Application } else { - primaryModel.ORDERNO = order.BOOKINGNO; + if (ediRouteEnum == EDIRouteEnum.INTTRA) + { + if (!string.IsNullOrWhiteSpace(order.BOOKINGNO) && order.BOOKINGNO.Length > 14) + { + var flowno = BusinessIDGenHelper.GenNext(UserManager.TENANT_ID); + + if(!string.IsNullOrWhiteSpace(flowno)) + { + order.BOOKINGNO = flowno; + await _rep.AsUpdateable(order).UpdateColumns(x => new { x.BOOKINGNO }).ExecuteCommandAsync(); + + _logger.LogInformation("批次={no} INTTRA 判断业务编号长度不能大于14,重新生成 MBLNO={mblno} custno={custno} 新单号{flowno}", batchNo, primaryModel.MBLNO, order.BOOKINGNO, flowno); + } + } + } + else + { + primaryModel.ORDERNO = order.BOOKINGNO; + } + } //2023-06-15 按照沟通要求,如果主提单号为空,并且订舱编号不为空,可以去订舱编号填入主提单号 diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskPOLContainerNotPickUpService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskPOLContainerNotPickUpService.cs index 4e3ac5a7..ecbcff00 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskPOLContainerNotPickUpService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskPOLContainerNotPickUpService.cs @@ -33,6 +33,7 @@ using System.Numerics; using SqlSugar; using System.Reflection.Metadata.Ecma335; using Microsoft.Extensions.Primitives; +using Myshipping.Core.Helper; namespace Myshipping.Application {