修改INTTRA订舱增加流水号重新生成功能

master
jianghaiqing 6 months ago
parent 2b1a085342
commit 71aa96eb0b

@ -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
{
/// <summary>
/// 生成流水号
/// </summary>
/// <param name="tenantId">租户ID</param>
/// <returns></returns>
public static string GenNext(long tenantId)
{
if (tenantId <= 0)
throw Oops.Oh($"租户ID不能为空");
var _djyTenantParamService = App.GetService<IDjyTenantParamService>();
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<ISysCacheService>();
//生成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;
}
}
}

@ -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 按照沟通要求,如果主提单号为空,并且订舱编号不为空,可以去订舱编号填入主提单号

@ -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
{

Loading…
Cancel
Save