style: 修改rbac service结构

This commit is contained in:
陈淳
2024-02-18 09:35:35 +08:00
parent 4673398976
commit 26dd107f48
11 changed files with 86 additions and 88 deletions

View File

@@ -1,37 +0,0 @@
using SqlSugar;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Yi.Framework.Ddd.Application;
using Yi.Framework.Rbac.Application.Contracts.Dtos.LoginLog;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.Application.Services
{
public class LoginLogService : YiCrudAppService<LoginLogEntity, LoginLogGetListOutputDto, Guid, LoginLogGetListInputVo>
{
private readonly ISqlSugarRepository<LoginLogEntity> _repository;
public LoginLogService(ISqlSugarRepository<LoginLogEntity, Guid> repository) : base(repository)
{
_repository = repository;
}
public override async Task<PagedResultDto<LoginLogGetListOutputDto>> GetListAsync(LoginLogGetListInputVo input)
{
RefAsync<int> total = 0;
var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.LoginIp), x => x.LoginIp.Contains(input.LoginIp!))
.WhereIF(!string.IsNullOrEmpty(input.LoginUser), x => x.LoginUser!.Contains(input.LoginUser!))
.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<LoginLogGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
}
[RemoteService(false)]
public override Task<LoginLogGetListOutputDto> UpdateAsync(Guid id, LoginLogGetListOutputDto input)
{
return base.UpdateAsync(id, input);
}
}
}

View File

