mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-12-22 14:05:48 +08:00
feat: ✨ 框架代码同步
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using NetAdmin.Domain.DbMaps.Sys;
|
||||
using NetAdmin.Domain.DbMaps.Sys;
|
||||
|
||||
namespace NetAdmin.Domain.Dto.Sys.Api;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
namespace NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑计划作业执行记录
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Domain.Dto.Sys.LoginLog;
|
||||
namespace NetAdmin.Domain.Dto.Sys.LoginLog;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑登录日志
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Domain.Dto.Sys.RequestLog;
|
||||
namespace NetAdmin.Domain.Dto.Sys.RequestLog;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑请求日志
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Domain.Dto.Sys.RequestLogDetail;
|
||||
namespace NetAdmin.Domain.Dto.Sys.RequestLogDetail;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑请求日志明细
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Domain.Dto.Sys.SiteMsgDept;
|
||||
namespace NetAdmin.Domain.Dto.Sys.SiteMsgDept;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑站内信-部门映射
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Domain.Dto.Sys.SiteMsgFlag;
|
||||
namespace NetAdmin.Domain.Dto.Sys.SiteMsgFlag;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑站内信标记
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Domain.Dto.Sys.SiteMsgRole;
|
||||
namespace NetAdmin.Domain.Dto.Sys.SiteMsgRole;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑站内信-角色映射
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Domain.Dto.Sys.SiteMsgUser;
|
||||
namespace NetAdmin.Domain.Dto.Sys.SiteMsgUser;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑站内信-用户映射
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using NetAdmin.Domain.DbMaps.Sys;
|
||||
|
||||
namespace NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:创建用户-角色映射
|
||||
/// </summary>
|
||||
public record CreateUserRoleReq : Sys_UserRole;
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑用户-角色映射
|
||||
/// </summary>
|
||||
public sealed record EditUserRoleReq : CreateUserRoleReq;
|
||||
@@ -0,0 +1,8 @@
|
||||
using NetAdmin.Domain.DbMaps.Sys;
|
||||
|
||||
namespace NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:查询用户-角色映射
|
||||
/// </summary>
|
||||
public sealed record QueryUserRoleReq : Sys_UserRole;
|
||||
@@ -0,0 +1,13 @@
|
||||
using NetAdmin.Domain.DbMaps.Sys;
|
||||
|
||||
namespace NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
/// <summary>
|
||||
/// 响应:查询用户-角色映射
|
||||
/// </summary>
|
||||
public sealed record QueryUserRoleRsp : Sys_UserRole
|
||||
{
|
||||
/// <inheritdoc cref="EntityBase{T}.Id" />
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public override long Id { get; init; }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Domain.Dto.Sys.VerifyCode;
|
||||
namespace NetAdmin.Domain.Dto.Sys.VerifyCode;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑验证码
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Domain.Dto.Tpl.Example;
|
||||
namespace NetAdmin.Domain.Dto.Tpl.Example;
|
||||
|
||||
/// <summary>
|
||||
/// 请求:编辑示例
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CronExpressionDescriptor" Version="2.36.0"/>
|
||||
<PackageReference Include="Cronos" Version="0.8.4"/>
|
||||
<PackageReference Include="Cronos" Version="0.9.0"/>
|
||||
<PackageReference Include="NetAdmin.CsvHelper" Version="1.0.0"/>
|
||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14"/>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Infrastructure.Enums;
|
||||
namespace NetAdmin.Infrastructure.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 枚举扩展方法
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NetAdmin.Infrastructure.Extensions;
|
||||
namespace NetAdmin.Infrastructure.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// CountryCodes 扩展方法
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Role;
|
||||
using NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
@@ -25,4 +26,9 @@ public interface IRoleModule : ICrudModule<CreateRoleReq, QueryRoleRsp // 创建
|
||||
/// 设置是否忽略权限控制
|
||||
/// </summary>
|
||||
Task<int> SetIgnorePermissionControlAsync(SetIgnorePermissionControlReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 角色用户映射分组计数
|
||||
/// </summary>
|
||||
Task<IOrderedEnumerable<KeyValuePair<IImmutableDictionary<string, string>, int>>> UserCountByAsync(QueryReq<QueryUserRoleReq> req);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
/// <summary>
|
||||
/// 用户-角色映射模块
|
||||
/// </summary>
|
||||
public interface IUserRoleModule : ICrudModule<CreateUserRoleReq, QueryUserRoleRsp // 创建类型
|
||||
, EditUserRoleReq // 编辑类型
|
||||
, QueryUserRoleReq, QueryUserRoleRsp // 查询类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
||||
@@ -1,3 +1,3 @@
|
||||
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve">
|
||||
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules_005Csys_005Csession/@EntryIndexedValue">True</s:Boolean>
|
||||
</wpf:ResourceDictionary>
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
/// <summary>
|
||||
/// 用户角-色映射服务
|
||||
/// </summary>
|
||||
public interface IUserRoleService : IService, IUserRoleModule;
|
||||
@@ -1,10 +1,11 @@
|
||||
using NetAdmin.Domain.DbMaps.Sys;
|
||||
using NetAdmin.Domain.Dto.Sys.Role;
|
||||
using NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IRoleService" />
|
||||
public sealed class RoleService(BasicRepository<Sys_Role, long> rpo) //
|
||||
public sealed class RoleService(BasicRepository<Sys_Role, long> rpo, IUserRoleService userRoleService) //
|
||||
: RepositoryService<Sys_Role, long, IRoleService>(rpo), IRoleService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -134,6 +135,13 @@ public sealed class RoleService(BasicRepository<Sys_Role, long> rpo) //
|
||||
return UpdateAsync(req, [nameof(req.IgnorePermissionControl)]);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IOrderedEnumerable<KeyValuePair<IImmutableDictionary<string, string>, int>>> UserCountByAsync(QueryReq<QueryUserRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return userRoleService.CountByAsync(req);
|
||||
}
|
||||
|
||||
private ISelect<Sys_Role> QueryInternal(QueryReq<QueryRoleReq> req)
|
||||
{
|
||||
#pragma warning disable RCS1196
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
using NetAdmin.Domain.DbMaps.Sys;
|
||||
using NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IUserRoleService" />
|
||||
public sealed class UserRoleService(BasicRepository<Sys_UserRole, long> rpo) //
|
||||
: RepositoryService<Sys_UserRole, long, IUserRoleService>(rpo), IUserRoleService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = 0;
|
||||
|
||||
// ReSharper disable once LoopCanBeConvertedToQuery
|
||||
foreach (var item in req.Items) {
|
||||
ret += await DeleteAsync(item).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<long> CountAsync(QueryReq<QueryUserRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).WithNoLockNoWait().CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IOrderedEnumerable<KeyValuePair<IImmutableDictionary<string, string>, int>>> CountByAsync(QueryReq<QueryUserRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req with { Order = Orders.None })
|
||||
.WithNoLockNoWait()
|
||||
.GroupBy(req.GetToListExp<Sys_UserRole>())
|
||||
.ToDictionaryAsync(a => a.Count())
|
||||
.ConfigureAwait(false);
|
||||
return ret.Select(x => new KeyValuePair<IImmutableDictionary<string, string>, int>(
|
||||
req.RequiredFields.ToImmutableDictionary(y => y, y => typeof(Sys_UserRole).GetProperty(y)!.GetValue(x.Key)!.ToString())
|
||||
, x.Value))
|
||||
.OrderByDescending(x => x.Value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryUserRoleRsp> CreateAsync(CreateUserRoleReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await Rpo.InsertAsync(req).ConfigureAwait(false);
|
||||
return ret.Adapt<QueryUserRoleRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<int> DeleteAsync(DelReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return Rpo.DeleteAsync(a => a.Id == req.Id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<QueryUserRoleRsp> EditAsync(EditUserRoleReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IActionResult> ExportAsync(QueryReq<QueryUserRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryUserRoleRsp> GetAsync(QueryUserRoleReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(new QueryReq<QueryUserRoleReq> { Filter = req, Order = Orders.None }).ToOneAsync().ConfigureAwait(false);
|
||||
return ret.Adapt<QueryUserRoleRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<PagedQueryRsp<QueryUserRoleRsp>> PagedQueryAsync(PagedQueryReq<QueryUserRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req).Page(req.Page, req.PageSize).WithNoLockNoWait().Count(out var total).ToListAsync().ConfigureAwait(false);
|
||||
|
||||
return new PagedQueryRsp<QueryUserRoleRsp>(req.Page, req.PageSize, total, list.Adapt<IEnumerable<QueryUserRoleRsp>>());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IEnumerable<QueryUserRoleRsp>> QueryAsync(QueryReq<QueryUserRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).WithNoLockNoWait().Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryUserRoleRsp>>();
|
||||
}
|
||||
|
||||
private ISelect<Sys_UserRole> QueryInternal(QueryReq<QueryUserRoleReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
||||
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
|
||||
switch (req.Order) {
|
||||
case Orders.None:
|
||||
return ret;
|
||||
case Orders.Random:
|
||||
return ret.OrderByRandom();
|
||||
}
|
||||
|
||||
ret = ret.OrderByPropertyNameIf(req.Prop?.Length > 0, req.Prop, req.Order == Orders.Ascending);
|
||||
if (!req.Prop?.Equals(nameof(req.Filter.Id), StringComparison.OrdinalIgnoreCase) ?? true) {
|
||||
ret = ret.OrderByDescending(a => a.Id);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Role;
|
||||
using NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
namespace NetAdmin.SysComponent.Cache.Sys;
|
||||
|
||||
@@ -83,4 +84,10 @@ public sealed class RoleCache(IDistributedCache cache, IRoleService service) //
|
||||
{
|
||||
return Service.SetIgnorePermissionControlAsync(req);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IOrderedEnumerable<KeyValuePair<IImmutableDictionary<string, string>, int>>> UserCountByAsync(QueryReq<QueryUserRoleReq> req)
|
||||
{
|
||||
return Service.UserCountByAsync(req);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Role;
|
||||
using NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
namespace NetAdmin.SysComponent.Host.Controllers.Sys;
|
||||
|
||||
@@ -116,4 +117,12 @@ public sealed class RoleController(IRoleCache cache) : ControllerBase<IRoleCache
|
||||
{
|
||||
return Cache.SetIgnorePermissionControlAsync(req);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色用户映射分组计数
|
||||
/// </summary>
|
||||
public Task<IOrderedEnumerable<KeyValuePair<IImmutableDictionary<string, string>, int>>> UserCountByAsync(QueryReq<QueryUserRoleReq> req)
|
||||
{
|
||||
return Cache.UserCountByAsync(req);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using NetAdmin.Domain.Dto.Sys.Role;
|
||||
using NetAdmin.Domain.Dto.Sys.UserRole;
|
||||
|
||||
namespace UnitTests.Sys;
|
||||
|
||||
@@ -139,4 +140,14 @@ public class RoleTests(WebTestApplicationFactory<Startup> factory, ITestOutputHe
|
||||
Assert.True(rsp.IsSuccessStatusCode);
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[InlineData(default)]
|
||||
[Theory]
|
||||
public async Task<IOrderedEnumerable<KeyValuePair<IImmutableDictionary<string, string>, int>>> UserCountByAsync(QueryReq<QueryUserRoleReq> req)
|
||||
{
|
||||
var rsp = await PostJsonAsync(typeof(RoleController), req);
|
||||
Assert.True(rsp.IsSuccessStatusCode);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user