using Fake.Application; using Fake.Users; using Oms.Domain.CustomersAggregate.Repositories; namespace Oms.Application.Shared; /// /// 仓储模块客户上下文解析。 /// public static class WarehouseCustomerHelper { /// /// 列表/汇总查询用的客户 ID:客户登录强制为自身;管理员未传或传入 ≤0 时返回 null(查询全部)。 /// public static async Task ResolveListCustomerIdAsync( ICustomerRepository customerRepository, ICurrentUser currentUser, int? requestedCustomerId = null) { var normalizedRequest = requestedCustomerId is > 0 ? requestedCustomerId : null; return await OmsSessionHelper.ResolveListCustomerIdAsync( customerRepository, currentUser, normalizedRequest); } /// /// 写入/删除等必须明确客户归属的操作:客户登录强制为自身;管理员须传有效 customerId(>0)。 /// public static async Task ResolveRequiredCustomerIdAsync( ICustomerRepository customerRepository, ICurrentUser currentUser, int? requestedCustomerId = null) { var customerId = await ResolveListCustomerIdAsync(customerRepository, currentUser, requestedCustomerId); if (!customerId.HasValue || customerId.Value <= 0) { throw new BusinessException("客户ID不能为空"); } return customerId.Value; } public static (bool HasFilter, int Value) ToCustomerFilter(int? customerId) => (customerId.HasValue, customerId.GetValueOrDefault()); public static string GenerateInboundNoticeNo() => $"IN{DateTime.Now:yyyyMMddHHmmss}{Random.Shared.Next(1000, 9999)}"; }