admin/src/Oms.Application/Shared/PriceAreaSnapshotHelper.cs
zzh 3a65e8c58f feat: 价格发布快照固化分区规则,查价优先从快照匹配不再查库
发布/LIVE 快照写入 PriceAreaId、PriceAreaInfos;US+06000 命中分区键 3 单测通过。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 11:20:33 +08:00

52 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Oms.Application.Dtos.Channels;
using Oms.Application.Dtos.Orders;
using Oms.Domain.ChannelsAggregate.Entities;
using Oms.Domain.ChannelsAggregate.Repositories;
namespace Oms.Application.Shared;
/// <summary>
/// 将价格分区(t_kpi_area + t_kpi_area_info)固化进卖价发布快照。
/// </summary>
public static class PriceAreaSnapshotHelper
{
/// <summary>
/// 按产品 PriceAreaId 加载分区头与明细写入快照。
/// </summary>
public static async Task ApplyPriceAreaToSnapshotAsync(
SalesProductPricePublishSnapshotDto snapshot,
SalesProduct product,
IKpiAreaRepository kpiAreaRepository,
CancellationToken cancellationToken = default)
{
if (!product.PriceAreaId.HasValue || product.PriceAreaId <= 0)
{
snapshot.PriceAreaId = null;
snapshot.PriceAreaName = null;
snapshot.PriceAreaInfos = [];
return;
}
snapshot.PriceAreaId = product.PriceAreaId;
var area = await kpiAreaRepository.FirstOrDefaultAsync(x => x.Id == product.PriceAreaId.Value, cancellationToken);
snapshot.PriceAreaName = area?.Name;
var infos = await kpiAreaRepository.GetAllInfosByAreaIdAsync(product.PriceAreaId.Value, cancellationToken);
snapshot.PriceAreaInfos = infos.Select(MapInfoOutput).ToList();
}
private static KpiAreaInfoOutput MapInfoOutput(KpiAreaInfo entity) =>
new()
{
Id = entity.Id,
AreaId = entity.AreaId,
CountryCode = entity.CountryCode,
CountryName = entity.CountryName,
Province = entity.Province,
City = entity.City,
LeftPostcode = entity.LeftPostcode,
RightPostcode = entity.RightPostcode,
CreateTime = entity.CreateTime,
UpdateTime = OmsDocHelper.NullIfDefault(entity.UpdateTime)
};
}