20261116 #24
@ -18,6 +18,40 @@ public class DataResourceMetaDto
|
|||||||
public string? MainTable { get; set; }
|
public string? MainTable { get; set; }
|
||||||
|
|
||||||
public List<string>? FilterableFields { get; set; }
|
public List<string>? FilterableFields { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 业务列表查询是否已真正接入数据权限过滤(未接入时配置仅作预留)。
|
||||||
|
/// </summary>
|
||||||
|
public bool IsEnforced { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按目标用户生效范围预览订单可见量(运营验收用)。
|
||||||
|
/// </summary>
|
||||||
|
public class OrderScopePreviewDto
|
||||||
|
{
|
||||||
|
public string UserId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public bool IsAdmin { get; set; }
|
||||||
|
|
||||||
|
public bool Enforced { get; set; } = true;
|
||||||
|
|
||||||
|
public int TotalCount { get; set; }
|
||||||
|
|
||||||
|
public List<OrderScopePreviewItemDto> Samples { get; set; } = [];
|
||||||
|
|
||||||
|
public string? SummaryText { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OrderScopePreviewItemDto
|
||||||
|
{
|
||||||
|
public int OrderId { get; set; }
|
||||||
|
|
||||||
|
public string ServiceNo { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string? ClientNo { get; set; }
|
||||||
|
|
||||||
|
public string? OrderStatus { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DataPermMetaDto
|
public class DataPermMetaDto
|
||||||
@ -217,12 +251,19 @@ public class EffectiveDataScopeDto
|
|||||||
|
|
||||||
public string? DataResourceCode { get; set; }
|
public string? DataResourceCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前预览模块是否已接入业务过滤。
|
||||||
|
/// </summary>
|
||||||
|
public bool IsEnforced { get; set; }
|
||||||
|
|
||||||
public List<string>? OrganizationIds { get; set; }
|
public List<string>? OrganizationIds { get; set; }
|
||||||
|
|
||||||
public List<string>? OrganizationNames { get; set; }
|
public List<string>? OrganizationNames { get; set; }
|
||||||
|
|
||||||
public int? DataScope { get; set; }
|
public int? DataScope { get; set; }
|
||||||
|
|
||||||
|
public string? DataScopeLabel { get; set; }
|
||||||
|
|
||||||
public List<BizFilterGroupDto>? BizFilters { get; set; }
|
public List<BizFilterGroupDto>? BizFilters { get; set; }
|
||||||
|
|
||||||
public List<int>? SecretLevels { get; set; }
|
public List<int>? SecretLevels { get; set; }
|
||||||
|
|||||||
@ -9,6 +9,8 @@ using Oms.Application.Dtos.DataPerm;
|
|||||||
using Oms.Application.Shared;
|
using Oms.Application.Shared;
|
||||||
using Oms.Domain.ChannelsAggregate.Entities;
|
using Oms.Domain.ChannelsAggregate.Entities;
|
||||||
using Oms.Domain.ChannelsAggregate.Repositories;
|
using Oms.Domain.ChannelsAggregate.Repositories;
|
||||||
|
using Oms.Domain.OrdersAggregate;
|
||||||
|
using Oms.Domain.OrdersAggregate.Repositories;
|
||||||
using Oms.Domain.SystemAggregate.Entities;
|
using Oms.Domain.SystemAggregate.Entities;
|
||||||
using Oms.Domain.SystemAggregate.Repositories;
|
using Oms.Domain.SystemAggregate.Repositories;
|
||||||
|
|
||||||
@ -28,6 +30,10 @@ public partial class DataPermService : ApplicationService
|
|||||||
private ISalesProductRepository SalesProductRepository => LazyServiceProvider.GetRequiredService<ISalesProductRepository>();
|
private ISalesProductRepository SalesProductRepository => LazyServiceProvider.GetRequiredService<ISalesProductRepository>();
|
||||||
private IKpiAreaRepository KpiAreaRepository => LazyServiceProvider.GetRequiredService<IKpiAreaRepository>();
|
private IKpiAreaRepository KpiAreaRepository => LazyServiceProvider.GetRequiredService<IKpiAreaRepository>();
|
||||||
private IWarehouseAddressRepository WarehouseRepository => LazyServiceProvider.GetRequiredService<IWarehouseAddressRepository>();
|
private IWarehouseAddressRepository WarehouseRepository => LazyServiceProvider.GetRequiredService<IWarehouseAddressRepository>();
|
||||||
|
private IOrderRepository OrderRepository => LazyServiceProvider.GetRequiredService<IOrderRepository>();
|
||||||
|
|
||||||
|
private static readonly HashSet<string> EnforcedResourceCodes =
|
||||||
|
new(StringComparer.OrdinalIgnoreCase) { DataScopeApplier.OrderResourceCode };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取数据权限元数据
|
/// 获取数据权限元数据
|
||||||
@ -106,27 +112,36 @@ public partial class DataPermService : ApplicationService
|
|||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var id = ParseGuid(userId, "userId");
|
var id = ParseGuid(userId, "userId");
|
||||||
var context = await ScopeBuilder.BuildAsync(id, dataResourceCode, useCache: true, cancellationToken);
|
var resourceCode = string.IsNullOrWhiteSpace(dataResourceCode)
|
||||||
|
? DataScopeApplier.OrderResourceCode
|
||||||
|
: dataResourceCode.Trim();
|
||||||
|
var isEnforced = EnforcedResourceCodes.Contains(resourceCode);
|
||||||
|
var context = await ScopeBuilder.BuildAsync(id, resourceCode, useCache: true, cancellationToken);
|
||||||
if (context.IsAdmin)
|
if (context.IsAdmin)
|
||||||
{
|
{
|
||||||
return new EffectiveDataScopeDto
|
return new EffectiveDataScopeDto
|
||||||
{
|
{
|
||||||
UserId = id.ToString(),
|
UserId = id.ToString(),
|
||||||
IsAdmin = true,
|
IsAdmin = true,
|
||||||
DataResourceCode = dataResourceCode,
|
DataResourceCode = resourceCode,
|
||||||
|
IsEnforced = isEnforced,
|
||||||
SummaryText = "管理员:跳过五维数据权限"
|
SummaryText = "管理员:跳过五维数据权限"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var orgNames = await Repository.GetOrganizationNamesAsync(context.OrganizationIds, cancellationToken);
|
var orgNames = await Repository.GetOrganizationNamesAsync(context.OrganizationIds, cancellationToken);
|
||||||
|
var scopeLabel = DataPermConstants.DataScopeOptions
|
||||||
|
.FirstOrDefault(x => x.Value == context.DataScope).Label;
|
||||||
return new EffectiveDataScopeDto
|
return new EffectiveDataScopeDto
|
||||||
{
|
{
|
||||||
UserId = id.ToString(),
|
UserId = id.ToString(),
|
||||||
IsAdmin = false,
|
IsAdmin = false,
|
||||||
DataResourceCode = dataResourceCode,
|
DataResourceCode = resourceCode,
|
||||||
|
IsEnforced = isEnforced,
|
||||||
OrganizationIds = context.OrganizationIds.Select(x => x.ToString()).ToList(),
|
OrganizationIds = context.OrganizationIds.Select(x => x.ToString()).ToList(),
|
||||||
OrganizationNames = orgNames.Values.ToList(),
|
OrganizationNames = orgNames.Values.ToList(),
|
||||||
DataScope = context.DataScope,
|
DataScope = context.DataScope,
|
||||||
|
DataScopeLabel = scopeLabel,
|
||||||
SecretLevels = context.SecretLevels.OrderBy(x => x).ToList(),
|
SecretLevels = context.SecretLevels.OrderBy(x => x).ToList(),
|
||||||
BizFilters = context.BizFilters?.Select(x => new BizFilterGroupDto
|
BizFilters = context.BizFilters?.Select(x => new BizFilterGroupDto
|
||||||
{
|
{
|
||||||
@ -137,6 +152,56 @@ public partial class DataPermService : ApplicationService
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按目标用户生效范围预览订单可见量(抽样,供运营验收配置是否生效)。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">目标用户 GUID。</param>
|
||||||
|
/// <param name="sampleSize">抽样条数,默认 5,最大 20。</param>
|
||||||
|
/// <param name="cancellationToken">取消令牌。</param>
|
||||||
|
/// <returns>可见订单总数与抽样服务单号;非订单模块不执行计数。</returns>
|
||||||
|
[HttpGet("/rbac/data-perm/preview-order-scope")]
|
||||||
|
public async Task<OrderScopePreviewDto> PreviewOrderScopeAsync(
|
||||||
|
[FromQuery] string userId,
|
||||||
|
[FromQuery] int sampleSize = 5,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var id = ParseGuid(userId, "userId");
|
||||||
|
sampleSize = Math.Clamp(sampleSize, 1, 20);
|
||||||
|
var context = await ScopeBuilder.BuildAsync(id, DataScopeApplier.OrderResourceCode, useCache: true, cancellationToken);
|
||||||
|
var summary = await ScopeBuilder.BuildSummaryTextAsync(context, cancellationToken);
|
||||||
|
|
||||||
|
if (context.IsAdmin)
|
||||||
|
{
|
||||||
|
var (adminItems, adminTotal) = await OrderRepository.GetFilteredPagedListAsync(
|
||||||
|
1,
|
||||||
|
sampleSize,
|
||||||
|
new OrderListFilter(),
|
||||||
|
cancellationToken);
|
||||||
|
return new OrderScopePreviewDto
|
||||||
|
{
|
||||||
|
UserId = id.ToString(),
|
||||||
|
IsAdmin = true,
|
||||||
|
Enforced = true,
|
||||||
|
TotalCount = adminTotal,
|
||||||
|
SummaryText = summary,
|
||||||
|
Samples = adminItems.Select(MapPreviewItem).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var filter = new OrderListFilter();
|
||||||
|
DataScopeApplier.ApplyToOrderListFilter(filter, context);
|
||||||
|
var (items, total) = await OrderRepository.GetFilteredPagedListAsync(1, sampleSize, filter, cancellationToken);
|
||||||
|
return new OrderScopePreviewDto
|
||||||
|
{
|
||||||
|
UserId = id.ToString(),
|
||||||
|
IsAdmin = false,
|
||||||
|
Enforced = true,
|
||||||
|
TotalCount = total,
|
||||||
|
SummaryText = summary,
|
||||||
|
Samples = items.Select(MapPreviewItem).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存用户数据权限
|
/// 保存用户数据权限
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -275,6 +340,11 @@ public partial class DataPermService : ApplicationService
|
|||||||
var rows = await Repository.GetDataResourcesAsync(cancellationToken);
|
var rows = await Repository.GetDataResourcesAsync(cancellationToken);
|
||||||
if (rows.Count > 0)
|
if (rows.Count > 0)
|
||||||
{
|
{
|
||||||
|
foreach (var row in rows)
|
||||||
|
{
|
||||||
|
row.IsEnforced = EnforcedResourceCodes.Contains(row.Code);
|
||||||
|
}
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,12 +357,33 @@ public partial class DataPermService : ApplicationService
|
|||||||
.Select(kv => new DataResourceMetaDto
|
.Select(kv => new DataResourceMetaDto
|
||||||
{
|
{
|
||||||
Code = kv.Key,
|
Code = kv.Key,
|
||||||
Name = kv.Key,
|
Name = ResolveResourceDisplayName(kv.Key),
|
||||||
FilterableFields = kv.Value.ToList()
|
FilterableFields = kv.Value.ToList(),
|
||||||
|
IsEnforced = EnforcedResourceCodes.Contains(kv.Key)
|
||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string ResolveResourceDisplayName(string code) =>
|
||||||
|
code.ToLowerInvariant() switch
|
||||||
|
{
|
||||||
|
"order" => "订单",
|
||||||
|
"customer" => "客户",
|
||||||
|
"recharge" => "充值",
|
||||||
|
"channelproduct" => "销售产品",
|
||||||
|
"xhs" => "小红书",
|
||||||
|
_ => code
|
||||||
|
};
|
||||||
|
|
||||||
|
private static OrderScopePreviewItemDto MapPreviewItem(Domain.OrdersAggregate.Entities.Order order) =>
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
OrderId = order.Id,
|
||||||
|
ServiceNo = order.ServiceNo,
|
||||||
|
ClientNo = order.ClientNo,
|
||||||
|
OrderStatus = order.OrderStatus
|
||||||
|
};
|
||||||
|
|
||||||
private Guid GetCurrentUserGuid()
|
private Guid GetCurrentUserGuid()
|
||||||
{
|
{
|
||||||
var raw = CurrentUser.FindClaimValueOrNull(ClaimTypes.NameIdentifier);
|
var raw = CurrentUser.FindClaimValueOrNull(ClaimTypes.NameIdentifier);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user