Compare commits

..

5 Commits

Author SHA1 Message Date
橙子
1a22aa0bfb Update README.md 2022-04-18 23:34:03 +08:00
橙子
d18e5eec99 添加定时任务 2022-04-18 23:33:11 +08:00
橙子
0fcf172192 更换swaggerui 2022-04-16 00:16:32 +08:00
橙子
88b968e826 添加导航属性 2022-04-16 00:01:00 +08:00
橙子
f15d99e168 Update README.md 2022-04-15 00:16:56 +08:00
19 changed files with 295 additions and 43 deletions

View File

@@ -20,6 +20,10 @@ Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
适合.Net6学习、Sqlsugar学习 、项目二次开发。
集大成者,终究轮子
Yi框架最新版本标签`v1.0.3` 更新时间2022/4/18
项目与Sqlsugar同步更新但这作者老杰哥代码天天爆肝到凌晨两点我们也尽量会跟上他的脚步。更新频繁所以可watching持续关注。
————这不仅仅是一个程序,更是一个艺术品,面向艺术的开发!
**分支**

Binary file not shown.

View File

@@ -87,5 +87,23 @@
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.IncludeTest">
<summary>
极爽导航属性
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.JobTest">
<summary>
启动一个定时任务每5秒访问一次百度
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.stopJob">
<summary>
停止任务
</summary>
<returns></returns>
</member>
</members>
</doc>

View File

@@ -15,12 +15,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers
/// </summary>
/// <typeparam name="T"></typeparam>
[ApiController]
[Route("api/[controller]/[action]")]
public class BaseCrudController<T> : ControllerBase where T : BaseModelEntity,new()
{
public readonly ILogger<T> _logger;
public IBaseService<T> _baseService;
public IRepository<T> _repository;
private readonly ILogger<T> _logger;
private IBaseService<T> _baseService;
private IRepository<T> _repository;
public BaseCrudController(ILogger<T> logger, IBaseService<T> iBaseService)
{
_logger = logger;

View File

@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AttributeExtend;
using Yi.Framework.WebCore.AuthorizationPolicy;
namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
public class RoleController : BaseCrudController<RoleEntity>
{
private IRoleService _iRoleService;
public RoleController(ILogger<RoleEntity> logger, IRoleService iRoleService) : base(logger, iRoleService)
{
_iRoleService = iRoleService;
}
}
}

View File

@@ -6,7 +6,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Const;
using Yi.Framework.Common.Models;
using Yi.Framework.Core;
using Yi.Framework.Interface;
using Yi.Framework.Language;
using Yi.Framework.Model.Models;
@@ -23,11 +25,15 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
private IStringLocalizer<LocalLanguage> _local;
private IUserService _iUserService;
private IRoleService _iRoleService;
private QuartzInvoker _quartzInvoker;
//你可以依赖注入服务层各各接口,也可以注入其他仓储层,怎么爽怎么来!
public TestController(ILogger<UserEntity> logger, IUserService iUserService, IStringLocalizer<LocalLanguage> local)
public TestController(ILogger<UserEntity> logger, IRoleService iRoleService, IUserService iUserService, IStringLocalizer<LocalLanguage> local, QuartzInvoker quartzInvoker)
{
_local = local;
_iUserService = iUserService;
_iRoleService = iRoleService;
_quartzInvoker = quartzInvoker;
}
/// <summary>
@@ -42,19 +48,19 @@ namespace Yi.Framework.ApiMicroservice.Controllers
//非常好使用UserService的特有方法
await _iUserService.DbTest();
//非常好依赖注入使用其他Service的特有方法(就tm一张表现在自己注入自己)
await _iUserService.DbTest();
//非常好依赖注入使用其他Service的特有方法
await _iRoleService.DbTest();
//很核理,使用仓储的通用方法
await _iUserService._repository.GetListAsync();
//挺不错,依赖注入其他仓储(就tm一张表现在自己注入自己)
await _iUserService._repository.GetListAsync();
//挺不错,依赖注入其他仓储
await _iRoleService._repository.GetListAsync();
//不建议操作,直接切换其他仓储(就tm一张表现在自己切换自己)
await _iUserService._repository.ChangeRepository<Repository<UserEntity>>().GetListAsync();
//不建议操作,直接切换其他仓储
await _iUserService._repository.ChangeRepository<Repository<RoleEntity>>().GetListAsync();
//恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。
//直接操作Db对象恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。
await _iUserService._repository._Db.Queryable<UserEntity>().ToListAsync();
return Result.Success().SetData(await _iUserService.DbTest());
@@ -132,6 +138,43 @@ namespace Yi.Framework.ApiMicroservice.Controllers
}
//emmmm看来一张表已经满足不了接下来将要大更新一波
/// <summary>
/// 极爽导航属性
/// </summary>
/// <returns></returns>
[HttpGet]
//Sqlsugar精髓之一必学最新版本
public async Task<Result> IncludeTest()
{
return Result.Success().SetData(await _iUserService.GetListInRole());
}
/// <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" }
};
await _quartzInvoker.start("*/5 * * * * ?", new Quartz.JobKey("test", "my"), "Yi.Framework.Job", "HttpJob", data: data);
return Result.Success();
}
/// <summary>
/// 停止任务
/// </summary>
/// <returns></returns>
[HttpPut]
public async Task<Result> stopJob()
{
await _quartzInvoker.Stop(new Quartz.JobKey("test", "my"));
return Result.Success();
}
}
}

