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

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