namespace Oms.Application.Shared;
///
/// 微信注册字段裁剪,避免超出库表长度触发保存失败。
///
public static class WeChatRegistrationFieldNormalizer
{
public const int CustomerNameMaxLength = 128;
public const int PhoneMaxLength = 16;
public const int EmailMaxLength = 64;
/// 客户表 WechatAvatar 列长度。
public const int CustomerWechatAvatarMaxLength = 255;
public const int NicknameMaxLength = 64;
public const int OpenidMaxLength = 64;
/// 微信头像仅写入 t_customer;RBAC user.Avatar 列更短,注册时不写入。
public static string? NormalizeCustomerWechatAvatar(string? avatar) =>
TruncateOptional(avatar, CustomerWechatAvatarMaxLength);
public static string TruncateRequired(string value, int maxLength)
{
var normalized = value.Trim();
return normalized.Length <= maxLength ? normalized : normalized[..maxLength];
}
public static string? TruncateOptional(string? value, int maxLength)
{
var normalized = value?.Trim();
if (string.IsNullOrWhiteSpace(normalized))
{
return null;
}
return normalized.Length <= maxLength ? normalized : normalized[..maxLength];
}
}