@@ -3,7 +3,7 @@ using Volo.Abp.Application.Services;
using Yi.Framework.Rbac.Application.Contracts.Dtos.MonitorCache;
using Yi.Framework.Rbac.Application.Contracts.IServices;
namespace Yi.Framework.Rbac.Application.Services
namespace Yi.Framework.Rbac.Application.Services.Monitor
{
public class MonitorCacheService : ApplicationService, IMonitorCacheService
{

View File

@@ -7,7 +7,7 @@ using Volo.Abp.Application.Services;
using Yi.Framework.Core.Helper;
using Yi.Framework.Rbac.Application.Contracts.IServices;
namespace Yi.Framework.Rbac.Application.Services
namespace Yi.Framework.Rbac.Application.Services.Monitor
{
public class MonitorServerService : ApplicationService, IMonitorServerService
{

View File

@@ -7,7 +7,7 @@ using Yi.Framework.Rbac.Application.Contracts.IServices;
using Yi.Framework.Rbac.Application.SignalRHubs;
using Yi.Framework.Rbac.Domain.Shared.Model;
namespace Yi.Framework.Rbac.Application.Services
namespace Yi.Framework.Rbac.Application.Services.Monitor
{
public class OnlineService : ApplicationService, IOnlineService
{
@@ -37,7 +37,7 @@ namespace Yi.Framework.Rbac.Application.Services
{
dataWhere = dataWhere.Where((u) => u.UserName!.Contains(online.UserName));
}
return Task.FromResult(new PagedResultDto<OnlineUserModel>() { TotalCount = data.Count, Items = dataWhere.ToList() }) ;
return Task.FromResult(new PagedResultDto<OnlineUserModel>() { TotalCount = data.Count, Items = dataWhere.ToList() });
}

View File

@@ -11,7 +11,7 @@ using Yi.Framework.Rbac.Application.Contracts.Dtos.Task;
using Yi.Framework.Rbac.Application.Contracts.IServices;
using Yi.Framework.Rbac.Domain.Shared.Enums;
namespace Yi.Framework.Rbac.Application.Services
namespace Yi.Framework.Rbac.Application.Services.Monitor
{
public class TaskService : ApplicationService, ITaskService
{
@@ -19,7 +19,7 @@ namespace Yi.Framework.Rbac.Application.Services
private readonly IClock _clock;
public TaskService(ISchedulerFactory schedulerFactory, IClock clock)
{
_clock=clock;
_clock = clock;
_schedulerFactory = schedulerFactory;
}
@@ -39,7 +39,7 @@ namespace Yi.Framework.Rbac.Application.Services
//状态
var state = await scheduler.GetTriggerState(trigger.Key);
var output = new TaskGetOutput
{
JobId = jobDetail.Key.Name,
@@ -48,7 +48,7 @@ namespace Yi.Framework.Rbac.Application.Services
Properties = Newtonsoft.Json.JsonConvert.SerializeObject(jobDetail.JobDataMap),
Concurrent = !jobDetail.ConcurrentExecutionDisallowed,
Description = jobDetail.Description,
LastRunTime = _clock.Normalize( trigger.GetPreviousFireTimeUtc()?.DateTime??DateTime.MinValue),
LastRunTime = _clock.Normalize(trigger.GetPreviousFireTimeUtc()?.DateTime ?? DateTime.MinValue),
NextRunTime = _clock.Normalize(trigger.GetNextFireTimeUtc()?.DateTime ?? DateTime.MinValue),
AssemblyName = jobDetail.JobType.Assembly.GetName().Name,
Status = state.ToString()
@@ -56,7 +56,7 @@ namespace Yi.Framework.Rbac.Application.Services
if (trigger is ISimpleTrigger simple)
{
output.TriggerArgs =Math.Round(simple.RepeatInterval.TotalMinutes,2) .ToString() + "分钟";
output.TriggerArgs = Math.Round(simple.RepeatInterval.TotalMinutes, 2).ToString() + "分钟";
output.Type = JobTypeEnum.Millisecond;
output.Millisecond = simple.RepeatInterval.TotalMilliseconds;
}
@@ -64,7 +64,7 @@ namespace Yi.Framework.Rbac.Application.Services
{
output.TriggerArgs = cron.CronExpressionString!;
output.Type = JobTypeEnum.Cron;
output.Cron=cron.CronExpressionString;
output.Cron = cron.CronExpressionString;
}
return output;
}
@@ -159,7 +159,7 @@ namespace Yi.Framework.Rbac.Application.Services
/// <param name="id"></param>
/// <returns></returns>
public async Task DeleteAsync(IEnumerable<string> id)
{
{
var scheduler = await _schedulerFactory.GetScheduler();
await scheduler.DeleteJobs(id.Select(x => new JobKey(x)).ToList());
}

View File

@@ -1,40 +0,0 @@
using SqlSugar;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Yi.Framework.Ddd.Application;
using Yi.Framework.Rbac.Application.Contracts.Dtos.OperLog;
using Yi.Framework.Rbac.Application.Contracts.IServices;
using Yi.Framework.Rbac.Domain.Operlog;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.Application.Services
{
/// <summary>
/// OperationLog服务实现
/// </summary>
public class OperationLogService : YiCrudAppService<OperationLogEntity, OperationLogGetListOutputDto, Guid, OperationLogGetListInputVo>,
IOperationLogService
{
private ISqlSugarRepository<OperationLogEntity, Guid> _repository;
public OperationLogService(ISqlSugarRepository<OperationLogEntity, Guid> repository) : base(repository)
{
_repository=repository;
}
public override async Task<PagedResultDto<OperationLogGetListOutputDto>> GetListAsync(OperationLogGetListInputVo input)
{
RefAsync<int> total = 0;
var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.OperUser), x => x.OperUser.Contains(input.OperUser!))
.WhereIF(input.OperType is not null, x => x.OperType == input.OperType)
.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<OperationLogGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
}
[RemoteService(false)]
public override Task<OperationLogGetListOutputDto> UpdateAsync(Guid id, OperationLogGetListOutputDto input)
{
return base.UpdateAsync(id, input);
}
}
}

View File

@@ -0,0 +1,41 @@
## 模块与项目
意框架是一个基于Abp.VNext的框架完美使用模块化理念进行开发。既然是模块化开发就有`项目``项目`的概念。
很多人问到了我,我的代码应该放到哪里,其实是没有分清楚模块与项目,弄清楚这个,再下手撸码,才更有方向。
其实不必一堆概念,只需要心中思考一下
> 我接下来要开发的业务是否有必要被其他项目依赖使用?
例如内置的Rbac模块、Bbs模块单独具备权限管理和社区论坛的功能公开给大家复用引用这就可以当成一个模块
`但是`,有时候如果我不认为他有必要复用,就是公司的一个内部系统,想要快速开发并交付,要同时具备权限管理、商城、审批等各种功能,那就直接当一个项目开发即可,不一定需要将各个模块拆的太散
> 这个划分的界限,是由项目来决定
注意:模块的代码与项目的代码结构几乎没有区别
这意味,有一个最好的方式,先将业务全部写在项目中,等稳定之后,在复制抽象到模块中,完全没有问题。
### 模块的优缺点
- 优点:高度抽象复用
- 缺点:肉眼可见的程序集增加、维护成本更高
### 模块
![Alt text](image.png)
代码位置放在`module`目录下,单独建立一个自己的模块名称,可使用`脚手架使用`将默认代码生成在这里。
### 项目
![Alt text](image-1.png)
框架内置一个host项目代码位置存放在`src`中,直接使用即可,如果想更换命名,可以使用上一节的`脚手架使用`
## 总结
> 由于很多人询问我这个问题,所以单独写一篇,方便大家理解。
先区分模块还是项目,然后代码写到对应的位置即可
理论上,按这套规则意味着,只有在自己的`module``src`下才需要写代码,其他地方都是内置好了的,通过继承、实现等方式扩展即可
当然,你可以不按这套规则出发,目录结构按自己的舒服的方式去设计,当然也是可以的,不过这得花费一些时间了。

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -0,0 +1,34 @@
## 简介
上节说到真正关注的代码其实只用在src中
![image.png](/prod-api/file/7f52e9a7-6b6d-cc80-64f6-3a10031e9214/true)
当我们要新建一个项目或者模块的时候,并不想取这个`Yi.Abp`的名字我们可以使用dotnet的脚手架进行模板的生成
**环境**只需要dotnet sdk即可
## 步骤
![image.png](/prod-api/file/2a8d18c4-4899-433d-3553-3a10032e9645/true)
在模板文件目录上,有一个`.template.config`文件夹,就是通过这个进行控制模板的生成及替换
进入该目录使用cmd执行以以下命令
``` shell
dotnet new install . --force
```
![image.png](/prod-api/file/0a92e464-13af-ef93-77b9-3a10032fe20c/true)
出现 `已安装以下模板` 及代表安装完成
>我们只需要安装一次即可,如果模板文件发生变化,我们生成出来的文件也是一样会变化的
当模板安装完成,接下来我们可以选择一个自己想要的空白文件夹,输入命令:
``` shell
dotnet new yi --name=Acme.BookStore
#Acme.BookStore可以替换成你想要生成的名称即可
```
![image.png](/prod-api/file/55536e5a-ef47-1593-3701-3a100333df31/true)
最后查看目录:
![image.png](/prod-api/file/20286d62-a9d1-6ab0-7fc0-3a1003348554/true)
这个便是我们想要的结果了