From 3dfb5871438e7eade0f100777c79939ab78ff01d Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Thu, 12 Nov 2026 12:58:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=9A=E4=BB=B7=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E5=8F=B0=E9=A2=84=E8=A7=88=E5=88=86=E5=8C=BA=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E5=90=8D=E8=80=8C=E9=9D=9E=E6=98=8E=E7=BB=86?= =?UTF-8?q?=20Id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../Dtos/Channels/PricingWorkbenchDtos.cs | 10 +- .../Channels/PricingWorkbenchService.cs | 109 +++++++++++++++++- 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/src/Oms.Application/Dtos/Channels/PricingWorkbenchDtos.cs b/src/Oms.Application/Dtos/Channels/PricingWorkbenchDtos.cs index 9309769..ef7971a 100644 --- a/src/Oms.Application/Dtos/Channels/PricingWorkbenchDtos.cs +++ b/src/Oms.Application/Dtos/Channels/PricingWorkbenchDtos.cs @@ -100,9 +100,12 @@ public class PricingWorkbenchPreviewOutput /// 参与渠道摘要。 public List Channels { get; set; } = []; - /// 对齐后的分区键(行)。 + /// 对齐后的分区键(行;与明细 FactorValuesJson 一致,可能是分区明细 Id)。 public List Zones { get; set; } = []; + /// 分区键 → 可读名称(省/市/国家名或分区方案名)。 + public Dictionary ZoneLabels { get; set; } = new(StringComparer.OrdinalIgnoreCase); + /// 对齐后的重量段文本(列,左开右闭区间)。 public List WeightSegments { get; set; } = []; @@ -130,9 +133,12 @@ public class PricingWorkbenchPreviewOutput /// public class PricingWorkbenchCellOutput { - /// 分区键。 + /// 分区键(回写草稿仍用此值)。 public string Zone { get; set; } = string.Empty; + /// 分区展示名(勿当 FactorValues 回写键)。 + public string ZoneLabel { get; set; } = string.Empty; + /// 重量段文本。 public string WeightSegment { get; set; } = string.Empty; diff --git a/src/Oms.Application/Services/Channels/PricingWorkbenchService.cs b/src/Oms.Application/Services/Channels/PricingWorkbenchService.cs index 84392d7..57f847c 100644 --- a/src/Oms.Application/Services/Channels/PricingWorkbenchService.cs +++ b/src/Oms.Application/Services/Channels/PricingWorkbenchService.cs @@ -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(); + private IKpiAreaRepository KpiAreaRepository => + LazyServiceProvider.GetRequiredService(); + private SalesProductService SalesProductAppService => LazyServiceProvider.GetRequiredService(); @@ -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; } + /// + /// 将买价明细里的分区键解析为可读名:优先 KPI 分区明细(省/市/国家),其次分区方案名,否则原样。 + /// + private async Task> ResolveZoneLabelsAsync(IReadOnlyList zones) + { + var result = new Dictionary(StringComparer.OrdinalIgnoreCase); + if (zones.Count == 0) + { + return result; + } + + var numericIds = new List(); + 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(); + var areaIdsNeeded = new HashSet(); + 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(); + 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 LoadChannelPriceAsync(int serviceChannelId, string? costItem) { var channel = await ServiceChannelRepository.FirstOrDefaultAsync(x => x.Id == serviceChannelId)