diff --git a/db.sql b/db.sql
index 9b61816..2288bd6 100644
--- a/db.sql
+++ b/db.sql
@@ -721,6 +721,7 @@ CREATE TABLE `t_service_channel` (
`ForecastCode` VARCHAR(128) NULL COMMENT '预报单号',
`Description` TEXT COMMENT '描述',
`RemoteAreaId` INT NULL COMMENT '偏远分区KPI AreaId',
+ `BlacklistAreaId` INT NULL COMMENT '黑名单分区KPI AreaId',
`WeightRuleId` INT NULL COMMENT '计重规则ID(应付)',
`WeightRoundingId` INT NULL COMMENT '计重进位ID(应付)',
`PreScript` TEXT COMMENT '入库前脚本',
diff --git a/sql/migrate_channel_payable_weight_20261123.sql b/sql/migrate_channel_payable_weight_20261123.sql
index fd06e4c..09e78a3 100644
--- a/sql/migrate_channel_payable_weight_20261123.sql
+++ b/sql/migrate_channel_payable_weight_20261123.sql
@@ -1,8 +1,25 @@
--- 服务渠道独立计重(应付);订单件重尺增加应付计费重。
+-- 服务渠道:黑名单分区 + 独立计重(应付);订单/揽收件重尺应付计费重。
-- 可重复执行。不改 ChargeableWeight 语义(仍为应收计费重)。
SET @db := DATABASE();
+-- t_service_channel.BlacklistAreaId
+SET @exists := (
+ SELECT COUNT(1)
+ FROM information_schema.COLUMNS
+ WHERE TABLE_SCHEMA = @db
+ AND TABLE_NAME = 't_service_channel'
+ AND COLUMN_NAME = 'BlacklistAreaId'
+);
+SET @sql := IF(
+ @exists = 0,
+ 'ALTER TABLE `t_service_channel` ADD COLUMN `BlacklistAreaId` INT NULL COMMENT ''黑名单分区KPI AreaId'' AFTER `RemoteAreaId`',
+ 'SELECT ''t_service_channel.BlacklistAreaId already exists'' AS info'
+);
+PREPARE stmt FROM @sql;
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+
-- t_service_channel.WeightRuleId
SET @exists := (
SELECT COUNT(1)
@@ -13,7 +30,7 @@ SET @exists := (
);
SET @sql := IF(
@exists = 0,
- 'ALTER TABLE `t_service_channel` ADD COLUMN `WeightRuleId` INT NULL COMMENT ''计重规则ID(应付)'' AFTER `RemoteAreaId`',
+ 'ALTER TABLE `t_service_channel` ADD COLUMN `WeightRuleId` INT NULL COMMENT ''计重规则ID(应付)'' AFTER `BlacklistAreaId`',
'SELECT ''t_service_channel.WeightRuleId already exists'' AS info'
);
PREPARE stmt FROM @sql;
diff --git a/src/Oms.Application/Dtos/Channels/ServiceChannelDetailOutput.cs b/src/Oms.Application/Dtos/Channels/ServiceChannelDetailOutput.cs
index 165f781..99124e6 100644
--- a/src/Oms.Application/Dtos/Channels/ServiceChannelDetailOutput.cs
+++ b/src/Oms.Application/Dtos/Channels/ServiceChannelDetailOutput.cs
@@ -60,6 +60,11 @@ public class ServiceChannelDetailOutput
///
public int? RemoteAreaId { get; set; }
+ ///
+ /// 黑名单分区 KPI AreaId。
+ ///
+ public int? BlacklistAreaId { get; set; }
+
///
/// 计重规则 ID(应付)。
///
diff --git a/src/Oms.Application/Dtos/Channels/ServiceChannelListOutput.cs b/src/Oms.Application/Dtos/Channels/ServiceChannelListOutput.cs
index b419110..8849b0f 100644
--- a/src/Oms.Application/Dtos/Channels/ServiceChannelListOutput.cs
+++ b/src/Oms.Application/Dtos/Channels/ServiceChannelListOutput.cs
@@ -60,6 +60,11 @@ public class ServiceChannelListOutput
///
public int? RemoteAreaId { get; set; }
+ ///
+ /// 黑名单分区 KPI AreaId。
+ ///
+ public int? BlacklistAreaId { get; set; }
+
///
/// 计重规则 ID(应付)。
///
diff --git a/src/Oms.Application/Dtos/Channels/ServiceChannelRulesPublishSnapshotDto.cs b/src/Oms.Application/Dtos/Channels/ServiceChannelRulesPublishSnapshotDto.cs
index 53bcb69..740b205 100644
--- a/src/Oms.Application/Dtos/Channels/ServiceChannelRulesPublishSnapshotDto.cs
+++ b/src/Oms.Application/Dtos/Channels/ServiceChannelRulesPublishSnapshotDto.cs
@@ -25,6 +25,19 @@ public class ServiceChannelRulesPublishSnapshotDto
[JsonIgnore]
public List RemoteAreaInfos { get; set; } = [];
+ /// 黑名单分区 ID。
+ public int? BlacklistAreaId { get; set; }
+
+ /// 黑名单分区名称。
+ public string? BlacklistAreaName { get; set; }
+
+ /// 黑名单分区包引用(规则发布时钉包)。
+ public KpiAreaPackRefDto? BlacklistAreaRef { get; set; }
+
+ /// 运行时 hydrate / LIVE 用,不落发布 JSON。
+ [JsonIgnore]
+ public List BlacklistAreaInfos { get; set; } = [];
+
/// 计重规则 ID(应付,发布时固化)。
public int? WeightRuleId { get; set; }
diff --git a/src/Oms.Application/Dtos/Channels/ServiceChannelSaveInput.cs b/src/Oms.Application/Dtos/Channels/ServiceChannelSaveInput.cs
index be46ba4..216699e 100644
--- a/src/Oms.Application/Dtos/Channels/ServiceChannelSaveInput.cs
+++ b/src/Oms.Application/Dtos/Channels/ServiceChannelSaveInput.cs
@@ -57,6 +57,11 @@ public class ServiceChannelSaveInput
///
public int? RemoteAreaId { get; set; }
+ ///
+ /// 黑名单分区 KPI AreaId。
+ ///
+ public int? BlacklistAreaId { get; set; }
+
///
/// 计重规则 ID(应付)。
///
diff --git a/src/Oms.Application/Services/Channels/ServiceChannelService.Helpers.cs b/src/Oms.Application/Services/Channels/ServiceChannelService.Helpers.cs
index 738db6e..db60ec8 100644
--- a/src/Oms.Application/Services/Channels/ServiceChannelService.Helpers.cs
+++ b/src/Oms.Application/Services/Channels/ServiceChannelService.Helpers.cs
@@ -301,7 +301,8 @@ public partial class ServiceChannelService
{
Channel = MapChannelToSaveInput(entity),
Downstream = downstream,
- RemoteAreaInfos = []
+ RemoteAreaInfos = [],
+ BlacklistAreaInfos = []
};
if (entity.RemoteAreaId is > 0)
@@ -322,12 +323,30 @@ public partial class ServiceChannelService
snapshot.RemoteAreaRef = null;
}
+ if (entity.BlacklistAreaId is > 0)
+ {
+ var packRef = await KpiAreaPackService.EnsurePackAsync(
+ entity.BlacklistAreaId.Value,
+ KpiAreaPackService.AreaTypeBlacklist,
+ ResolvePublishUser(),
+ description: "service-channel-rules-publish");
+ snapshot.BlacklistAreaId = entity.BlacklistAreaId;
+ snapshot.BlacklistAreaName = packRef.AreaName;
+ snapshot.BlacklistAreaRef = packRef;
+ }
+ else
+ {
+ snapshot.BlacklistAreaId = null;
+ snapshot.BlacklistAreaName = null;
+ snapshot.BlacklistAreaRef = null;
+ }
+
await ApplyChannelWeightToRulesSnapshotAsync(snapshot, entity);
return snapshot;
}
///
- /// 渠道规则同步态:偏远分区不 Ensure。
+ /// 渠道规则同步态:偏远/黑名单分区不 Ensure。
///
private async Task BuildRulesPublishSnapshotForSyncAsync(int serviceChannelId)
{
@@ -346,7 +365,8 @@ public partial class ServiceChannelService
{
Channel = MapChannelToSaveInput(entity),
Downstream = downstream,
- RemoteAreaInfos = []
+ RemoteAreaInfos = [],
+ BlacklistAreaInfos = []
};
if (entity.RemoteAreaId is > 0)
@@ -363,6 +383,20 @@ public partial class ServiceChannelService
snapshot.RemoteAreaRef = null;
}
+ if (entity.BlacklistAreaId is > 0)
+ {
+ var packRef = await KpiAreaPackService.ResolvePackRefForSyncAsync(entity.BlacklistAreaId.Value);
+ snapshot.BlacklistAreaId = entity.BlacklistAreaId;
+ snapshot.BlacklistAreaName = packRef.AreaName;
+ snapshot.BlacklistAreaRef = packRef;
+ }
+ else
+ {
+ snapshot.BlacklistAreaId = null;
+ snapshot.BlacklistAreaName = null;
+ snapshot.BlacklistAreaRef = null;
+ }
+
await ApplyChannelWeightToRulesSnapshotAsync(snapshot, entity);
return snapshot;
}
@@ -423,6 +457,7 @@ public partial class ServiceChannelService
ForecastCode = entity.ForecastCode,
Description = entity.Description,
RemoteAreaId = entity.RemoteAreaId,
+ BlacklistAreaId = entity.BlacklistAreaId,
WeightRuleId = entity.WeightRuleId,
WeightRoundingId = entity.WeightRoundingId,
PreScript = entity.PreScript,
@@ -511,6 +546,7 @@ public partial class ServiceChannelService
entity.ForecastCode = input.ForecastCode;
entity.Description = input.Description;
entity.RemoteAreaId = input.RemoteAreaId;
+ entity.BlacklistAreaId = input.BlacklistAreaId;
entity.WeightRuleId = input.WeightRuleId;
entity.WeightRoundingId = input.WeightRoundingId;
entity.PreScript = input.PreScript;
@@ -608,6 +644,7 @@ public partial class ServiceChannelService
ForecastCode = entity.ForecastCode,
Description = entity.Description,
RemoteAreaId = entity.RemoteAreaId,
+ BlacklistAreaId = entity.BlacklistAreaId,
WeightRuleId = entity.WeightRuleId,
WeightRoundingId = entity.WeightRoundingId,
IsActive = (byte)entity.IsActive,
@@ -636,6 +673,7 @@ public partial class ServiceChannelService
ForecastCode = entity.ForecastCode,
Description = entity.Description,
RemoteAreaId = entity.RemoteAreaId,
+ BlacklistAreaId = entity.BlacklistAreaId,
WeightRuleId = entity.WeightRuleId,
WeightRoundingId = entity.WeightRoundingId,
PreScript = entity.PreScript,
diff --git a/src/Oms.Application/Services/Orders/OrderService.ParcelBilling.cs b/src/Oms.Application/Services/Orders/OrderService.ParcelBilling.cs
index ee97e12..9db89e7 100644
--- a/src/Oms.Application/Services/Orders/OrderService.ParcelBilling.cs
+++ b/src/Oms.Application/Services/Orders/OrderService.ParcelBilling.cs
@@ -1263,6 +1263,25 @@ public partial class OrderService
var channelRulesBinding = await ResolveChannelRulesBindingAsync(channel, bindTime);
+ if (IsChannelBlacklistHit(
+ channelRulesBinding,
+ order.ConsigneeCountry ?? string.Empty,
+ recipient?.Province,
+ recipient?.City,
+ recipient?.ZipCode))
+ {
+ skipped.Add(new OrderAllocationSkippedOutput
+ {
+ ServiceChannelId = channel.Id,
+ ChannelCode = channel.ChannelCode,
+ ChannelName = channel.ChannelName,
+ Stage = AllocationResolver.SkipStageChannel,
+ MatchCondition = AllocationResolver.TruncateMatchCondition(provider.MatchCondition),
+ Reason = "收件地址命中渠道黑名单区域"
+ });
+ continue;
+ }
+
decimal channelPayableWeight;
try
{
@@ -1714,16 +1733,21 @@ public partial class OrderService
{
Id = channel.Id,
RemoteAreaId = channel.RemoteAreaId,
+ BlacklistAreaId = channel.BlacklistAreaId,
WeightRuleId = channel.WeightRuleId,
WeightRoundingId = channel.WeightRoundingId
},
WeightRuleId = channel.WeightRuleId,
WeightRoundingId = channel.WeightRoundingId,
- RemoteAreaInfos = []
+ RemoteAreaInfos = [],
+ BlacklistAreaInfos = []
};
await KpiAreaPackService.LoadLiveRemoteIntoChannelRulesSnapshotAsync(
live,
channel.RemoteAreaId);
+ await KpiAreaPackService.LoadLiveBlacklistIntoChannelRulesSnapshotAsync(
+ live,
+ channel.BlacklistAreaId);
// LIVE:计重明细即时读库(不固化到发布 JSON)。
if (channel.WeightRuleId is > 0)
{
@@ -1834,6 +1858,33 @@ public partial class OrderService
return false;
}
+ private static bool IsChannelBlacklistHit(
+ ChannelRulesBinding binding,
+ string countryCode,
+ string? province,
+ string? city,
+ string? zipCode)
+ {
+ var snapshot = binding.Snapshot;
+ if (snapshot.BlacklistAreaRef != null && snapshot.BlacklistAreaInfos is not { Count: > 0 })
+ {
+ throw new BusinessException(
+ $"渠道黑名单分区包未加载: areaId={snapshot.BlacklistAreaRef.AreaId} version={snapshot.BlacklistAreaRef.PackVersion}");
+ }
+
+ if (snapshot.BlacklistAreaInfos is { Count: > 0 })
+ {
+ return GeoPartitionMatcher.IsHit(
+ snapshot.BlacklistAreaInfos,
+ countryCode,
+ province,
+ city,
+ zipCode);
+ }
+
+ return false;
+ }
+
private async Task BuildLiveRulesSnapshotAsync(SalesProduct product)
{
var snapshot = new SalesProductRulesPublishSnapshotDto
diff --git a/src/Oms.Application/Shared/KpiAreaPackService.cs b/src/Oms.Application/Shared/KpiAreaPackService.cs
index 576fcbd..0b8d474 100644
--- a/src/Oms.Application/Shared/KpiAreaPackService.cs
+++ b/src/Oms.Application/Shared/KpiAreaPackService.cs
@@ -331,7 +331,7 @@ public class KpiAreaPackService : IScopedDependency
}
///
- /// 渠道规则:偏远 Ref hydrate。
+ /// 渠道规则:偏远 / 黑名单 Ref hydrate。
///
public async Task HydrateChannelRulesSnapshotAsync(
ServiceChannelRulesPublishSnapshotDto snapshot,
@@ -343,6 +343,13 @@ public class KpiAreaPackService : IScopedDependency
snapshot.RemoteAreaId = snapshot.RemoteAreaRef.AreaId;
snapshot.RemoteAreaName = snapshot.RemoteAreaRef.AreaName;
}
+
+ if (snapshot.BlacklistAreaRef != null)
+ {
+ snapshot.BlacklistAreaInfos = await GetRulesOrThrowAsync(snapshot.BlacklistAreaRef, cancellationToken);
+ snapshot.BlacklistAreaId = snapshot.BlacklistAreaRef.AreaId;
+ snapshot.BlacklistAreaName = snapshot.BlacklistAreaRef.AreaName;
+ }
}
public async Task LoadLiveInfosIntoChannelPriceSnapshotAsync(
@@ -412,6 +419,30 @@ public class KpiAreaPackService : IScopedDependency
}
}
+ public async Task LoadLiveBlacklistIntoChannelRulesSnapshotAsync(
+ ServiceChannelRulesPublishSnapshotDto snapshot,
+ int? blacklistAreaId,
+ CancellationToken cancellationToken = default)
+ {
+ snapshot.BlacklistAreaRef = null;
+ if (blacklistAreaId is > 0)
+ {
+ var area = await _kpiAreaRepository.FirstOrDefaultAsync(x => x.Id == blacklistAreaId.Value, cancellationToken);
+ var infos = await _kpiAreaRepository.GetAllInfosByAreaIdAsync(blacklistAreaId.Value, cancellationToken);
+ var rules = infos.Select(i => KpiAreaSnapshotMapper.MapToSnapshotRule(i, area?.Name)).ToList();
+ PublishSnapshotNormalizer.NormalizeKpiAreas(rules);
+ snapshot.BlacklistAreaId = blacklistAreaId;
+ snapshot.BlacklistAreaName = area?.Name;
+ snapshot.BlacklistAreaInfos = rules;
+ }
+ else
+ {
+ snapshot.BlacklistAreaId = null;
+ snapshot.BlacklistAreaName = null;
+ snapshot.BlacklistAreaInfos = [];
+ }
+ }
+
public async Task LoadLiveInfosIntoRulesSnapshotAsync(
SalesProductRulesPublishSnapshotDto snapshot,
int? blacklistAreaId,
diff --git a/src/Oms.Domain/ChannelsAggregate/Entities/ServiceChannel.cs b/src/Oms.Domain/ChannelsAggregate/Entities/ServiceChannel.cs
index 7c067b7..1ef5f07 100644
--- a/src/Oms.Domain/ChannelsAggregate/Entities/ServiceChannel.cs
+++ b/src/Oms.Domain/ChannelsAggregate/Entities/ServiceChannel.cs
@@ -28,6 +28,11 @@ public class ServiceChannel : OmsAuditedAggregateRoot
///
public int? RemoteAreaId { get; set; }
+ ///
+ /// 黑名单分区 KPI AreaId(渠道侧排货命中则跳过)。
+ ///
+ public int? BlacklistAreaId { get; set; }
+
///
/// 计重规则 ID(应付计费重)。
///