feat: 框架代码同步 (#148)

[skip ci]

Co-authored-by: tk <fiyne1a@dingtalk.com>
This commit is contained in:
2024-06-24 16:04:28 +08:00
committed by GitHub
parent d00f0d2d9c
commit 8bc8aa960c
121 changed files with 2369 additions and 1497 deletions

View File

@ -954,6 +954,13 @@ public class AllTests(WebApplicationFactory<Startup> factory, ITestOutputHelper
return default;
}
/// <inheritdoc />
[Fact]
public Task<GetSessionUserAppConfigRsp> GetSessionUserAppConfigAsync()
{
return default;
}
/// <inheritdoc />
[Fact]
public async Task<string> GetVersionAsync()
@ -1342,7 +1349,7 @@ public class AllTests(WebApplicationFactory<Startup> factory, ITestOutputHelper
/// <inheritdoc />
[InlineData(default)]
[Theory]
public Task<uint> ResetPasswordAsync(ResetPasswordReq req)
public Task<int> ResetPasswordAsync(ResetPasswordReq req)
{
return default;
}
@ -1363,6 +1370,14 @@ public class AllTests(WebApplicationFactory<Startup> factory, ITestOutputHelper
return default;
}
/// <inheritdoc />
[InlineData(default)]
[Theory]
public Task<int> SetDisplayDashboardAsync(SetDisplayDashboardReq req)
{
return default;
}
/// <inheritdoc />
[InlineData(default)]
[Theory]
@ -1374,7 +1389,7 @@ public class AllTests(WebApplicationFactory<Startup> factory, ITestOutputHelper
/// <inheritdoc />
[InlineData(default)]
[Theory]
public Task SetEnabledAsync(SetDeptEnabledReq req)
public Task<int> SetEnabledAsync(SetDeptEnabledReq req)
{
return default;
}
@ -1382,7 +1397,7 @@ public class AllTests(WebApplicationFactory<Startup> factory, ITestOutputHelper
/// <inheritdoc />
[InlineData(default)]
[Theory]
public Task SetEnabledAsync(SetRoleEnabledReq req)
public Task<int> SetEnabledAsync(SetConfigEnabledReq req)
{
return default;
}
@ -1390,7 +1405,7 @@ public class AllTests(WebApplicationFactory<Startup> factory, ITestOutputHelper
/// <inheritdoc />
[InlineData(default)]
[Theory]
public Task SetEnabledAsync(SetJobEnabledReq req)
public Task<int> SetEnabledAsync(SetRoleEnabledReq req)
{
return default;
}
@ -1398,7 +1413,23 @@ public class AllTests(WebApplicationFactory<Startup> factory, ITestOutputHelper
/// <inheritdoc />
[InlineData(default)]
[Theory]
public Task SetEnabledAsync(SetUserEnabledReq req)
public Task<int> SetEnabledAsync(SetJobEnabledReq req)
{
return default;
}
/// <inheritdoc />
[InlineData(default)]
[Theory]
public Task<int> SetEnabledAsync(SetUserEnabledReq req)
{
return default;
}
/// <inheritdoc />
[InlineData(default)]
[Theory]
public Task<int> SetIgnorePermissionControlAsync(SetIgnorePermissionControlReq req)
{
return default;
}
@ -1414,7 +1445,15 @@ public class AllTests(WebApplicationFactory<Startup> factory, ITestOutputHelper
/// <inheritdoc />
[InlineData(default)]
[Theory]
public Task<uint> SetPasswordAsync(SetPasswordReq req)
public Task<int> SetPasswordAsync(SetPasswordReq req)
{
return default;
}
/// <inheritdoc />
[InlineData(default)]
[Theory]
public Task<int> SetSessionUserAppConfigAsync(SetSessionUserAppConfigReq req)
{
return default;
}

View File

@ -9,6 +9,7 @@ namespace NetAdmin.Domain.DbMaps.Sys;
[Index($"{Chars.FLG_DB_INDEX_PREFIX}{nameof(JobId)}_{nameof(TimeId)}", $"{nameof(JobId)},{nameof(TimeId)}", true)]
[Index(Chars.FLG_DB_INDEX_PREFIX + nameof(CreatedTime), nameof(CreatedTime), false)]
[Index(Chars.FLG_DB_INDEX_PREFIX + nameof(JobId), nameof(JobId), false)]
[Index(Chars.FLG_DB_INDEX_PREFIX + nameof(HttpStatusCode), nameof(HttpStatusCode), false)]
[Table(Name = Chars.FLG_DB_TABLE_NAME_PREFIX + nameof(Sys_JobRecord))]
public record Sys_JobRecord : LiteImmutableEntity
{

View File

@ -115,7 +115,7 @@ public record Sys_User : VersionEntity, IFieldSummary, IFieldEnabled, IRegister
? Array.Empty<Sys_Role>()
: s.RoleIds.Select(x => new Sys_Role { Id = x }));
_ = config.ForType<EditSingleUserReq, Sys_User>()
_ = config.ForType<EditUserReq, Sys_User>()
.Map( //
d => d.Password, s => s.PasswordText.NullOrEmpty() ? Guid.Empty : s.PasswordText.Pwd().Guid())
.Map( //

View File

@ -9,6 +9,17 @@ namespace NetAdmin.Domain.DbMaps.Sys;
[Table(Name = Chars.FLG_DB_TABLE_NAME_PREFIX + nameof(Sys_UserProfile))]
public record Sys_UserProfile : VersionEntity, IRegister
{
/// <summary>
/// 应用配置
/// </summary>
#if DBTYPE_SQLSERVER
[Column(DbType = Chars.FLG_DB_FIELD_TYPE_VARCHAR_MAX)]
#else
[Column(DbType = Chars.FLG_DB_FIELD_TYPE_VARCHAR_255)]
#endif
[JsonIgnore]
public virtual string AppConfig { get; init; }
/// <summary>
/// 出生日期
/// </summary>

View File

@ -8,5 +8,5 @@ public sealed record GetAllEntriesReq : DataAbstraction
/// <summary>
/// 数据库索引号
/// </summary>
public uint DbIndex { get; init; }
public int DbIndex { get; init; }
}

View File

@ -1,22 +1,22 @@
using NetAdmin.Domain.DbMaps.Dependency;
using NetAdmin.Domain.DbMaps.Dependency.Fields;
using NetAdmin.Domain.DbMaps.Sys;
using NetAdmin.Domain.Dto.Sys.UserProfile;
namespace NetAdmin.Domain.Dto.Sys.User;
namespace NetAdmin.Domain.Dto.Sys.Config;
/// <summary>
/// 请求:编辑用户单体
/// 请求:启用/禁用配置
/// </summary>
public sealed record EditSingleUserReq : CreateEditUserReq
public sealed record SetConfigEnabledReq : Sys_Config
{
/// <inheritdoc cref="IFieldEnabled.Enabled" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override bool Enabled { get; init; }
/// <inheritdoc cref="EntityBase{T}.Id" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override long Id { get; init; }
/// <inheritdoc cref="Sys_User.Profile" />
public new EditUserProfileReq Profile { get; init; }
/// <inheritdoc cref="IFieldVersion.Version" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override long Version { get; init; }

View File

@ -5,4 +5,11 @@ namespace NetAdmin.Domain.Dto.Sys.Job;
/// <summary>
/// 请求:完成计划作业
/// </summary>
public sealed record FinishJobReq : Sys_Job;
public sealed record FinishJobReq : Sys_Job, IRegister
{
/// <inheritdoc />
public void Register(TypeAdapterConfig config)
{
_ = config.ForType<QueryJobRsp, FinishJobReq>().Map(d => d.LastStatusCode, s => ((Sys_Job)s).LastStatusCode);
}
}

View File

@ -12,6 +12,17 @@ namespace NetAdmin.Domain.Dto.Sys.Job;
/// </summary>
public sealed record QueryJobRsp : Sys_Job
{
/// <inheritdoc cref="Sys_Job.LastStatusCode" />
public new string LastStatusCode =>
#pragma warning disable IDE0072
base.LastStatusCode switch {
#pragma warning restore IDE0072
null => null
, _ => (int)base.LastStatusCode.Value == Numbers.HTTP_STATUS_BIZ_FAIL
? nameof(ErrorCodes.Unhandled).ToLowerCamelCase()
: base.LastStatusCode.Value.ToString().ToLowerCamelCase()
};
/// <inheritdoc cref="IFieldCreatedTime.CreatedTime" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override DateTime CreatedTime { get; init; }
@ -52,10 +63,6 @@ public sealed record QueryJobRsp : Sys_Job
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public override DateTime? LastExecTime { get; init; }
/// <inheritdoc cref="Sys_Job.LastStatusCode" />
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public override HttpStatusCode? LastStatusCode { get; init; }
/// <inheritdoc cref="IFieldModifiedTime.ModifiedTime" />
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public override DateTime? ModifiedTime { get; init; }

View File

@ -1,6 +1,7 @@
using NetAdmin.Domain.DbMaps.Dependency;
using NetAdmin.Domain.DbMaps.Dependency.Fields;
using NetAdmin.Domain.DbMaps.Sys;
using NetAdmin.Domain.Dto.Sys.Job;
using HttpMethods = NetAdmin.Domain.Enums.HttpMethods;
namespace NetAdmin.Domain.Dto.Sys.JobRecord;
@ -11,8 +12,10 @@ namespace NetAdmin.Domain.Dto.Sys.JobRecord;
public sealed record QueryJobRecordRsp : Sys_JobRecord
{
/// <inheritdoc cref="Sys_JobRecord.HttpStatusCode" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public new HttpStatusCode HttpStatusCode => (HttpStatusCode)base.HttpStatusCode;
public new string HttpStatusCode =>
base.HttpStatusCode == Numbers.HTTP_STATUS_BIZ_FAIL
? nameof(ErrorCodes.Unhandled).ToLowerCamelCase()
: ((HttpStatusCode)base.HttpStatusCode).ToString().ToLowerCamelCase();
/// <inheritdoc cref="IFieldCreatedTime.CreatedTime" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
@ -30,6 +33,11 @@ public sealed record QueryJobRecordRsp : Sys_JobRecord
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override long Id { get; init; }
/// <summary>
/// 作业信息
/// </summary>
public new QueryJobRsp Job { get; init; }
/// <inheritdoc cref="Sys_JobRecord.JobId" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override long JobId { get; init; }

View File

@ -0,0 +1,23 @@
using NetAdmin.Domain.DbMaps.Dependency;
using NetAdmin.Domain.DbMaps.Dependency.Fields;
using NetAdmin.Domain.DbMaps.Sys;
namespace NetAdmin.Domain.Dto.Sys.Role;
/// <summary>
/// 请求:设置是否显示仪表板
/// </summary>
public sealed record SetDisplayDashboardReq : Sys_Role
{
/// <inheritdoc cref="Sys_Role.DisplayDashboard" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override bool DisplayDashboard { get; init; }
/// <inheritdoc cref="EntityBase{T}.Id" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override long Id { get; init; }
/// <inheritdoc cref="IFieldVersion.Version" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override long Version { get; init; }
}

View File

@ -0,0 +1,23 @@
using NetAdmin.Domain.DbMaps.Dependency;
using NetAdmin.Domain.DbMaps.Dependency.Fields;
using NetAdmin.Domain.DbMaps.Sys;
namespace NetAdmin.Domain.Dto.Sys.Role;
/// <summary>
/// 请求:设置是否忽略权限控制
/// </summary>
public sealed record SetIgnorePermissionControlReq : Sys_Role
{
/// <inheritdoc cref="EntityBase{T}.Id" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override long Id { get; init; }
/// <inheritdoc cref="Sys_Role.IgnorePermissionControl" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override bool IgnorePermissionControl { get; init; }
/// <inheritdoc cref="IFieldVersion.Version" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override long Version { get; init; }
}

View File

@ -0,0 +1,23 @@
using NetAdmin.Domain.DbMaps.Dependency;
using NetAdmin.Domain.DbMaps.Dependency.Fields;
using NetAdmin.Domain.DbMaps.Sys;
namespace NetAdmin.Domain.Dto.Sys.UserProfile;
/// <summary>
/// 响应:获取当前用户应用配置
/// </summary>
public sealed record GetSessionUserAppConfigRsp : Sys_UserProfile
{
/// <inheritdoc cref="Sys_UserProfile.AppConfig" />
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public override string AppConfig { get; init; }
/// <inheritdoc cref="EntityBase{T}.Id" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override long Id { get; init; }
/// <inheritdoc cref="IFieldVersion.Version" />
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public override long Version { get; init; }
}

View File

@ -0,0 +1,13 @@
using NetAdmin.Domain.DbMaps.Sys;
namespace NetAdmin.Domain.Dto.Sys.UserProfile;
/// <summary>
/// 请求:设置当前用户应用配置
/// </summary>
public record SetSessionUserAppConfigReq : Sys_UserProfile
{
/// <inheritdoc cref="Sys_UserProfile.AppConfig" />
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public override string AppConfig { get; init; }
}

View File

@ -21,7 +21,8 @@ public static class UnitOfWorkManagerExtensions
unitOfWork.Commit();
logger?.Info($"{Ln.事务已提交}: {hashCode}");
}
catch {
catch (Exception ex) {
logger?.Warn(ex);
unitOfWork.Rollback();
logger?.Warn($"{Ln.事务已回滚}: {hashCode}");
throw;

View File

@ -21,4 +21,9 @@ public interface IConfigModule : ICrudModule<CreateConfigReq, QueryConfigRsp //
/// 获取最新有效配置
/// </summary>
Task<QueryConfigRsp> GetLatestConfigAsync();
/// <summary>
/// 设置配置启用状态
/// </summary>
Task<int> SetEnabledAsync(SetConfigEnabledReq req);
}

View File

@ -20,5 +20,5 @@ public interface IDeptModule : ICrudModule<CreateDeptReq, QueryDeptRsp // 创建
/// <summary>
/// 启用/禁用部门
/// </summary>
Task SetEnabledAsync(SetDeptEnabledReq req);
Task<int> SetEnabledAsync(SetDeptEnabledReq req);
}

View File

@ -52,5 +52,5 @@ public interface IJobModule : ICrudModule<CreateJobReq, QueryJobRsp // 创建类
/// <summary>
/// 设置计划作业启用状态
/// </summary>
Task SetEnabledAsync(SetJobEnabledReq req);
Task<int> SetEnabledAsync(SetJobEnabledReq req);
}

View File

@ -17,8 +17,18 @@ public interface IRoleModule : ICrudModule<CreateRoleReq, QueryRoleRsp // 创建
/// </summary>
Task<QueryRoleRsp> EditAsync(EditRoleReq req);
/// <summary>
/// 设置是否显示仪表板
/// </summary>
Task<int> SetDisplayDashboardAsync(SetDisplayDashboardReq req);
/// <summary>
/// 启用/禁用角色
/// </summary>
Task SetEnabledAsync(SetRoleEnabledReq req);
Task<int> SetEnabledAsync(SetRoleEnabledReq req);
/// <summary>
/// 设置是否忽略权限控制
/// </summary>
Task<int> SetIgnorePermissionControlAsync(SetIgnorePermissionControlReq req);
}

View File

@ -8,9 +8,9 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
/// <summary>
/// 用户模块
/// </summary>
public interface IUserModule : ICrudModule<CreateUserReq, QueryUserRsp // 创建类型
, QueryUserReq, QueryUserRsp // 查询类型
, DelReq // 删除类型
public partial interface IUserModule : ICrudModule<CreateUserReq, QueryUserRsp // 创建类型
, QueryUserReq, QueryUserRsp // 查询类型
, DelReq // 删除类型
>
{
/// <summary>
@ -51,7 +51,7 @@ public interface IUserModule : ICrudModule<CreateUserReq, QueryUserRsp // 创建
/// <summary>
/// 重设密码
/// </summary>
Task<uint> ResetPasswordAsync(ResetPasswordReq req);
Task<int> ResetPasswordAsync(ResetPasswordReq req);
/// <summary>
/// 设置用户头像
@ -66,7 +66,7 @@ public interface IUserModule : ICrudModule<CreateUserReq, QueryUserRsp // 创建
/// <summary>
/// 启用/禁用用户
/// </summary>
Task SetEnabledAsync(SetUserEnabledReq req);
Task<int> SetEnabledAsync(SetUserEnabledReq req);
/// <summary>
/// 设置手机号码
@ -76,7 +76,7 @@ public interface IUserModule : ICrudModule<CreateUserReq, QueryUserRsp // 创建
/// <summary>
/// 设置密码
/// </summary>
Task<uint> SetPasswordAsync(SetPasswordReq req);
Task<int> SetPasswordAsync(SetPasswordReq req);
/// <summary>
/// 当前用户信息

View File

@ -0,0 +1,17 @@
using NetAdmin.Domain.Dto.Sys.UserProfile;
// ReSharper disable once CheckNamespace
namespace NetAdmin.SysComponent.Application.Modules.Sys;
public partial interface IUserModule
{
/// <summary>
/// 获取当前用户应用配置
/// </summary>
Task<GetSessionUserAppConfigRsp> GetSessionUserAppConfigAsync();
/// <summary>
/// 设置当前用户应用配置
/// </summary>
Task<int> SetSessionUserAppConfigAsync(SetSessionUserAppConfigReq req);
}

View File

@ -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)

View File

@ -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 />

View File

@ -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);
}

View File

@ -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)]);

View File

@ -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

View File

@ -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)]);

