2024-01-25 10:06:32 +08:00
|
|
|
|
using Mapster;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-02-26 13:42:37 +08:00
|
|
|
|
using Microsoft.AspNetCore.RateLimiting;
|
2024-01-25 10:06:32 +08:00
|
|
|
|
using Volo.Abp.Application.Services;
|
2024-06-27 18:37:49 +08:00
|
|
|
|
using Volo.Abp.Settings;
|
2024-01-25 01:43:00 +08:00
|
|
|
|
using Volo.Abp.Uow;
|
2024-01-25 10:06:32 +08:00
|
|
|
|
using Yi.Framework.Bbs.Application.Contracts.Dtos.Banner;
|
2024-01-25 01:43:00 +08:00
|
|
|
|
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
2024-01-25 10:06:32 +08:00
|
|
|
|
using Yi.Framework.Rbac.Domain.Authorization;
|
|
|
|
|
|
using Yi.Framework.Rbac.Domain.Extensions;
|
2024-06-27 18:37:49 +08:00
|
|
|
|
using Yi.Framework.SettingManagement.Domain;
|
2024-01-25 01:43:00 +08:00
|
|
|
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
2023-12-14 14:15:56 +08:00
|
|
|
|
|
2023-12-15 23:44:35 +08:00
|
|
|
|
namespace Yi.Abp.Application.Services
|
2023-12-14 14:15:56 +08:00
|
|
|
|
{
|
2024-01-25 01:43:00 +08:00
|
|
|
|
/// <summary>
|
2024-01-25 10:06:32 +08:00
|
|
|
|
/// 常用魔改及扩展示例
|
2024-01-25 01:43:00 +08:00
|
|
|
|
/// </summary>
|
2023-12-14 14:15:56 +08:00
|
|
|
|
public class TestService : ApplicationService
|
|
|
|
|
|
{
|
2024-01-25 10:20:46 +08:00
|
|
|
|
/// <summary>
|
2024-01-25 10:26:10 +08:00
|
|
|
|
/// 属性注入
|
|
|
|
|
|
/// 不推荐,坑太多,容易把自己玩死,简单的东西可以用一用
|
2024-01-25 10:20:46 +08:00
|
|
|
|
/// </summary>
|
2024-05-22 14:35:08 +08:00
|
|
|
|
public ISqlSugarRepository<BannerAggregateRoot> sqlSugarRepository { get; set; }
|
2024-01-25 10:06:32 +08:00
|
|
|
|
|
2023-12-14 14:15:56 +08:00
|
|
|
|
/// <summary>
|
2024-01-25 10:06:32 +08:00
|
|
|
|
/// 动态Api
|
2023-12-14 14:15:56 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-01-25 10:06:32 +08:00
|
|
|
|
[HttpGet("hello-world")]
|
2023-12-14 14:15:56 +08:00
|
|
|
|
public string GetHelloWorld(string? name)
|
|
|
|
|
|
{
|
2024-01-25 10:06:32 +08:00
|
|
|
|
//会自动添加前缀,而不是重置,更符合习惯
|
|
|
|
|
|
//如果需要重置以"/"根目录开头即可
|
|
|
|
|
|
//你好世界
|
2023-12-14 14:15:56 +08:00
|
|
|
|
return name ?? "HelloWord";
|
|
|
|
|
|
}
|
2024-01-25 01:43:00 +08:00
|
|
|
|
|
2024-01-25 10:06:32 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// SqlSugar
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<object> GetSqlSugarDbAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
//用户体验优先,可直接使用Db操作,依赖抽象
|
|
|
|
|
|
return await sqlSugarRepository._DbQueryable.ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-25 01:43:00 +08:00
|
|
|
|
/// <summary>
|
2024-01-25 10:26:10 +08:00
|
|
|
|
/// 工作单元
|
2024-01-25 01:43:00 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task GetUowAsync()
|
|
|
|
|
|
{
|
2024-01-25 10:26:10 +08:00
|
|
|
|
//魔改
|
2024-01-25 10:06:32 +08:00
|
|
|
|
// 用户体验优先,万金油模式,支持高并发。支持单、多线程并发安全,支持多线程工作单元,支持多线程无工作单元,支持。。。
|
|
|
|
|
|
// 自动在各个情况处理db客户端最优解之一
|
2024-06-11 22:34:36 +08:00
|
|
|
|
int i = 3;
|
2024-01-25 01:43:00 +08:00
|
|
|
|
List<Task> tasks = new List<Task>();
|
2024-06-11 22:34:36 +08:00
|
|
|
|
await sqlSugarRepository.GetListAsync();
|
|
|
|
|
|
await sqlSugarRepository.GetListAsync();
|
2024-01-25 01:43:00 +08:00
|
|
|
|
while (i > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
tasks.Add(Task.Run(async () =>
|
|
|
|
|
|
{
|
2024-05-22 14:35:08 +08:00
|
|
|
|
await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "插入2" });
|
2024-01-25 10:06:32 +08:00
|
|
|
|
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
|
2024-01-25 01:43:00 +08:00
|
|
|
|
{
|
2024-05-22 14:35:08 +08:00
|
|
|
|
await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "插入1" });
|
2024-01-25 01:43:00 +08:00
|
|
|
|
await uow.CompleteAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
}));
|
2024-05-22 14:35:08 +08:00
|
|
|
|
await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "插入3" });
|
2024-01-25 01:43:00 +08:00
|
|
|
|
i--;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(tasks);
|
|
|
|
|
|
}
|
2024-01-25 10:06:32 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 当前用户
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public void GetCurrentUser()
|
|
|
|
|
|
{
|
|
|
|
|
|
//当token鉴权之后,可以直接获取
|
|
|
|
|
|
if (CurrentUser.Id is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//权限
|
|
|
|
|
|
CurrentUser.GetPermissions();
|
|
|
|
|
|
|
|
|
|
|
|
//角色信息
|
|
|
|
|
|
CurrentUser.GetRoleInfo();
|
|
|
|
|
|
|
|
|
|
|
|
//部门id
|
|
|
|
|
|
CurrentUser.GetDeptId();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 数据权限
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void GetDataFilter()
|
|
|
|
|
|
{
|
|
|
|
|
|
//这里会数据权限过滤
|
|
|
|
|
|
using (DataFilter.DisablePermissionHandler())
|
|
|
|
|
|
{
|
|
|
|
|
|
//这里不会数据权限过滤
|
|
|
|
|
|
}
|
|
|
|
|
|
//这里会数据权限过滤
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 对象映射
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void GetMapper()
|
|
|
|
|
|
{
|
|
|
|
|
|
//直接无脑Adapt,无需配置
|
2024-05-22 14:35:08 +08:00
|
|
|
|
var entity = new BannerAggregateRoot();
|
2024-01-25 10:06:32 +08:00
|
|
|
|
var dto = entity.Adapt<BannerGetListOutputDto>();
|
|
|
|
|
|
}
|
2024-02-26 13:42:37 +08:00
|
|
|
|
|
2024-06-27 18:37:49 +08:00
|
|
|
|
private static int RequestNumber { get; set; } = 0;
|
2024-02-26 13:42:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 速率限制
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
// [DisableRateLimiting]
|
|
|
|
|
|
//[EnableRateLimiting("sliding")]
|
|
|
|
|
|
public int GetRateLimiting()
|
|
|
|
|
|
{
|
|
|
|
|
|
RequestNumber++;
|
|
|
|
|
|
return RequestNumber;
|
|
|
|
|
|
}
|
2024-06-27 18:37:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ISettingProvider _settingProvider { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public ISettingManager _settingManager { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 系统配置模块
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<string> GetSettingAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
//默认来说,不提供修改操作,配置应该独立
|
|
|
|
|
|
var enableOrNull = await _settingProvider.GetOrNullAsync("abp.ddd.enable");
|
|
|
|
|
|
|
|
|
|
|
|
//如果要进行修改,可使用yi.framework下的ISettingManager
|
|
|
|
|
|
await _settingManager.SetAsync("abp.ddd.enable", "false", "系统", "admin");
|
|
|
|
|
|
|
|
|
|
|
|
var enableOrNull2 = await _settingProvider.GetOrNullAsync("abp.ddd.enable");
|
|
|
|
|
|
|
|
|
|
|
|
return enableOrNull2 ?? string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-14 14:15:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|