发布/LIVE 快照写入 PriceAreaId、PriceAreaInfos;US+06000 命中分区键 3 单测通过。 Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
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)
|
||
};
|
||
}
|