mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-06-20 18:58:16 +08:00
refactor: ♻️ 基础框架的实体更新逻辑 (#137)
Co-authored-by: tk <fiyne1a@dingtalk.com>
This commit is contained in:
@ -9,7 +9,6 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IApiModule : ICrudModule<CreateApiReq, QueryApiRsp // 创建类型
|
||||
, QueryApiReq, QueryApiRsp // 查询类型
|
||||
, NopReq, NopReq // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>
|
||||
{
|
||||
|
@ -9,10 +9,14 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IConfigModule : ICrudModule<CreateConfigReq, QueryConfigRsp // 创建类型
|
||||
, QueryConfigReq, QueryConfigRsp // 查询类型
|
||||
, UpdateConfigReq, QueryConfigRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑配置
|
||||
/// </summary>
|
||||
Task<QueryConfigRsp> EditAsync(EditConfigReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 获取最新有效配置
|
||||
/// </summary>
|
||||
|
@ -9,6 +9,11 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IDeptModule : ICrudModule<CreateDeptReq, QueryDeptRsp // 创建类型
|
||||
, QueryDeptReq, QueryDeptRsp // 查询类型
|
||||
, UpdateDeptReq, QueryDeptRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
||||
>
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑部门
|
||||
/// </summary>
|
||||
Task<QueryDeptRsp> EditAsync(EditDeptReq req);
|
||||
}
|
@ -9,6 +9,5 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IDicCatalogModule : ICrudModule<CreateDicCatalogReq, QueryDicCatalogRsp // 创建类型
|
||||
, QueryDicCatalogReq, QueryDicCatalogRsp // 查询类型
|
||||
, UpdateDicCatalogReq, QueryDicCatalogRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
@ -9,6 +9,5 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IDicContentModule : ICrudModule<CreateDicContentReq, QueryDicContentRsp // 创建类型
|
||||
, QueryDicContentReq, QueryDicContentRsp // 查询类型
|
||||
, UpdateDicContentReq, QueryDicContentRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
@ -39,6 +39,16 @@ public interface IDicModule
|
||||
/// </summary>
|
||||
Task<int> DeleteContentAsync(DelReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 编辑字典目录
|
||||
/// </summary>
|
||||
Task<int> EditCatalogAsync(EditDicCatalogReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 编辑字典内容
|
||||
/// </summary>
|
||||
Task<QueryDicContentRsp> EditContentAsync(EditDicContentReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 获取单个字典目录
|
||||
/// </summary>
|
||||
@ -73,14 +83,4 @@ public interface IDicModule
|
||||
/// 查询字典内容
|
||||
/// </summary>
|
||||
Task<IEnumerable<QueryDicContentRsp>> QueryContentAsync(QueryReq<QueryDicContentReq> req);
|
||||
|
||||
/// <summary>
|
||||
/// 更新字典目录
|
||||
/// </summary>
|
||||
Task<QueryDicCatalogRsp> UpdateCatalogAsync(UpdateDicCatalogReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 更新字典内容
|
||||
/// </summary>
|
||||
Task<QueryDicContentRsp> UpdateContentAsync(UpdateDicContentReq req);
|
||||
}
|
@ -11,14 +11,13 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IJobModule : ICrudModule<CreateJobReq, QueryJobRsp // 创建类型
|
||||
, QueryJobReq, QueryJobRsp // 查询类型
|
||||
, UpdateJobReq, QueryJobRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑作业
|
||||
/// </summary>
|
||||
Task<QueryJobRsp> EditAsync(UpdateJobReq req);
|
||||
Task<QueryJobRsp> EditAsync(EditJobReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 执行作业
|
||||
@ -51,7 +50,7 @@ public interface IJobModule : ICrudModule<CreateJobReq, QueryJobRsp // 创建类
|
||||
Task<PagedQueryRsp<QueryJobRecordRsp>> RecordPagedQueryAsync(PagedQueryReq<QueryJobRecordReq> req);
|
||||
|
||||
/// <summary>
|
||||
/// 启用/禁用作业
|
||||
/// 设置计划作业启用状态
|
||||
/// </summary>
|
||||
Task SetEnabledAsync(UpdateJobReq req);
|
||||
Task SetEnabledAsync(SetJobEnabledReq req);
|
||||
}
|
@ -9,6 +9,5 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IJobRecordModule : ICrudModule<CreateJobRecordReq, QueryJobRecordRsp // 创建类型
|
||||
, QueryJobRecordReq, QueryJobRecordRsp // 查询类型
|
||||
, UpdateJobRecordReq, QueryJobRecordRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
@ -9,10 +9,14 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IMenuModule : ICrudModule<CreateMenuReq, QueryMenuRsp // 创建类型
|
||||
, QueryMenuReq, QueryMenuRsp // 查询类型
|
||||
, UpdateMenuReq, QueryMenuRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑菜单
|
||||
/// </summary>
|
||||
Task<QueryMenuRsp> EditAsync(EditMenuReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户菜单
|
||||
/// </summary>
|
||||
|
@ -10,7 +10,6 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IRequestLogModule : ICrudModule<CreateRequestLogReq, QueryRequestLogRsp // 创建类型
|
||||
, QueryRequestLogReq, QueryRequestLogRsp // 查询类型
|
||||
, NopReq, NopReq // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>
|
||||
{
|
||||
|
@ -9,6 +9,11 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IRoleModule : ICrudModule<CreateRoleReq, QueryRoleRsp // 创建类型
|
||||
, QueryRoleReq, QueryRoleRsp // 查询类型
|
||||
, UpdateRoleReq, QueryRoleRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
||||
>
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑角色
|
||||
/// </summary>
|
||||
Task<QueryRoleRsp> EditAsync(EditRoleReq req);
|
||||
}
|
@ -9,6 +9,5 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface ISiteMsgDeptModule : ICrudModule<CreateSiteMsgDeptReq, QuerySiteMsgDeptRsp // 创建类型
|
||||
, QuerySiteMsgDeptReq, QuerySiteMsgDeptRsp // 查询类型
|
||||
, UpdateSiteMsgDeptReq, QuerySiteMsgDeptRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
@ -9,6 +9,5 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface ISiteMsgFlagModule : ICrudModule<CreateSiteMsgFlagReq, QuerySiteMsgFlagRsp // 创建类型
|
||||
, QuerySiteMsgFlagReq, QuerySiteMsgFlagRsp // 查询类型
|
||||
, UpdateSiteMsgFlagReq, QuerySiteMsgFlagRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
@ -10,10 +10,14 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface ISiteMsgModule : ICrudModule<CreateSiteMsgReq, QuerySiteMsgRsp // 创建类型
|
||||
, QuerySiteMsgReq, QuerySiteMsgRsp // 查询类型
|
||||
, UpdateSiteMsgReq, QuerySiteMsgRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑站内信
|
||||
/// </summary>
|
||||
Task<QuerySiteMsgRsp> EditAsync(EditSiteMsgReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 获取单个我的站内信
|
||||
/// </summary>
|
||||
@ -27,7 +31,7 @@ public interface ISiteMsgModule : ICrudModule<CreateSiteMsgReq, QuerySiteMsgRsp
|
||||
/// <summary>
|
||||
/// 设置站内信状态
|
||||
/// </summary>
|
||||
Task SetSiteMsgStatusAsync(UpdateSiteMsgFlagReq req);
|
||||
Task SetSiteMsgStatusAsync(SetUserSiteMsgStatusReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 未读数量
|
||||
|
@ -9,6 +9,5 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface ISiteMsgRoleModule : ICrudModule<CreateSiteMsgRoleReq, QuerySiteMsgRoleRsp // 创建类型
|
||||
, QuerySiteMsgRoleReq, QuerySiteMsgRoleRsp // 查询类型
|
||||
, UpdateSiteMsgRoleReq, QuerySiteMsgRoleRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
@ -9,6 +9,5 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface ISiteMsgUserModule : ICrudModule<CreateSiteMsgUserReq, QuerySiteMsgUserRsp // 创建类型
|
||||
, QuerySiteMsgUserReq, QuerySiteMsgUserRsp // 查询类型
|
||||
, UpdateSiteMsgUserReq, QuerySiteMsgUserRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
@ -10,7 +10,6 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IUserModule : ICrudModule<CreateUserReq, QueryUserRsp // 创建类型
|
||||
, QueryUserReq, QueryUserRsp // 查询类型
|
||||
, UpdateUserReq, QueryUserRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>
|
||||
{
|
||||
@ -24,6 +23,11 @@ public interface IUserModule : ICrudModule<CreateUserReq, QueryUserRsp // 创建
|
||||
/// </summary>
|
||||
Task<bool> CheckUserNameAvailableAsync(CheckUserNameAvailableReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 编辑用户
|
||||
/// </summary>
|
||||
Task<QueryUserRsp> EditAsync(EditUserReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 密码登录
|
||||
/// </summary>
|
||||
|
@ -9,6 +9,5 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IUserProfileModule : ICrudModule<CreateUserProfileReq, QueryUserProfileRsp // 创建类型
|
||||
, QueryUserProfileReq, QueryUserProfileRsp // 查询类型
|
||||
, UpdateUserProfileReq, QueryUserProfileRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
@ -9,7 +9,6 @@ namespace NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
/// </summary>
|
||||
public interface IVerifyCodeModule : ICrudModule<CreateVerifyCodeReq, QueryVerifyCodeRsp // 创建类型
|
||||
, QueryVerifyCodeReq, QueryVerifyCodeRsp // 查询类型
|
||||
, UpdateVerifyCodeReq, QueryVerifyCodeRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>
|
||||
{
|
||||
|
@ -9,6 +9,5 @@ namespace NetAdmin.SysComponent.Application.Modules.Tpl;
|
||||
/// </summary>
|
||||
public interface IExampleModule : ICrudModule<CreateExampleReq, QueryExampleRsp // 创建类型
|
||||
, QueryExampleReq, QueryExampleRsp // 查询类型
|
||||
, UpdateExampleReq, QueryExampleRsp // 修改类型
|
||||
, DelReq // 删除类型
|
||||
>;
|
@ -9,10 +9,10 @@ namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IApiService" />
|
||||
public sealed class ApiService(
|
||||
DefaultRepository<Sys_Api> rpo //
|
||||
BasicRepository<Sys_Api, string> rpo //
|
||||
, XmlCommentReader xmlCommentReader //
|
||||
, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider) //
|
||||
: RepositoryService<Sys_Api, IApiService>(rpo), IApiService
|
||||
: RepositoryService<Sys_Api, string, IApiService>(rpo), IApiService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -25,7 +25,11 @@ public sealed class ApiService(
|
||||
public Task<long> CountAsync(QueryReq<QueryApiReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -46,7 +50,11 @@ public sealed class ApiService(
|
||||
public Task<bool> ExistAsync(QueryReq<QueryApiReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -119,19 +127,6 @@ public sealed class ApiService(
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<NopReq> UpdateAsync(NopReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task<Sys_Api> UpdateForSqliteAsync(Sys_Api req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private IEnumerable<QueryApiRsp> GetChildren(IEnumerable<ControllerActionDescriptor> actionDescriptors)
|
||||
{
|
||||
return actionDescriptors //
|
||||
|
@ -4,13 +4,12 @@ using NetAdmin.Domain.DbMaps.Sys;
|
||||
using NetAdmin.Domain.Dto.Dependency;
|
||||
using NetAdmin.Domain.Dto.Sys.Config;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
using DataType = FreeSql.DataType;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IConfigService" />
|
||||
public sealed class ConfigService(DefaultRepository<Sys_Config> rpo) //
|
||||
: RepositoryService<Sys_Config, IConfigService>(rpo), IConfigService
|
||||
public sealed class ConfigService(BasicRepository<Sys_Config, long> rpo) //
|
||||
: RepositoryService<Sys_Config, long, IConfigService>(rpo), IConfigService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -30,7 +29,11 @@ public sealed class ConfigService(DefaultRepository<Sys_Config> rpo) //
|
||||
public Task<long> CountAsync(QueryReq<QueryConfigReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -48,11 +51,27 @@ public sealed class ConfigService(DefaultRepository<Sys_Config> rpo) //
|
||||
return Rpo.DeleteAsync(a => a.Id == req.Id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryConfigRsp> EditAsync(EditConfigReq req)
|
||||
{
|
||||
#if DBTYPE_SQLSERVER
|
||||
return (await UpdateEntityAsync(req, null).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryConfigRsp>();
|
||||
#else
|
||||
return await UpdateAsync(req, null).ConfigureAwait(false) > 0
|
||||
? await GetAsync(new QueryConfigReq { Id = req.Id }).ConfigureAwait(false)
|
||||
: null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ExistAsync(QueryReq<QueryConfigReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -78,6 +97,9 @@ public sealed class ConfigService(DefaultRepository<Sys_Config> rpo) //
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -90,30 +112,16 @@ public sealed class ConfigService(DefaultRepository<Sys_Config> rpo) //
|
||||
public async Task<IEnumerable<QueryConfigRsp>> QueryAsync(QueryReq<QueryConfigReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryConfigRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryConfigRsp> UpdateAsync(UpdateConfigReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
return await UpdateForSqliteAsync(req).ConfigureAwait(false) as QueryConfigRsp;
|
||||
}
|
||||
|
||||
var ret = await Rpo.UpdateDiy.SetSource(req).ExecuteUpdatedAsync().ConfigureAwait(false);
|
||||
return ret.FirstOrDefault()?.Adapt<QueryConfigRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Sys_Config> UpdateForSqliteAsync(Sys_Config req)
|
||||
{
|
||||
return await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QueryConfigReq { Id = req.Id }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private ISelect<Sys_Config> QueryInternal(QueryReq<QueryConfigReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.Include(a => a.UserRegisterDept)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using NetAdmin.Application.Services;
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Catalog;
|
||||
using NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
@ -6,4 +7,10 @@ namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
/// <summary>
|
||||
/// 字典目录服务
|
||||
/// </summary>
|
||||
public interface IDicCatalogService : IService, IDicCatalogModule;
|
||||
public interface IDicCatalogService : IService, IDicCatalogModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑字典目录
|
||||
/// </summary>
|
||||
Task<int> EditAsync(EditDicCatalogReq req);
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using NetAdmin.Application.Services;
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Content;
|
||||
using NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
@ -6,4 +7,10 @@ namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
/// <summary>
|
||||
/// 字典内容服务
|
||||
/// </summary>
|
||||
public interface IDicContentService : IService, IDicContentModule;
|
||||
public interface IDicContentService : IService, IDicContentModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑字典内容
|
||||
/// </summary>
|
||||
Task<QueryDicContentRsp> EditAsync(EditDicContentReq req);
|
||||
}
|
@ -12,7 +12,7 @@ public interface IJobService : IService, IJobModule
|
||||
/// <summary>
|
||||
/// 完成计划作业
|
||||
/// </summary>
|
||||
Task FinishJobAsync(UpdateJobReq req);
|
||||
Task FinishJobAsync(FinishJobReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 获取下一个要执行的计划作业
|
||||
|
@ -1,4 +1,5 @@
|
||||
using NetAdmin.Application.Services;
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgFlag;
|
||||
using NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
@ -6,4 +7,10 @@ namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
/// <summary>
|
||||
/// 站内信标记服务
|
||||
/// </summary>
|
||||
public interface ISiteMsgFlagService : IService, ISiteMsgFlagModule;
|
||||
public interface ISiteMsgFlagService : IService, ISiteMsgFlagModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置用户站内信状态
|
||||
/// </summary>
|
||||
Task SetUserSiteMsgStatusAsync(SetUserSiteMsgStatusReq req);
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using NetAdmin.Application.Services;
|
||||
using NetAdmin.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
@ -6,4 +7,10 @@ namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
/// <summary>
|
||||
/// 用户档案服务
|
||||
/// </summary>
|
||||
public interface IUserProfileService : IService, IUserProfileModule;
|
||||
public interface IUserProfileService : IService, IUserProfileModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑用户档案
|
||||
/// </summary>
|
||||
Task<int> EditAsync(EditUserProfileReq req);
|
||||
}
|
@ -9,18 +9,8 @@ namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
/// </summary>
|
||||
public interface IUserService : IService, IUserModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取单个用户(带更新锁)
|
||||
/// </summary>
|
||||
Task<QueryUserRsp> GetForUpdateAsync(QueryUserReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 用户编号登录
|
||||
/// </summary>
|
||||
Task<LoginRsp> LoginByUserIdAsync(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 单体更新
|
||||
/// </summary>
|
||||
Task UpdateSingleAsync(UpdateUserReq req);
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using NetAdmin.Application.Services;
|
||||
using NetAdmin.Domain.Dto.Sys.VerifyCode;
|
||||
using NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
@ -6,4 +7,10 @@ namespace NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
/// <summary>
|
||||
/// 验证码服务
|
||||
/// </summary>
|
||||
public interface IVerifyCodeService : IService, IVerifyCodeModule;
|
||||
public interface IVerifyCodeService : IService, IVerifyCodeModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置验证码状态
|
||||
/// </summary>
|
||||
Task<int> SetVerifyCodeStatusAsync(SetVerifyCodeStatusReq req);
|
||||
}
|
@ -8,8 +8,8 @@ using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IDeptService" />
|
||||
public sealed class DeptService(DefaultRepository<Sys_Dept> rpo) //
|
||||
: RepositoryService<Sys_Dept, IDeptService>(rpo), IDeptService
|
||||
public sealed class DeptService(BasicRepository<Sys_Dept, long> rpo) //
|
||||
: RepositoryService<Sys_Dept, long, IDeptService>(rpo), IDeptService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -29,7 +29,11 @@ public sealed class DeptService(DefaultRepository<Sys_Dept> rpo) //
|
||||
public Task<long> CountAsync(QueryReq<QueryDeptReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -65,11 +69,27 @@ public sealed class DeptService(DefaultRepository<Sys_Dept> rpo) //
|
||||
return await Rpo.DeleteAsync(x => x.Id == req.Id).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryDeptRsp> EditAsync(EditDeptReq req)
|
||||
{
|
||||
#if DBTYPE_SQLSERVER
|
||||
return (await UpdateEntityAsync(req, null).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryDeptRsp>();
|
||||
#else
|
||||
return await UpdateAsync(req, null).ConfigureAwait(false) > 0
|
||||
? await GetAsync(new QueryDeptReq { Id = req.Id }).ConfigureAwait(false)
|
||||
: null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ExistAsync(QueryReq<QueryDeptReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -91,25 +111,12 @@ public sealed class DeptService(DefaultRepository<Sys_Dept> rpo) //
|
||||
public async Task<IEnumerable<QueryDeptRsp>> QueryAsync(QueryReq<QueryDeptReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return (await QueryInternal(req).ToTreeListAsync().ConfigureAwait(false)).Adapt<IEnumerable<QueryDeptRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryDeptRsp> UpdateAsync(UpdateDeptReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: (await QueryInternal(new QueryReq<QueryDeptReq> { Filter = new QueryDeptReq { Id = req.Id } }, true)
|
||||
.ToTreeListAsync()
|
||||
.ConfigureAwait(false))[0]
|
||||
.Adapt<QueryDeptRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task<Sys_Dept> UpdateForSqliteAsync(Sys_Dept req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return (await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.ToTreeListAsync()
|
||||
.ConfigureAwait(false)).Adapt<IEnumerable<QueryDeptRsp>>();
|
||||
}
|
||||
|
||||
private ISelect<Sys_Dept> QueryInternal(QueryReq<QueryDeptReq> req, bool asTreeCte = false)
|
||||
|
@ -64,11 +64,6 @@ public sealed class DevService(IApiService apiService) : ServiceBase<DevService>
|
||||
, Path.Combine(dtoDir, $"Create{req.ModuleName}Req.cs"))
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// UpdateReq
|
||||
await WriteCodeFileAsync(req, Path.Combine(dataDir, "Dto", "Tpl", "Example", "UpdateExampleReq.cs")
|
||||
, Path.Combine(dtoDir, $"Update{req.ModuleName}Req.cs"))
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// QueryReq
|
||||
await WriteCodeFileAsync(req, Path.Combine(dataDir, "Dto", "Tpl", "Example", "QueryExampleReq.cs")
|
||||
, Path.Combine(dtoDir, $"Query{req.ModuleName}Req.cs"))
|
||||
|
@ -8,8 +8,8 @@ using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IDicCatalogService" />
|
||||
public sealed class DicCatalogService(DefaultRepository<Sys_DicCatalog> rpo) //
|
||||
: RepositoryService<Sys_DicCatalog, IDicCatalogService>(rpo), IDicCatalogService
|
||||
public sealed class DicCatalogService(BasicRepository<Sys_DicCatalog, long> rpo) //
|
||||
: RepositoryService<Sys_DicCatalog, long, IDicCatalogService>(rpo), IDicCatalogService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -29,7 +29,11 @@ public sealed class DicCatalogService(DefaultRepository<Sys_DicCatalog> rpo) //
|
||||
public Task<long> CountAsync(QueryReq<QueryDicCatalogReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -54,11 +58,26 @@ public sealed class DicCatalogService(DefaultRepository<Sys_DicCatalog> rpo) //
|
||||
return ret.Count;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="NetAdminInvalidOperationException">The_parent_node_does_not_exist</exception>
|
||||
public async Task<int> EditAsync(EditDicCatalogReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return req.ParentId == 0 ||
|
||||
await Rpo.Where(a => a.Id == req.ParentId).ForUpdate().AnyAsync().ConfigureAwait(false)
|
||||
? await UpdateAsync(req, null).ConfigureAwait(false)
|
||||
: throw new NetAdminInvalidOperationException(Ln.父节点不存在);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ExistAsync(QueryReq<QueryDicCatalogReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -77,6 +96,9 @@ public sealed class DicCatalogService(DefaultRepository<Sys_DicCatalog> rpo) //
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -89,34 +111,15 @@ public sealed class DicCatalogService(DefaultRepository<Sys_DicCatalog> rpo) //
|
||||
public async Task<IEnumerable<QueryDicCatalogRsp>> QueryAsync(QueryReq<QueryDicCatalogReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).ToTreeListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.ToTreeListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryDicCatalogRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="NetAdminInvalidOperationException">The_parent_node_does_not_exist</exception>
|
||||
public async Task<QueryDicCatalogRsp> UpdateAsync(UpdateDicCatalogReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (req.ParentId != 0 &&
|
||||
!await Rpo.Where(a => a.Id == req.ParentId).ForUpdate().AnyAsync().ConfigureAwait(false)) {
|
||||
throw new NetAdminInvalidOperationException(Ln.父节点不存在);
|
||||
}
|
||||
|
||||
if (await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var ret = await Rpo.Where(a => a.Id == req.Id).ToOneAsync().ConfigureAwait(false);
|
||||
return ret.Adapt<QueryDicCatalogRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task<Sys_DicCatalog> UpdateForSqliteAsync(Sys_DicCatalog req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private ISelect<Sys_DicCatalog> QueryInternal(QueryReq<QueryDicCatalogReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
@ -8,8 +8,8 @@ using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IDicContentService" />
|
||||
public sealed class DicContentService(DefaultRepository<Sys_DicContent> rpo) //
|
||||
: RepositoryService<Sys_DicContent, IDicContentService>(rpo), IDicContentService
|
||||
public sealed class DicContentService(BasicRepository<Sys_DicContent, long> rpo) //
|
||||
: RepositoryService<Sys_DicContent, long, IDicContentService>(rpo), IDicContentService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -29,7 +29,11 @@ public sealed class DicContentService(DefaultRepository<Sys_DicContent> rpo) //
|
||||
public Task<long> CountAsync(QueryReq<QueryDicContentReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -56,11 +60,37 @@ public sealed class DicContentService(DefaultRepository<Sys_DicContent> rpo) //
|
||||
return Rpo.DeleteAsync(a => a.Id == req.Id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="NetAdminInvalidOperationException">Dictionary_directory_does_not_exist</exception>
|
||||
public async Task<QueryDicContentRsp> EditAsync(EditDicContentReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (!await Rpo.Orm.Select<Sys_DicCatalog>()
|
||||
.Where(a => a.Id == req.CatalogId)
|
||||
.ForUpdate()
|
||||
.AnyAsync()
|
||||
.ConfigureAwait(false)) {
|
||||
throw new NetAdminInvalidOperationException(Ln.字典目录不存在);
|
||||
}
|
||||
|
||||
#if DBTYPE_SQLSERVER
|
||||
return (await UpdateEntityAsync(req, null).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryDicContentRsp>();
|
||||
#else
|
||||
return await UpdateAsync(req, null).ConfigureAwait(false) > 0
|
||||
? await GetAsync(new QueryDicContentReq { Id = req.Id }).ConfigureAwait(false)
|
||||
: null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ExistAsync(QueryReq<QueryDicContentReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -79,6 +109,9 @@ public sealed class DicContentService(DefaultRepository<Sys_DicContent> rpo) //
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -91,37 +124,16 @@ public sealed class DicContentService(DefaultRepository<Sys_DicContent> rpo) //
|
||||
public async Task<IEnumerable<QueryDicContentRsp>> QueryAsync(QueryReq<QueryDicContentReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryDicContentRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="NetAdminInvalidOperationException">Dictionary_directory_does_not_exist</exception>
|
||||
public async Task<QueryDicContentRsp> UpdateAsync(UpdateDicContentReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (!await Rpo.Orm.Select<Sys_DicCatalog>()
|
||||
.Where(a => a.Id == req.CatalogId)
|
||||
.ForUpdate()
|
||||
.AnyAsync()
|
||||
.ConfigureAwait(false)) {
|
||||
throw new NetAdminInvalidOperationException(Ln.字典目录不存在);
|
||||
}
|
||||
|
||||
if (await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var ret = await Rpo.Where(a => a.Id == req.Id).ToOneAsync().ConfigureAwait(false);
|
||||
return ret.Adapt<QueryDicContentRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task<Sys_DicContent> UpdateForSqliteAsync(Sys_DicContent req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private ISelect<Sys_DicContent> QueryInternal(QueryReq<QueryDicContentReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
@ -52,6 +52,20 @@ public sealed class DicService(IDicCatalogService catalogService, IDicContentSer
|
||||
return contentService.DeleteAsync(req);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<int> EditCatalogAsync(EditDicCatalogReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return catalogService.EditAsync(req);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<QueryDicContentRsp> EditContentAsync(EditDicContentReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return contentService.EditAsync(req);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<QueryDicCatalogRsp> GetCatalogAsync(QueryDicCatalogReq req)
|
||||
{
|
||||
@ -115,18 +129,4 @@ public sealed class DicService(IDicCatalogService catalogService, IDicContentSer
|
||||
req.ThrowIfInvalid();
|
||||
return contentService.QueryAsync(req);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<QueryDicCatalogRsp> UpdateCatalogAsync(UpdateDicCatalogReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return catalogService.UpdateAsync(req);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<QueryDicContentRsp> UpdateContentAsync(UpdateDicContentReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return contentService.UpdateAsync(req);
|
||||
}
|
||||
}
|
@ -5,13 +5,12 @@ using NetAdmin.Domain.Dto.Dependency;
|
||||
using NetAdmin.Domain.Dto.Sys;
|
||||
using NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
using DataType = FreeSql.DataType;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IJobRecordService" />
|
||||
public sealed class JobRecordService(DefaultRepository<Sys_JobRecord> rpo) //
|
||||
: RepositoryService<Sys_JobRecord, IJobRecordService>(rpo), IJobRecordService
|
||||
public sealed class JobRecordService(BasicRepository<Sys_JobRecord, long> rpo) //
|
||||
: RepositoryService<Sys_JobRecord, long, IJobRecordService>(rpo), IJobRecordService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -31,7 +30,11 @@ public sealed class JobRecordService(DefaultRepository<Sys_JobRecord> rpo) //
|
||||
public Task<long> CountAsync(QueryReq<QueryJobRecordReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -53,7 +56,11 @@ public sealed class JobRecordService(DefaultRepository<Sys_JobRecord> rpo) //
|
||||
public Task<bool> ExistAsync(QueryReq<QueryJobRecordReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -72,6 +79,9 @@ public sealed class JobRecordService(DefaultRepository<Sys_JobRecord> rpo) //
|
||||
req.ThrowIfInvalid();
|
||||
|
||||
var ret = await QueryInternal(req with { Order = Orders.None })
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.GroupBy(a => new {
|
||||
a.CreatedTime.Year
|
||||
, a.CreatedTime.Month
|
||||
@ -94,6 +104,9 @@ public sealed class JobRecordService(DefaultRepository<Sys_JobRecord> rpo) //
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req with { Order = Orders.None })
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Include(a => a.Job)
|
||||
.GroupBy(a => a.HttpStatusCode)
|
||||
#pragma warning disable CA1305
|
||||
@ -109,6 +122,9 @@ public sealed class JobRecordService(DefaultRepository<Sys_JobRecord> rpo) //
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req with { Order = Orders.None })
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Include(a => a.Job)
|
||||
.GroupBy(a => a.Job.JobName)
|
||||
.ToListAsync(a => new GetPieChartRsp { Value = a.Count(), Key = a.Key })
|
||||
@ -122,6 +138,9 @@ public sealed class JobRecordService(DefaultRepository<Sys_JobRecord> rpo) //
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -134,30 +153,16 @@ public sealed class JobRecordService(DefaultRepository<Sys_JobRecord> rpo) //
|
||||
public async Task<IEnumerable<QueryJobRecordRsp>> QueryAsync(QueryReq<QueryJobRecordReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryJobRecordRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryJobRecordRsp> UpdateAsync(UpdateJobRecordReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
return await UpdateForSqliteAsync(req).ConfigureAwait(false) as QueryJobRecordRsp;
|
||||
}
|
||||
|
||||
var ret = await Rpo.UpdateDiy.SetSource(req).ExecuteUpdatedAsync().ConfigureAwait(false);
|
||||
return ret.FirstOrDefault()?.Adapt<QueryJobRecordRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Sys_JobRecord> UpdateForSqliteAsync(Sys_JobRecord req)
|
||||
{
|
||||
return await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QueryJobRecordReq { Id = req.Id }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private ISelect<Sys_JobRecord> QueryInternal(QueryReq<QueryJobRecordReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter)
|
||||
|
@ -9,13 +9,12 @@ using NetAdmin.Domain.Dto.Sys.Job;
|
||||
using NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
using NetAdmin.Domain.Enums.Sys;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
using DataType = FreeSql.DataType;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IJobService" />
|
||||
public sealed class JobService(DefaultRepository<Sys_Job> rpo, IJobRecordService jobRecordService) //
|
||||
: RepositoryService<Sys_Job, IJobService>(rpo), IJobService
|
||||
public sealed class JobService(BasicRepository<Sys_Job, long> rpo, IJobRecordService jobRecordService) //
|
||||
: RepositoryService<Sys_Job, long, IJobService>(rpo), IJobService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -35,7 +34,11 @@ public sealed class JobService(DefaultRepository<Sys_Job> rpo, IJobRecordService
|
||||
public Task<long> CountAsync(QueryReq<QueryJobReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -61,7 +64,7 @@ public sealed class JobService(DefaultRepository<Sys_Job> rpo, IJobRecordService
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryJobRsp> EditAsync(UpdateJobReq req)
|
||||
public async Task<QueryJobRsp> EditAsync(EditJobReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var update = Rpo.UpdateDiy.Set(a => a.ExecutionCron == req.ExecutionCron)
|
||||
@ -72,17 +75,16 @@ public sealed class JobService(DefaultRepository<Sys_Job> rpo, IJobRecordService
|
||||
.Set(a => a.RequestBody == req.RequestBody)
|
||||
.Set(a => a.RequestUrl == req.RequestUrl)
|
||||
.Set(a => a.UserId == req.UserId)
|
||||
.Where(a => a.Id == req.Id);
|
||||
.Where(a => a.Id == req.Id)
|
||||
.Where(a => a.Version == req.Version);
|
||||
|
||||
#pragma warning disable IDE0046
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
#pragma warning restore IDE0046
|
||||
return await update.ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QueryJobReq { Id = req.Id }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return (await update.ExecuteUpdatedAsync().ConfigureAwait(false))[0].Adapt<QueryJobRsp>();
|
||||
#if DBTYPE_SQLSERVER
|
||||
return (await update.ExecuteUpdatedAsync().ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryJobRsp>();
|
||||
#else
|
||||
return await update.ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QueryJobReq { Id = req.Id }).ConfigureAwait(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -109,14 +111,13 @@ public sealed class JobService(DefaultRepository<Sys_Job> rpo, IJobRecordService
|
||||
|
||||
var nextExecTime = GetNextExecTime(Chars.FLG_CRON_PER_SECS);
|
||||
try {
|
||||
_ = await UpdateAsync(job.Adapt<UpdateJobReq>() with {
|
||||
NextExecTime = nextExecTime
|
||||
, NextTimeId = nextExecTime?.TimeUnixUtc()
|
||||
})
|
||||
_ = await UpdateAsync( //
|
||||
job with { NextExecTime = nextExecTime, NextTimeId = nextExecTime?.TimeUnixUtc() }
|
||||
, [nameof(job.NextExecTime), nameof(job.NextTimeId)])
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (DbUpdateVersionException) {
|
||||
throw new NetAdminInvalidOperationException(Ln.并发冲突请稍后重试);
|
||||
throw new NetAdminInvalidOperationException(Ln.并发冲突_请稍后重试);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,19 +125,28 @@ public sealed class JobService(DefaultRepository<Sys_Job> rpo, IJobRecordService
|
||||
public Task<bool> ExistAsync(QueryReq<QueryJobReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task FinishJobAsync(UpdateJobReq req)
|
||||
public async Task FinishJobAsync(FinishJobReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var nextExecTime = GetNextExecTime(req.ExecutionCron);
|
||||
_ = await UpdateAsync(req with {
|
||||
Status = JobStatues.Idle
|
||||
, NextExecTime = nextExecTime
|
||||
, NextTimeId = nextExecTime?.TimeUnixUtc()
|
||||
})
|
||||
_ = await UpdateAsync(
|
||||
req with {
|
||||
Status = JobStatues.Idle
|
||||
, NextExecTime = nextExecTime
|
||||
, NextTimeId = nextExecTime?.TimeUnixUtc()
|
||||
}
|
||||
, [
|
||||
nameof(req.Status), nameof(req.NextExecTime), nameof(req.NextTimeId), nameof(req.LastDuration)
|
||||
, nameof(req.LastStatusCode)
|
||||
])
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@ -178,13 +188,25 @@ public sealed class JobService(DefaultRepository<Sys_Job> rpo, IJobRecordService
|
||||
.Any())
|
||||
.ToOneAsync()
|
||||
.ConfigureAwait(false);
|
||||
return job == null
|
||||
? null
|
||||
: await UpdateAsync(job.Adapt<UpdateJobReq>() with {
|
||||
Status = JobStatues.Running
|
||||
, LastExecTime = DateTime.Now
|
||||
})
|
||||
.ConfigureAwait(false);
|
||||
if (job == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
#if DBTYPE_SQLSERVER
|
||||
var ret = await UpdateEntityAsync( //
|
||||
job with { Status = JobStatues.Running, LastExecTime = DateTime.Now }
|
||||
, [nameof(job.Status), nameof(job.LastExecTime)])
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return ret.FirstOrDefault()?.Adapt<QueryJobRsp>();
|
||||
#else
|
||||
return await UpdateAsync( //
|
||||
job with { Status = JobStatues.Running, LastExecTime = DateTime.Now }
|
||||
, [nameof(job.Status), nameof(job.LastExecTime)])
|
||||
.ConfigureAwait(false) > 0
|
||||
? await GetAsync(new QueryJobReq { Id = job.Id }).ConfigureAwait(false)
|
||||
: null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -215,6 +237,9 @@ public sealed class JobService(DefaultRepository<Sys_Job> rpo, IJobRecordService
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -226,7 +251,13 @@ public sealed class JobService(DefaultRepository<Sys_Job> rpo, IJobRecordService
|
||||
public async Task<IEnumerable<QueryJobRsp>> QueryAsync(QueryReq<QueryJobReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryJobRsp>>();
|
||||
}
|
||||
|
||||
@ -247,36 +278,16 @@ public sealed class JobService(DefaultRepository<Sys_Job> rpo, IJobRecordService
|
||||
/// <inheritdoc />
|
||||
public Task<int> ReleaseStuckTaskAsync()
|
||||
{
|
||||
return Rpo.UpdateDiy.Set(a => a.Status == JobStatues.Idle)
|
||||
.Where(a => a.Status == JobStatues.Running &&
|
||||
a.LastExecTime < DateTime.Now.AddSeconds(-Numbers.SECS_TIMEOUT_JOB))
|
||||
.ExecuteAffrowsAsync();
|
||||
return UpdateAsync( //
|
||||
new Sys_Job { Status = JobStatues.Idle }, [nameof(Sys_Job.Status)], null
|
||||
, a => a.Status == JobStatues.Running && a.LastExecTime < DateTime.Now.AddSeconds(-Numbers.SECS_TIMEOUT_JOB));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetEnabledAsync(UpdateJobReq req)
|
||||
public Task SetEnabledAsync(SetJobEnabledReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return Rpo.UpdateDiy.Set(a => a.Enabled == req.Enabled).Where(a => a.Id == req.Id).ExecuteAffrowsAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryJobRsp> UpdateAsync(UpdateJobReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
return (await UpdateForSqliteAsync(req).ConfigureAwait(false)).Adapt<QueryJobRsp>();
|
||||
}
|
||||
|
||||
_ = await Rpo.UpdateAsync(req).ConfigureAwait(false);
|
||||
return req.Adapt<QueryJobRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Sys_Job> UpdateForSqliteAsync(Sys_Job req)
|
||||
{
|
||||
_ = await Rpo.UpdateAsync(req).ConfigureAwait(false);
|
||||
return req;
|
||||
return UpdateAsync(req, [nameof(Sys_Job.Enabled)]);
|
||||
}
|
||||
|
||||
private static DateTime? GetNextExecTime(string cron)
|
||||
|
@ -8,8 +8,8 @@ using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IMenuService" />
|
||||
public sealed class MenuService(DefaultRepository<Sys_Menu> rpo, IUserService userService) //
|
||||
: RepositoryService<Sys_Menu, IMenuService>(rpo), IMenuService
|
||||
public sealed class MenuService(BasicRepository<Sys_Menu, long> rpo, IUserService userService) //
|
||||
: RepositoryService<Sys_Menu, long, IMenuService>(rpo), IMenuService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -29,7 +29,11 @@ public sealed class MenuService(DefaultRepository<Sys_Menu> rpo, IUserService us
|
||||
public Task<long> CountAsync(QueryReq<QueryMenuReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -52,11 +56,27 @@ public sealed class MenuService(DefaultRepository<Sys_Menu> rpo, IUserService us
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryMenuRsp> EditAsync(EditMenuReq req)
|
||||
{
|
||||
#if DBTYPE_SQLSERVER
|
||||
return (await UpdateEntityAsync(req, null).ConfigureAwait(false)).FirstOrDefault()?.Adapt<QueryMenuRsp>();
|
||||
#else
|
||||
return await UpdateAsync(req, null).ConfigureAwait(false) > 0
|
||||
? await GetAsync(new QueryMenuReq { Id = req.Id }).ConfigureAwait(false)
|
||||
: null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ExistAsync(QueryReq<QueryMenuReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -78,22 +98,15 @@ public sealed class MenuService(DefaultRepository<Sys_Menu> rpo, IUserService us
|
||||
public async Task<IEnumerable<QueryMenuRsp>> QueryAsync(QueryReq<QueryMenuReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).ToTreeListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.ToTreeListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryMenuRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryMenuRsp> UpdateAsync(UpdateMenuReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var ret = await Rpo.Where(a => a.Id == req.Id).ToOneAsync().ConfigureAwait(false);
|
||||
return ret.Adapt<QueryMenuRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IEnumerable<QueryMenuRsp>> UserMenusAsync()
|
||||
{
|
||||
@ -122,12 +135,6 @@ public sealed class MenuService(DefaultRepository<Sys_Menu> rpo, IUserService us
|
||||
return await ret.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task<Sys_Menu> UpdateForSqliteAsync(Sys_Menu req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private ISelect<Sys_Menu> QueryInternal(QueryReq<QueryMenuReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
@ -9,8 +9,8 @@ using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IRequestLogService" />
|
||||
public sealed class RequestLogService(DefaultRepository<Sys_RequestLog> rpo) //
|
||||
: RepositoryService<Sys_RequestLog, IRequestLogService>(rpo), IRequestLogService
|
||||
public sealed class RequestLogService(BasicRepository<Sys_RequestLog, long> rpo) //
|
||||
: RepositoryService<Sys_RequestLog, long, IRequestLogService>(rpo), IRequestLogService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -30,7 +30,11 @@ public sealed class RequestLogService(DefaultRepository<Sys_RequestLog> rpo) //
|
||||
public Task<long> CountAsync(QueryReq<QueryRequestLogReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -52,7 +56,11 @@ public sealed class RequestLogService(DefaultRepository<Sys_RequestLog> rpo) //
|
||||
public Task<bool> ExistAsync(QueryReq<QueryRequestLogReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -71,6 +79,9 @@ public sealed class RequestLogService(DefaultRepository<Sys_RequestLog> rpo) //
|
||||
req.ThrowIfInvalid();
|
||||
|
||||
var ret = await QueryInternal(req with { Order = Orders.None })
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.GroupBy(a => new {
|
||||
a.CreatedTime.Year
|
||||
, a.CreatedTime.Month
|
||||
@ -92,6 +103,9 @@ public sealed class RequestLogService(DefaultRepository<Sys_RequestLog> rpo) //
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req with { Order = Orders.None })
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.GroupBy(a => a.Api.Summary)
|
||||
.ToListAsync(a => new GetPieChartRsp { Value = a.Count(), Key = a.Key })
|
||||
.ConfigureAwait(false);
|
||||
@ -104,6 +118,9 @@ public sealed class RequestLogService(DefaultRepository<Sys_RequestLog> rpo) //
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req with { Order = Orders.None })
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.GroupBy(a => a.HttpStatusCode)
|
||||
#pragma warning disable CA1305
|
||||
.ToListAsync(a => new GetPieChartRsp { Value = a.Count(), Key = a.Key.ToString() })
|
||||
@ -119,6 +136,9 @@ public sealed class RequestLogService(DefaultRepository<Sys_RequestLog> rpo) //
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync(a => new {
|
||||
a.ApiId
|
||||
@ -143,23 +163,16 @@ public sealed class RequestLogService(DefaultRepository<Sys_RequestLog> rpo) //
|
||||
public async Task<IEnumerable<QueryRequestLogRsp>> QueryAsync(QueryReq<QueryRequestLogReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryRequestLogRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<NopReq> UpdateAsync(NopReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task<Sys_RequestLog> UpdateForSqliteAsync(Sys_RequestLog req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private ISelect<Sys_RequestLog> QueryInternal(QueryReq<QueryRequestLogReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.Include(a => a.Api).WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
@ -8,8 +8,8 @@ using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IRoleService" />
|
||||
public sealed class RoleService(DefaultRepository<Sys_Role> rpo) //
|
||||
: RepositoryService<Sys_Role, IRoleService>(rpo), IRoleService
|
||||
public sealed class RoleService(BasicRepository<Sys_Role, long> rpo) //
|
||||
: RepositoryService<Sys_Role, long, IRoleService>(rpo), IRoleService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -29,7 +29,11 @@ public sealed class RoleService(DefaultRepository<Sys_Role> rpo) //
|
||||
public Task<long> CountAsync(QueryReq<QueryRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -57,11 +61,29 @@ public sealed class RoleService(DefaultRepository<Sys_Role> rpo) //
|
||||
: await Rpo.DeleteAsync(a => a.Id == req.Id).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryRoleRsp> EditAsync(EditRoleReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var entity = req.Adapt<Sys_Role>();
|
||||
_ = await Rpo.UpdateAsync(entity).ConfigureAwait(false);
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Depts)).ConfigureAwait(false);
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Menus)).ConfigureAwait(false);
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Apis)).ConfigureAwait(false);
|
||||
|
||||
return (await QueryAsync(new QueryReq<QueryRoleReq> { Filter = new QueryRoleReq { Id = req.Id } })
|
||||
.ConfigureAwait(false)).First();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ExistAsync(QueryReq<QueryRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -78,6 +100,9 @@ public sealed class RoleService(DefaultRepository<Sys_Role> rpo) //
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -89,30 +114,15 @@ public sealed class RoleService(DefaultRepository<Sys_Role> rpo) //
|
||||
public async Task<IEnumerable<QueryRoleRsp>> QueryAsync(QueryReq<QueryRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryRoleRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryRoleRsp> UpdateAsync(UpdateRoleReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var entity = req.Adapt<Sys_Role>();
|
||||
_ = await Rpo.UpdateAsync(entity).ConfigureAwait(false);
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Depts)).ConfigureAwait(false);
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Menus)).ConfigureAwait(false);
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Apis)).ConfigureAwait(false);
|
||||
|
||||
return (await QueryAsync(new QueryReq<QueryRoleReq> { Filter = new QueryRoleReq { Id = req.Id } })
|
||||
.ConfigureAwait(false)).First();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task<Sys_Role> UpdateForSqliteAsync(Sys_Role req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private ISelect<Sys_Role> QueryInternal(QueryReq<QueryRoleReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.IncludeMany(a => a.Depts.Select(b => new Sys_Dept { Id = b.Id }))
|
||||
|
@ -4,13 +4,12 @@ using NetAdmin.Domain.DbMaps.Sys;
|
||||
using NetAdmin.Domain.Dto.Dependency;
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgDept;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
using DataType = FreeSql.DataType;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="ISiteMsgDeptService" />
|
||||
public sealed class SiteMsgDeptService(DefaultRepository<Sys_SiteMsgDept> rpo) //
|
||||
: RepositoryService<Sys_SiteMsgDept, ISiteMsgDeptService>(rpo), ISiteMsgDeptService
|
||||
public sealed class SiteMsgDeptService(BasicRepository<Sys_SiteMsgDept, long> rpo) //
|
||||
: RepositoryService<Sys_SiteMsgDept, long, ISiteMsgDeptService>(rpo), ISiteMsgDeptService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -30,7 +29,11 @@ public sealed class SiteMsgDeptService(DefaultRepository<Sys_SiteMsgDept> rpo) /
|
||||
public Task<long> CountAsync(QueryReq<QuerySiteMsgDeptReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -52,7 +55,11 @@ public sealed class SiteMsgDeptService(DefaultRepository<Sys_SiteMsgDept> rpo) /
|
||||
public Task<bool> ExistAsync(QueryReq<QuerySiteMsgDeptReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -71,6 +78,9 @@ public sealed class SiteMsgDeptService(DefaultRepository<Sys_SiteMsgDept> rpo) /
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -83,30 +93,16 @@ public sealed class SiteMsgDeptService(DefaultRepository<Sys_SiteMsgDept> rpo) /
|
||||
public async Task<IEnumerable<QuerySiteMsgDeptRsp>> QueryAsync(QueryReq<QuerySiteMsgDeptReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QuerySiteMsgDeptRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QuerySiteMsgDeptRsp> UpdateAsync(UpdateSiteMsgDeptReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
return await UpdateForSqliteAsync(req).ConfigureAwait(false) as QuerySiteMsgDeptRsp;
|
||||
}
|
||||
|
||||
var ret = await Rpo.UpdateDiy.SetSource(req).ExecuteUpdatedAsync().ConfigureAwait(false);
|
||||
return ret.FirstOrDefault()?.Adapt<QuerySiteMsgDeptRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Sys_SiteMsgDept> UpdateForSqliteAsync(Sys_SiteMsgDept req)
|
||||
{
|
||||
return await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QuerySiteMsgDeptReq { Id = req.Id }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private ISelect<Sys_SiteMsgDept> QueryInternal(QueryReq<QuerySiteMsgDeptReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
@ -4,13 +4,12 @@ using NetAdmin.Domain.DbMaps.Sys;
|
||||
using NetAdmin.Domain.Dto.Dependency;
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgFlag;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
using DataType = FreeSql.DataType;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="ISiteMsgFlagService" />
|
||||
public sealed class SiteMsgFlagService(DefaultRepository<Sys_SiteMsgFlag> rpo) //
|
||||
: RepositoryService<Sys_SiteMsgFlag, ISiteMsgFlagService>(rpo), ISiteMsgFlagService
|
||||
public sealed class SiteMsgFlagService(BasicRepository<Sys_SiteMsgFlag, long> rpo) //
|
||||
: RepositoryService<Sys_SiteMsgFlag, long, ISiteMsgFlagService>(rpo), ISiteMsgFlagService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -30,7 +29,11 @@ public sealed class SiteMsgFlagService(DefaultRepository<Sys_SiteMsgFlag> rpo) /
|
||||
public Task<long> CountAsync(QueryReq<QuerySiteMsgFlagReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -52,7 +55,11 @@ public sealed class SiteMsgFlagService(DefaultRepository<Sys_SiteMsgFlag> rpo) /
|
||||
public Task<bool> ExistAsync(QueryReq<QuerySiteMsgFlagReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -71,6 +78,9 @@ public sealed class SiteMsgFlagService(DefaultRepository<Sys_SiteMsgFlag> rpo) /
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -83,34 +93,22 @@ public sealed class SiteMsgFlagService(DefaultRepository<Sys_SiteMsgFlag> rpo) /
|
||||
public async Task<IEnumerable<QuerySiteMsgFlagRsp>> QueryAsync(QueryReq<QuerySiteMsgFlagReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QuerySiteMsgFlagRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QuerySiteMsgFlagRsp> UpdateAsync(UpdateSiteMsgFlagReq req)
|
||||
public Task SetUserSiteMsgStatusAsync(SetUserSiteMsgStatusReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
return await UpdateForSqliteAsync(req).ConfigureAwait(false) as QuerySiteMsgFlagRsp;
|
||||
}
|
||||
|
||||
var ret = await Rpo.UpdateDiy.Set(a => a.UserSiteMsgStatus == req.UserSiteMsgStatus)
|
||||
.Where(a => a.UserId == req.UserId && a.SiteMsgId == req.SiteMsgId)
|
||||
.ExecuteUpdatedAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.FirstOrDefault()?.Adapt<QuerySiteMsgFlagRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Sys_SiteMsgFlag> UpdateForSqliteAsync(Sys_SiteMsgFlag req)
|
||||
{
|
||||
return await Rpo.UpdateDiy.Set(a => a.UserSiteMsgStatus == req.UserSiteMsgStatus)
|
||||
.Where(a => a.UserId == req.UserId && a.SiteMsgId == req.SiteMsgId)
|
||||
.ExecuteAffrowsAsync()
|
||||
.ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QuerySiteMsgFlagReq { Id = req.Id }).ConfigureAwait(false);
|
||||
return UpdateAsync(req, [nameof(req.UserSiteMsgStatus)], null
|
||||
, a => a.UserId == req.UserId && a.SiteMsgId == req.SiteMsgId);
|
||||
}
|
||||
|
||||
private ISelect<Sys_SiteMsgFlag> QueryInternal(QueryReq<QuerySiteMsgFlagReq> req)
|
||||
|
@ -4,13 +4,12 @@ using NetAdmin.Domain.DbMaps.Sys;
|
||||
using NetAdmin.Domain.Dto.Dependency;
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgRole;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
using DataType = FreeSql.DataType;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="ISiteMsgRoleService" />
|
||||
public sealed class SiteMsgRoleService(DefaultRepository<Sys_SiteMsgRole> rpo) //
|
||||
: RepositoryService<Sys_SiteMsgRole, ISiteMsgRoleService>(rpo), ISiteMsgRoleService
|
||||
public sealed class SiteMsgRoleService(BasicRepository<Sys_SiteMsgRole, long> rpo) //
|
||||
: RepositoryService<Sys_SiteMsgRole, long, ISiteMsgRoleService>(rpo), ISiteMsgRoleService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -30,7 +29,11 @@ public sealed class SiteMsgRoleService(DefaultRepository<Sys_SiteMsgRole> rpo) /
|
||||
public Task<long> CountAsync(QueryReq<QuerySiteMsgRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -52,7 +55,11 @@ public sealed class SiteMsgRoleService(DefaultRepository<Sys_SiteMsgRole> rpo) /
|
||||
public Task<bool> ExistAsync(QueryReq<QuerySiteMsgRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -71,6 +78,9 @@ public sealed class SiteMsgRoleService(DefaultRepository<Sys_SiteMsgRole> rpo) /
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -83,30 +93,16 @@ public sealed class SiteMsgRoleService(DefaultRepository<Sys_SiteMsgRole> rpo) /
|
||||
public async Task<IEnumerable<QuerySiteMsgRoleRsp>> QueryAsync(QueryReq<QuerySiteMsgRoleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QuerySiteMsgRoleRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QuerySiteMsgRoleRsp> UpdateAsync(UpdateSiteMsgRoleReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
return await UpdateForSqliteAsync(req).ConfigureAwait(false) as QuerySiteMsgRoleRsp;
|
||||
}
|
||||
|
||||
var ret = await Rpo.UpdateDiy.SetSource(req).ExecuteUpdatedAsync().ConfigureAwait(false);
|
||||
return ret.FirstOrDefault()?.Adapt<QuerySiteMsgRoleRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Sys_SiteMsgRole> UpdateForSqliteAsync(Sys_SiteMsgRole req)
|
||||
{
|
||||
return await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QuerySiteMsgRoleReq { Id = req.Id }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private ISelect<Sys_SiteMsgRole> QueryInternal(QueryReq<QuerySiteMsgRoleReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
@ -13,10 +13,10 @@ namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="ISiteMsgService" />
|
||||
public sealed class SiteMsgService(
|
||||
DefaultRepository<Sys_SiteMsg> rpo
|
||||
, ContextUserInfo contextUserInfo
|
||||
, ISiteMsgFlagService siteMsgFlagService) //
|
||||
: RepositoryService<Sys_SiteMsg, ISiteMsgService>(rpo), ISiteMsgService
|
||||
BasicRepository<Sys_SiteMsg, long> rpo
|
||||
, ContextUserInfo contextUserInfo
|
||||
, ISiteMsgFlagService siteMsgFlagService) //
|
||||
: RepositoryService<Sys_SiteMsg, long, ISiteMsgService>(rpo), ISiteMsgService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -36,14 +36,18 @@ public sealed class SiteMsgService(
|
||||
public Task<long> CountAsync(QueryReq<QuerySiteMsgReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QuerySiteMsgRsp> CreateAsync(CreateSiteMsgReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
await CreateUpdateCheckAsync(req).ConfigureAwait(false);
|
||||
await CreateEditCheckAsync(req).ConfigureAwait(false);
|
||||
|
||||
// 主表
|
||||
var entity = req.Adapt<Sys_SiteMsg>();
|
||||
@ -72,11 +76,38 @@ public sealed class SiteMsgService(
|
||||
return ret.Count;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QuerySiteMsgRsp> EditAsync(EditSiteMsgReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
await CreateEditCheckAsync(req).ConfigureAwait(false);
|
||||
|
||||
// 主表
|
||||
var entity = req.Adapt<Sys_SiteMsg>();
|
||||
_ = await UpdateAsync(entity, null).ConfigureAwait(false);
|
||||
|
||||
// 分表
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Roles)).ConfigureAwait(false);
|
||||
|
||||
// 分表
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Users)).ConfigureAwait(false);
|
||||
|
||||
// 分表
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Depts)).ConfigureAwait(false);
|
||||
|
||||
return (await QueryAsync(new QueryReq<QuerySiteMsgReq> { Filter = new QuerySiteMsgReq { Id = req.Id } })
|
||||
.ConfigureAwait(false)).First();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ExistAsync(QueryReq<QuerySiteMsgReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -115,6 +146,9 @@ public sealed class SiteMsgService(
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync(a => new {
|
||||
a.CreatedTime
|
||||
@ -142,12 +176,18 @@ public sealed class SiteMsgService(
|
||||
public async Task<IEnumerable<QuerySiteMsgRsp>> QueryAsync(QueryReq<QuerySiteMsgReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QuerySiteMsgRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SetSiteMsgStatusAsync(UpdateSiteMsgFlagReq req)
|
||||
public async Task SetSiteMsgStatusAsync(SetUserSiteMsgStatusReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (!await ExistAsync(new QueryReq<QuerySiteMsgReq> { Filter = new QuerySiteMsgReq { Id = req.SiteMsgId } })
|
||||
@ -159,7 +199,8 @@ public sealed class SiteMsgService(
|
||||
_ = await siteMsgFlagService.CreateAsync(req with { UserId = contextUserInfo.Id }).ConfigureAwait(false);
|
||||
}
|
||||
catch {
|
||||
_ = await siteMsgFlagService.UpdateAsync(req with { UserId = contextUserInfo.Id }).ConfigureAwait(false);
|
||||
await siteMsgFlagService.SetUserSiteMsgStatusAsync(req with { UserId = contextUserInfo.Id })
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,38 +217,7 @@ public sealed class SiteMsgService(
|
||||
return await QueryMineInternal(new QueryReq<QuerySiteMsgReq>()).CountAsync().ConfigureAwait(false) - subtract;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QuerySiteMsgRsp> UpdateAsync(UpdateSiteMsgReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
await CreateUpdateCheckAsync(req).ConfigureAwait(false);
|
||||
|
||||
// 主表
|
||||
var entity = req.Adapt<Sys_SiteMsg>();
|
||||
_ = await Rpo.UpdateDiy.SetSource(entity).ExecuteAffrowsAsync().ConfigureAwait(false);
|
||||
|
||||
// 分表
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Roles)).ConfigureAwait(false);
|
||||
|
||||
// 分表
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Users)).ConfigureAwait(false);
|
||||
|
||||
// 分表
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Depts)).ConfigureAwait(false);
|
||||
|
||||
return (await QueryAsync(new QueryReq<QuerySiteMsgReq> { Filter = new QuerySiteMsgReq { Id = req.Id } })
|
||||
.ConfigureAwait(false)).First();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Sys_SiteMsg> UpdateForSqliteAsync(Sys_SiteMsg req)
|
||||
{
|
||||
return await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QuerySiteMsgReq { Id = req.Id }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task CreateUpdateCheckAsync(CreateSiteMsgReq req)
|
||||
private async Task CreateEditCheckAsync(CreateSiteMsgReq req)
|
||||
{
|
||||
// 检查角色是否存在
|
||||
if (!req.RoleIds.NullOrEmpty()) {
|
||||
@ -306,19 +316,22 @@ public sealed class SiteMsgService(
|
||||
{
|
||||
var roleIds = contextUserInfo.Roles.Select(x => x.Id).ToList();
|
||||
|
||||
return Rpo.Orm
|
||||
.Select<Sys_SiteMsg, Sys_User, Sys_SiteMsgDept, Sys_SiteMsgRole, Sys_SiteMsgUser, Sys_SiteMsgFlag>()
|
||||
.LeftJoin((a, b, _, _, _, _) => a.CreatedUserId == b.Id)
|
||||
.LeftJoin((a, _, c, _, _, _) => a.Id == c.SiteMsgId)
|
||||
.LeftJoin((a, _, _, d, _, _) => a.Id == d.SiteMsgId)
|
||||
.LeftJoin((a, _, _, _, e, _) => a.Id == e.SiteMsgId)
|
||||
.LeftJoin((a, _, _, _, _, f) => a.Id == f.SiteMsgId)
|
||||
.WhereDynamicFilter(req.DynamicFilter)
|
||||
.Where((a, _, c, d, e, f) =>
|
||||
(SqlExt.EqualIsNull(f.UserSiteMsgStatus) ||
|
||||
f.UserSiteMsgStatus != UserSiteMsgStatues.Deleted) &&
|
||||
(a.MsgType == SiteMsgTypes.Public || c.DeptId == contextUserInfo.DeptId ||
|
||||
roleIds.Contains(d.RoleId) || e.UserId == contextUserInfo.Id))
|
||||
.GroupBy((a, _, _, _, _, _) => a.Id);
|
||||
return Rpo
|
||||
.Orm.Select<Sys_SiteMsg, Sys_User, Sys_SiteMsgDept, Sys_SiteMsgRole, Sys_SiteMsgUser, Sys_SiteMsgFlag>()
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.LeftJoin((a, b, _, _, _, _) => a.CreatedUserId == b.Id)
|
||||
.LeftJoin((a, _, c, _, _, _) => a.Id == c.SiteMsgId)
|
||||
.LeftJoin((a, _, _, d, _, _) => a.Id == d.SiteMsgId)
|
||||
.LeftJoin((a, _, _, _, e, _) => a.Id == e.SiteMsgId)
|
||||
.LeftJoin((a, _, _, _, _, f) => a.Id == f.SiteMsgId)
|
||||
.WhereDynamicFilter(req.DynamicFilter)
|
||||
.Where((a, _, c, d, e, f) =>
|
||||
(SqlExt.EqualIsNull(f.UserSiteMsgStatus) ||
|
||||
f.UserSiteMsgStatus != UserSiteMsgStatues.Deleted) &&
|
||||
(a.MsgType == SiteMsgTypes.Public || c.DeptId == contextUserInfo.DeptId ||
|
||||
roleIds.Contains(d.RoleId) || e.UserId == contextUserInfo.Id))
|
||||
.GroupBy((a, _, _, _, _, _) => a.Id);
|
||||
}
|
||||
}
|
@ -4,13 +4,12 @@ using NetAdmin.Domain.DbMaps.Sys;
|
||||
using NetAdmin.Domain.Dto.Dependency;
|
||||
using NetAdmin.Domain.Dto.Sys.SiteMsgUser;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
using DataType = FreeSql.DataType;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="ISiteMsgUserService" />
|
||||
public sealed class SiteMsgUserService(DefaultRepository<Sys_SiteMsgUser> rpo) //
|
||||
: RepositoryService<Sys_SiteMsgUser, ISiteMsgUserService>(rpo), ISiteMsgUserService
|
||||
public sealed class SiteMsgUserService(BasicRepository<Sys_SiteMsgUser, long> rpo) //
|
||||
: RepositoryService<Sys_SiteMsgUser, long, ISiteMsgUserService>(rpo), ISiteMsgUserService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -30,7 +29,11 @@ public sealed class SiteMsgUserService(DefaultRepository<Sys_SiteMsgUser> rpo) /
|
||||
public Task<long> CountAsync(QueryReq<QuerySiteMsgUserReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -52,7 +55,11 @@ public sealed class SiteMsgUserService(DefaultRepository<Sys_SiteMsgUser> rpo) /
|
||||
public Task<bool> ExistAsync(QueryReq<QuerySiteMsgUserReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -71,6 +78,9 @@ public sealed class SiteMsgUserService(DefaultRepository<Sys_SiteMsgUser> rpo) /
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -83,30 +93,16 @@ public sealed class SiteMsgUserService(DefaultRepository<Sys_SiteMsgUser> rpo) /
|
||||
public async Task<IEnumerable<QuerySiteMsgUserRsp>> QueryAsync(QueryReq<QuerySiteMsgUserReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QuerySiteMsgUserRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QuerySiteMsgUserRsp> UpdateAsync(UpdateSiteMsgUserReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
return await UpdateForSqliteAsync(req).ConfigureAwait(false) as QuerySiteMsgUserRsp;
|
||||
}
|
||||
|
||||
var ret = await Rpo.UpdateDiy.SetSource(req).ExecuteUpdatedAsync().ConfigureAwait(false);
|
||||
return ret.FirstOrDefault()?.Adapt<QuerySiteMsgUserRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Sys_SiteMsgUser> UpdateForSqliteAsync(Sys_SiteMsgUser req)
|
||||
{
|
||||
return await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QuerySiteMsgUserReq { Id = req.Id }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private ISelect<Sys_SiteMsgUser> QueryInternal(QueryReq<QuerySiteMsgUserReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
@ -5,13 +5,12 @@ using NetAdmin.Domain.Dto.Dependency;
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Content;
|
||||
using NetAdmin.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
using DataType = FreeSql.DataType;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IUserProfileService" />
|
||||
public sealed class UserProfileService(DefaultRepository<Sys_UserProfile> rpo) //
|
||||
: RepositoryService<Sys_UserProfile, IUserProfileService>(rpo), IUserProfileService
|
||||
public sealed class UserProfileService(BasicRepository<Sys_UserProfile, long> rpo) //
|
||||
: RepositoryService<Sys_UserProfile, long, IUserProfileService>(rpo), IUserProfileService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -31,7 +30,11 @@ public sealed class UserProfileService(DefaultRepository<Sys_UserProfile> rpo) /
|
||||
public Task<long> CountAsync(QueryReq<QueryUserProfileReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -50,11 +53,21 @@ public sealed class UserProfileService(DefaultRepository<Sys_UserProfile> rpo) /
|
||||
return Rpo.DeleteAsync(a => a.Id == req.Id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<int> EditAsync(EditUserProfileReq req)
|
||||
{
|
||||
return UpdateAsync(req, null);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ExistAsync(QueryReq<QueryUserProfileReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -73,6 +86,9 @@ public sealed class UserProfileService(DefaultRepository<Sys_UserProfile> rpo) /
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync((a, b, c, d, e) => new {
|
||||
a
|
||||
@ -99,6 +115,9 @@ public sealed class UserProfileService(DefaultRepository<Sys_UserProfile> rpo) /
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync((a, b, c, d, e) => new {
|
||||
a
|
||||
@ -128,27 +147,6 @@ public sealed class UserProfileService(DefaultRepository<Sys_UserProfile> rpo) /
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryUserProfileRsp> UpdateAsync(UpdateUserProfileReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var entity = req.Adapt<Sys_UserProfile>();
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
return await UpdateForSqliteAsync(entity).ConfigureAwait(false) as QueryUserProfileRsp;
|
||||
}
|
||||
|
||||
var ret = await Rpo.UpdateDiy.SetSource(entity).ExecuteUpdatedAsync().ConfigureAwait(false);
|
||||
return ret.FirstOrDefault()?.Adapt<QueryUserProfileRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Sys_UserProfile> UpdateForSqliteAsync(Sys_UserProfile req)
|
||||
{
|
||||
return await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QueryUserProfileReq { Id = req.Id }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private ISelect<Sys_UserProfile, Sys_DicContent, Sys_DicContent, Sys_DicContent, Sys_DicContent> QueryInternal(
|
||||
QueryReq<QueryUserProfileReq> req)
|
||||
{
|
||||
|
@ -14,11 +14,11 @@ namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IUserService" />
|
||||
public sealed class UserService(
|
||||
DefaultRepository<Sys_User> rpo //
|
||||
, IUserProfileService userProfileService //
|
||||
, IVerifyCodeService verifyCodeService //
|
||||
, IEventPublisher eventPublisher) //
|
||||
: RepositoryService<Sys_User, IUserService>(rpo), IUserService
|
||||
BasicRepository<Sys_User, long> rpo //
|
||||
, IUserProfileService userProfileService //
|
||||
, IVerifyCodeService verifyCodeService //
|
||||
, IEventPublisher eventPublisher) //
|
||||
: RepositoryService<Sys_User, long, IUserService>(rpo), IUserService
|
||||
{
|
||||
private readonly Expression<Func<Sys_User, Sys_User>> _selectUserFields = a => new Sys_User {
|
||||
Id = a.Id
|
||||
@ -69,7 +69,11 @@ public sealed class UserService(
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
#pragma warning disable VSTHRD103
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
#pragma warning restore VSTHRD103
|
||||
}
|
||||
|
||||
@ -77,7 +81,7 @@ public sealed class UserService(
|
||||
public async Task<QueryUserRsp> CreateAsync(CreateUserReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
await CreateUpdateCheckAsync(req).ConfigureAwait(false);
|
||||
await CreateEditCheckAsync(req).ConfigureAwait(false);
|
||||
|
||||
// 主表
|
||||
var entity = req.Adapt<Sys_User>();
|
||||
@ -111,6 +115,37 @@ public sealed class UserService(
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryUserRsp> EditAsync(EditUserReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
await CreateEditCheckAsync(req).ConfigureAwait(false);
|
||||
|
||||
// 主表
|
||||
var entity = req.Adapt<Sys_User>();
|
||||
var ignoreCols = new List<string> { nameof(Sys_User.Id), nameof(Sys_User.Token) };
|
||||
if (entity.Password == Guid.Empty) {
|
||||
ignoreCols.Add(nameof(Sys_User.Password));
|
||||
}
|
||||
|
||||
_ = await UpdateAsync(entity, null, ignoreCols.ToArray()).ConfigureAwait(false);
|
||||
|
||||
// 档案表
|
||||
if (req.Profile != null) {
|
||||
_ = await userProfileService.EditAsync(req.Profile).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// 分表
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Roles)).ConfigureAwait(false);
|
||||
|
||||
var ret = (await QueryAsync(new QueryReq<QueryUserReq> { Filter = new QueryUserReq { Id = req.Id } })
|
||||
.ConfigureAwait(false)).First();
|
||||
|
||||
// 发布用户更新事件
|
||||
await eventPublisher.PublishAsync(new UserUpdatedEvent(ret.Adapt<UserInfoRsp>())).ConfigureAwait(false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> ExistAsync(QueryReq<QueryUserReq> req)
|
||||
{
|
||||
@ -128,20 +163,6 @@ public sealed class UserService(
|
||||
return ret.Adapt<QueryUserRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryUserRsp> GetForUpdateAsync(QueryUserReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
|
||||
// ReSharper disable once MethodHasAsyncOverload
|
||||
#pragma warning disable VSTHRD103,S6966
|
||||
return (await QueryInternal(new QueryReq<QueryUserReq> { Filter = req })
|
||||
#pragma warning restore S6966, VSTHRD103
|
||||
.ForUpdate()
|
||||
.ToOneAsync()
|
||||
.ConfigureAwait(false)).Adapt<QueryUserRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="NetAdminInvalidOperationException">用户名或密码错误</exception>
|
||||
public async Task<LoginRsp> LoginByPwdAsync(LoginByPwdReq req)
|
||||
@ -195,6 +216,10 @@ public sealed class UserService(
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var list = await (await QueryInternalAsync(req).ConfigureAwait(false)).Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock |
|
||||
SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync(_selectUserFields)
|
||||
.ConfigureAwait(false);
|
||||
@ -237,33 +262,31 @@ public sealed class UserService(
|
||||
public async Task<uint> ResetPasswordAsync(ResetPasswordReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return !await verifyCodeService.VerifyAsync(req.VerifySmsCodeReq).ConfigureAwait(false)
|
||||
? throw new NetAdminInvalidOperationException(Ln.验证码不正确)
|
||||
: (uint)await Rpo.UpdateDiy
|
||||
.SetSource((await Rpo.Where(a => a.Mobile == req.VerifySmsCodeReq.DestDevice)
|
||||
.ToOneAsync(a => new { a.Version, a.Id })
|
||||
.ConfigureAwait(false)).Adapt<Sys_User>() with {
|
||||
Password = req.PasswordText.Pwd().Guid()
|
||||
})
|
||||
.UpdateColumns(a => a.Password)
|
||||
.ExecuteAffrowsAsync()
|
||||
.ConfigureAwait(false);
|
||||
if (await verifyCodeService.VerifyAsync(req.VerifySmsCodeReq).ConfigureAwait(false)) {
|
||||
var dto = (await Rpo.Where(a => a.Mobile == req.VerifySmsCodeReq.DestDevice)
|
||||
.ToOneAsync(a => new { a.Version, a.Id })
|
||||
.ConfigureAwait(false)).Adapt<Sys_User>() with {
|
||||
Password = req.PasswordText.Pwd()
|
||||
.Guid()
|
||||
};
|
||||
return (uint)await UpdateAsync(dto, [nameof(Sys_User.Password)]).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
throw new NetAdminInvalidOperationException(Ln.验证码不正确);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<UserInfoRsp> SetAvatarAsync(SetAvatarReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (await Rpo.UpdateDiy
|
||||
.SetSource(req with {
|
||||
Id = UserToken.Id
|
||||
, Version = await Rpo.Where(a => a.Id == UserToken.Id)
|
||||
.ToOneAsync(a => a.Version)
|
||||
.ConfigureAwait(false)
|
||||
})
|
||||
.UpdateColumns(a => a.Avatar)
|
||||
.ExecuteAffrowsAsync()
|
||||
.ConfigureAwait(false) <= 0) {
|
||||
if (await UpdateAsync(
|
||||
req with {
|
||||
Id = UserToken.Id
|
||||
, Version = await Rpo.Where(a => a.Id == UserToken.Id)
|
||||
.ToOneAsync(a => a.Version)
|
||||
.ConfigureAwait(false)
|
||||
}, [nameof(Sys_User.Avatar)])
|
||||
.ConfigureAwait(false) <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -295,11 +318,10 @@ public sealed class UserService(
|
||||
}
|
||||
}
|
||||
|
||||
if (await Rpo.UpdateDiy
|
||||
.SetSource(new Sys_User { Email = req.DestDevice, Id = UserToken.Id, Version = user.Version })
|
||||
.UpdateColumns(a => a.Email)
|
||||
.ExecuteAffrowsAsync()
|
||||
.ConfigureAwait(false) <= 0) {
|
||||
if (await UpdateAsync( //
|
||||
new Sys_User { Email = req.DestDevice, Id = UserToken.Id, Version = user.Version }
|
||||
, [nameof(Sys_User.Email)])
|
||||
.ConfigureAwait(false) <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -316,7 +338,7 @@ public sealed class UserService(
|
||||
public Task SetEnabledAsync(SetUserEnabledReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return Rpo.UpdateDiy.Set(a => a.Enabled == req.Enabled).Where(a => a.Id == req.Id).ExecuteAffrowsAsync();
|
||||
return UpdateAsync(req, [nameof(req.Enabled)]);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -343,15 +365,14 @@ public sealed class UserService(
|
||||
throw new NetAdminInvalidOperationException($"{Ln.新手机号码验证码不正确}");
|
||||
}
|
||||
|
||||
if (await Rpo.UpdateDiy
|
||||
.SetSource(new Sys_User {
|
||||
Version = user.Version
|
||||
, Id = UserToken.Id
|
||||
, Mobile = req.NewVerifySmsCodeReq.DestDevice
|
||||
})
|
||||
.UpdateColumns(a => a.Mobile)
|
||||
.ExecuteAffrowsAsync()
|
||||
.ConfigureAwait(false) <= 0) {
|
||||
if (await UpdateAsync(
|
||||
new Sys_User {
|
||||
Version = user.Version
|
||||
, Id = UserToken.Id
|
||||
, Mobile = req.NewVerifySmsCodeReq.DestDevice
|
||||
}
|
||||
, [nameof(Sys_User.Mobile)])
|
||||
.ConfigureAwait(false) <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -372,59 +393,13 @@ public sealed class UserService(
|
||||
.ToOneAsync(a => new long?(a.Version))
|
||||
.ConfigureAwait(false) ?? throw new NetAdminInvalidOperationException($"{Ln.旧密码不正确}");
|
||||
|
||||
var ret = await Rpo.UpdateDiy
|
||||
.SetSource(new Sys_User {
|
||||
Id = UserToken.Id
|
||||
, Password = req.NewPassword.Pwd().Guid()
|
||||
, Version = version
|
||||
})
|
||||
.UpdateColumns(a => a.Password)
|
||||
.ExecuteAffrowsAsync()
|
||||
.ConfigureAwait(false);
|
||||
var ret = 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 async Task<QueryUserRsp> UpdateAsync(UpdateUserReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
await CreateUpdateCheckAsync(req).ConfigureAwait(false);
|
||||
|
||||
// 主表
|
||||
var entity = req.Adapt<Sys_User>();
|
||||
var ignoreCols = new List<string> { nameof(Sys_User.Token) };
|
||||
if (entity.Password == Guid.Empty) {
|
||||
ignoreCols.Add(nameof(Sys_User.Password));
|
||||
}
|
||||
|
||||
_ = await Rpo.UpdateDiy.SetSource(entity)
|
||||
.IgnoreColumns(ignoreCols.ToArray())
|
||||
.ExecuteAffrowsAsync()
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// 档案表
|
||||
if (req.Profile != null) {
|
||||
_ = await userProfileService.UpdateAsync(req.Profile).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// 分表
|
||||
await Rpo.SaveManyAsync(entity, nameof(entity.Roles)).ConfigureAwait(false);
|
||||
|
||||
var ret = (await QueryAsync(new QueryReq<QueryUserReq> { Filter = new QueryUserReq { Id = req.Id } })
|
||||
.ConfigureAwait(false)).First();
|
||||
|
||||
// 发布用户更新事件
|
||||
await eventPublisher.PublishAsync(new UserUpdatedEvent(ret.Adapt<UserInfoRsp>())).ConfigureAwait(false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task UpdateSingleAsync(UpdateUserReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return Rpo.UpdateAsync(req);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<UserInfoRsp> UserInfoAsync()
|
||||
{
|
||||
@ -441,12 +416,6 @@ public sealed class UserService(
|
||||
return dbUser.Adapt<UserInfoRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task<Sys_User> UpdateForSqliteAsync(Sys_User req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static LoginRsp LoginInternal(Sys_User dbUser)
|
||||
{
|
||||
if (!dbUser.Enabled) {
|
||||
@ -463,7 +432,7 @@ public sealed class UserService(
|
||||
};
|
||||
}
|
||||
|
||||
private async Task CreateUpdateCheckAsync(CreateUpdateUserReq req)
|
||||
private async Task CreateEditCheckAsync(CreateEditUserReq req)
|
||||
{
|
||||
// 检查角色是否存在
|
||||
var roles = await Rpo.Orm.Select<Sys_Role>()
|
||||
|
@ -6,13 +6,12 @@ using NetAdmin.Domain.Dto.Sys.VerifyCode;
|
||||
using NetAdmin.Domain.Enums.Sys;
|
||||
using NetAdmin.Domain.Events.Sys;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
using DataType = FreeSql.DataType;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Sys;
|
||||
|
||||
/// <inheritdoc cref="IVerifyCodeService" />
|
||||
public sealed class VerifyCodeService(DefaultRepository<Sys_VerifyCode> rpo, IEventPublisher eventPublisher) //
|
||||
: RepositoryService<Sys_VerifyCode, IVerifyCodeService>(rpo), IVerifyCodeService
|
||||
public sealed class VerifyCodeService(BasicRepository<Sys_VerifyCode, long> rpo, IEventPublisher eventPublisher) //
|
||||
: RepositoryService<Sys_VerifyCode, long, IVerifyCodeService>(rpo), IVerifyCodeService
|
||||
{
|
||||
private static readonly int[] _randRange = [0, 10000];
|
||||
|
||||
@ -34,7 +33,11 @@ public sealed class VerifyCodeService(DefaultRepository<Sys_VerifyCode> rpo, IEv
|
||||
public Task<long> CountAsync(QueryReq<QueryVerifyCodeReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -62,7 +65,11 @@ public sealed class VerifyCodeService(DefaultRepository<Sys_VerifyCode> rpo, IEv
|
||||
public Task<bool> ExistAsync(QueryReq<QueryVerifyCodeReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -81,6 +88,9 @@ public sealed class VerifyCodeService(DefaultRepository<Sys_VerifyCode> rpo, IEv
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -93,7 +103,13 @@ public sealed class VerifyCodeService(DefaultRepository<Sys_VerifyCode> rpo, IEv
|
||||
public async Task<IEnumerable<QueryVerifyCodeRsp>> QueryAsync(QueryReq<QueryVerifyCodeReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryVerifyCodeRsp>>();
|
||||
}
|
||||
|
||||
@ -125,15 +141,9 @@ public sealed class VerifyCodeService(DefaultRepository<Sys_VerifyCode> rpo, IEv
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryVerifyCodeRsp> UpdateAsync(UpdateVerifyCodeReq req)
|
||||
public Task<int> SetVerifyCodeStatusAsync(SetVerifyCodeStatusReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
return await UpdateForSqliteAsync(req).ConfigureAwait(false) as QueryVerifyCodeRsp;
|
||||
}
|
||||
|
||||
var ret = await Rpo.UpdateDiy.SetSource(req).ExecuteUpdatedAsync().ConfigureAwait(false);
|
||||
return ret.FirstOrDefault()?.Adapt<QueryVerifyCodeRsp>();
|
||||
return UpdateAsync(req, [nameof(req.Status)]);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -156,20 +166,12 @@ public sealed class VerifyCodeService(DefaultRepository<Sys_VerifyCode> rpo, IEv
|
||||
return false;
|
||||
}
|
||||
|
||||
_ = await UpdateAsync((lastSent with { Status = VerifyCodeStatues.Verified }).Adapt<UpdateVerifyCodeReq>())
|
||||
_ = await UpdateAsync(lastSent with { Status = VerifyCodeStatues.Verified }, [nameof(lastSent.Status)])
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Sys_VerifyCode> UpdateForSqliteAsync(Sys_VerifyCode req)
|
||||
{
|
||||
return await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QueryVerifyCodeReq { Id = req.Id }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private Task<Sys_VerifyCode> GetLastSentAsync(string destDevice)
|
||||
{
|
||||
return QueryInternal(new QueryReq<QueryVerifyCodeReq> {
|
||||
@ -181,6 +183,9 @@ public sealed class VerifyCodeService(DefaultRepository<Sys_VerifyCode> rpo, IEv
|
||||
, Value = destDevice
|
||||
}
|
||||
})
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(1)
|
||||
.ToOneAsync();
|
||||
}
|
||||
|
@ -4,13 +4,12 @@ using NetAdmin.Domain.DbMaps.Tpl;
|
||||
using NetAdmin.Domain.Dto.Dependency;
|
||||
using NetAdmin.Domain.Dto.Tpl.Example;
|
||||
using NetAdmin.SysComponent.Application.Services.Tpl.Dependency;
|
||||
using DataType = FreeSql.DataType;
|
||||
|
||||
namespace NetAdmin.SysComponent.Application.Services.Tpl;
|
||||
|
||||
/// <inheritdoc cref="IExampleService" />
|
||||
public sealed class ExampleService(DefaultRepository<Tpl_Example> rpo) //
|
||||
: RepositoryService<Tpl_Example, IExampleService>(rpo), IExampleService
|
||||
public sealed class ExampleService(BasicRepository<Tpl_Example, long> rpo) //
|
||||
: RepositoryService<Tpl_Example, long, IExampleService>(rpo), IExampleService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<int> BulkDeleteAsync(BulkReq<DelReq> req)
|
||||
@ -30,7 +29,11 @@ public sealed class ExampleService(DefaultRepository<Tpl_Example> rpo) //
|
||||
public Task<long> CountAsync(QueryReq<QueryExampleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).CountAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -52,7 +55,11 @@ public sealed class ExampleService(DefaultRepository<Tpl_Example> rpo) //
|
||||
public Task<bool> ExistAsync(QueryReq<QueryExampleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
return QueryInternal(req).AnyAsync();
|
||||
return QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -71,6 +78,9 @@ public sealed class ExampleService(DefaultRepository<Tpl_Example> rpo) //
|
||||
req.ThrowIfInvalid();
|
||||
var list = await QueryInternal(req)
|
||||
.Page(req.Page, req.PageSize)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Count(out var total)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
@ -83,30 +93,16 @@ public sealed class ExampleService(DefaultRepository<Tpl_Example> rpo) //
|
||||
public async Task<IEnumerable<QueryExampleRsp>> QueryAsync(QueryReq<QueryExampleReq> req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
var ret = await QueryInternal(req).Take(req.Count).ToListAsync().ConfigureAwait(false);
|
||||
var ret = await QueryInternal(req)
|
||||
#if DBTYPE_SQLSERVER
|
||||
.WithLock(SqlServerLock.NoLock | SqlServerLock.NoWait)
|
||||
#endif
|
||||
.Take(req.Count)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<IEnumerable<QueryExampleRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<QueryExampleRsp> UpdateAsync(UpdateExampleReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (Rpo.Orm.Ado.DataType == DataType.Sqlite) {
|
||||
return await UpdateForSqliteAsync(req).ConfigureAwait(false) as QueryExampleRsp;
|
||||
}
|
||||
|
||||
var ret = await Rpo.UpdateDiy.SetSource(req).ExecuteUpdatedAsync().ConfigureAwait(false);
|
||||
return ret.FirstOrDefault()?.Adapt<QueryExampleRsp>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task<Tpl_Example> UpdateForSqliteAsync(Tpl_Example req)
|
||||
{
|
||||
return await Rpo.UpdateDiy.SetSource(req).ExecuteAffrowsAsync().ConfigureAwait(false) <= 0
|
||||
? null
|
||||
: await GetAsync(new QueryExampleReq { Id = req.Id }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private ISelect<Tpl_Example> QueryInternal(QueryReq<QueryExampleReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
Reference in New Issue
Block a user