fix: 分区展示名优先用 KPI 方案名而非省市区
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
3dfb587143
commit
40b2b7cb72
@ -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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将买价明细里的分区键解析为可读名:优先 KPI 分区明细(省/市/国家),其次分区方案名,否则原样。
|
||||
/// 将买价明细分区键解析为可读名(与渠道/销售产品价格表一致):
|
||||
/// 优先 <c>t_kpi_area.Id</c> → 方案名;其次明细 Id → 所属方案名;非数字原样。
|
||||
/// 不使用省/市作展示(同一方案下多条明细会撞名,且与价格表下拉不一致)。
|
||||
/// </summary>
|
||||
private async Task<Dictionary<string, string>> ResolveZoneLabelsAsync(IReadOnlyList<string> zones)
|
||||
{
|
||||
@ -411,32 +412,39 @@ public class PricingWorkbenchService : ApplicationService
|
||||
}
|
||||
|
||||
var distinctIds = numericIds.Distinct().ToList();
|
||||
var infoById = new Dictionary<int, KpiAreaInfo>();
|
||||
var areaIdsNeeded = new HashSet<int>();
|
||||
var unresolved = new List<int>();
|
||||
var areaById = new Dictionary<int, KpiArea>();
|
||||
|
||||
// 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<int, KpiArea>();
|
||||
foreach (var areaId in areaIdsNeeded)
|
||||
// 2) 剩余再按明细 Id → 所属方案名(兼容误存 info.Id 的旧数据)
|
||||
var infoParentAreaId = new Dictionary<int, int>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user