mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-02 15:50:54 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3871a7de84 | ||
|
|
c6931e3492 | ||
|
|
c8b2a38c99 | ||
|
|
a7bdcd8dd8 | ||
|
|
8196cd597a | ||
|
|
52deb6bb79 |
@@ -20,7 +20,7 @@ Yi框架-一套与SqlSugar一样爽的.Net6低代码开源框架。
|
||||
适合.Net6学习、Sqlsugar学习 、项目二次开发。
|
||||
集大成者,终究轮子
|
||||
|
||||
Yi框架最新版本标签:`v1.0.3` 更新时间:2022/4/18
|
||||
Yi框架最新版本标签:`v1.0.3`
|
||||
|
||||
(项目与Sqlsugar同步更新,但这作者老杰哥代码天天爆肝到凌晨两点,我们也尽量会跟上他的脚步。更新频繁,所以可watching持续关注。)
|
||||
|
||||
@@ -126,6 +126,7 @@ WebFirst开发:所有代码生成器已经配置完成,无需任何操作数
|
||||
- [x] 支持`单表多租户`常用功能
|
||||
- [x] 支持`逻辑删除`常用功能
|
||||
- [x] 支持`操作日志`常用功能
|
||||
- [x] 支持`自动分表`
|
||||
- [x] 支持 太多了忘了
|
||||
|
||||
****
|
||||
|
||||
Binary file not shown.
@@ -51,6 +51,18 @@
|
||||
<param name="ids"></param>
|
||||
<returns></returns>
|
||||
</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">
|
||||
<summary>
|
||||
仓储上下文对象测试
|
||||
@@ -95,7 +107,7 @@
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.JobTest">
|
||||
<summary>
|
||||
启动一个定时任务,每5秒访问一次百度
|
||||
启动一个定时任务
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -10,5 +10,7 @@ namespace Yi.Framework.Common.IOCOptions
|
||||
{
|
||||
public string Url { 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)
|
||||
{
|
||||
_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);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NEST" Version="7.16.0" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.0.7.2" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.0.7.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
{
|
||||
public static void AddSqlsugarServer(this IServiceCollection services)
|
||||
{
|
||||
|
||||
|
||||
|
||||
DbType dbType;
|
||||
var slavaConFig = new List<SlaveConnectionConfig>();
|
||||
if (Appsettings.appBool("MutiDB_Enabled"))
|
||||
@@ -42,7 +45,19 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
DisableNvarchar = true
|
||||
},
|
||||
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 =>
|
||||
{
|
||||
@@ -80,6 +95,10 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
|
||||
Console.WriteLine("_______________________________________________");
|
||||
Console.WriteLine("执行SQL:"+s.ToString());
|
||||
foreach (var i in p)
|
||||
{
|
||||
Console.WriteLine("参数:" +i.ParameterName+",参数值"+i.Value);
|
||||
}
|
||||
Console.WriteLine("_______________________________________________");
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user