mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-19 16:06:36 +08:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3871a7de84 | ||
|
|
c6931e3492 | ||
|
|
c8b2a38c99 | ||
|
|
a7bdcd8dd8 | ||
|
|
8196cd597a | ||
|
|
52deb6bb79 | ||
|
|
1a22aa0bfb | ||
|
|
d18e5eec99 | ||
|
|
0fcf172192 | ||
|
|
88b968e826 | ||
|
|
f15d99e168 | ||
|
|
bbeea2cf62 | ||
|
|
65ac020d72 | ||
|
|
3ed42384af | ||
|
|
d780529313 |
@@ -20,7 +20,12 @@ Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
|
|||||||
适合.Net6学习、Sqlsugar学习 、项目二次开发。
|
适合.Net6学习、Sqlsugar学习 、项目二次开发。
|
||||||
集大成者,终究轮子
|
集大成者,终究轮子
|
||||||
|
|
||||||
|
Yi框架最新版本标签:`v1.0.3`
|
||||||
|
|
||||||
|
(项目与Sqlsugar同步更新,但这作者老杰哥代码天天爆肝到凌晨两点,我们也尽量会跟上他的脚步。更新频繁,所以可watching持续关注。)
|
||||||
|
|
||||||
————这不仅仅是一个程序,更是一个艺术品,面向艺术的开发!
|
————这不仅仅是一个程序,更是一个艺术品,面向艺术的开发!
|
||||||
|
|
||||||
**分支**:
|
**分支**:
|
||||||
|
|
||||||
(本项目由EFCore版本历经3年不断迭代至Sqlsugar版本,现EFcore版本已弃用,目前sqlsugar不带任何业务,之后会更新业务功能)
|
(本项目由EFCore版本历经3年不断迭代至Sqlsugar版本,现EFcore版本已弃用,目前sqlsugar不带任何业务,之后会更新业务功能)
|
||||||
@@ -121,6 +126,7 @@ WebFirst开发:所有代码生成器已经配置完成,无需任何操作数
|
|||||||
- [x] 支持`单表多租户`常用功能
|
- [x] 支持`单表多租户`常用功能
|
||||||
- [x] 支持`逻辑删除`常用功能
|
- [x] 支持`逻辑删除`常用功能
|
||||||
- [x] 支持`操作日志`常用功能
|
- [x] 支持`操作日志`常用功能
|
||||||
|
- [x] 支持`自动分表`
|
||||||
- [x] 支持 太多了忘了
|
- [x] 支持 太多了忘了
|
||||||
|
|
||||||
****
|
****
|
||||||
|
|||||||
Binary file not shown.
@@ -51,12 +51,30 @@
|
|||||||
<param name="ids"></param>
|
<param name="ids"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.LogController.Add">
|
||||||
|
<summary>
|
||||||
|
自动分表,日志添加
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.LogController.GetList">
|
||||||
|
<summary>
|
||||||
|
查询近20年与21年的日志表
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.DbTest">
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.DbTest">
|
||||||
<summary>
|
<summary>
|
||||||
仓储上下文对象测试
|
仓储上下文对象测试
|
||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.SqlTest">
|
||||||
|
<summary>
|
||||||
|
执行Sql返回
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.LocalTest">
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.LocalTest">
|
||||||
<summary>
|
<summary>
|
||||||
国际化测试
|
国际化测试
|
||||||
@@ -69,7 +87,7 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.AutnTest">
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.AuthTest">
|
||||||
<summary>
|
<summary>
|
||||||
策略授权测试
|
策略授权测试
|
||||||
</summary>
|
</summary>
|
||||||
@@ -81,5 +99,23 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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>
|
||||||
|
启动一个定时任务
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.stopJob">
|
||||||
|
<summary>
|
||||||
|
停止任务
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
|||||||
@@ -15,12 +15,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]/[action]")]
|
|
||||||
public class BaseCrudController<T> : ControllerBase where T : BaseModelEntity,new()
|
public class BaseCrudController<T> : ControllerBase where T : BaseModelEntity,new()
|
||||||
{
|
{
|
||||||
public readonly ILogger<T> _logger;
|
private readonly ILogger<T> _logger;
|
||||||
public IBaseService<T> _baseService;
|
private IBaseService<T> _baseService;
|
||||||
public IRepository<T> _repository;
|
private IRepository<T> _repository;
|
||||||
public BaseCrudController(ILogger<T> logger, IBaseService<T> iBaseService)
|
public BaseCrudController(ILogger<T> logger, IBaseService<T> iBaseService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
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 LogController : ControllerBase
|
||||||
|
{
|
||||||
|
private ILogService _iLogService;
|
||||||
|
//大量日志,将采用自动分表形式,默认1年分一次表
|
||||||
|
public LogController(ILogger<LogEntity> logger, ILogService iLogService)
|
||||||
|
{
|
||||||
|
_iLogService = iLogService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自动分表,日志添加
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<Result> Add()
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
var logList = new List<LogEntity>() {
|
||||||
|
new LogEntity() { LogCreateTime = Convert.ToDateTime("2019-12-1"), Message = "jack"+random.Next() } ,
|
||||||
|
new LogEntity() { LogCreateTime = Convert.ToDateTime("2022-02-1"), Message = "jack"+random.Next() },
|
||||||
|
new LogEntity() { LogCreateTime = Convert.ToDateTime("2020-02-1"), Message = "jack"+random.Next() },
|
||||||
|
new LogEntity() { LogCreateTime = Convert.ToDateTime("2021-12-1"), Message = "jack"+random.Next() } };
|
||||||
|
return Result.Success().SetData(await _iLogService.AddListTest(logList));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询近20年与21年的日志表
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<Result> GetList()
|
||||||
|
{
|
||||||
|
return Result.Success().SetData(await _iLogService.GetListTest());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,9 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Common.Const;
|
||||||
using Yi.Framework.Common.Models;
|
using Yi.Framework.Common.Models;
|
||||||
|
using Yi.Framework.Core;
|
||||||
using Yi.Framework.Interface;
|
using Yi.Framework.Interface;
|
||||||
using Yi.Framework.Language;
|
using Yi.Framework.Language;
|
||||||
using Yi.Framework.Model.Models;
|
using Yi.Framework.Model.Models;
|
||||||
@@ -23,11 +25,15 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
{
|
{
|
||||||
private IStringLocalizer<LocalLanguage> _local;
|
private IStringLocalizer<LocalLanguage> _local;
|
||||||
private IUserService _iUserService;
|
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;
|
_local = local;
|
||||||
_iUserService = iUserService;
|
_iUserService = iUserService;
|
||||||
|
_iRoleService = iRoleService;
|
||||||
|
_quartzInvoker = quartzInvoker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -36,30 +42,41 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
// 特点:化繁为简!意框架仓储代理上下文对象,用起来就是爽,但最好按规范来爽!
|
// 特点:化繁为简!意框架仓储代理上下文对象,用起来就是爽,但最好按规范来爽!
|
||||||
// 规范:控制器建议不要使用切换仓储方法,控制器严禁使用DB上下文对象,其它怎么爽怎么来!
|
// 规范:控制器不建议使用切换仓储方法、控制器严禁使用DB上下文对象,其它怎么爽怎么来!
|
||||||
public async Task<Result> DbTest()
|
public async Task<Result> DbTest()
|
||||||
{
|
{
|
||||||
//非常好,使用UserService的特有方法
|
//非常好,使用UserService的特有方法
|
||||||
await _iUserService.DbTest();
|
await _iUserService.DbTest();
|
||||||
|
|
||||||
//非常好,依赖注入使用其他Service的特有方法(就tm一张表,自己注入自己)
|
//非常好,依赖注入使用其他Service的特有方法
|
||||||
await _iUserService.DbTest();
|
await _iRoleService.DbTest();
|
||||||
|
|
||||||
//很核理,使用仓储的通用方法
|
//很核理,使用仓储的通用方法
|
||||||
await _iUserService._repository.GetListAsync();
|
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();
|
await _iUserService._repository._Db.Queryable<UserEntity>().ToListAsync();
|
||||||
|
|
||||||
return Result.Success().SetData(await _iUserService.DbTest());
|
return Result.Success().SetData(await _iUserService.DbTest());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行Sql返回
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
//简单语句不推荐!
|
||||||
|
public async Task<Result> SqlTest()
|
||||||
|
{
|
||||||
|
return Result.Success().SetData(await _iUserService._repository.UseSqlAsync<UserEntity>("select * from User"));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 国际化测试
|
/// 国际化测试
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -88,7 +105,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Authorize(PolicyName.Sid)]
|
[Authorize(PolicyName.Sid)]
|
||||||
public Result AutnTest()
|
public Result AuthTest()
|
||||||
{
|
{
|
||||||
return Result.Success();
|
return Result.Success();
|
||||||
}
|
}
|
||||||
@@ -121,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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -10,5 +10,7 @@ namespace Yi.Framework.Common.IOCOptions
|
|||||||
{
|
{
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
public string IndexName { get; set; }
|
public string IndexName { get; set; }
|
||||||
|
public string UserName { get; set; }
|
||||||
|
public string PassWord { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Yi.Framework.Core
|
|||||||
public ElasticSearchInvoker(IOptionsMonitor<ElasticSearchOptions> optionsMonitor)
|
public ElasticSearchInvoker(IOptionsMonitor<ElasticSearchOptions> optionsMonitor)
|
||||||
{
|
{
|
||||||
_elasticSearchOptions = optionsMonitor.CurrentValue;
|
_elasticSearchOptions = optionsMonitor.CurrentValue;
|
||||||
var settings = new ConnectionSettings(new Uri(_elasticSearchOptions.Url)).DefaultIndex(this._elasticSearchOptions.IndexName);
|
var settings = new ConnectionSettings(new Uri(_elasticSearchOptions.Url)).DefaultIndex(this._elasticSearchOptions.IndexName).BasicAuthentication(this._elasticSearchOptions.UserName, this._elasticSearchOptions.PassWord); ;
|
||||||
Client = new ElasticClient(settings);
|
Client = new ElasticClient(settings);
|
||||||
}
|
}
|
||||||
private ElasticClient Client;
|
private ElasticClient Client;
|
||||||
|
|||||||
13
Yi.Framework.Net6/Yi.Framework.Interface/ILogService.cs
Normal file
13
Yi.Framework.Net6/Yi.Framework.Interface/ILogService.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Model.Models;
|
||||||
|
using Yi.Framework.Repository;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Interface
|
||||||
|
{
|
||||||
|
public partial interface ILogService
|
||||||
|
{
|
||||||
|
Task<List<long>> AddListTest(List<LogEntity> logEntities);
|
||||||
|
Task<List<LogEntity>> GetListTest();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
Normal file
16
Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Model.Models;
|
||||||
|
using Yi.Framework.Repository;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Interface
|
||||||
|
{
|
||||||
|
public partial interface ILogService : IBaseService<LogEntity>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using Yi.Framework.Model.Models;
|
||||||
|
using Yi.Framework.Repository;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Interface
|
||||||
|
{
|
||||||
|
public partial interface IRoleService:IBaseService<RoleEntity>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using Yi.Framework.Model.Models;
|
||||||
|
using Yi.Framework.Repository;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Interface
|
||||||
|
{
|
||||||
|
public partial interface IUserRoleService:IBaseService<UserRoleEntity>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,5 +30,12 @@ namespace Yi.Framework.Interface
|
|||||||
/// <param name="userAction"></param>
|
/// <param name="userAction"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<bool> Register(UserEntity userEntity, Action<UserEntity> userAction = null);
|
public Task<bool> Register(UserEntity userEntity, Action<UserEntity> userAction = null);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导航属性关联角色
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task<List<UserEntity>> GetListInRole();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
Yi.Framework.Net6/Yi.Framework.Model/LogEntity.cs
Normal file
17
Yi.Framework.Net6/Yi.Framework.Model/LogEntity.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using SqlSugar;
|
||||||
|
namespace Yi.Framework.Model.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 日志表
|
||||||
|
///</summary>
|
||||||
|
[SplitTable(SplitType.Year)]
|
||||||
|
[SugarTable("SplitLog_{year}{month}{day}")]
|
||||||
|
public partial class LogEntity
|
||||||
|
{
|
||||||
|
[SplitField] //分表字段 在插入的时候会根据这个字段插入哪个表,在更新删除的时候用这个字段找出相关表
|
||||||
|
public DateTime? LogCreateTime { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
23
Yi.Framework.Net6/Yi.Framework.Model/Models/LogEntity.cs
Normal file
23
Yi.Framework.Net6/Yi.Framework.Model/Models/LogEntity.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using SqlSugar;
|
||||||
|
namespace Yi.Framework.Model.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 日志表
|
||||||
|
///</summary>
|
||||||
|
public partial class LogEntity:BaseModelEntity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 租户Id
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnName="TenantId" )]
|
||||||
|
public long? TenantId { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 日志信息
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnName="Message" )]
|
||||||
|
public string Message { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
24
Yi.Framework.Net6/Yi.Framework.Model/Models/RoleEntity.cs
Normal file
24
Yi.Framework.Net6/Yi.Framework.Model/Models/RoleEntity.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs
Normal file
15
Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="NEST" Version="7.16.0" />
|
<PackageReference Include="NEST" Version="7.16.0" />
|
||||||
<PackageReference Include="SqlSugarCore" Version="5.0.6.5" />
|
<PackageReference Include="SqlSugarCore" Version="5.0.7.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -21,5 +21,8 @@ namespace Yi.Framework.Repository
|
|||||||
public Task<List<T>> GetListAsync(QueryCondition pars);
|
public Task<List<T>> GetListAsync(QueryCondition pars);
|
||||||
public Task<bool> DeleteByLogicAsync(List<long> ids);
|
public Task<bool> DeleteByLogicAsync(List<long> ids);
|
||||||
public Task<bool> UpdateIgnoreNullAsync(T entity);
|
public Task<bool> UpdateIgnoreNullAsync(T entity);
|
||||||
|
public Task<List<S>> UseSqlAsync<S>(string sql);
|
||||||
|
public Task<bool> UseSqlAsync(string sql);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,29 @@ namespace Yi.Framework.Repository
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行查询sql返回dto列表
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="S"></typeparam>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<S>> UseSqlAsync<S>(string sql)
|
||||||
|
{
|
||||||
|
return await Db.Ado.SqlQueryAsync<S>(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行增删改sql返回状态
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> UseSqlAsync(string sql)
|
||||||
|
{
|
||||||
|
return await Db.Ado.ExecuteCommandAsync(sql)>0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 添加返回实体
|
/// 添加返回实体
|
||||||
|
|||||||
23
Yi.Framework.Net6/Yi.Framework.Service/LogService.cs
Normal file
23
Yi.Framework.Net6/Yi.Framework.Service/LogService.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Interface;
|
||||||
|
using Yi.Framework.Model.Models;
|
||||||
|
using Yi.Framework.Repository;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Service
|
||||||
|
{
|
||||||
|
public partial class LogService
|
||||||
|
{
|
||||||
|
public async Task<List<long>> AddListTest(List<LogEntity> logEntities)
|
||||||
|
{
|
||||||
|
return await _repository._Db.Insertable(logEntities).SplitTable().ExecuteReturnSnowflakeIdListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<LogEntity>> GetListTest()
|
||||||
|
{
|
||||||
|
return await _repository._Db.Queryable<LogEntity>().SplitTable(tas => tas.Where(u => u.TableName.Contains("2020") || u.TableName.Contains("2021"))).ToListAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
Normal file
17
Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 LogService : BaseService<LogEntity>, ILogService
|
||||||
|
{
|
||||||
|
public LogService(IRepository<LogEntity> repository) : base(repository)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,5 +65,11 @@ namespace Yi.Framework.Service
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<UserEntity>> GetListInRole()
|
||||||
|
{
|
||||||
|
return await _repository._Db.Queryable<UserEntity>().Includes(u => u.Roles).ToListAsync();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
|||||||
{
|
{
|
||||||
public static void AddSqlsugarServer(this IServiceCollection services)
|
public static void AddSqlsugarServer(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbType dbType;
|
DbType dbType;
|
||||||
var slavaConFig = new List<SlaveConnectionConfig>();
|
var slavaConFig = new List<SlaveConnectionConfig>();
|
||||||
if (Appsettings.appBool("MutiDB_Enabled"))
|
if (Appsettings.appBool("MutiDB_Enabled"))
|
||||||
@@ -42,7 +45,19 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
|||||||
DisableNvarchar = true
|
DisableNvarchar = true
|
||||||
},
|
},
|
||||||
SlaveConnectionConfigs = slavaConFig,
|
SlaveConnectionConfigs = slavaConFig,
|
||||||
|
//设置codefirst非空值判断
|
||||||
|
ConfigureExternalServices = new ConfigureExternalServices
|
||||||
|
{
|
||||||
|
EntityService = (c, p) =>
|
||||||
|
{
|
||||||
|
// int? decimal?这种 isnullable=true
|
||||||
|
if (c.PropertyType.IsGenericType &&
|
||||||
|
c.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||||
|
{
|
||||||
|
p.IsNullable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
db =>
|
db =>
|
||||||
{
|
{
|
||||||
@@ -80,6 +95,10 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
|||||||
|
|
||||||
Console.WriteLine("_______________________________________________");
|
Console.WriteLine("_______________________________________________");
|
||||||
Console.WriteLine("执行SQL:"+s.ToString());
|
Console.WriteLine("执行SQL:"+s.ToString());
|
||||||
|
foreach (var i in p)
|
||||||
|
{
|
||||||
|
Console.WriteLine("参数:" +i.ParameterName+",参数值"+i.Value);
|
||||||
|
}
|
||||||
Console.WriteLine("_______________________________________________");
|
Console.WriteLine("_______________________________________________");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -62,16 +62,16 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
|||||||
}, Array.Empty<string>() }
|
}, Array.Empty<string>() }
|
||||||
});
|
});
|
||||||
|
|
||||||
c.AddServer(new OpenApiServer()
|
//c.AddServer(new OpenApiServer()
|
||||||
{
|
//{
|
||||||
Url = "https://ccnetcore.com",
|
// Url = "https://ccnetcore.com",
|
||||||
Description = "Yi-Framework"
|
// Description = "Yi-Framework"
|
||||||
});
|
//});
|
||||||
c.CustomOperationIds(apiDesc =>
|
//c.CustomOperationIds(apiDesc =>
|
||||||
{
|
//{
|
||||||
var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
|
// var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
|
||||||
return controllerAction.ActionName;
|
// return controllerAction.ActionName;
|
||||||
});
|
//});
|
||||||
});
|
});
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -85,27 +85,12 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
|
|
||||||
|
|
||||||
app.UseKnife4UI(c =>
|
//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 =>
|
|
||||||
//{
|
//{
|
||||||
|
// c.RoutePrefix = "swagger"; // serve the UI at root
|
||||||
// if (swaggerModels.Length == 0)
|
// if (swaggerModels.Length == 0)
|
||||||
// {
|
// {
|
||||||
// c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework");
|
// c.SwaggerEndpoint("/v1/swagger.json", "Yi.Framework");
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
@@ -114,10 +99,25 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
|||||||
// c.SwaggerEndpoint(k.url, k.name);
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//);
|
}
|
||||||
|
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user