2022-11-29 18:47:26 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2022-04-09 16:16:32 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2022-10-03 17:04:59 +08:00
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
2022-04-09 16:16:32 +08:00
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2022-10-09 17:32:44 +08:00
|
|
|
|
using Yi.Framework.Common.Attribute;
|
2022-04-18 23:33:11 +08:00
|
|
|
|
using Yi.Framework.Common.Const;
|
2022-04-09 16:16:32 +08:00
|
|
|
|
using Yi.Framework.Common.Models;
|
2022-04-18 23:33:11 +08:00
|
|
|
|
using Yi.Framework.Core;
|
2022-04-09 16:16:32 +08:00
|
|
|
|
using Yi.Framework.Interface;
|
2022-11-27 15:05:27 +08:00
|
|
|
|
using Yi.Framework.Job;
|
2022-04-09 16:16:32 +08:00
|
|
|
|
using Yi.Framework.Language;
|
|
|
|
|
|
using Yi.Framework.Model.Models;
|
|
|
|
|
|
using Yi.Framework.Repository;
|
2022-12-26 14:19:12 +08:00
|
|
|
|
using Yi.Framework.Uow.Interceptors;
|
2022-04-09 16:16:32 +08:00
|
|
|
|
using Yi.Framework.WebCore;
|
|
|
|
|
|
using Yi.Framework.WebCore.AttributeExtend;
|
|
|
|
|
|
using Yi.Framework.WebCore.AuthorizationPolicy;
|
2022-09-25 20:41:55 +08:00
|
|
|
|
using Yi.Framework.WebCore.DbExtend;
|
2022-10-03 17:04:59 +08:00
|
|
|
|
using Yi.Framework.WebCore.SignalRHub;
|
2022-04-09 16:16:32 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.ApiMicroservice.Controllers
|
|
|
|
|
|
{
|
2022-04-24 23:09:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 测试控制器
|
|
|
|
|
|
/// </summary>
|
2022-04-09 16:16:32 +08:00
|
|
|
|
[ApiController]
|
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
|
public class TestController : ControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private IStringLocalizer<LocalLanguage> _local;
|
2022-04-12 18:09:13 +08:00
|
|
|
|
private IUserService _iUserService;
|
2022-04-16 00:01:00 +08:00
|
|
|
|
private IRoleService _iRoleService;
|
2022-04-18 23:33:11 +08:00
|
|
|
|
private QuartzInvoker _quartzInvoker;
|
2022-10-03 17:04:59 +08:00
|
|
|
|
private IHubContext<MainHub> _hub;
|
2022-10-17 01:10:31 +08:00
|
|
|
|
private ThumbnailSharpInvoer _thumbnailSharpInvoer;
|
2022-10-26 20:08:16 +08:00
|
|
|
|
private CacheInvoker _cacheDb;
|
2022-11-07 01:31:37 +08:00
|
|
|
|
private ILogger<TestController> _logger;
|
|
|
|
|
|
[Autowired]
|
|
|
|
|
|
public CacheInvoker CacheInvoker { get; set; }
|
2022-04-13 21:36:50 +08:00
|
|
|
|
//你可以依赖注入服务层各各接口,也可以注入其他仓储层,怎么爽怎么来!
|
2022-10-03 17:04:59 +08:00
|
|
|
|
/// <summary>
|
2022-11-07 01:31:37 +08:00
|
|
|
|
/// 依赖注入,优雅写法
|
2022-10-03 17:04:59 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="hub"></param>
|
|
|
|
|
|
/// <param name="logger"></param>
|
|
|
|
|
|
/// <param name="iRoleService"></param>
|
|
|
|
|
|
/// <param name="iUserService"></param>
|
|
|
|
|
|
/// <param name="local"></param>
|
|
|
|
|
|
/// <param name="quartzInvoker"></param>
|
2022-10-17 01:10:31 +08:00
|
|
|
|
/// <param name="thumbnailSharpInvoer"></param>
|
2022-10-26 20:08:16 +08:00
|
|
|
|
/// <param name="cacheInvoker"></param>
|
|
|
|
|
|
public TestController(IHubContext<MainHub> hub,
|
2022-11-07 01:31:37 +08:00
|
|
|
|
ILogger<TestController> logger,
|
2022-10-26 20:08:16 +08:00
|
|
|
|
IRoleService iRoleService,
|
|
|
|
|
|
IUserService iUserService,
|
|
|
|
|
|
IStringLocalizer<LocalLanguage> local,
|
|
|
|
|
|
QuartzInvoker quartzInvoker,
|
|
|
|
|
|
ThumbnailSharpInvoer thumbnailSharpInvoer,
|
2022-11-07 01:31:37 +08:00
|
|
|
|
CacheInvoker cacheInvoker) =>
|
|
|
|
|
|
|
2022-12-26 14:19:12 +08:00
|
|
|
|
(_logger, _iUserService, _iRoleService, _quartzInvoker, _hub, _local, _thumbnailSharpInvoer, _cacheDb) =
|
2022-11-07 01:31:37 +08:00
|
|
|
|
|
|
|
|
|
|
(logger, iUserService, iRoleService, quartzInvoker, hub, local, thumbnailSharpInvoer, cacheInvoker);
|
2022-12-26 14:19:12 +08:00
|
|
|
|
|
2022-04-12 18:09:13 +08:00
|
|
|
|
|
2022-09-25 20:41:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// swagger跳转
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
[Route("/")]
|
|
|
|
|
|
public IActionResult Swagger()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Redirect("/Swagger");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-12 18:09:13 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 仓储上下文对象测试
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
2022-04-13 21:36:50 +08:00
|
|
|
|
// 特点:化繁为简!意框架仓储代理上下文对象,用起来就是爽,但最好按规范来爽!
|
2022-05-05 17:04:49 +08:00
|
|
|
|
// 规范:控制器严禁使用DB上下文对象,其它怎么爽怎么来!
|
2022-04-12 18:09:13 +08:00
|
|
|
|
public async Task<Result> DbTest()
|
|
|
|
|
|
{
|
2022-04-13 21:36:50 +08:00
|
|
|
|
//非常好,使用UserService的特有方法
|
|
|
|
|
|
await _iUserService.DbTest();
|
|
|
|
|
|
|
2022-04-16 00:01:00 +08:00
|
|
|
|
//非常好,依赖注入使用其他Service的特有方法
|
|
|
|
|
|
await _iRoleService.DbTest();
|
2022-04-13 21:36:50 +08:00
|
|
|
|
|
|
|
|
|
|
//很核理,使用仓储的通用方法
|
|
|
|
|
|
await _iUserService._repository.GetListAsync();
|
|
|
|
|
|
|
2022-04-16 00:01:00 +08:00
|
|
|
|
//挺不错,依赖注入其他仓储
|
|
|
|
|
|
await _iRoleService._repository.GetListAsync();
|
2022-04-13 21:36:50 +08:00
|
|
|
|
|
2022-05-05 17:04:49 +08:00
|
|
|
|
//还行,直接切换其他仓储,怎么爽怎么来
|
2022-04-16 00:01:00 +08:00
|
|
|
|
await _iUserService._repository.ChangeRepository<Repository<RoleEntity>>().GetListAsync();
|
2022-04-13 21:36:50 +08:00
|
|
|
|
|
2022-09-10 13:36:01 +08:00
|
|
|
|
//最好不要在控制器直接操作Db对象
|
2022-04-13 21:36:50 +08:00
|
|
|
|
await _iUserService._repository._Db.Queryable<UserEntity>().ToListAsync();
|
2022-09-10 13:36:01 +08:00
|
|
|
|
await _iUserService._repository._DbQueryable.ToListAsync();
|
2022-04-13 21:36:50 +08:00
|
|
|
|
|
2022-04-12 18:09:13 +08:00
|
|
|
|
return Result.Success().SetData(await _iUserService.DbTest());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-26 14:19:12 +08:00
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public async Task<Result> TestUnitOfWork()
|
|
|
|
|
|
{
|
|
|
|
|
|
var userId = await _iUserService.AddInfo(new DTOModel.UserInfoDto { User = new UserEntity { Address = "", UserName = "lisi", Password = "123456" }.BuildPassword() });
|
|
|
|
|
|
throw new ApplicationException("测试uow");
|
|
|
|
|
|
await _iRoleService._repository.InsertReturnSnowflakeIdAsync(new RoleEntity { RoleName = "测试", RoleCode = "tt" });
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-14 20:44:28 +08:00
|
|
|
|
/// <summary>
|
2022-04-14 23:13:34 +08:00
|
|
|
|
/// 执行Sql返回
|
2022-04-14 20:44:28 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
2022-05-05 17:04:49 +08:00
|
|
|
|
//简单语句不推荐使用sql!
|
2022-04-14 20:44:28 +08:00
|
|
|
|
public async Task<Result> SqlTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Result.Success().SetData(await _iUserService._repository.UseSqlAsync<UserEntity>("select * from User"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-09 16:16:32 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 国际化测试
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
2022-04-13 21:36:50 +08:00
|
|
|
|
//根据浏览器语言设置来切换输出
|
2022-04-09 16:16:32 +08:00
|
|
|
|
public Result LocalTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Result.Success().SetData(_local["succeed"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 权限测试
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
[Permission("user:get:test")]
|
|
|
|
|
|
public Result PermissionTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 策略授权测试
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
[Authorize(PolicyName.Sid)]
|
2022-04-14 23:13:34 +08:00
|
|
|
|
public Result AuthTest()
|
2022-04-09 16:16:32 +08:00
|
|
|
|
{
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
2022-04-13 21:36:50 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 异步事务测试
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
//注册一个用户获取它的信息之后再更新它,但是这个年龄可能会报错
|
|
|
|
|
|
//如果一个事务中有任何一个错误,将会把所有执行过的操作进行回滚,确保数据的原子性
|
|
|
|
|
|
public async Task<Result> TranTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
UserEntity user = new() { UserName = $"杰哥{DateTime.Now}", Password = "5201314", Age = 99 };
|
|
|
|
|
|
|
|
|
|
|
|
var res = await _iUserService._repository.UseTranAsync(async () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
await _iUserService.Register(user, (o) => user = o);
|
|
|
|
|
|
user.Age = 18 / (new Random().Next(0, 2));
|
|
|
|
|
|
await _iUserService._repository.UpdateAsync(user);
|
|
|
|
|
|
});
|
|
|
|
|
|
if (res)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Result.Success("执行成功!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return Result.Error("发生错误,插入已回滚!");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-16 00:01:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 极爽导航属性
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
//Sqlsugar精髓之一!必学!最新版本
|
|
|
|
|
|
public async Task<Result> IncludeTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Result.Success().SetData(await _iUserService.GetListInRole());
|
|
|
|
|
|
}
|
2022-04-18 23:33:11 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启动一个定时任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
//每5秒访问一次百度,可查看控制台
|
|
|
|
|
|
public async Task<Result> JobTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
Dictionary<string, object> data = new Dictionary<string, object>()
|
|
|
|
|
|
{
|
|
|
|
|
|
{JobConst.method,"get" },
|
|
|
|
|
|
{JobConst.url,"https://www.baidu.com" }
|
|
|
|
|
|
};
|
2022-09-08 18:18:34 +08:00
|
|
|
|
await _quartzInvoker.StartAsync("*/5 * * * * ?", "HttpJob", jobName: "test", jobGroup: "my", data: data);
|
2022-04-18 23:33:11 +08:00
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 停止任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPut]
|
2022-09-08 18:18:34 +08:00
|
|
|
|
public async Task<Result> StopJob()
|
2022-04-18 23:33:11 +08:00
|
|
|
|
{
|
2022-08-13 18:10:11 +08:00
|
|
|
|
await _quartzInvoker.StopAsync(new Quartz.JobKey("test", "my"));
|
2022-11-27 15:05:27 +08:00
|
|
|
|
return Result.Success("http://localhost:19001/hangfire");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-29 12:49:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// job异常处理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public async Task<Result> ErrorJob()
|
|
|
|
|
|
{
|
|
|
|
|
|
await _quartzInvoker.StartAsync("*/5 * * * * ?", "ErrorJob");
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-08 18:18:34 +08:00
|
|
|
|
/// <summary>
|
2022-09-08 18:24:51 +08:00
|
|
|
|
/// 树形结构构建测试
|
2022-09-08 18:18:34 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public Result TreeTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<VueRouterModel> vueRouterModels = new()
|
|
|
|
|
|
{
|
2022-09-11 16:49:40 +08:00
|
|
|
|
new VueRouterModel { Id = 1, OrderNum = 1, ParentId = 0, Name = "001" },
|
|
|
|
|
|
new VueRouterModel { Id = 2, OrderNum = 1, ParentId = 1, Name = "001001" },
|
|
|
|
|
|
new VueRouterModel { Id = 3, OrderNum = 1, ParentId = 1, Name = "001002" }
|
2022-09-08 18:18:34 +08:00
|
|
|
|
};
|
|
|
|
|
|
var treeData = Common.Helper.TreeHelper.SetTree(vueRouterModels);
|
|
|
|
|
|
return Result.Success().SetData(treeData);
|
|
|
|
|
|
}
|
2022-09-15 18:40:24 +08:00
|
|
|
|
|
2022-09-25 20:41:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 授权测试
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2022-09-15 18:40:24 +08:00
|
|
|
|
[Authorize]
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public Result AuthorizeTest()
|
2022-09-25 18:06:07 +08:00
|
|
|
|
{
|
2022-09-15 18:40:24 +08:00
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
2022-09-25 18:06:07 +08:00
|
|
|
|
|
2022-10-01 23:53:43 +08:00
|
|
|
|
|
2022-09-25 20:41:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 清空数据库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2022-09-25 18:06:07 +08:00
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public async Task<Result> ClearDb()
|
|
|
|
|
|
{
|
|
|
|
|
|
var rep = _iUserService._repository;
|
|
|
|
|
|
return Result.Success().SetStatus(await rep.UseTranAsync(async () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
await rep.DeleteAsync(u => true);
|
|
|
|
|
|
await rep.ChangeRepository<Repository<MenuEntity>>().DeleteAsync(u => true);
|
|
|
|
|
|
await rep.ChangeRepository<Repository<RoleEntity>>().DeleteAsync(u => true);
|
|
|
|
|
|
await rep.ChangeRepository<Repository<RoleMenuEntity>>().DeleteAsync(u => true);
|
|
|
|
|
|
await rep.ChangeRepository<Repository<UserRoleEntity>>().DeleteAsync(u => true);
|
|
|
|
|
|
await rep.ChangeRepository<Repository<DictionaryEntity>>().DeleteAsync(u => true);
|
|
|
|
|
|
await rep.ChangeRepository<Repository<DictionaryInfoEntity>>().DeleteAsync(u => true);
|
|
|
|
|
|
await rep.ChangeRepository<Repository<ConfigEntity>>().DeleteAsync(u => true);
|
2022-09-25 18:58:17 +08:00
|
|
|
|
await rep.ChangeRepository<Repository<PostEntity>>().DeleteAsync(u => true);
|
|
|
|
|
|
await rep.ChangeRepository<Repository<DeptEntity>>().DeleteAsync(u => true);
|
2022-09-25 18:06:07 +08:00
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-09-25 20:41:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 种子数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
2022-10-17 01:10:31 +08:00
|
|
|
|
public Result SeedDb()
|
2022-09-25 20:41:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
var rep = _iUserService._repository;
|
2022-10-18 18:01:16 +08:00
|
|
|
|
return Result.Success().SetStatus(DbSeedExtend.DataInvoer(rep._Db));
|
2022-09-25 20:41:55 +08:00
|
|
|
|
}
|
2022-10-01 23:53:43 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 操作日志测试
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="par"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[Log("测试模块", Common.Enum.OperEnum.Insert)]
|
|
|
|
|
|
public Result LogTest(List<string> par)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Result.Success().SetData(par);
|
|
|
|
|
|
}
|
2022-10-03 17:04:59 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Signalr实时推送测试
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="msg"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
2022-10-17 01:10:31 +08:00
|
|
|
|
public async Task<Result> SignalrTest(int msg)
|
2022-10-03 17:04:59 +08:00
|
|
|
|
{
|
|
|
|
|
|
await _hub.Clients.All.SendAsync("onlineNum", msg);
|
|
|
|
|
|
return Result.Success("向所有连接客户端发送一个消息");
|
|
|
|
|
|
}
|
2022-10-04 15:22:34 +08:00
|
|
|
|
//job任务与公告管理
|
2022-10-17 01:10:31 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 缩略图测试,需要生成前及生成后的路径
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public Result ThumbnailTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var path = @"D:\App\test11.jpg";
|
|
|
|
|
|
var result = _thumbnailSharpInvoer.CreateThumbnailBytes(thumbnailSize: 300,
|
|
|
|
|
|
imageStream: new FileStream(path, FileMode.Open, FileAccess.ReadWrite),
|
|
|
|
|
|
imageFormat: Format.Jpeg);
|
|
|
|
|
|
System.IO.File.WriteAllBytes(@"D:\App\test222.jpg", result);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Result.Error(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
2022-10-26 20:08:16 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 缓存测试
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public Result CacheDBTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
var key = "Yi:Test";
|
|
|
|
|
|
var item = "你好世界";
|
|
|
|
|
|
_cacheDb.Set(key, item);
|
|
|
|
|
|
|
|
|
|
|
|
var data = _cacheDb.Get<string>(key);
|
|
|
|
|
|
return Result.Success().SetData(data);
|
|
|
|
|
|
}
|
2022-11-07 01:31:37 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 自定义日志
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public Result CustomLogTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogWarning("输出一条日志");
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 属性注入测试
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public Result PropertyTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Result.Success().SetStatus(CacheInvoker is not null);
|
|
|
|
|
|
}
|
2022-04-09 16:16:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|