diff --git a/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs b/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs index 2f8f431..7e2de52 100644 --- a/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs +++ b/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs @@ -101,17 +101,20 @@ public partial class SalesProductService /// /// 一次性装配价格项、因子和明细,避免接口层 N+1 查询。 + /// includeDetails=false 时跳过明细(列表页首屏),显著减小载荷。 /// - private async Task> GetPriceOutputsAsync(int salesProductId) + private async Task> GetPriceOutputsAsync(int salesProductId, bool includeDetails = true) { var prices = await SalesProductRepository.GetPricesAsync(salesProductId); var priceIds = prices.Select(x => x.Id).ToArray(); var factorMap = (await SalesProductRepository.GetPriceFactorsAsync(priceIds)) .GroupBy(x => x.PriceId) .ToDictionary(x => x.Key, x => x.OrderBy(item => item.SerialNumber).ToList()); - var detailMap = (await SalesProductRepository.GetPriceDetailsAsync(priceIds)) - .GroupBy(x => x.PriceId) - .ToDictionary(x => x.Key, x => x.OrderBy(item => item.Id).ToList()); + var detailMap = includeDetails + ? (await SalesProductRepository.GetPriceDetailsAsync(priceIds)) + .GroupBy(x => x.PriceId) + .ToDictionary(x => x.Key, x => x.OrderBy(item => item.Id).ToList()) + : new Dictionary>(); var auditUserNameMap = await UserDisplayNameResolver.ResolveManyAsync( prices.SelectMany(x => new[] { x.CreateUserId, x.UpdateUserId })); @@ -128,7 +131,9 @@ public partial class SalesProductService Currency = price.Currency, ChargingCondition = price.ChargingCondition, Factors = factorMap.TryGetValue(price.Id, out var factors) ? factors.Select(MapPriceFactorOutput).ToList() : [], - Details = detailMap.TryGetValue(price.Id, out var details) ? details.Select(MapPriceDetailOutput).ToList() : [], + Details = includeDetails && detailMap.TryGetValue(price.Id, out var details) + ? details.Select(MapPriceDetailOutput).ToList() + : [], CreateTime = price.CreateTime, CreateBy = OmsRbacUserDisplayNameResolver.FormatUserId(price.CreateUserId, auditUserNameMap), UpdateTime = OmsDocHelper.NullIfDefault(price.UpdateTime), @@ -136,6 +141,38 @@ public partial class SalesProductService }).ToList(); } + /// + /// 单条价格项(含因子+明细),供编辑弹窗按需加载。 + /// + private async Task GetPriceOutputByIdAsync(int priceId) + { + var price = await GetPriceOrThrowAsync(priceId); + var priceIds = new[] { price.Id }; + var factors = await SalesProductRepository.GetPriceFactorsAsync(priceIds); + var details = await SalesProductRepository.GetPriceDetailsAsync(priceIds); + var auditUserNameMap = await UserDisplayNameResolver.ResolveManyAsync( + [price.CreateUserId, price.UpdateUserId]); + + return new SalesProductPriceListOutput + { + Id = price.Id, + SalesProductId = price.SalesProductId, + SerialNumber = price.SerialNumber, + Status = (byte)price.Status, + PriceName = price.PriceName, + CostItem = price.CostItem, + CostUnit = price.CostUnit, + Currency = price.Currency, + ChargingCondition = price.ChargingCondition, + Factors = factors.OrderBy(item => item.SerialNumber).Select(MapPriceFactorOutput).ToList(), + Details = details.OrderBy(item => item.Id).Select(MapPriceDetailOutput).ToList(), + CreateTime = price.CreateTime, + CreateBy = OmsRbacUserDisplayNameResolver.FormatUserId(price.CreateUserId, auditUserNameMap), + UpdateTime = OmsDocHelper.NullIfDefault(price.UpdateTime), + UpdateBy = OmsRbacUserDisplayNameResolver.FormatUserId(price.UpdateUserId, auditUserNameMap) + }; + } + /// /// 获取排货方案,并补充服务渠道名称。 /// diff --git a/src/Oms.Application/Services/Channels/SalesProductService.cs b/src/Oms.Application/Services/Channels/SalesProductService.cs index 03cd705..5647829 100644 --- a/src/Oms.Application/Services/Channels/SalesProductService.cs +++ b/src/Oms.Application/Services/Channels/SalesProductService.cs @@ -169,17 +169,29 @@ public partial class SalesProductService : ApplicationService /// 查询销售产品价格项列表。 /// /// 入参:销售产品主键。 + /// 是否返回价格明细矩阵;列表页建议 false。 /// 销售产品价格项列表结果。 [HttpGet("/channel/sales-product/price/list")] - public async Task> GetPriceListAsync([FromQuery] int salesProductId) + public async Task> GetPriceListAsync( + [FromQuery] int salesProductId, + [FromQuery] bool includeDetails = true) { await GetProductOrThrowAsync(salesProductId); return new OmsItemsResult { - Items = await GetPriceOutputsAsync(salesProductId) + Items = await GetPriceOutputsAsync(salesProductId, includeDetails) }; } + /// + /// 获取单条销售产品价格项(含计费因子与价格明细)。 + /// + [HttpGet("/channel/sales-product/price/get")] + public async Task GetPriceAsync([FromQuery] int id) + { + return await GetPriceOutputByIdAsync(id); + } + /// /// 新增销售产品价格项。 /// diff --git a/src/Oms.Application/Services/Channels/ServiceChannelService.Helpers.cs b/src/Oms.Application/Services/Channels/ServiceChannelService.Helpers.cs index e92c099..1317ee5 100644 --- a/src/Oms.Application/Services/Channels/ServiceChannelService.Helpers.cs +++ b/src/Oms.Application/Services/Channels/ServiceChannelService.Helpers.cs @@ -146,17 +146,22 @@ public partial class ServiceChannelService /// /// 一次性装配买价项、因子和明细,避免接口层 N+1 查询。 + /// includeDetails=false 时跳过明细(列表页首屏),显著减小载荷。 /// - private async Task> GetPriceOutputsAsync(int serviceChannelId) + private async Task> GetPriceOutputsAsync( + int serviceChannelId, + bool includeDetails = true) { var prices = await ServiceChannelRepository.GetPricesAsync(serviceChannelId); var priceIds = prices.Select(x => x.Id).ToArray(); var factorMap = (await ServiceChannelRepository.GetPriceFactorsAsync(priceIds)) .GroupBy(x => x.PriceId) .ToDictionary(x => x.Key, x => x.OrderBy(item => item.SerialNumber).ToList()); - var detailMap = (await ServiceChannelRepository.GetPriceDetailsAsync(priceIds)) - .GroupBy(x => x.PriceId) - .ToDictionary(x => x.Key, x => x.OrderBy(item => item.Id).ToList()); + var detailMap = includeDetails + ? (await ServiceChannelRepository.GetPriceDetailsAsync(priceIds)) + .GroupBy(x => x.PriceId) + .ToDictionary(x => x.Key, x => x.OrderBy(item => item.Id).ToList()) + : new Dictionary>(); return prices.Select(price => new ServiceChannelPriceListOutput { @@ -170,12 +175,42 @@ public partial class ServiceChannelService Currency = price.Currency, ChargingCondition = price.ChargingCondition, Factors = factorMap.TryGetValue(price.Id, out var factors) ? factors.Select(MapPriceFactorOutput).ToList() : [], - Details = detailMap.TryGetValue(price.Id, out var details) ? details.Select(MapPriceDetailOutput).ToList() : [], + Details = includeDetails && detailMap.TryGetValue(price.Id, out var details) + ? details.Select(MapPriceDetailOutput).ToList() + : [], CreateTime = price.CreateTime, UpdateTime = OmsDocHelper.NullIfDefault(price.UpdateTime) }).ToList(); } + /// + /// 单条买价项(含因子+明细),供编辑弹窗按需加载。 + /// + private async Task GetPriceOutputByIdAsync(int priceId) + { + var price = await GetPriceOrThrowAsync(priceId); + var priceIds = new[] { price.Id }; + var factors = await ServiceChannelRepository.GetPriceFactorsAsync(priceIds); + var details = await ServiceChannelRepository.GetPriceDetailsAsync(priceIds); + + return new ServiceChannelPriceListOutput + { + Id = price.Id, + ServiceChannelId = price.ServiceChannelId, + SerialNumber = price.SerialNumber, + Status = (byte)price.Status, + PriceName = price.PriceName, + CostItem = price.CostItem, + CostUnit = price.CostUnit, + Currency = price.Currency, + ChargingCondition = price.ChargingCondition, + Factors = factors.OrderBy(item => item.SerialNumber).Select(MapPriceFactorOutput).ToList(), + Details = details.OrderBy(item => item.Id).Select(MapPriceDetailOutput).ToList(), + CreateTime = price.CreateTime, + UpdateTime = OmsDocHelper.NullIfDefault(price.UpdateTime) + }; + } + /// /// 获取指定类型的发布记录。 /// diff --git a/src/Oms.Application/Services/Channels/ServiceChannelService.cs b/src/Oms.Application/Services/Channels/ServiceChannelService.cs index ade005a..fdad653 100644 --- a/src/Oms.Application/Services/Channels/ServiceChannelService.cs +++ b/src/Oms.Application/Services/Channels/ServiceChannelService.cs @@ -215,17 +215,29 @@ public partial class ServiceChannelService : ApplicationService /// 查询服务渠道价格项列表。 /// /// 入参:serviceChannelId。 + /// 是否返回价格明细矩阵;列表页建议 false。 /// 服务渠道价格项列表结果。 [HttpGet("/channel/service-channel/price/list")] - public async Task> GetPriceListAsync([FromQuery] int serviceChannelId) + public async Task> GetPriceListAsync( + [FromQuery] int serviceChannelId, + [FromQuery] bool includeDetails = true) { await GetEntityOrThrowAsync(serviceChannelId); return new OmsItemsResult { - Items = await GetPriceOutputsAsync(serviceChannelId) + Items = await GetPriceOutputsAsync(serviceChannelId, includeDetails) }; } + /// + /// 获取单条服务渠道价格项(含计费因子与价格明细)。 + /// + [HttpGet("/channel/service-channel/price/get")] + public async Task GetPriceAsync([FromQuery] int id) + { + return await GetPriceOutputByIdAsync(id); + } + /// /// 新增服务渠道价格项。 ///