admin/src/Oms.Application/Shared/WeChatRegistrationFieldNormalizer.cs
zzh 36525ca688 fix: 微信注册头像仅写入客户表避免 RBAC Avatar 超长
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-11 10:26:50 +08:00

37 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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];
}
}