admin/src/Oms.Application/Shared/PublishSnapshotNormalizer.cs
zzh 7827b4803e feat: slim rules/price publish snapshots with PostcodeRange (left,right]
Use slim DTOs without audit timestamps; migrate legacy LeftPostcode/RightPostcode on read.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 14:10:34 +08:00

51 lines
1.3 KiB
C#

using Oms.Application.Dtos.Orders;
namespace Oms.Application.Shared;
/// <summary>
/// 发布快照读取后规范化(旧字段迁移、去掉冗余)。
/// </summary>
public static class PublishSnapshotNormalizer
{
public static void NormalizeRulesSnapshot(SalesProductRulesPublishSnapshotDto? snapshot)
{
if (snapshot is null)
{
return;
}
NormalizeKpiAreas(snapshot.BlacklistAreaInfos);
NormalizeKpiAreas(snapshot.RemoteAreaInfos);
}
public static void NormalizePriceSnapshot(SalesProductPricePublishSnapshotDto? snapshot)
{
if (snapshot is null)
{
return;
}
NormalizeKpiAreas(snapshot.PriceAreaInfos);
}
public static void NormalizeKpiAreas(List<KpiAreaSnapshotRuleDto>? areas)
{
if (areas is null)
{
return;
}
foreach (var area in areas)
{
if (string.IsNullOrWhiteSpace(area.PostcodeRange)
&& (!string.IsNullOrWhiteSpace(area.LeftPostcode) || !string.IsNullOrWhiteSpace(area.RightPostcode)))
{
area.PostcodeRange = KpiAreaSnapshotMapper.BuildPostcodeRange(area.LeftPostcode, area.RightPostcode);
}
area.LeftPostcode = null;
area.RightPostcode = null;
}
}
}