feat: 轨迹拉取配置支持按订单类型区分

同一应用+服务商下可分别配置小包/大包/主单拉取,唯一性与缓存查找同步带上 OrderType。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-09-28 16:21:03 +08:00
parent bb15b24829
commit 481fc4a772
9 changed files with 61 additions and 11 deletions

View File

@ -0,0 +1,18 @@
-- 轨迹拉取配置增加订单类型(小包/大包/主单),用于同一应用+服务商下按订单类型区分配置
-- 库:TrackCenter(t_track_pull_config)
IF COL_LENGTH('dbo.t_track_pull_config', 'OrderType') IS NULL
BEGIN
ALTER TABLE dbo.t_track_pull_config
ADD OrderType INT NOT NULL
CONSTRAINT DF_t_track_pull_config_OrderType DEFAULT (1);
-- 历史数据默认小包(1);如需调整请人工核对后更新
EXEC sp_addextendedproperty
@name = N'MS_Description',
@value = N'订单类型(TrackOrderType:1小包 2大包 4主单)',
@level0type = N'SCHEMA', @level0name = N'dbo',
@level1type = N'TABLE', @level1name = N't_track_pull_config',
@level2type = N'COLUMN', @level2name = N'OrderType';
END
GO

View File

@ -81,7 +81,7 @@ public class TrackRefreshEventHandler(
// 客户A 渠道B 产品A
var config = await trackPullCacheService.GetPullParamsWithContentAsync(attach.AppKey,
attach.ServiceProviderCode);
attach.ServiceProviderCode, attach.OrderType);
if (config is null)
{
logger.LogWarning("请求id: {@RequestId},轨迹消费失败,找不到拉取配置:{@Attach}", attach.ToJson(), @event.RequestId);

View File

@ -20,12 +20,12 @@ public class TrackPullCacheService : ITransientDependency
$"{GlobalConst.TrackPullKeyPrefix}:{config.AppKey}:{config.ServiceProviderCode}:{config.Customer}";
public async Task<TrackPullParamsWithContentDto?> GetPullParamsWithContentAsync(string appKey,
string serviceProviderCode)
string serviceProviderCode, TrackOrderType orderType)
{
var data = await RedisHelper.Client.GetAsync<TrackPullParamsWithContentDto>(TrackPullContentKey(
appKey, serviceProviderCode));
appKey, serviceProviderCode, orderType));
var pullId = await _trackPullConfigRepository.FindIdAsync(appKey, serviceProviderCode);
var pullId = await _trackPullConfigRepository.FindIdAsync(appKey, serviceProviderCode, orderType);
data ??= await SetPullConfigAsync(pullId);
return data;
@ -53,12 +53,13 @@ public class TrackPullCacheService : ITransientDependency
trackPullContentList)
};
var key = TrackPullContentKey(trackPullConfigDetail.AppKey, trackPullConfigDetail.ServiceProviderCode);
var key = TrackPullContentKey(trackPullConfigDetail.AppKey, trackPullConfigDetail.ServiceProviderCode,
trackPullConfigDetail.OrderType);
await RedisHelper.Client.SetAsync(key, data, TimeSpan.FromHours(24));
return data;
}
public static string TrackPullContentKey(string appKey, string serviceProviderCode) =>
$"{GlobalConst.TrackPullContentKeyPrefix}:{appKey}:{serviceProviderCode}";
public static string TrackPullContentKey(string appKey, string serviceProviderCode, TrackOrderType orderType) =>
$"{GlobalConst.TrackPullContentKeyPrefix}:{appKey}:{serviceProviderCode}:{(int)orderType}";
}

View File