View File

@ -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 }))

View File

@ -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)
{

View File

@ -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;

View File

@ -69,4 +69,10 @@ public sealed class ConfigCache(IDistributedCache cache, IConfigService service)
{
return Service.QueryAsync(req);
}
/// <inheritdoc />
public Task<int> SetEnabledAsync(SetConfigEnabledReq req)
{
return Service.SetEnabledAsync(req);
}
}

View File

@ -65,7 +65,7 @@ public sealed class DeptCache(IDistributedCache cache, IDeptService service) //
}
/// <inheritdoc />
public Task SetEnabledAsync(SetDeptEnabledReq req)
public Task<int> SetEnabledAsync(SetDeptEnabledReq req)
{
return Service.SetEnabledAsync(req);
}

View File

@ -123,7 +123,7 @@ public sealed class JobCache(IDistributedCache cache, IJobService service)
}
/// <inheritdoc />
public Task SetEnabledAsync(SetJobEnabledReq req)
public Task<int> SetEnabledAsync(SetJobEnabledReq req)
{
return Service.SetEnabledAsync(req);
}

View File

@ -65,8 +65,20 @@ public sealed class RoleCache(IDistributedCache cache, IRoleService service) //
}
/// <inheritdoc />
public Task SetEnabledAsync(SetRoleEnabledReq req)
public Task<int> SetDisplayDashboardAsync(SetDisplayDashboardReq req)
{
return Service.SetDisplayDashboardAsync(req);
}
/// <inheritdoc />
public Task<int> SetEnabledAsync(SetRoleEnabledReq req)
{
return Service.SetEnabledAsync(req);
}
/// <inheritdoc />
public Task<int> SetIgnorePermissionControlAsync(SetIgnorePermissionControlReq req)
{
return Service.SetIgnorePermissionControlAsync(req);
}
}

