37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
namespace Oms.Application.Shared;
|
||
|
||
/// <summary>
|
||
/// 微信注册字段裁剪,避免超出库表长度触发保存失败。
|
||
/// </summary>
|
||
public static class WeChatRegistrationFieldNormalizer
|
||
{
|
||
public const int CustomerNameMaxLength = 128;
|
||
public const int PhoneMaxLength = 16;
|
||
public const int EmailMaxLength = 64;
|
||
/// <summary>客户表 WechatAvatar 列长度。</summary>
|
||
public const int CustomerWechatAvatarMaxLength = 255;
|
||
public const int NicknameMaxLength = 64;
|
||
public const int OpenidMaxLength = 64;
|
||
|
||
/// <summary>微信头像仅写入 t_customer;RBAC user.Avatar 列更短,注册时不写入。</summary>
|
||
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];
|
||
}
|
||
}
|