@ -83,9 +83,13 @@ public class TrackPullService(
if (input.Options != OptionTypeNoNull.删除)
{
if (!Enum.IsDefined(typeof(TrackOrderType), input.OrderType))
throw new BusinessException("请选择订单类型");
Expression<Func<TrackPullConfigEntity, bool>> isAnyExp = x =>
x.AppKey == input.AppKey &&
x.ServiceProviderCode == input.ServiceProviderCode;
x.ServiceProviderCode == input.ServiceProviderCode &&
x.OrderType == input.OrderType;
if (input.Options == OptionTypeNoNull.修改) isAnyExp = isAnyExp.And(x => x.Id != input.Id);
if (await trackPullConfigRepository.IsAnyAsync(isAnyExp))

View File

@ -75,5 +75,5 @@ public interface ITrackPullConfigRepository : IBasicRepository<TrackPullConfigEn
Task<bool> IsPriorityAnyAsync(Expression<Func<TrackPullPriorityEntity, bool>> whereExpression);
Task<int> FindIdAsync(string appKey, string serviceProviderCode);
Task<int> FindIdAsync(string appKey, string serviceProviderCode, TrackOrderType orderType);
}

View File

@ -20,6 +20,12 @@ public class TrackPullConfigEntity : FullAuditedAggregateRoot<int, int>
[SugarColumn(ColumnName = "ServiceProviderCode")]
public string ServiceProviderCode { get; set; }
/// <summary>
/// 订单类型(主数据枚举TrackOrderType)
/// </summary>
[SugarColumn(ColumnName = "OrderType")]
public TrackOrderType OrderType { get; set; }
/// <summary>
/// 开始轨迹code
/// </summary>

View File

@ -26,6 +26,11 @@ public class GetTrackPullConfigDetailOutputVO
/// </summary>
public string AppKey { get; set; }
/// <summary>
/// 订单类型(主数据枚举TrackOrderType)
/// </summary>
public TrackOrderType OrderType { get; set; }
/// <summary>
/// 轨迹扩展信息参数名集合(逗号分割)
/// </summary>

View File

@ -1,3 +1,5 @@
using TrackCenter.Domain.Enums;
namespace TrackCenter.Domain.Dtos.TrackPull;
public class GetTrackPullConfigPageOutputVO
@ -14,6 +16,11 @@ public class GetTrackPullConfigPageOutputVO
/// </summary>
public string ServiceProvider { get; set; }
/// <summary>
/// 服务商code
/// </summary>
public string ServiceProviderCode { get; set; }
/// <summary>
/// 应用
/// </summary>
@ -23,4 +30,9 @@ public class GetTrackPullConfigPageOutputVO
/// 应用
/// </summary>
public string AppKey { get; set; }
/// <summary>
/// 订单类型(主数据枚举TrackOrderType)
/// </summary>
public TrackOrderType OrderType { get; set; }
}

View File

@ -5,6 +5,7 @@ using TrackCenter.Domain.Aggregates.TrackPullAggregate;
using TrackCenter.Domain.Aggregates.TrackStatusAggregate;
using TrackCenter.Domain.Dtos.Common;
using TrackCenter.Domain.Dtos.TrackPull;
using TrackCenter.Domain.Enums;
using TrackCenter.Domain.VEntities;
namespace TrackCenter.Repository.Repositories;
@ -27,6 +28,8 @@ public class TrackPullConfigRepository : BasicRepository<TrackPullConfigEntity>,
AppKey = system.AppKey,
App = system.Name,
ServiceProvider = service.Name,
ServiceProviderCode = service.Code,
OrderType = trackPull.OrderType,
CreateTime = trackPull.CreateTime
})
.ToPagedListAsync(input.PageIndex, input.PageSize);
@ -216,11 +219,12 @@ public class TrackPullConfigRepository : BasicRepository<TrackPullConfigEntity>,
return await Context.Queryable<TrackPullPriorityEntity>().Where(whereExpression).AnyAsync();
}
public async Task<int> FindIdAsync(string appKey, string serviceProviderCode)
public async Task<int> FindIdAsync(string appKey, string serviceProviderCode, TrackOrderType orderType)
{
return await AsQueryable()
.Where(trackPull => trackPull.AppKey == appKey
&& trackPull.ServiceProviderCode == serviceProviderCode)
&& trackPull.ServiceProviderCode == serviceProviderCode
&& trackPull.OrderType == orderType)
.Select(trackPull => trackPull.Id)
.FirstAsync();
}