From 40b2b7cb72864b6d7916cf01dc24f94bb710c800 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Thu, 12 Nov 2026 13:01:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=86=E5=8C=BA=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E5=90=8D=E4=BC=98=E5=85=88=E7=94=A8=20KPI=20=E6=96=B9=E6=A1=88?= =?UTF-8?q?=E5=90=8D=E8=80=8C=E9=9D=9E=E7=9C=81=E5=B8=82=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../Channels/PricingWorkbenchService.cs | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/Oms.Application/Services/Channels/PricingWorkbenchService.cs b/src/Oms.Application/Services/Channels/PricingWorkbenchService.cs index 57f847c..38b2d1b 100644 --- a/src/Oms.Application/Services/Channels/PricingWorkbenchService.cs +++ b/src/Oms.Application/Services/Channels/PricingWorkbenchService.cs @@ -4,7 +4,6 @@ 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; @@ -382,7 +381,9 @@ public class PricingWorkbenchService : ApplicationService } /// - /// 将买价明细里的分区键解析为可读名:优先 KPI 分区明细(省/市/国家),其次分区方案名,否则原样。 + /// 将买价明细分区键解析为可读名(与渠道/销售产品价格表一致): + /// 优先 t_kpi_area.Id → 方案名;其次明细 Id → 所属方案名;非数字原样。 + /// 不使用省/市作展示(同一方案下多条明细会撞名,且与价格表下拉不一致)。 /// private async Task> ResolveZoneLabelsAsync(IReadOnlyList zones) { @@ -411,32 +412,39 @@ public class PricingWorkbenchService : ApplicationService } var distinctIds = numericIds.Distinct().ToList(); - var infoById = new Dictionary(); - var areaIdsNeeded = new HashSet(); + var unresolved = new List(); + var areaById = new Dictionary(); + + // 1) 先按分区方案主键解析(买价 FactorValues 常态) foreach (var id in distinctIds) { - var info = await KpiAreaRepository.GetInfoByIdAsync(id); - if (info != null) + var area = await KpiAreaRepository.FirstOrDefaultAsync(x => x.Id == id); + if (area != null) { - infoById[id] = info; - if (info.AreaId > 0) - { - areaIdsNeeded.Add(info.AreaId); - } + areaById[id] = area; } else { - areaIdsNeeded.Add(id); + unresolved.Add(id); } } - var areaById = new Dictionary(); - foreach (var areaId in areaIdsNeeded) + // 2) 剩余再按明细 Id → 所属方案名(兼容误存 info.Id 的旧数据) + var infoParentAreaId = new Dictionary(); + foreach (var id in unresolved) { - var area = await KpiAreaRepository.FirstOrDefaultAsync(x => x.Id == areaId); - if (area != null) + var info = await KpiAreaRepository.GetInfoByIdAsync(id); + if (info?.AreaId > 0) { - areaById[areaId] = area; + infoParentAreaId[id] = info.AreaId; + if (!areaById.ContainsKey(info.AreaId)) + { + var parent = await KpiAreaRepository.FirstOrDefaultAsync(x => x.Id == info.AreaId); + if (parent != null) + { + areaById[info.AreaId] = parent; + } + } } } @@ -453,25 +461,20 @@ public class PricingWorkbenchService : ApplicationService 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; } + if (infoParentAreaId.TryGetValue(id, out var parentAreaId) + && areaById.TryGetValue(parentAreaId, out var parentArea) + && !string.IsNullOrWhiteSpace(parentArea.Name)) + { + result[zone] = parentArea.Name.Trim(); + continue; + } + result[zone] = zone; }