feat: 服务渠道支持黑名单区,排货命中跳过该渠道
All checks were successful
Build and Deploy / deploy (push) Successful in 1m21s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m21s
合并迁移脚本含 BlacklistAreaId 与应付计重字段;规则发布钉包,LIVE 即时加载。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
f66d567c49
commit
8545e6c28c
1
db.sql
1
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 '入库前脚本',
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -60,6 +60,11 @@ public class ServiceChannelDetailOutput
|
||||
/// </summary>
|
||||
public int? RemoteAreaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 黑名单分区 KPI AreaId。
|
||||
/// </summary>
|
||||
public int? BlacklistAreaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 计重规则 ID(应付)。
|
||||
/// </summary>
|
||||
|
||||
@ -60,6 +60,11 @@ public class ServiceChannelListOutput
|
||||
/// </summary>
|
||||
public int? RemoteAreaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 黑名单分区 KPI AreaId。
|
||||
/// </summary>
|
||||
public int? BlacklistAreaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 计重规则 ID(应付)。
|
||||
/// </summary>
|
||||
|
||||
@ -25,6 +25,19 @@ public class ServiceChannelRulesPublishSnapshotDto
|
||||
[JsonIgnore]
|
||||
public List<KpiAreaSnapshotRuleDto> RemoteAreaInfos { get; set; } = [];
|
||||
|
||||
/// <summary>黑名单分区 ID。</summary>
|
||||
public int? BlacklistAreaId { get; set; }
|
||||
|
||||
/// <summary>黑名单分区名称。</summary>
|
||||
public string? BlacklistAreaName { get; set; }
|
||||
|
||||
/// <summary>黑名单分区包引用(规则发布时钉包)。</summary>
|
||||
public KpiAreaPackRefDto? BlacklistAreaRef { get; set; }
|
||||
|
||||
/// <summary>运行时 hydrate / LIVE 用,不落发布 JSON。</summary>
|
||||
[JsonIgnore]
|
||||
public List<KpiAreaSnapshotRuleDto> BlacklistAreaInfos { get; set; } = [];
|
||||
|
||||
/// <summary>计重规则 ID(应付,发布时固化)。</summary>
|
||||
public int? WeightRuleId { get; set; }
|
||||
|
||||
|
||||
@ -57,6 +57,11 @@ public class ServiceChannelSaveInput
|
||||
/// </summary>
|
||||
public int? RemoteAreaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 黑名单分区 KPI AreaId。
|
||||
/// </summary>
|
||||
public int? BlacklistAreaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 计重规则 ID(应付)。
|
||||
/// </summary>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 渠道规则同步态:偏远分区不 Ensure。
|
||||
/// 渠道规则同步态:偏远/黑名单分区不 Ensure。
|
||||
/// </summary>
|
||||
private async Task<ServiceChannelRulesPublishSnapshotDto> 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,
|
||||
|
||||
@ -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<SalesProductRulesPublishSnapshotDto> BuildLiveRulesSnapshotAsync(SalesProduct product)
|
||||
{
|
||||
var snapshot = new SalesProductRulesPublishSnapshotDto
|
||||
|
||||
@ -331,7 +331,7 @@ public class KpiAreaPackService : IScopedDependency
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 渠道规则:偏远 Ref hydrate。
|
||||
/// 渠道规则:偏远 / 黑名单 Ref hydrate。
|
||||
/// </summary>
|
||||
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,
|
||||
|
||||
@ -28,6 +28,11 @@ public class ServiceChannel : OmsAuditedAggregateRoot
|
||||
/// </summary>
|
||||
public int? RemoteAreaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 黑名单分区 KPI AreaId(渠道侧排货命中则跳过)。
|
||||
/// </summary>
|
||||
public int? BlacklistAreaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 计重规则 ID(应付计费重)。
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user