mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-04-22 22:22:51 +08:00
refactor: ♻️ 国家代码表重构
[skip ci]
This commit is contained in:
parent
b24642e5c9
commit
4228bd5c32
@ -7,7 +7,7 @@ namespace NetAdmin.Infrastructure.Attributes;
|
|||||||
/// https://github.com/countries/countries
|
/// https://github.com/countries/countries
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Enum)]
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Enum)]
|
||||||
public sealed class CountryAttribute : Attribute
|
public sealed class CountryInfoAttribute : Attribute
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 三个字母的国家代码
|
/// 三个字母的国家代码
|
||||||
@ -22,7 +22,7 @@ public sealed class CountryAttribute : Attribute
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 国际电话子呼号(区分同一呼号不同国家)
|
/// 国际电话子呼号(区分同一呼号不同国家)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string CallingSubCode { get; set; }
|
public string[] CallingSubCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 货币代码
|
/// 货币代码
|
||||||
@ -37,7 +37,7 @@ public sealed class CountryAttribute : Attribute
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 官方语言代码
|
/// 官方语言代码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Languages { get; set; }
|
public string[] Languages { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 国家全称
|
/// 国家全称
|
||||||
@ -49,8 +49,13 @@ public sealed class CountryAttribute : Attribute
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ShortName { get; set; }
|
public string ShortName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 时区
|
||||||
|
/// </summary>
|
||||||
|
public string[] Timezones { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 非正式名称
|
/// 非正式名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UnofficialNames { get; set; }
|
public string[] UnofficialNames { get; set; }
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
2851
src/backend/NetAdmin/NetAdmin.Infrastructure/Enums/CountryCodes.cs
Normal file
2851
src/backend/NetAdmin/NetAdmin.Infrastructure/Enums/CountryCodes.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.OpenApi.Extensions;
|
||||||
|
|
||||||
|
namespace NetAdmin.Infrastructure.Extensions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CountryCodes 扩展方法
|
||||||
|
/// </summary>
|
||||||
|
public static class CountryCodesExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取国际电话呼号
|
||||||
|
/// </summary>
|
||||||
|
public static int GetCallingCode(this CountryCodes me)
|
||||||
|
{
|
||||||
|
return me.GetAttributeOfType<CountryInfoAttribute>().CallingCode;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
using Microsoft.OpenApi.Extensions;
|
||||||
|
|
||||||
|
namespace NetAdmin.Infrastructure.Utils;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 电话号相关工具类
|
||||||
|
/// </summary>
|
||||||
|
public static class PhoneNumberHelper
|
||||||
|
{
|
||||||
|
private static readonly IEnumerable<(string CallingCode, CountryCodes CountryCode)> _countryList;
|
||||||
|
|
||||||
|
#pragma warning disable S3963
|
||||||
|
static PhoneNumberHelper()
|
||||||
|
#pragma warning restore S3963
|
||||||
|
{
|
||||||
|
_countryList = Enum.GetValues<CountryCodes>()
|
||||||
|
.SelectMany(x => {
|
||||||
|
var attribute = x.GetAttributeOfType<CountryInfoAttribute>();
|
||||||
|
|
||||||
|
// ReSharper disable once UseCollectionExpression
|
||||||
|
return (attribute.CallingSubCode ?? new[] { string.Empty }).Select(y => (attribute.CallingCode + y, x));
|
||||||
|
})
|
||||||
|
.OrderBy(x => x.Item1)
|
||||||
|
.ThenByDescending(x => x.x.GetAttributeOfType<CountryInfoAttribute>().IsPreferred)
|
||||||
|
.DistinctBy(x => x.Item1)
|
||||||
|
.OrderByDescending(x => x.Item1.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 电话号码转国家代码
|
||||||
|
/// </summary>
|
||||||
|
public static CountryCodes PhoneNumberToCountryCode(string phoneNumber)
|
||||||
|
{
|
||||||
|
return _countryList.First(x => phoneNumber.Replace("+", string.Empty).Trim().StartsWith(x.CallingCode, StringComparison.Ordinal)).CountryCode;
|
||||||
|
}
|
||||||
|
}
|
@ -48,7 +48,7 @@ public sealed class ConfigService(BasicRepository<Sys_Config, long> rpo) //
|
|||||||
{
|
{
|
||||||
req.ThrowIfInvalid();
|
req.ThrowIfInvalid();
|
||||||
#if DBTYPE_SQLSERVER
|
#if DBTYPE_SQLSERVER
|
||||||
return (await UpdateReturnListAsync(req, null).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryConfigRsp>();
|
return (await UpdateReturnListAsync(req).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryConfigRsp>();
|
||||||
#else
|
#else
|
||||||
return await UpdateAsync(req, null).ConfigureAwait(false) > 0
|
return await UpdateAsync(req, null).ConfigureAwait(false) > 0
|
||||||
? await GetAsync(new QueryConfigReq { Id = req.Id }).ConfigureAwait(false)
|
? await GetAsync(new QueryConfigReq { Id = req.Id }).ConfigureAwait(false)
|
||||||
|
@ -32,6 +32,10 @@ public sealed class ConstantService : ServiceBase<IConstantService>, IConstantSe
|
|||||||
static string[] GetDicValue(Enum y)
|
static string[] GetDicValue(Enum y)
|
||||||
{
|
{
|
||||||
var ret = new[] { Convert.ToInt64(y, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture), y.ResDesc<Ln>() };
|
var ret = new[] { Convert.ToInt64(y, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture), y.ResDesc<Ln>() };
|
||||||
|
if (y is CountryCodes) {
|
||||||
|
return [..ret, y.GetAttributeOfType<CountryInfoAttribute>().CallingCode.ToInvString()];
|
||||||
|
}
|
||||||
|
|
||||||
var indicate = y.GetAttributeOfType<IndicatorAttribute>()?.Indicate.ToLowerInvariant();
|
var indicate = y.GetAttributeOfType<IndicatorAttribute>()?.Indicate.ToLowerInvariant();
|
||||||
return indicate.NullOrEmpty() ? ret : [..ret, indicate];
|
return indicate.NullOrEmpty() ? ret : [..ret, indicate];
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public sealed class DeptService(BasicRepository<Sys_Dept, long> rpo) //
|
|||||||
{
|
{
|
||||||
req.ThrowIfInvalid();
|
req.ThrowIfInvalid();
|
||||||
#if DBTYPE_SQLSERVER
|
#if DBTYPE_SQLSERVER
|
||||||
return (await UpdateReturnListAsync(req, null).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryDeptRsp>();
|
return (await UpdateReturnListAsync(req).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryDeptRsp>();
|
||||||
#else
|
#else
|
||||||
return await UpdateAsync(req, null).ConfigureAwait(false) > 0 ? await GetAsync(new QueryDeptReq { Id = req.Id }).ConfigureAwait(false) : null;
|
return await UpdateAsync(req, null).ConfigureAwait(false) > 0 ? await GetAsync(new QueryDeptReq { Id = req.Id }).ConfigureAwait(false) : null;
|
||||||
#endif
|
#endif
|
||||||
|
@ -55,7 +55,7 @@ public sealed class DicCatalogService(BasicRepository<Sys_DicCatalog, long> rpo)
|
|||||||
{
|
{
|
||||||
req.ThrowIfInvalid();
|
req.ThrowIfInvalid();
|
||||||
return req.ParentId == 0 || await Rpo.Where(a => a.Id == req.ParentId).WithNoLockNoWait().AnyAsync().ConfigureAwait(false)
|
return req.ParentId == 0 || await Rpo.Where(a => a.Id == req.ParentId).WithNoLockNoWait().AnyAsync().ConfigureAwait(false)
|
||||||
? await UpdateAsync(req, null).ConfigureAwait(false)
|
? await UpdateAsync(req).ConfigureAwait(false)
|
||||||
: throw new NetAdminInvalidOperationException(Ln.父节点不存在);
|
: throw new NetAdminInvalidOperationException(Ln.父节点不存在);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public sealed class DicContentService(BasicRepository<Sys_DicContent, long> rpo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if DBTYPE_SQLSERVER
|
#if DBTYPE_SQLSERVER
|
||||||
return (await UpdateReturnListAsync(req, null).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryDicContentRsp>();
|
return (await UpdateReturnListAsync(req).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryDicContentRsp>();
|
||||||
#else
|
#else
|
||||||
return await UpdateAsync(req, null).ConfigureAwait(false) > 0
|
return await UpdateAsync(req, null).ConfigureAwait(false) > 0
|
||||||
? await GetAsync(new QueryDicContentReq { Id = req.Id }).ConfigureAwait(false)
|
? await GetAsync(new QueryDicContentReq { Id = req.Id }).ConfigureAwait(false)
|
||||||
|
@ -55,7 +55,7 @@ public sealed class DocCatalogService(BasicRepository<Sys_DocCatalog, long> rpo)
|
|||||||
{
|
{
|
||||||
req.ThrowIfInvalid();
|
req.ThrowIfInvalid();
|
||||||
return req.ParentId == 0 || await Rpo.Where(a => a.Id == req.ParentId).WithNoLockNoWait().AnyAsync().ConfigureAwait(false)
|
return req.ParentId == 0 || await Rpo.Where(a => a.Id == req.ParentId).WithNoLockNoWait().AnyAsync().ConfigureAwait(false)
|
||||||
? await UpdateAsync(req, null).ConfigureAwait(false)
|
? await UpdateAsync(req).ConfigureAwait(false)
|
||||||
: throw new NetAdminInvalidOperationException(Ln.父节点不存在);
|
: throw new NetAdminInvalidOperationException(Ln.父节点不存在);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public sealed class DocContentService(BasicRepository<Sys_DocContent, long> rpo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if DBTYPE_SQLSERVER
|
#if DBTYPE_SQLSERVER
|
||||||
return (await UpdateReturnListAsync(req, null).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryDocContentRsp>();
|
return (await UpdateReturnListAsync(req).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryDocContentRsp>();
|
||||||
#else
|
#else
|
||||||
return await UpdateAsync(req, null, [nameof(IFieldOwner.OwnerId), nameof(IFieldOwner.OwnerDeptId)]).ConfigureAwait(false) > 0
|
return await UpdateAsync(req, null, [nameof(IFieldOwner.OwnerId), nameof(IFieldOwner.OwnerDeptId)]).ConfigureAwait(false) > 0
|
||||||
? await GetAsync(new QueryDocContentReq { Id = req.Id }).ConfigureAwait(false)
|
? await GetAsync(new QueryDocContentReq { Id = req.Id }).ConfigureAwait(false)
|
||||||
|
@ -50,7 +50,7 @@ public sealed class MenuService(BasicRepository<Sys_Menu, long> rpo, IUserServic
|
|||||||
{
|
{
|
||||||
req.ThrowIfInvalid();
|
req.ThrowIfInvalid();
|
||||||
#if DBTYPE_SQLSERVER
|
#if DBTYPE_SQLSERVER
|
||||||
return (await UpdateReturnListAsync(req, null).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryMenuRsp>();
|
return (await UpdateReturnListAsync(req).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryMenuRsp>();
|
||||||
#else
|
#else
|
||||||
return await UpdateAsync(req, null).ConfigureAwait(false) > 0 ? await GetAsync(new QueryMenuReq { Id = req.Id }).ConfigureAwait(false) : null;
|
return await UpdateAsync(req, null).ConfigureAwait(false) > 0 ? await GetAsync(new QueryMenuReq { Id = req.Id }).ConfigureAwait(false) : null;
|
||||||
#endif
|
#endif
|
||||||
|
@ -72,7 +72,7 @@ public sealed class SiteMsgService(BasicRepository<Sys_SiteMsg, long> rpo, Conte
|
|||||||
|
|
||||||
// 主表
|
// 主表
|
||||||
var entity = req.Adapt<Sys_SiteMsg>();
|
var entity = req.Adapt<Sys_SiteMsg>();
|
||||||
_ = await UpdateAsync(entity, null).ConfigureAwait(false);
|
_ = await UpdateAsync(entity).ConfigureAwait(false);
|
||||||
|
|
||||||
// 分表
|
// 分表
|
||||||
await Rpo.SaveManyAsync(entity, nameof(entity.Roles)).ConfigureAwait(false);
|
await Rpo.SaveManyAsync(entity, nameof(entity.Roles)).ConfigureAwait(false);
|
||||||
|
@ -67,7 +67,7 @@ public sealed class UserProfileService(BasicRepository<Sys_UserProfile, long> rp
|
|||||||
public Task<int> EditAsync(EditUserProfileReq req)
|
public Task<int> EditAsync(EditUserProfileReq req)
|
||||||
{
|
{
|
||||||
req.ThrowIfInvalid();
|
req.ThrowIfInvalid();
|
||||||
return UpdateAsync(req.Adapt<Sys_UserProfile>(), null);
|
return UpdateAsync(req.Adapt<Sys_UserProfile>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user