运行时优先读 t_system_other_config,修正管理端客户提示文案,并提供配置种子 SQL。 Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using Fake.Application;
|
||
using Fake.Users;
|
||
using Oms.Domain.CustomersAggregate.Repositories;
|
||
|
||
namespace Oms.Application.Shared;
|
||
|
||
/// <summary>
|
||
/// 仓储模块客户上下文解析。
|
||
/// </summary>
|
||
public static class WarehouseCustomerHelper
|
||
{
|
||
/// <summary>
|
||
/// 列表/汇总查询用的客户 ID:客户登录强制为自身;管理员未传或传入 ≤0 时返回 null(查询全部)。
|
||
/// </summary>
|
||
public static async Task<int?> ResolveListCustomerIdAsync(
|
||
ICustomerRepository customerRepository,
|
||
ICurrentUser currentUser,
|
||
int? requestedCustomerId = null)
|
||
{
|
||
var normalizedRequest = requestedCustomerId is > 0 ? requestedCustomerId : null;
|
||
return await OmsSessionHelper.ResolveListCustomerIdAsync(
|
||
customerRepository,
|
||
currentUser,
|
||
normalizedRequest);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 写入/删除等必须明确客户归属的操作:客户登录强制为自身;管理员须传有效 customerId(>0)。
|
||
/// </summary>
|
||
public static async Task<int> 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)}";
|
||
}
|