mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-06-21 03:08:16 +08:00
feat: ✨ 框架代码同步 (#148)
[skip ci] Co-authored-by: tk <fiyne1a@dingtalk.com>
This commit is contained in:
@ -122,6 +122,13 @@ public sealed class ConfigService(BasicRepository<Sys_Config, long> rpo) //
|
||||
return ret.Adapt<IEnumerable<QueryConfigRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<int> SetEnabledAsync(SetConfigEnabledReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return UpdateAsync(req, [nameof(req.Enabled)]);
|
||||
}
|
||||
|
||||
private ISelect<Sys_Config> QueryInternal(QueryReq<QueryConfigReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.Include(a => a.UserRegisterDept)
|
||||
|
@ -24,16 +24,14 @@ public sealed class ConstantService : ServiceBase<IConstantService>, IConstantSe
|
||||
.ToDictionary(x => x.Name, x => //
|
||||
x.GetEnumValues().Cast<Enum>().ToDictionary(y => y.ToString(), GetDicValue));
|
||||
|
||||
ret.Add( //
|
||||
$"{nameof(HttpStatusCode)}s" //
|
||||
, Enum.GetNames<HttpStatusCode>()
|
||||
.ToDictionary(
|
||||
x => x
|
||||
, x => new[] {
|
||||
Convert.ToInt64(Enum.Parse<HttpStatusCode>(x), CultureInfo.InvariantCulture)
|
||||
.ToString(CultureInfo.InvariantCulture)
|
||||
, x
|
||||
}));
|
||||
var httpStatusCodes = Enum.GetNames<HttpStatusCode>().ToDictionary(x => x, GetHttpStatusCodeDicValue);
|
||||
httpStatusCodes.Add( //
|
||||
nameof(ErrorCodes.Unhandled)
|
||||
, [
|
||||
Numbers.HTTP_STATUS_BIZ_FAIL.ToInvString(), nameof(ErrorCodes.Unhandled)
|
||||
, nameof(Indicates.Danger).ToLowerInvariant()
|
||||
]);
|
||||
ret.Add($"{nameof(HttpStatusCode)}s", httpStatusCodes);
|
||||
return ret;
|
||||
|
||||
static string[] GetDicValue(Enum y)
|
||||
@ -45,6 +43,19 @@ public sealed class ConstantService : ServiceBase<IConstantService>, IConstantSe
|
||||
var indicate = y.GetAttributeOfType<IndicatorAttribute>()?.Indicate.ToLowerInvariant();
|
||||
return indicate.NullOrEmpty() ? ret : [..ret, indicate];
|
||||
}
|
||||
|
||||
static string[] GetHttpStatusCodeDicValue(string name)
|
||||
{
|
||||
var codeInt = Convert.ToInt64(Enum.Parse<HttpStatusCode>(name), CultureInfo.InvariantCulture);
|
||||
return [
|
||||
codeInt.ToString(CultureInfo.InvariantCulture), name
|
||||
, (codeInt switch {
|
||||
>= 200 and < 300 => nameof(Indicates.Success)
|
||||
, < 400 => nameof(Indicates.Warning)
|
||||
, _ => nameof(Indicates.Danger)
|
||||
}).ToLowerInvariant()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -13,4 +13,14 @@ public interface IUserProfileService : IService, IUserProfileModule
|
||||
/// 编辑用户档案
|
||||
/// </summary>
|
||||
Task<int> EditAsync(EditUserProfileReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户配置
|
||||
/// </summary>
|
||||
Task<GetSessionUserAppConfigRsp> GetSessionUserAppConfigAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 设置当前用户配置
|
||||
/// </summary>
|
||||
Task<int> SetSessionUserAppConfigAsync(SetSessionUserAppConfigReq req);
|
||||
}
|
@ -120,7 +120,7 @@ public sealed class DeptService(BasicRepository<Sys_Dept, long> rpo) //
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetEnabledAsync(SetDeptEnabledReq req)
|
||||
public Task<int> SetEnabledAsync(SetDeptEnabledReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return UpdateAsync(req, [nameof(req.Enabled)]);
|
||||
|
@ -165,7 +165,8 @@ public sealed class JobRecordService(BasicRepository<Sys_JobRecord, long> rpo) /
|
||||
|
||||
private ISelect<Sys_JobRecord> QueryInternal(QueryReq<QueryJobRecordReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter)
|
||||
var ret = Rpo.Select.Include(a => a.Job)
|
||||
.WhereDynamicFilter(req.DynamicFilter)
|
||||
.WhereDynamic(req.Filter)
|
||||
.WhereIf( //
|
||||
req.Keywords?.Length > 0
|
||||
|
@ -295,7 +295,7 @@ public sealed class JobService(BasicRepository<Sys_Job, long> rpo, IJobRecordSer
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetEnabledAsync(SetJobEnabledReq req)
|
||||
public Task<int> SetEnabledAsync(SetJobEnabledReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return UpdateAsync(req, [nameof(Sys_Job.Enabled)]);
|
||||
|
@ -124,12 +124,26 @@ public sealed class RoleService(BasicRepository<Sys_Role, long> rpo) //
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetEnabledAsync(SetRoleEnabledReq req)
|
||||
public Task<int> SetDisplayDashboardAsync(SetDisplayDashboardReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return UpdateAsync(req, [nameof(req.DisplayDashboard)]);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<int> SetEnabledAsync(SetRoleEnabledReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return UpdateAsync(req, [nameof(req.Enabled)]);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<int> SetIgnorePermissionControlAsync(SetIgnorePermissionControlReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return UpdateAsync(req, [nameof(req.IgnorePermissionControl)]);
|
||||
}
|
||||
|
||||
private ISelect<Sys_Role> QueryInternal(QueryReq<QueryRoleReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.IncludeMany(a => a.Depts.Select(b => new Sys_Dept { Id = b.Id }))
|
||||
|
@ -56,7 +56,7 @@ public sealed class UserProfileService(BasicRepository<Sys_UserProfile, long> rp
|
||||
/// <inheritdoc />
|
||||
public Task<int> EditAsync(EditUserProfileReq req)
|
||||
{
|
||||
return UpdateAsync(req, null);
|
||||
return UpdateAsync(req.Adapt<Sys_UserProfile>(), null);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -80,6 +80,13 @@ public sealed class UserProfileService(BasicRepository<Sys_UserProfile, long> rp
|
||||
return ret.Adapt<QueryUserProfileRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<GetSessionUserAppConfigRsp> GetSessionUserAppConfigAsync()
|
||||
{
|
||||
var ret = await Rpo.Select.Where(a => a.Id == UserToken.Id).ToOneAsync().ConfigureAwait(false);
|
||||
return ret.Adapt<GetSessionUserAppConfigRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<PagedQueryRsp<QueryUserProfileRsp>> PagedQueryAsync(PagedQueryReq<QueryUserProfileReq> req)
|
||||
{
|
||||
@ -147,6 +154,13 @@ public sealed class UserProfileService(BasicRepository<Sys_UserProfile, long> rp
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<int> SetSessionUserAppConfigAsync(SetSessionUserAppConfigReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return UpdateAsync(req, [nameof(req.AppConfig)], null, a => a.Id == UserToken.Id, null, true);
|
||||
}
|
||||
|
||||
private ISelect<Sys_UserProfile, Sys_DicContent, Sys_DicContent, Sys_DicContent, Sys_DicContent> QueryInternal(
|
||||
QueryReq<QueryUserProfileReq> req)
|
||||
{
|
||||
|
@ -163,6 +163,12 @@ public sealed class UserService(
|
||||
return ret.Adapt<QueryUserRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<GetSessionUserAppConfigRsp> GetSessionUserAppConfigAsync()
|
||||
{
|
||||
return userProfileService.GetSessionUserAppConfigAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="NetAdminInvalidOperationException">用户名或密码错误</exception>
|
||||
public async Task<LoginRsp> LoginByPwdAsync(LoginByPwdReq req)
|
||||
@ -259,7 +265,7 @@ public sealed class UserService(
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="NetAdminInvalidOperationException">验证码不正确</exception>
|
||||
/// <exception cref="NetAdminInvalidOperationException">用户不存在</exception>
|
||||
public async Task<uint> ResetPasswordAsync(ResetPasswordReq req)
|
||||
public async Task<int> ResetPasswordAsync(ResetPasswordReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (await verifyCodeService.VerifyAsync(req.VerifySmsCodeReq).ConfigureAwait(false)) {
|
||||
@ -269,7 +275,7 @@ public sealed class UserService(
|
||||
Password = req.PasswordText.Pwd()
|
||||
.Guid()
|
||||
};
|
||||
return (uint)await UpdateAsync(dto, [nameof(Sys_User.Password)]).ConfigureAwait(false);
|
||||
return await UpdateAsync(dto, [nameof(Sys_User.Password)]).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
throw new NetAdminInvalidOperationException(Ln.验证码不正确);
|
||||
@ -335,7 +341,7 @@ public sealed class UserService(
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetEnabledAsync(SetUserEnabledReq req)
|
||||
public Task<int> SetEnabledAsync(SetUserEnabledReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return UpdateAsync(req, [nameof(req.Enabled)]);
|
||||
@ -386,18 +392,23 @@ public sealed class UserService(
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<uint> SetPasswordAsync(SetPasswordReq req)
|
||||
public async Task<int> SetPasswordAsync(SetPasswordReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var version = await Rpo.Where(a => a.Id == UserToken.Id && a.Password == req.OldPassword.Pwd().Guid())
|
||||
.ToOneAsync(a => new long?(a.Version))
|
||||
.ConfigureAwait(false) ?? throw new NetAdminInvalidOperationException($"{Ln.旧密码不正确}");
|
||||
|
||||
var ret = await UpdateAsync(
|
||||
return await UpdateAsync(
|
||||
new Sys_User { Id = UserToken.Id, Password = req.NewPassword.Pwd().Guid(), Version = version }
|
||||
, [nameof(Sys_User.Password)])
|
||||
.ConfigureAwait(false);
|
||||
return (uint)ret;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<int> SetSessionUserAppConfigAsync(SetSessionUserAppConfigReq req)
|
||||
{
|
||||
return userProfileService.SetSessionUserAppConfigAsync(req);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -495,9 +506,9 @@ public sealed class UserService(
|
||||
req.Filter?.RoleId > 0, a => a.Roles.Any(b => b.Id == req.Filter.RoleId))
|
||||
.WhereIf( //
|
||||
req.Keywords?.Length > 0
|
||||
, a => a.Id == req.Keywords.Int64Try(0) || a.UserName.Contains(req.Keywords) ||
|
||||
a.Mobile.Contains(req.Keywords) || a.Email.Contains(req.Keywords) ||
|
||||
a.Summary.Contains(req.Keywords));
|
||||
, a => a.Id == req.Keywords.Int64Try(0) || a.UserName == req.Keywords ||
|
||||
a.Mobile == req.Keywords ||
|
||||
a.Email == req.Keywords || a.Summary.Contains(req.Keywords));
|
||||
switch (req.Order) {
|
||||
case Orders.None:
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user