From 481fc4a7726ee9e265cee8de021ee707843c3e10 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Mon, 28 Sep 2026 16:21:03 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E8=BD=A8=E8=BF=B9=E6=8B=89?= =?UTF-8?q?=E5=8F=96=E9=85=8D=E7=BD=AE=E6=94=AF=E6=8C=81=E6=8C=89=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=B1=BB=E5=9E=8B=E5=8C=BA=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 同一应用+服务商下可分别配置小包/大包/主单拉取,唯一性与缓存查找同步带上 OrderType。 Co-authored-by: Cursor --- .../migrate_track_pull_config_order_type.sql | 18 ++++++++++++++++++ .../Rabbit/TrackRefreshEventHandler.cs | 2 +- .../TrackPull/TrackPullCacheService.cs | 13 +++++++------ .../Services/TrackPull/TrackPullService.cs | 6 +++++- .../ITrackPullConfigRepository.cs | 2 +- .../TrackPullConfigEntity.cs | 6 ++++++ .../GetTrackPullConfigDetailOutputVO.cs | 5 +++++ .../GetTrackPullConfigPageOutputVO.cs | 12 ++++++++++++ .../Repositories/TrackPullConfigRepository.cs | 8 ++++++-- 9 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 scripts/sql/migrate_track_pull_config_order_type.sql diff --git a/scripts/sql/migrate_track_pull_config_order_type.sql b/scripts/sql/migrate_track_pull_config_order_type.sql new file mode 100644 index 00000000..3de31cf3 --- /dev/null +++ b/scripts/sql/migrate_track_pull_config_order_type.sql @@ -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 diff --git a/src/TrackCenter.Application/Rabbit/TrackRefreshEventHandler.cs b/src/TrackCenter.Application/Rabbit/TrackRefreshEventHandler.cs index eb5b6206..6d5f68d1 100644 --- a/src/TrackCenter.Application/Rabbit/TrackRefreshEventHandler.cs +++ b/src/TrackCenter.Application/Rabbit/TrackRefreshEventHandler.cs @@ -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); diff --git a/src/TrackCenter.Application/Services/TrackPull/TrackPullCacheService.cs b/src/TrackCenter.Application/Services/TrackPull/TrackPullCacheService.cs index d44624fe..306580c7 100644 --- a/src/TrackCenter.Application/Services/TrackPull/TrackPullCacheService.cs +++ b/src/TrackCenter.Application/Services/TrackPull/TrackPullCacheService.cs @@ -20,12 +20,12 @@ public class TrackPullCacheService : ITransientDependency $"{GlobalConst.TrackPullKeyPrefix}:{config.AppKey}:{config.ServiceProviderCode}:{config.Customer}"; public async Task GetPullParamsWithContentAsync(string appKey, - string serviceProviderCode) + string serviceProviderCode, TrackOrderType orderType) { var data = await RedisHelper.Client.GetAsync(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}"; } diff --git a/src/TrackCenter.Application/Services/TrackPull/TrackPullService.cs b/src/TrackCenter.Application/Services/TrackPull/TrackPullService.cs index 0506cead..8c4b6322 100644 --- a/src/TrackCenter.Application/Services/TrackPull/TrackPullService.cs +++ b/src/TrackCenter.Application/Services/TrackPull/TrackPullService.cs @@ -83,9 +83,13 @@ public class TrackPullService( if (input.Options != OptionTypeNoNull.删除) { + if (!Enum.IsDefined(typeof(TrackOrderType), input.OrderType)) + throw new BusinessException("请选择订单类型"); + Expression> 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)) diff --git a/src/TrackCenter.Domain/Aggregates/TrackPullAggregate/ITrackPullConfigRepository.cs b/src/TrackCenter.Domain/Aggregates/TrackPullAggregate/ITrackPullConfigRepository.cs index 492b5874..5e0cbb77 100644 --- a/src/TrackCenter.Domain/Aggregates/TrackPullAggregate/ITrackPullConfigRepository.cs +++ b/src/TrackCenter.Domain/Aggregates/TrackPullAggregate/ITrackPullConfigRepository.cs @@ -75,5 +75,5 @@ public interface ITrackPullConfigRepository : IBasicRepository IsPriorityAnyAsync(Expression> whereExpression); - Task FindIdAsync(string appKey, string serviceProviderCode); + Task FindIdAsync(string appKey, string serviceProviderCode, TrackOrderType orderType); } diff --git a/src/TrackCenter.Domain/Aggregates/TrackPullAggregate/TrackPullConfigEntity.cs b/src/TrackCenter.Domain/Aggregates/TrackPullAggregate/TrackPullConfigEntity.cs index 43820fcb..4f90a91f 100644 --- a/src/TrackCenter.Domain/Aggregates/TrackPullAggregate/TrackPullConfigEntity.cs +++ b/src/TrackCenter.Domain/Aggregates/TrackPullAggregate/TrackPullConfigEntity.cs @@ -20,6 +20,12 @@ public class TrackPullConfigEntity : FullAuditedAggregateRoot [SugarColumn(ColumnName = "ServiceProviderCode")] public string ServiceProviderCode { get; set; } + /// + /// 订单类型(主数据枚举TrackOrderType) + /// + [SugarColumn(ColumnName = "OrderType")] + public TrackOrderType OrderType { get; set; } + /// /// 开始轨迹code /// diff --git a/src/TrackCenter.Domain/Dtos/TrackPull/GetTrackPullConfigDetailOutputVO.cs b/src/TrackCenter.Domain/Dtos/TrackPull/GetTrackPullConfigDetailOutputVO.cs index a3892ef5..4a5cbd8f 100644 --- a/src/TrackCenter.Domain/Dtos/TrackPull/GetTrackPullConfigDetailOutputVO.cs +++ b/src/TrackCenter.Domain/Dtos/TrackPull/GetTrackPullConfigDetailOutputVO.cs @@ -26,6 +26,11 @@ public class GetTrackPullConfigDetailOutputVO /// public string AppKey { get; set; } + /// + /// 订单类型(主数据枚举TrackOrderType) + /// + public TrackOrderType OrderType { get; set; } + /// /// 轨迹扩展信息参数名集合(逗号分割) /// diff --git a/src/TrackCenter.Domain/Dtos/TrackPull/GetTrackPullConfigPageOutputVO.cs b/src/TrackCenter.Domain/Dtos/TrackPull/GetTrackPullConfigPageOutputVO.cs index cce27290..ebe196a5 100644 --- a/src/TrackCenter.Domain/Dtos/TrackPull/GetTrackPullConfigPageOutputVO.cs +++ b/src/TrackCenter.Domain/Dtos/TrackPull/GetTrackPullConfigPageOutputVO.cs @@ -1,3 +1,5 @@ +using TrackCenter.Domain.Enums; + namespace TrackCenter.Domain.Dtos.TrackPull; public class GetTrackPullConfigPageOutputVO @@ -14,6 +16,11 @@ public class GetTrackPullConfigPageOutputVO /// public string ServiceProvider { get; set; } + /// + /// 服务商code + /// + public string ServiceProviderCode { get; set; } + /// /// 应用 /// @@ -23,4 +30,9 @@ public class GetTrackPullConfigPageOutputVO /// 应用 /// public string AppKey { get; set; } + + /// + /// 订单类型(主数据枚举TrackOrderType) + /// + public TrackOrderType OrderType { get; set; } } diff --git a/src/TrackCenter.Repository/Repositories/TrackPullConfigRepository.cs b/src/TrackCenter.Repository/Repositories/TrackPullConfigRepository.cs index 08bea8ee..8e16bfe2 100644 --- a/src/TrackCenter.Repository/Repositories/TrackPullConfigRepository.cs +++ b/src/TrackCenter.Repository/Repositories/TrackPullConfigRepository.cs @@ -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, 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, return await Context.Queryable().Where(whereExpression).AnyAsync(); } - public async Task FindIdAsync(string appKey, string serviceProviderCode) + public async Task 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(); } From 2ad7afea0f094674e4c86a6b6d68daf807108984 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Mon, 28 Sep 2026 16:24:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E6=8B=89=E5=8F=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=20OrderType=20=E8=BF=81=E7=A7=BB=E6=94=B9=E4=B8=BA=20MySQL=20?= =?UTF-8?q?=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../migrate_track_pull_config_order_type.sql | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/scripts/sql/migrate_track_pull_config_order_type.sql b/scripts/sql/migrate_track_pull_config_order_type.sql index 3de31cf3..a7894259 100644 --- a/scripts/sql/migrate_track_pull_config_order_type.sql +++ b/scripts/sql/migrate_track_pull_config_order_type.sql @@ -1,18 +1,6 @@ -- 轨迹拉取配置增加订单类型(小包/大包/主单),用于同一应用+服务商下按订单类型区分配置 -- 库:TrackCenter(t_track_pull_config) +-- MySQL;若 OrderType 列已存在可跳过 -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 +ALTER TABLE t_track_pull_config + ADD COLUMN OrderType INT NOT NULL DEFAULT 1 COMMENT '订单类型(TrackOrderType:1小包 2大包 4主单)' AFTER ServiceProviderCode; From f6590de824204529267fef13cb9418cfc3f53e22 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Mon, 28 Sep 2026 16:57:59 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20UpsertBigBag=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=20apiCode=20=E5=B9=B6=E5=8C=B9=E9=85=8D=E5=A4=A7=E5=8C=85?= =?UTF-8?q?=E6=8B=89=E5=8F=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../Dtos/ProvideServices/V2/OrderDtos.cs | 7 ++++- .../ProvideServices/OrderService.V2.cs | 30 +++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/TrackCenter.Application/Dtos/ProvideServices/V2/OrderDtos.cs b/src/TrackCenter.Application/Dtos/ProvideServices/V2/OrderDtos.cs index edf9b3aa..8256c0d4 100644 --- a/src/TrackCenter.Application/Dtos/ProvideServices/V2/OrderDtos.cs +++ b/src/TrackCenter.Application/Dtos/ProvideServices/V2/OrderDtos.cs @@ -80,6 +80,11 @@ public class Consignee public class UpsertBigBagInput { + /// + /// 服务商code + /// + public string ApiCode { get; set; } + /// /// 客户名称,或者code,必填 /// @@ -108,7 +113,7 @@ public class UpsertBigBagInput public string Product { get; set; } /// - /// 产品名称,或者code + /// 目的国家二字码 /// public string Country { get; set; } } diff --git a/src/TrackCenter.Application/Services/ProvideServices/OrderService.V2.cs b/src/TrackCenter.Application/Services/ProvideServices/OrderService.V2.cs index f8949f36..cbcfc734 100644 --- a/src/TrackCenter.Application/Services/ProvideServices/OrderService.V2.cs +++ b/src/TrackCenter.Application/Services/ProvideServices/OrderService.V2.cs @@ -179,7 +179,8 @@ public partial class OrderService var config = await _trackPullConfigRepository .FirstOrDefaultAsync(x => x.AppKey == AppKey - && x.ServiceProviderCode == input.ApiCode); + && x.ServiceProviderCode == input.ApiCode + && x.OrderType == TrackOrderType.小包); if (config == null) { @@ -192,11 +193,12 @@ public partial class OrderService return order; } - private Task BuiltOrder(UpsertBigBagInput input) + private async Task BuiltOrder(UpsertBigBagInput input) { var order = new OrderEntity { AppKey = AppKey!, + ServiceProviderCode = input.ApiCode, OrderType = TrackOrderType.大包, OrderNo = input.BagNo, ThirdPartyOrderNumber = input.OtherNo, @@ -206,8 +208,25 @@ public partial class OrderService ArrivalCountry = input.Country }; - // tips: 2025-11-29 zzh 大包没有轨迹拉取能力 - return Task.FromResult(order); + if (string.IsNullOrWhiteSpace(input.ApiCode)) + { + // 未传 apiCode 时保持兼容:不挂拉取配置 + return order; + } + + var config = await _trackPullConfigRepository + .FirstOrDefaultAsync(x => x.AppKey == AppKey + && x.ServiceProviderCode == input.ApiCode + && x.OrderType == TrackOrderType.大包); + + if (config == null) + { + throw ProviderServiceActionResult.Exception("创建/更新失败", + "没有适用的大包拉取配置,请先配置轨迹拉取,否则无法拉取轨迹"); + } + + order.OrderPullStatus = [CreateOrderPullStatus(config, order)]; + return order; } private async Task BuiltOrder(UpsertMasterOrderInput input) @@ -227,7 +246,8 @@ public partial class OrderService var config = await _trackPullConfigRepository .FirstOrDefaultAsync(x => x.AppKey == AppKey - && x.ServiceProviderCode == input.ApiCode); + && x.ServiceProviderCode == input.ApiCode + && x.OrderType == TrackOrderType.小包); if (config == null) {