20261116 #24
@ -100,9 +100,12 @@ public class PricingWorkbenchPreviewOutput
|
||||
/// <summary>参与渠道摘要。</summary>
|
||||
public List<PricingWorkbenchChannelSummaryOutput> Channels { get; set; } = [];
|
||||
|
||||
/// <summary>对齐后的分区键(行)。</summary>
|
||||
/// <summary>对齐后的分区键(行;与明细 FactorValuesJson 一致,可能是分区明细 Id)。</summary>
|
||||
public List<string> Zones { get; set; } = [];
|
||||
|
||||
/// <summary>分区键 → 可读名称(省/市/国家名或分区方案名)。</summary>
|
||||
public Dictionary<string, string> ZoneLabels { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>对齐后的重量段文本(列,左开右闭区间)。</summary>
|
||||
public List<string> WeightSegments { get; set; } = [];
|
||||
|
||||
@ -130,9 +133,12 @@ public class PricingWorkbenchPreviewOutput
|
||||
/// </summary>
|
||||
public class PricingWorkbenchCellOutput
|
||||
{
|
||||
/// <summary>分区键。</summary>
|
||||
/// <summary>分区键(回写草稿仍用此值)。</summary>
|
||||
public string Zone { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>分区展示名(勿当 FactorValues 回写键)。</summary>
|
||||
public string ZoneLabel { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>重量段文本。</summary>
|
||||
public string WeightSegment { get; set; } = string.Empty;
|
||||
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using Fake.Application;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Oms.Application.Dtos.Channels;
|
||||
using Oms.Application.Services.Orders;
|
||||
using Oms.Application.Shared;
|
||||
using Oms.Domain.ChannelsAggregate.Entities;
|
||||
using Oms.Domain.ChannelsAggregate.Repositories;
|
||||
@ -25,6 +27,9 @@ public class PricingWorkbenchService : ApplicationService
|
||||
private ISalesProductRepository SalesProductRepository =>
|
||||
LazyServiceProvider.GetRequiredService<ISalesProductRepository>();
|
||||
|
||||
private IKpiAreaRepository KpiAreaRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IKpiAreaRepository>();
|
||||
|
||||
private SalesProductService SalesProductAppService =>
|
||||
LazyServiceProvider.GetRequiredService<SalesProductService>();
|
||||
|
||||
@ -289,6 +294,7 @@ public class PricingWorkbenchService : ApplicationService
|
||||
|
||||
output.Zones = zones;
|
||||
output.WeightSegments = weightSegments;
|
||||
output.ZoneLabels = await ResolveZoneLabelsAsync(zones);
|
||||
|
||||
var moneyScale = input.MoneyScale <= 0 ? 2 : input.MoneyScale;
|
||||
var onlineMap = await LoadOnlineSellMapAsync(
|
||||
@ -298,11 +304,13 @@ public class PricingWorkbenchService : ApplicationService
|
||||
|
||||
foreach (var zone in zones)
|
||||
{
|
||||
var zoneLabel = output.ZoneLabels.TryGetValue(zone, out var zl) ? zl : zone;
|
||||
foreach (var seg in weightSegments)
|
||||
{
|
||||
var cell = new PricingWorkbenchCellOutput
|
||||
{
|
||||
Zone = zone,
|
||||
ZoneLabel = zoneLabel,
|
||||
WeightSegment = seg
|
||||
};
|
||||
|
||||
@ -346,7 +354,7 @@ public class PricingWorkbenchService : ApplicationService
|
||||
SuggestedSell = sell,
|
||||
DeltaRatio = cell.OnlineDeltaRatio.Value,
|
||||
Message =
|
||||
$"分区 {zone} 段 {seg}:现网 {online} → 建议 {sell}({cell.OnlineDeltaRatio:P1})"
|
||||
$"分区 {zoneLabel} 段 {seg}:现网 {online} → 建议 {sell}({cell.OnlineDeltaRatio:P1})"
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -354,7 +362,7 @@ public class PricingWorkbenchService : ApplicationService
|
||||
catch (Exception ex)
|
||||
{
|
||||
cell.Flag = "计算失败";
|
||||
output.Warnings.Add($"{zone}/{seg}: {ex.Message}");
|
||||
output.Warnings.Add($"{zoneLabel}/{seg}: {ex.Message}");
|
||||
}
|
||||
|
||||
output.Cells.Add(cell);
|
||||
@ -373,6 +381,103 @@ public class PricingWorkbenchService : ApplicationService
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将买价明细里的分区键解析为可读名:优先 KPI 分区明细(省/市/国家),其次分区方案名,否则原样。
|
||||
/// </summary>
|
||||
private async Task<Dictionary<string, string>> ResolveZoneLabelsAsync(IReadOnlyList<string> zones)
|
||||
{
|
||||
var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
if (zones.Count == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var numericIds = new List<int>();
|
||||
foreach (var zone in zones)
|
||||
{
|
||||
if (int.TryParse(zone.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var id) && id > 0)
|
||||
{
|
||||
numericIds.Add(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
result[zone] = zone;
|
||||
}
|
||||
}
|
||||
|
||||
if (numericIds.Count == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var distinctIds = numericIds.Distinct().ToList();
|
||||
var infoById = new Dictionary<int, KpiAreaInfo>();
|
||||
var areaIdsNeeded = new HashSet<int>();
|
||||
foreach (var id in distinctIds)
|
||||
{
|
||||
var info = await KpiAreaRepository.GetInfoByIdAsync(id);
|
||||
if (info != null)
|
||||
{
|
||||
infoById[id] = info;
|
||||
if (info.AreaId > 0)
|
||||
{
|
||||
areaIdsNeeded.Add(info.AreaId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
areaIdsNeeded.Add(id);
|
||||
}
|
||||
}
|
||||
|
||||
var areaById = new Dictionary<int, KpiArea>();
|
||||
foreach (var areaId in areaIdsNeeded)
|
||||
{
|
||||
var area = await KpiAreaRepository.FirstOrDefaultAsync(x => x.Id == areaId);
|
||||
if (area != null)
|
||||
{
|
||||
areaById[areaId] = area;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var zone in zones)
|
||||
{
|
||||
if (result.ContainsKey(zone))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!int.TryParse(zone.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var id))
|
||||
{
|
||||
result[zone] = zone;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (infoById.TryGetValue(id, out var info))
|
||||
{
|
||||
areaById.TryGetValue(info.AreaId, out var area);
|
||||
var name = ParcelBillingCalculator.ResolveZoneName(info, area);
|
||||
if (string.IsNullOrWhiteSpace(name) && area != null && !string.IsNullOrWhiteSpace(area.Name))
|
||||
{
|
||||
name = area.Name;
|
||||
}
|
||||
|
||||
result[zone] = string.IsNullOrWhiteSpace(name) ? zone : name.Trim();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (areaById.TryGetValue(id, out var scheme) && !string.IsNullOrWhiteSpace(scheme.Name))
|
||||
{
|
||||
result[zone] = scheme.Name.Trim();
|
||||
continue;
|
||||
}
|
||||
|
||||
result[zone] = zone;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<LoadedChannelPrice> LoadChannelPriceAsync(int serviceChannelId, string? costItem)
|
||||
{
|
||||
var channel = await ServiceChannelRepository.FirstOrDefaultAsync(x => x.Id == serviceChannelId)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user