View File

@ -65,6 +65,12 @@ public sealed class UserCache(IDistributedCache cache, IUserService service, IVe
return Service.GetAsync(req);
}
/// <inheritdoc />
public Task<GetSessionUserAppConfigRsp> GetSessionUserAppConfigAsync()
{
return Service.GetSessionUserAppConfigAsync();
}
/// <inheritdoc />
public Task<LoginRsp> LoginByPwdAsync(LoginByPwdReq req)
{
@ -157,7 +163,7 @@ public sealed class UserCache(IDistributedCache cache, IUserService service, IVe
}
/// <inheritdoc />
public Task<uint> ResetPasswordAsync(ResetPasswordReq req)
public Task<int> ResetPasswordAsync(ResetPasswordReq req)
{
return Service.ResetPasswordAsync(req);
}
@ -177,7 +183,7 @@ public sealed class UserCache(IDistributedCache cache, IUserService service, IVe
}
/// <inheritdoc />
public Task SetEnabledAsync(SetUserEnabledReq req)
public Task<int> SetEnabledAsync(SetUserEnabledReq req)
{
return Service.SetEnabledAsync(req);
}
@ -189,11 +195,17 @@ public sealed class UserCache(IDistributedCache cache, IUserService service, IVe
}
/// <inheritdoc />
public Task<uint> SetPasswordAsync(SetPasswordReq req)
public Task<int> SetPasswordAsync(SetPasswordReq req)
{
return Service.SetPasswordAsync(req);
}
/// <inheritdoc />
public Task<int> SetSessionUserAppConfigAsync(SetSessionUserAppConfigReq req)
{
return Service.SetSessionUserAppConfigAsync(req);
}
/// <inheritdoc />
public Task<UserInfoRsp> UserInfoAsync()
{

View File

@ -99,4 +99,12 @@ public sealed class ConfigController(IConfigCache cache) : ControllerBase<IConfi
{
return Cache.QueryAsync(req);
}
/// <summary>
/// 设置配置启用状态
/// </summary>
public Task<int> SetEnabledAsync(SetConfigEnabledReq req)
{
return Cache.SetEnabledAsync(req);
}
}

View File

@ -95,7 +95,7 @@ public sealed class DeptController(IDeptCache cache) : ControllerBase<IDeptCache
/// <summary>
/// 启用/禁用部门
/// </summary>
public Task SetEnabledAsync(SetDeptEnabledReq req)
public Task<int> SetEnabledAsync(SetDeptEnabledReq req)
{
return Cache.SetEnabledAsync(req);
}

View File

@ -144,7 +144,7 @@ public sealed class JobController(IJobCache cache) : ControllerBase<IJobCache, I
/// <summary>
/// 启用/禁用作业
/// </summary>
public Task SetEnabledAsync(SetJobEnabledReq req)
public Task<int> SetEnabledAsync(SetJobEnabledReq req)
{
return Cache.SetEnabledAsync(req);
}

View File

@ -91,11 +91,27 @@ public sealed class RoleController(IRoleCache cache) : ControllerBase<IRoleCache
return Cache.QueryAsync(req);
}
/// <summary>
/// 设置是否显示仪表板
/// </summary>
public Task<int> SetDisplayDashboardAsync(SetDisplayDashboardReq req)
{
return Cache.SetDisplayDashboardAsync(req);
}
/// <summary>
/// 启用/禁用角色
/// </summary>
public Task SetEnabledAsync(SetRoleEnabledReq req)
public Task<int> SetEnabledAsync(SetRoleEnabledReq req)
{
return Cache.SetEnabledAsync(req);
}
/// <summary>
/// 设置是否忽略权限控制
/// </summary>
public Task<int> SetIgnorePermissionControlAsync(SetIgnorePermissionControlReq req)
{
return Cache.SetIgnorePermissionControlAsync(req);
}
}

