2025-11-11 19:49:52 +00:00
|
|
|
|
using System;
|
2025-10-07 20:55:42 +00:00
|
|
|
|
using System.Globalization;
|
2025-11-11 19:49:52 +00:00
|
|
|
|
using Erp.Platform;
|
2025-10-07 20:55:42 +00:00
|
|
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
|
|
using Volo.Abp.MultiTenancy;
|
2025-10-23 12:05:16 +00:00
|
|
|
|
using Volo.Abp.Timing;
|
2025-10-07 20:55:42 +00:00
|
|
|
|
using Volo.Abp.Users;
|
|
|
|
|
|
|
|
|
|
|
|
public class DefaultValueHelper : ITransientDependency
|
|
|
|
|
|
{
|
2025-10-08 09:04:32 +00:00
|
|
|
|
private readonly ICurrentUser _currentUser;
|
|
|
|
|
|
private readonly ICurrentTenant _currentTenant;
|
2025-10-23 12:05:16 +00:00
|
|
|
|
private readonly IClock _clock;
|
|
|
|
|
|
|
2025-10-07 20:55:42 +00:00
|
|
|
|
public DefaultValueHelper(
|
|
|
|
|
|
ICurrentUser currentUser,
|
2025-10-23 12:05:16 +00:00
|
|
|
|
ICurrentTenant currentTenant,
|
|
|
|
|
|
IClock clock
|
2025-10-07 20:55:42 +00:00
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
_currentUser = currentUser;
|
|
|
|
|
|
_currentTenant = currentTenant;
|
2025-10-23 12:05:16 +00:00
|
|
|
|
_clock = clock;
|
2025-10-07 20:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetDefaultValue(string strValue)
|
2025-10-23 12:05:16 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(strValue))
|
2025-10-21 12:14:30 +00:00
|
|
|
|
return strValue;
|
2025-10-07 20:55:42 +00:00
|
|
|
|
|
2025-10-23 12:05:16 +00:00
|
|
|
|
var now = _clock.Now;
|
|
|
|
|
|
|
|
|
|
|
|
var result = strValue
|
|
|
|
|
|
.Replace(PlatformConsts.DefaultValues.UserId, _currentUser.Id?.ToString() ?? Guid.Empty.ToString())
|
|
|
|
|
|
.Replace(PlatformConsts.DefaultValues.UserName, _currentUser.UserName ?? string.Empty)
|
2025-11-08 09:42:38 +00:00
|
|
|
|
.Replace(PlatformConsts.DefaultValues.Roles, string.Join("','", _currentUser.Roles ?? []))
|
2025-10-23 12:05:16 +00:00
|
|
|
|
.Replace(PlatformConsts.DefaultValues.Now, now.ToString("O", CultureInfo.InvariantCulture))
|
|
|
|
|
|
.Replace(PlatformConsts.DefaultValues.Day, now.Day.ToString(CultureInfo.InvariantCulture))
|
|
|
|
|
|
.Replace(PlatformConsts.DefaultValues.Month, now.Month.ToString(CultureInfo.InvariantCulture))
|
|
|
|
|
|
.Replace(PlatformConsts.DefaultValues.Year, now.Year.ToString(CultureInfo.InvariantCulture));
|
2025-10-08 09:04:32 +00:00
|
|
|
|
|
2025-11-12 12:59:31 +00:00
|
|
|
|
// 🔹 TenantId özel durumu: NULL => IS NULL, varsa => = 'GUID'
|
2025-10-21 12:14:30 +00:00
|
|
|
|
if (_currentTenant?.Id.HasValue == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
result = result.Replace(
|
|
|
|
|
|
$"= '{PlatformConsts.DefaultValues.TenantId}'",
|
|
|
|
|
|
$"= '{_currentTenant.Id}'"
|
|
|
|
|
|
).Replace(
|
|
|
|
|
|
PlatformConsts.DefaultValues.TenantId,
|
|
|
|
|
|
_currentTenant.Id.ToString()
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2025-10-08 09:04:32 +00:00
|
|
|
|
{
|
2025-10-21 12:14:30 +00:00
|
|
|
|
result = result.Replace(
|
|
|
|
|
|
$"= '{PlatformConsts.DefaultValues.TenantId}'",
|
|
|
|
|
|
"IS NULL"
|
|
|
|
|
|
).Replace(
|
|
|
|
|
|
PlatformConsts.DefaultValues.TenantId,
|
|
|
|
|
|
"NULL"
|
|
|
|
|
|
);
|
2025-10-08 09:04:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
2025-10-07 20:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-11 19:49:52 +00:00
|
|
|
|
|