View File

@@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Interface
{
public partial interface IRoleService
{
/// <summary>
/// DbTest
/// </summary>
/// <returns></returns>
public Task<List<RoleEntity>> DbTest();
}
}

View File

@@ -0,0 +1,9 @@
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Interface
{
public partial interface IRoleService:IBaseService<RoleEntity>
{
}
}

View File

@@ -0,0 +1,9 @@
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Interface
{
public partial interface IUserRoleService:IBaseService<UserRoleEntity>
{
}
}

View File

@@ -30,5 +30,12 @@ namespace Yi.Framework.Interface
/// <param name="userAction"></param>
/// <returns></returns>
public Task<bool> Register(UserEntity userEntity, Action<UserEntity> userAction = null);
/// <summary>
/// 导航属性关联角色
/// </summary>
/// <returns></returns>
public Task<List<UserEntity>> GetListInRole();
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;
namespace Yi.Framework.Model.Models
{
/// <summary>
///
///</summary>
[SugarTable("Role")]
public partial class RoleEntity:BaseModelEntity
{
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="RoleName" )]
public string RoleName { get; set; }
/// <summary>
/// 租户Id
///</summary>
[SugarColumn(ColumnName="TenantId" )]
public long? TenantId { get; set; }
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;
namespace Yi.Framework.Model.Models
{
/// <summary>
///
///</summary>
[SugarTable("UserRole")]
public partial class UserRoleEntity:BaseModelEntity
{
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="RoleId" )]
public long? RoleId { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName="UserId" )]
public long? UserId { get; set; }
/// <summary>
/// 租户Id
///</summary>
[SugarColumn(ColumnName="TenantId" )]
public long? TenantId { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;
namespace Yi.Framework.Model.Models
{
public partial class UserEntity:BaseModelEntity
{
/// <summary>
/// 看好啦ORM精髓导航属性
///</summary>
[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.UserId), nameof(UserRoleEntity.RoleId))]
public List<RoleEntity> Roles { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using SqlSugar;
using System.Collections.Generic;
using System.Threading.Tasks;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class RoleService
{
public async Task<List<RoleEntity>> DbTest()
{
return await _repository._Db.Queryable<RoleEntity>().ToListAsync();
}
}
}

View File

@@ -0,0 +1,14 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class RoleService : BaseService<RoleEntity>, IRoleService
{
public RoleService(IRepository<RoleEntity> repository) : base(repository)
{
}
}
}

View File

@@ -0,0 +1,14 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class UserRoleService : BaseService<UserRoleEntity>, IUserRoleService
{
public UserRoleService(IRepository<UserRoleEntity> repository) : base(repository)
{
}
}
}

View File

@@ -65,5 +65,11 @@ namespace Yi.Framework.Service
}
return false;
}
public async Task<List<UserEntity>> GetListInRole()
{
return await _repository._Db.Queryable<UserEntity>().Includes(u => u.Roles).ToListAsync();
}
}
}

View File

@@ -62,16 +62,16 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
}, Array.Empty<string>() }
});
c.AddServer(new OpenApiServer()
{
Url = "https://ccnetcore.com",
Description = "Yi-Framework"
});
c.CustomOperationIds(apiDesc =>
{
var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
return controllerAction.ActionName;
});
//c.AddServer(new OpenApiServer()
//{
// Url = "https://ccnetcore.com",
// Description = "Yi-Framework"
//});
//c.CustomOperationIds(apiDesc =>
//{
// var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
// return controllerAction.ActionName;
//});
});
#endregion
@@ -85,27 +85,12 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
app.UseSwagger();
app.UseKnife4UI(c =>
{
c.RoutePrefix = "swagger"; // serve the UI at root
if (swaggerModels.Length == 0)
{
c.SwaggerEndpoint("/v1/swagger.json", "Yi.Framework");
}
else
{
foreach (var k in swaggerModels)
{
c.SwaggerEndpoint(k.url, k.name);
}
}
});
//app.UseSwaggerUI(c =>
//app.UseKnife4UI(c =>
//{
// c.RoutePrefix = "swagger"; // serve the UI at root
// if (swaggerModels.Length == 0)
// {
// c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework");
// c.SwaggerEndpoint("/v1/swagger.json", "Yi.Framework");
// }
// else
// {
@@ -114,10 +99,25 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
// c.SwaggerEndpoint(k.url, k.name);
// }
// }
//});
//}
app.UseSwaggerUI(c =>
{
if (swaggerModels.Length == 0)
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework");
}
else
{
foreach (var k in swaggerModels)
{
c.SwaggerEndpoint(k.url, k.name);
}
}
//);
}
);
}
}