View File

@ -96,6 +96,14 @@ public sealed class UserController(IUserCache cache, IConfigCache configCache)
return Cache.GetAsync(req);
}
/// <summary>
/// 获取当前用户应用配置
/// </summary>
public Task<GetSessionUserAppConfigRsp> GetSessionUserAppConfigAsync()
{
return Cache.GetSessionUserAppConfigAsync();
}
/// <summary>
/// 密码登录
/// </summary>
@ -168,7 +176,7 @@ public sealed class UserController(IUserCache cache, IConfigCache configCache)
/// </summary>
[AllowAnonymous]
[Transaction]
public Task<uint> ResetPasswordAsync(ResetPasswordReq req)
public Task<int> ResetPasswordAsync(ResetPasswordReq req)
{
return Cache.ResetPasswordAsync(req);
}
@ -195,7 +203,7 @@ public sealed class UserController(IUserCache cache, IConfigCache configCache)
/// 启用/禁用用户
/// </summary>
[Transaction]
public Task SetEnabledAsync(SetUserEnabledReq req)
public Task<int> SetEnabledAsync(SetUserEnabledReq req)
{
return Cache.SetEnabledAsync(req);
}
@ -213,11 +221,19 @@ public sealed class UserController(IUserCache cache, IConfigCache configCache)
/// 设置密码
/// </summary>
[Transaction]
public Task<uint> SetPasswordAsync(SetPasswordReq req)
public Task<int> SetPasswordAsync(SetPasswordReq req)
{
return Cache.SetPasswordAsync(req);
}
/// <summary>
/// 设置当前用户应用配置
/// </summary>
public Task<int> SetSessionUserAppConfigAsync(SetSessionUserAppConfigReq req)
{
return Cache.SetSessionUserAppConfigAsync(req);
}
/// <summary>
/// 当前用户信息
/// </summary>